Skip to content

Commit 3e2eaf4

Browse files
committed
Remove unneeded calls to SQLiteDatabase.close
The SQLiteOpenHelper is always closed in a finally block and closing the database is handled there.
1 parent c546afc commit 3e2eaf4

File tree

1 file changed

+14
-22
lines changed

1 file changed

+14
-22
lines changed

‎app/src/main/java/com/github/mobile/persistence/DatabaseCache.java‎

Lines changed: 14 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -126,16 +126,12 @@ private <E> List<E> requestAndStore(final SQLiteOpenHelper helper,
126126
if (db == null)
127127
returnitems;
128128

129+
db.beginTransaction();
129130
try{
130-
db.beginTransaction();
131-
try{
132-
persistableResource.store(db, items);
133-
db.setTransactionSuccessful();
134-
} finally{
135-
db.endTransaction();
136-
}
131+
persistableResource.store(db, items);
132+
db.setTransactionSuccessful();
137133
} finally{
138-
db.close();
134+
db.endTransaction();
139135
}
140136
returnitems;
141137
}
@@ -146,22 +142,18 @@ private <E> List<E> loadFromDB(final SQLiteOpenHelper helper,
146142
if (db == null)
147143
returnnull;
148144

145+
Cursorcursor = persistableResource.getCursor(db);
149146
try{
150-
Cursorcursor = persistableResource.getCursor(db);
151-
try{
152-
if (!cursor.moveToFirst())
153-
returnnull;
154-
155-
List<E> cached = newArrayList<E>();
156-
do{
157-
cached.add(persistableResource.loadFrom(cursor));
158-
} while (cursor.moveToNext());
159-
returncached;
160-
} finally{
161-
cursor.close();
162-
}
147+
if (!cursor.moveToFirst())
148+
returnnull;
149+
150+
List<E> cached = newArrayList<E>();
151+
do{
152+
cached.add(persistableResource.loadFrom(cursor));
153+
} while (cursor.moveToNext());
154+
returncached;
163155
} finally{
164-
db.close();
156+
cursor.close();
165157
}
166158
}
167159

0 commit comments

Comments
(0)