Skip to content

Commit

Permalink
Remove unneeded calls to SQLiteDatabase.close
Browse files Browse the repository at this point in the history
The SQLiteOpenHelper is always closed in a finally
block and closing the database is handled there.
  • Loading branch information
kevinsawicki committed Jul 11, 2012
1 parent c546afc commit 3e2eaf4
Showing 1 changed file with 14 additions and 22 deletions.
36 changes: 14 additions & 22 deletions app/src/main/java/com/github/mobile/persistence/DatabaseCache.java
Original file line number Diff line number Diff line change
Expand Up @@ -126,16 +126,12 @@ private <E> List<E> requestAndStore(final 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;
}
Expand All @@ -146,22 +142,18 @@ private <E> List<E> loadFromDB(final 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();
}
}

Expand Down

0 comments on commit 3e2eaf4

Please sign in to comment.