File tree Expand file tree Collapse file tree 2 files changed +30
-1
lines changed Expand file tree Collapse file tree 2 files changed +30
-1
lines changed Original file line number Diff line number Diff line change 2020import android .database .sqlite .SQLiteDatabase ;
2121
2222import com .activeandroid .util .Log ;
23+ import android .os .Build ;
2324
2425public final class ActiveAndroid {
2526 //////////////////////////////////////////////////////////////////////////////////////
@@ -60,8 +61,16 @@ public static SQLiteDatabase getDatabase() {
6061 return Cache .openDatabase ();
6162 }
6263
64+ /**
65+ * Non-exclusive transactions allows BEGIN IMMEDIATE
66+ * blocks, allowing better read concurrency.
67+ */
6368 public static void beginTransaction () {
64- Cache .openDatabase ().beginTransaction ();
69+ if (Build .VERSION .SDK_INT < Build .VERSION_CODES .HONEYCOMB ) {
70+ Cache .openDatabase ().beginTransaction ();
71+ } else {
72+ Cache .openDatabase ().beginTransactionNonExclusive ();
73+ }
6574 }
6675
6776 public static void endTransaction () {
Original file line number Diff line number Diff line change 3737import com .activeandroid .util .NaturalOrderComparator ;
3838import com .activeandroid .util .SQLiteUtils ;
3939import com .activeandroid .util .SqlParser ;
40+ import android .os .Build ;
4041
4142public final class DatabaseHelper extends SQLiteOpenHelper {
4243 //////////////////////////////////////////////////////////////////////////////////////
@@ -65,6 +66,25 @@ public DatabaseHelper(Configuration configuration) {
6566 // OVERRIDEN METHODS
6667 //////////////////////////////////////////////////////////////////////////////////////
6768
69+ /**
70+ * onConfigure is called when the db connection
71+ * is being configured. It's the right place
72+ * to enable write-ahead logging or foreign
73+ * key support.
74+ *
75+ * Available for API level 16 (JellyBean) and above.
76+ */
77+ @ Override
78+ public void onConfigure (SQLiteDatabase db ) {
79+ if (Build .VERSION .SDK_INT >= Build .VERSION_CODES .HONEYCOMB ) {
80+ db .enableWriteAheadLogging ();
81+ }
82+ if (Build .VERSION .SDK_INT >= Build .VERSION_CODES .JELLY_BEAN ) {
83+ db .setForeignKeyConstraintsEnabled (true );
84+ }
85+ executePragmas (db );
86+ }
87+
6888 @ Override
6989 public void onOpen (SQLiteDatabase db ) {
7090 executePragmas (db );
You can’t perform that action at this time.
0 commit comments