diff --git a/src/com/activeandroid/ActiveAndroid.java b/src/com/activeandroid/ActiveAndroid.java index c58c8efd8..f7d9b3e07 100644 --- a/src/com/activeandroid/ActiveAndroid.java +++ b/src/com/activeandroid/ActiveAndroid.java @@ -60,8 +60,16 @@ public static SQLiteDatabase getDatabase() { return Cache.openDatabase(); } + /** + * Non-exclusive transactions allows BEGIN IMMEDIATE + * blocks, allowing better read concurrency. + */ public static void beginTransaction() { - Cache.openDatabase().beginTransaction(); + if (Build.VERSION.SDK_INT < Build.VERSION_CODES.HONEYCOMB) { + Cache.openDatabase().beginTransaction(); + } else { + Cache.openDatabase().beginTransactionNonExclusive(); + } } public static void endTransaction() { diff --git a/src/com/activeandroid/DatabaseHelper.java b/src/com/activeandroid/DatabaseHelper.java index 7158c5bb6..4c864d810 100644 --- a/src/com/activeandroid/DatabaseHelper.java +++ b/src/com/activeandroid/DatabaseHelper.java @@ -65,6 +65,25 @@ public DatabaseHelper(Configuration configuration) { // OVERRIDEN METHODS ////////////////////////////////////////////////////////////////////////////////////// + /** + * onConfigure is called when the db connection + * is being configured. It's the right place + * to enable write-ahead logging or foreign + * key support. + * + * Available for API level 16 (JellyBean) and above. + */ + @Override + public void onConfigure(SQLiteDatabase db) { + if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB) { + db.enableWriteAheadLogging(); + } + if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) { + db.setForeignKeyConstraintsEnabled(true); + } + executePragmas(db); + } + @Override public void onOpen(SQLiteDatabase db) { executePragmas(db);