Skip to content

Commit

Permalink
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 1 deletion.
10 changes: 9 additions & 1 deletion src/com/activeandroid/ActiveAndroid.java
Original file line number Diff line number Diff line change
Expand Up @@ -60,8 +60,16 @@ public static SQLiteDatabase getDatabase() {
return Cache.openDatabase();
}

/**
* Non-exclusive transactions allows BEGIN IMMEDIATE
* blocks, allowing better read concurrency.
*/
public static void beginTransaction() {
Cache.openDatabase().beginTransaction();
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.HONEYCOMB) {
Cache.openDatabase().beginTransaction();
} else {
Cache.openDatabase().beginTransactionNonExclusive();
}
}

public static void endTransaction() {
Expand Down
19 changes: 19 additions & 0 deletions src/com/activeandroid/DatabaseHelper.java
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,25 @@ public DatabaseHelper(Configuration configuration) {
// OVERRIDEN METHODS
//////////////////////////////////////////////////////////////////////////////////////

/**
* onConfigure is called when the db connection
* is being configured. It's the right place
* to enable write-ahead logging or foreign
* key support.
*
* Available for API level 16 (JellyBean) and above.
*/
@Override
public void onConfigure(SQLiteDatabase db) {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB) {
db.enableWriteAheadLogging();
}
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) {
db.setForeignKeyConstraintsEnabled(true);
}
executePragmas(db);
}

@Override
public void onOpen(SQLiteDatabase db) {
executePragmas(db);
Expand Down

0 comments on commit d618190

Please sign in to comment.