Skip to content
This repository was archived by the owner on Jun 27, 2020. It is now read-only.
Next Next commit
Remove db.close() to speed up DB requests.
  • Loading branch information
Evgenii Kanivets committed Apr 26, 2016
commit 86ae9e2689085d91b7343634b119b2eb626de18f
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@

/**
* Base implementation of {@link IRepo}.
* No need to call db.close() at all, because SQLiteOpenHelper manage it for us + cache instances.
* It will speed up all DB operations.
* Created on 2/15/16.
*
* @author Evgenii Kanivets
Expand Down Expand Up @@ -43,8 +45,6 @@ public T create(@Nullable T instance) {

long id = db.insert(getTable(), null, contentValues(instance));

db.close();

if (id == -1) {
Log.d(TAG, "Couldn't create record : " + instance);
return null;
Expand Down Expand Up @@ -74,8 +74,6 @@ public T update(@Nullable T instance) {
String[] args = new String[]{Long.valueOf(instance.getId()).toString()};
long rowsAffected = db.update(getTable(), contentValues(instance), "id=?", args);

db.close();

if (rowsAffected == 0) {
Log.d(TAG, "Couldn't update record : " + instance);
return null;
Expand All @@ -101,8 +99,6 @@ public boolean delete(@Nullable T instance) {
String[] args = new String[]{Long.toString(instance.getId())};
long rowsAffected = db.delete(getTable(), "id=?", args);

db.close();

Log.d(TAG, instance + (rowsAffected == 0 ? " didn't " : " ") + "deleted");

return rowsAffected != 0;
Expand All @@ -118,7 +114,6 @@ public List<T> readWithCondition(@Nullable String condition, @Nullable String[]
List<T> recordList = getListFromCursor(cursor);

cursor.close();
db.close();

return recordList;
}
Expand Down