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() {
6060 return Cache .openDatabase ();
6161 }
6262
63+ /**
64+ * Non-exclusive transactions allows BEGIN IMMEDIATE
65+ * blocks, allowing better read concurrency.
66+ */
6367 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+ }
6573 }
6674
6775 public static void endTransaction () {
Original file line number Diff line number Diff line change @@ -65,6 +65,25 @@ public DatabaseHelper(Configuration configuration) {
6565 // OVERRIDEN METHODS
6666 //////////////////////////////////////////////////////////////////////////////////////
6767
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+
6887 @ Override
6988 public void onOpen (SQLiteDatabase db ) {
7089 executePragmas (db );
You can’t perform that action at this time.
0 commit comments