Permalink
Browse files

Remove unneeded calls to SQLiteDatabase.close

The SQLiteOpenHelper is always closed in a finally
block and closing the database is handled there.
  • Loading branch information...
1 parent c546afc commit 3e2eaf402df39a78e1a96ebbcb5834d1d1cbab81 @kevinsawicki kevinsawicki committed Jul 11, 2012
Showing with 14 additions and 22 deletions.
  1. +14 −22 app/src/main/java/com/github/mobile/persistence/DatabaseCache.java
@@ -126,16 +126,12 @@ protected SQLiteDatabase getReadable(SQLiteOpenHelper helper) {
if (db == null)
return items;
+ db.beginTransaction();
try {
- db.beginTransaction();
- try {
- persistableResource.store(db, items);
- db.setTransactionSuccessful();
- } finally {
- db.endTransaction();
- }
+ persistableResource.store(db, items);
+ db.setTransactionSuccessful();
} finally {
- db.close();
+ db.endTransaction();
}
return items;
}
@@ -146,22 +142,18 @@ protected SQLiteDatabase getReadable(SQLiteOpenHelper helper) {
if (db == null)
return null;
+ Cursor cursor = persistableResource.getCursor(db);
try {
- Cursor cursor = persistableResource.getCursor(db);
- try {
- if (!cursor.moveToFirst())
- return null;
-
- List<E> cached = new ArrayList<E>();
- do {
- cached.add(persistableResource.loadFrom(cursor));
- } while (cursor.moveToNext());
- return cached;
- } finally {
- cursor.close();
- }
+ if (!cursor.moveToFirst())
+ return null;
+
+ List<E> cached = new ArrayList<E>();
+ do {
+ cached.add(persistableResource.loadFrom(cursor));
+ } while (cursor.moveToNext());
+ return cached;
} finally {
- db.close();
+ cursor.close();
}
}

0 comments on commit 3e2eaf4

Please sign in to comment.