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 20
20
import android .database .sqlite .SQLiteDatabase ;
21
21
22
22
import com .activeandroid .util .Log ;
23
+ import android .os .Build ;
23
24
24
25
public final class ActiveAndroid {
25
26
//////////////////////////////////////////////////////////////////////////////////////
@@ -60,8 +61,16 @@ public static SQLiteDatabase getDatabase() {
60
61
return Cache .openDatabase ();
61
62
}
62
63
64
+ /**
65
+ * Non-exclusive transactions allows BEGIN IMMEDIATE
66
+ * blocks, allowing better read concurrency.
67
+ */
63
68
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
+ }
65
74
}
66
75
67
76
public static void endTransaction () {
Original file line number Diff line number Diff line change 37
37
import com .activeandroid .util .NaturalOrderComparator ;
38
38
import com .activeandroid .util .SQLiteUtils ;
39
39
import com .activeandroid .util .SqlParser ;
40
+ import android .os .Build ;
40
41
41
42
public final class DatabaseHelper extends SQLiteOpenHelper {
42
43
//////////////////////////////////////////////////////////////////////////////////////
@@ -65,6 +66,25 @@ public DatabaseHelper(Configuration configuration) {
65
66
// OVERRIDEN METHODS
66
67
//////////////////////////////////////////////////////////////////////////////////////
67
68
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
+
68
88
@ Override
69
89
public void onOpen (SQLiteDatabase db ) {
70
90
executePragmas (db );
You can’t perform that action at this time.
0 commit comments