File tree Expand file tree Collapse file tree 2 files changed +28
-1
lines changed Expand file tree Collapse file tree 2 files changed +28
-1
lines changed Original file line number Diff line number Diff line change @@ -60,8 +60,16 @@ public static SQLiteDatabase getDatabase() {
60
60
return Cache .openDatabase ();
61
61
}
62
62
63
+ /**
64
+ * Non-exclusive transactions allows BEGIN IMMEDIATE
65
+ * blocks, allowing better read concurrency.
66
+ */
63
67
public static void beginTransaction () {
64
- Cache .openDatabase ().beginTransaction ();
68
+ if (Build .VERSION .SDK_INT < Build .VERSION_CODES .HONEYCOMB ) {
69
+ Cache .openDatabase ().beginTransaction ();
70
+ } else {
71
+ Cache .openDatabase ().beginTransactionNonExclusive ();
72
+ }
65
73
}
66
74
67
75
public static void endTransaction () {
Original file line number Diff line number Diff line change @@ -65,6 +65,25 @@ public DatabaseHelper(Configuration configuration) {
65
65
// OVERRIDEN METHODS
66
66
//////////////////////////////////////////////////////////////////////////////////////
67
67
68
+ /**
69
+ * onConfigure is called when the db connection
70
+ * is being configured. It's the right place
71
+ * to enable write-ahead logging or foreign
72
+ * key support.
73
+ *
74
+ * Available for API level 16 (JellyBean) and above.
75
+ */
76
+ @ Override
77
+ public void onConfigure (SQLiteDatabase db ) {
78
+ if (Build .VERSION .SDK_INT >= Build .VERSION_CODES .HONEYCOMB ) {
79
+ db .enableWriteAheadLogging ();
80
+ }
81
+ if (Build .VERSION .SDK_INT >= Build .VERSION_CODES .JELLY_BEAN ) {
82
+ db .setForeignKeyConstraintsEnabled (true );
83
+ }
84
+ executePragmas (db );
85
+ }
86
+
68
87
@ Override
69
88
public void onOpen (SQLiteDatabase db ) {
70
89
executePragmas (db );
You can’t perform that action at this time.
0 commit comments