]> git.ktnx.net Git - mobile-ledger.git/blobdiff - app/src/main/java/net/ktnx/mobileledger/utils/MLDB.java
these constants may be private
[mobile-ledger.git] / app / src / main / java / net / ktnx / mobileledger / utils / MLDB.java
index a7e124d7735ce8d83049295eac380f172f7db391..582e73b437441b32cf4d7b3bfbbd0da40b2c7a15 100644 (file)
@@ -58,12 +58,11 @@ public final class MLDB {
         if (context == null)
             throw new IllegalStateException("First call init with a valid context");
     }
-    public static synchronized SQLiteDatabase getDatabase() {
+    public static SQLiteDatabase getDatabase() {
         checkState();
 
         SQLiteDatabase db;
 
-        if (dbHelper == null) dbHelper = new MobileLedgerDatabase(context);
         db = dbHelper.getWritableDatabase();
 
         db.execSQL("pragma case_sensitive_like=ON;");
@@ -196,20 +195,23 @@ public final class MLDB {
             });
         }
     }
-    public static void init(Application context) {
+    public static synchronized void init(Application context) {
         MLDB.context = context;
+        if (dbHelper != null) throw new IllegalStateException("It appears init() was already called");
+        dbHelper = new MobileLedgerDatabase(context);
     }
-    public static void done() {
+    public static synchronized void done() {
         if (dbHelper != null) {
             Log.d("db", "Closing DB helper");
             dbHelper.close();
+            dbHelper = null;
         }
     }
 }
 
 class MobileLedgerDatabase extends SQLiteOpenHelper implements AutoCloseable {
-    public static final String DB_NAME = "MoLe.db";
-    public static final int LATEST_REVISION = 20;
+    private static final String DB_NAME = "MoLe.db";
+    private static final int LATEST_REVISION = 20;
 
     private final Application mContext;