Messaging: Use try-with-resource
Change-Id: I6649517cbd990502dfcb54f078764cf05f210268
This commit is contained in:
@@ -466,23 +466,17 @@ public class ConversationListItemData {
|
||||
ConversationListItemData conversation = null;
|
||||
|
||||
// Look for an existing conversation in the db with this conversation id
|
||||
Cursor cursor = null;
|
||||
try {
|
||||
try (Cursor cursor = dbWrapper.query(getConversationListView(),
|
||||
PROJECTION,
|
||||
ConversationColumns._ID + "=?",
|
||||
new String[]{conversationId},
|
||||
null, null, null)) {
|
||||
// TODO: Should we be able to read a row from just the conversation table?
|
||||
cursor = dbWrapper.query(getConversationListView(),
|
||||
PROJECTION,
|
||||
ConversationColumns._ID + "=?",
|
||||
new String[] { conversationId },
|
||||
null, null, null);
|
||||
Assert.inRange(cursor.getCount(), 0, 1);
|
||||
if (cursor.moveToFirst()) {
|
||||
conversation = new ConversationListItemData();
|
||||
conversation.bind(cursor);
|
||||
}
|
||||
} finally {
|
||||
if (cursor != null) {
|
||||
cursor.close();
|
||||
}
|
||||
}
|
||||
|
||||
return conversation;
|
||||
|
||||
@@ -152,22 +152,16 @@ public class ParticipantData implements Parcelable {
|
||||
|
||||
public static ParticipantData getFromId(final DatabaseWrapper dbWrapper,
|
||||
final String participantId) {
|
||||
Cursor cursor = null;
|
||||
try {
|
||||
cursor = dbWrapper.query(DatabaseHelper.PARTICIPANTS_TABLE,
|
||||
ParticipantsQuery.PROJECTION,
|
||||
ParticipantColumns._ID + " =?",
|
||||
new String[] { participantId }, null, null, null);
|
||||
try (Cursor cursor = dbWrapper.query(DatabaseHelper.PARTICIPANTS_TABLE,
|
||||
ParticipantsQuery.PROJECTION,
|
||||
ParticipantColumns._ID + " =?",
|
||||
new String[]{participantId}, null, null, null)) {
|
||||
|
||||
if (cursor.moveToFirst()) {
|
||||
return ParticipantData.getFromCursor(cursor);
|
||||
} else {
|
||||
return null;
|
||||
}
|
||||
} finally {
|
||||
if (cursor != null) {
|
||||
cursor.close();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user