summaryrefslogtreecommitdiffstats
path: root/core
diff options
context:
space:
mode:
Diffstat (limited to 'core')
-rw-r--r--core/java/android/database/sqlite/SQLiteDatabase.java91
1 files changed, 44 insertions, 47 deletions
diff --git a/core/java/android/database/sqlite/SQLiteDatabase.java b/core/java/android/database/sqlite/SQLiteDatabase.java
index 891a5d9..2e43eef 100644
--- a/core/java/android/database/sqlite/SQLiteDatabase.java
+++ b/core/java/android/database/sqlite/SQLiteDatabase.java
@@ -2354,39 +2354,37 @@ public class SQLiteDatabase extends SQLiteClosable {
* @return true if write-ahead-logging is set. false otherwise
*/
public boolean enableWriteAheadLogging() {
- // turn off WAL until lockingprotocolerror bug and diskIO bug are fixed
- return false;
-// // make sure the database is not READONLY. WAL doesn't make sense for readonly-databases.
-// if (isReadOnly()) {
-// return false;
-// }
-// // acquire lock - no that no other thread is enabling WAL at the same time
-// lock();
-// try {
-// if (mConnectionPool != null) {
-// // already enabled
-// return true;
-// }
-// if (mPath.equalsIgnoreCase(MEMORY_DB_PATH)) {
-// Log.i(TAG, "can't enable WAL for memory databases.");
-// return false;
-// }
-//
-// // make sure this database has NO attached databases because sqlite's write-ahead-logging
-// // doesn't work for databases with attached databases
-// if (mHasAttachedDbs) {
-// if (Log.isLoggable(TAG, Log.DEBUG)) {
-// Log.d(TAG,
-// "this database: " + mPath + " has attached databases. can't enable WAL.");
-// }
-// return false;
-// }
-// mConnectionPool = new DatabaseConnectionPool(this);
-// setJournalMode(mPath, "WAL");
-// return true;
-// } finally {
-// unlock();
-// }
+ // make sure the database is not READONLY. WAL doesn't make sense for readonly-databases.
+ if (isReadOnly()) {
+ return false;
+ }
+ // acquire lock - no that no other thread is enabling WAL at the same time
+ lock();
+ try {
+ if (mConnectionPool != null) {
+ // already enabled
+ return true;
+ }
+ if (mPath.equalsIgnoreCase(MEMORY_DB_PATH)) {
+ Log.i(TAG, "can't enable WAL for memory databases.");
+ return false;
+ }
+
+ // make sure this database has NO attached databases because sqlite's write-ahead-logging
+ // doesn't work for databases with attached databases
+ if (mHasAttachedDbs) {
+ if (Log.isLoggable(TAG, Log.DEBUG)) {
+ Log.d(TAG,
+ "this database: " + mPath + " has attached databases. can't enable WAL.");
+ }
+ return false;
+ }
+ mConnectionPool = new DatabaseConnectionPool(this);
+ setJournalMode(mPath, "WAL");
+ return true;
+ } finally {
+ unlock();
+ }
}
/**
@@ -2394,20 +2392,19 @@ public class SQLiteDatabase extends SQLiteClosable {
* @hide
*/
public void disableWriteAheadLogging() {
- return;
-// // grab database lock so that writeAheadLogging is not disabled from 2 different threads
-// // at the same time
-// lock();
-// try {
-// if (mConnectionPool == null) {
-// return; // already disabled
-// }
-// mConnectionPool.close();
-// setJournalMode(mPath, "TRUNCATE");
-// mConnectionPool = null;
-// } finally {
-// unlock();
-// }
+ // grab database lock so that writeAheadLogging is not disabled from 2 different threads
+ // at the same time
+ lock();
+ try {
+ if (mConnectionPool == null) {
+ return; // already disabled
+ }
+ mConnectionPool.close();
+ setJournalMode(mPath, "TRUNCATE");
+ mConnectionPool = null;
+ } finally {
+ unlock();
+ }
}
/* package */ SQLiteDatabase getDatabaseHandle(String sql) {