Skip to content

Commit

Permalink
lock cache returns the db itself to be handle as try-with-resources
Browse files Browse the repository at this point in the history
  • Loading branch information
shubham1g5 committed Apr 9, 2024
1 parent 39e1a6a commit ca6a5d9
Showing 1 changed file with 4 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
import org.commcare.suite.model.DetailField;
import org.commcare.utils.SessionUnavailableException;

import java.io.Closeable;
import java.util.Collection;
import java.util.Hashtable;
import java.util.List;
Expand Down Expand Up @@ -72,18 +73,12 @@ public static void createIndexes(SQLiteDatabase db) {
db.execSQL(DatabaseIndexingUtils.indexOnTableCommand("NAME_ENTITY_KEY", TABLE_NAME, COL_CACHE_NAME + ", " + COL_ENTITY_KEY + ", " + COL_CACHE_KEY));
}

public boolean lockCache() {
public Closeable lockCache() {
//Get a db handle so we can get an outer lock
SQLiteDatabase db;
try {
db = CommCareApplication.instance().getUserDbHandle();
} catch (SessionUnavailableException e) {
return false;
}

SQLiteDatabase db = CommCareApplication.instance().getUserDbHandle();
//get the db lock
db.beginTransaction();
return true;
return db;
}

public void releaseCache() {
Expand Down

0 comments on commit ca6a5d9

Please sign in to comment.