Skip to content

File tree

2 files changed

+30
-1
lines changed

2 files changed

+30
-1
lines changed

src/com/activeandroid/ActiveAndroid.java

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
import android.database.sqlite.SQLiteDatabase;
2121

2222
import com.activeandroid.util.Log;
23+
import android.os.Build;
2324

2425
public 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() {

src/com/activeandroid/DatabaseHelper.java

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@
3737
import com.activeandroid.util.NaturalOrderComparator;
3838
import com.activeandroid.util.SQLiteUtils;
3939
import com.activeandroid.util.SqlParser;
40+
import android.os.Build;
4041

4142
public 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);

0 commit comments

Comments
 (0)