Loading core/java/android/database/sqlite/SQLiteConnection.java +51 −1 Original line number Diff line number Diff line Loading @@ -208,6 +208,11 @@ public final class SQLiteConnection implements CancellationSignal.OnCancelListen mConfiguration.label, SQLiteDebug.DEBUG_SQL_STATEMENTS, SQLiteDebug.DEBUG_SQL_TIME); setSyncMode(); setPageSize(); setAutoCheckpointInterval(); setJournalSizeLimit(); setJournalModeFromConfiguration(); setLocaleFromConfiguration(); } Loading @@ -231,6 +236,44 @@ public final class SQLiteConnection implements CancellationSignal.OnCancelListen } } private void setSyncMode() { if (!mConfiguration.isInMemoryDb()) { execute("PRAGMA synchronous=" + SQLiteGlobal.getSyncMode(), null, null); } } private void setPageSize() { if (!mConfiguration.isInMemoryDb()) { execute("PRAGMA page_size=" + SQLiteGlobal.getDefaultPageSize(), null, null); } } private void setAutoCheckpointInterval() { if (!mConfiguration.isInMemoryDb()) { executeForLong("PRAGMA wal_autocheckpoint=" + SQLiteGlobal.getWALAutoCheckpoint(), null, null); } } private void setJournalSizeLimit() { if (!mConfiguration.isInMemoryDb()) { executeForLong("PRAGMA journal_size_limit=" + SQLiteGlobal.getJournalSizeLimit(), null, null); } } private void setJournalModeFromConfiguration() { if (!mConfiguration.isInMemoryDb()) { String result = executeForString("PRAGMA journal_mode=" + mConfiguration.journalMode, null, null); if (!result.equalsIgnoreCase(mConfiguration.journalMode)) { Log.e(TAG, "setting journal_mode to " + mConfiguration.journalMode + " failed for db: " + mConfiguration.label + " (on pragma set journal_mode, sqlite returned:" + result); } } } private void setLocaleFromConfiguration() { nativeSetLocale(mConnectionPtr, mConfiguration.locale.toString()); } Loading @@ -246,7 +289,9 @@ public final class SQLiteConnection implements CancellationSignal.OnCancelListen } } // Remember whether locale has changed. // Remember what changed. boolean journalModeChanged = !configuration.journalMode.equalsIgnoreCase( mConfiguration.journalMode); boolean localeChanged = !configuration.locale.equals(mConfiguration.locale); // Update configuration parameters. Loading @@ -255,6 +300,11 @@ public final class SQLiteConnection implements CancellationSignal.OnCancelListen // Update prepared statement cache size. mPreparedStatementCache.resize(configuration.maxSqlCacheSize); // Update journal mode. if (journalModeChanged) { setJournalModeFromConfiguration(); } // Update locale. if (localeChanged) { setLocaleFromConfiguration(); Loading core/java/android/database/sqlite/SQLiteDatabase.java +3 −23 Original line number Diff line number Diff line Loading @@ -717,9 +717,6 @@ public class SQLiteDatabase extends SQLiteClosable { onCorruption(); openInner(); } // Disable WAL if it was previously enabled. setJournalMode("TRUNCATE"); } catch (SQLiteException ex) { Log.e(TAG, "Failed to open database '" + getLabel() + "'.", ex); close(); Loading @@ -739,19 +736,6 @@ public class SQLiteDatabase extends SQLiteClosable { } } private void setJournalMode(String mode) { // Journal mode can be set only for non-memory databases // AND can't be set for readonly databases if (isInMemoryDatabase() || isReadOnly()) { return; } String s = DatabaseUtils.stringForQuery(this, "PRAGMA journal_mode=" + mode, null); if (!s.equalsIgnoreCase(mode)) { Log.e(TAG, "setting journal_mode to " + mode + " failed for db: " + getLabel() + " (on pragma set journal_mode, sqlite returned:" + s); } } /** * Create a memory backed SQLite database. Its contents will be destroyed * when the database is closed. Loading Loading @@ -1761,13 +1745,10 @@ public class SQLiteDatabase extends SQLiteClosable { } mIsWALEnabledLocked = true; mConfigurationLocked.maxConnectionPoolSize = Math.max(2, Resources.getSystem().getInteger( com.android.internal.R.integer.db_connection_pool_size)); mConfigurationLocked.maxConnectionPoolSize = SQLiteGlobal.getWALConnectionPoolSize(); mConfigurationLocked.journalMode = "WAL"; mConnectionPoolLocked.reconfigure(mConfigurationLocked); } setJournalMode("WAL"); return true; } Loading @@ -1785,10 +1766,9 @@ public class SQLiteDatabase extends SQLiteClosable { mIsWALEnabledLocked = false; mConfigurationLocked.maxConnectionPoolSize = 1; mConfigurationLocked.journalMode = SQLiteGlobal.getDefaultJournalMode(); mConnectionPoolLocked.reconfigure(mConfigurationLocked); } setJournalMode("TRUNCATE"); } /** Loading core/java/android/database/sqlite/SQLiteDatabaseConfiguration.java +9 −0 Original line number Diff line number Diff line Loading @@ -84,6 +84,13 @@ public final class SQLiteDatabaseConfiguration { */ public Locale locale; /** * The database journal mode. * * Default is {@link SQLiteGlobal#getDefaultJournalMode()}. */ public String journalMode; /** * The custom functions to register. */ Loading @@ -110,6 +117,7 @@ public final class SQLiteDatabaseConfiguration { maxConnectionPoolSize = 1; maxSqlCacheSize = 25; locale = Locale.getDefault(); journalMode = SQLiteGlobal.getDefaultJournalMode(); } /** Loading Loading @@ -146,6 +154,7 @@ public final class SQLiteDatabaseConfiguration { maxConnectionPoolSize = other.maxConnectionPoolSize; maxSqlCacheSize = other.maxSqlCacheSize; locale = other.locale; journalMode = other.journalMode; customFunctions.clear(); customFunctions.addAll(other.customFunctions); } Loading core/java/android/database/sqlite/SQLiteGlobal.java +41 −0 Original line number Diff line number Diff line Loading @@ -16,6 +16,7 @@ package android.database.sqlite; import android.content.res.Resources; import android.os.StatFs; /** Loading Loading @@ -64,4 +65,44 @@ public final class SQLiteGlobal { return sDefaultPageSize; } } /** * Gets the default journal mode when WAL is not in use. */ public static String getDefaultJournalMode() { return Resources.getSystem().getString( com.android.internal.R.string.db_default_journal_mode); } /** * Gets the journal size limit in bytes. */ public static int getJournalSizeLimit() { return Resources.getSystem().getInteger( com.android.internal.R.integer.db_journal_size_limit); } /** * Gets the database synchronization mode. */ public static String getSyncMode() { return Resources.getSystem().getString( com.android.internal.R.string.db_sync_mode); } /** * Gets the WAL auto-checkpoint integer in database pages. */ public static int getWALAutoCheckpoint() { return Math.max(1, Resources.getSystem().getInteger( com.android.internal.R.integer.db_wal_autocheckpoint)); } /** * Gets the default connection pool size when in WAL mode. */ public static int getWALConnectionPoolSize() { return Math.max(2, Resources.getSystem().getInteger( com.android.internal.R.integer.db_connection_pool_size)); } } core/jni/android_database_SQLiteConnection.cpp +0 −9 Original line number Diff line number Diff line Loading @@ -128,15 +128,6 @@ static jint nativeOpen(JNIEnv* env, jclass clazz, jstring pathStr, jint openFlag return 0; } // Enable WAL auto-checkpointing after a commit whenever at least one frame is in the log. // This ensures that a checkpoint will occur after each transaction if needed. err = sqlite3_wal_autocheckpoint(db, 1); if (err) { throw_sqlite3_exception(env, db, "Could not enable auto-checkpointing."); sqlite3_close(db); return 0; } // Register custom Android functions. err = register_android_functions(db, UTF16_STORAGE); if (err) { Loading Loading
core/java/android/database/sqlite/SQLiteConnection.java +51 −1 Original line number Diff line number Diff line Loading @@ -208,6 +208,11 @@ public final class SQLiteConnection implements CancellationSignal.OnCancelListen mConfiguration.label, SQLiteDebug.DEBUG_SQL_STATEMENTS, SQLiteDebug.DEBUG_SQL_TIME); setSyncMode(); setPageSize(); setAutoCheckpointInterval(); setJournalSizeLimit(); setJournalModeFromConfiguration(); setLocaleFromConfiguration(); } Loading @@ -231,6 +236,44 @@ public final class SQLiteConnection implements CancellationSignal.OnCancelListen } } private void setSyncMode() { if (!mConfiguration.isInMemoryDb()) { execute("PRAGMA synchronous=" + SQLiteGlobal.getSyncMode(), null, null); } } private void setPageSize() { if (!mConfiguration.isInMemoryDb()) { execute("PRAGMA page_size=" + SQLiteGlobal.getDefaultPageSize(), null, null); } } private void setAutoCheckpointInterval() { if (!mConfiguration.isInMemoryDb()) { executeForLong("PRAGMA wal_autocheckpoint=" + SQLiteGlobal.getWALAutoCheckpoint(), null, null); } } private void setJournalSizeLimit() { if (!mConfiguration.isInMemoryDb()) { executeForLong("PRAGMA journal_size_limit=" + SQLiteGlobal.getJournalSizeLimit(), null, null); } } private void setJournalModeFromConfiguration() { if (!mConfiguration.isInMemoryDb()) { String result = executeForString("PRAGMA journal_mode=" + mConfiguration.journalMode, null, null); if (!result.equalsIgnoreCase(mConfiguration.journalMode)) { Log.e(TAG, "setting journal_mode to " + mConfiguration.journalMode + " failed for db: " + mConfiguration.label + " (on pragma set journal_mode, sqlite returned:" + result); } } } private void setLocaleFromConfiguration() { nativeSetLocale(mConnectionPtr, mConfiguration.locale.toString()); } Loading @@ -246,7 +289,9 @@ public final class SQLiteConnection implements CancellationSignal.OnCancelListen } } // Remember whether locale has changed. // Remember what changed. boolean journalModeChanged = !configuration.journalMode.equalsIgnoreCase( mConfiguration.journalMode); boolean localeChanged = !configuration.locale.equals(mConfiguration.locale); // Update configuration parameters. Loading @@ -255,6 +300,11 @@ public final class SQLiteConnection implements CancellationSignal.OnCancelListen // Update prepared statement cache size. mPreparedStatementCache.resize(configuration.maxSqlCacheSize); // Update journal mode. if (journalModeChanged) { setJournalModeFromConfiguration(); } // Update locale. if (localeChanged) { setLocaleFromConfiguration(); Loading
core/java/android/database/sqlite/SQLiteDatabase.java +3 −23 Original line number Diff line number Diff line Loading @@ -717,9 +717,6 @@ public class SQLiteDatabase extends SQLiteClosable { onCorruption(); openInner(); } // Disable WAL if it was previously enabled. setJournalMode("TRUNCATE"); } catch (SQLiteException ex) { Log.e(TAG, "Failed to open database '" + getLabel() + "'.", ex); close(); Loading @@ -739,19 +736,6 @@ public class SQLiteDatabase extends SQLiteClosable { } } private void setJournalMode(String mode) { // Journal mode can be set only for non-memory databases // AND can't be set for readonly databases if (isInMemoryDatabase() || isReadOnly()) { return; } String s = DatabaseUtils.stringForQuery(this, "PRAGMA journal_mode=" + mode, null); if (!s.equalsIgnoreCase(mode)) { Log.e(TAG, "setting journal_mode to " + mode + " failed for db: " + getLabel() + " (on pragma set journal_mode, sqlite returned:" + s); } } /** * Create a memory backed SQLite database. Its contents will be destroyed * when the database is closed. Loading Loading @@ -1761,13 +1745,10 @@ public class SQLiteDatabase extends SQLiteClosable { } mIsWALEnabledLocked = true; mConfigurationLocked.maxConnectionPoolSize = Math.max(2, Resources.getSystem().getInteger( com.android.internal.R.integer.db_connection_pool_size)); mConfigurationLocked.maxConnectionPoolSize = SQLiteGlobal.getWALConnectionPoolSize(); mConfigurationLocked.journalMode = "WAL"; mConnectionPoolLocked.reconfigure(mConfigurationLocked); } setJournalMode("WAL"); return true; } Loading @@ -1785,10 +1766,9 @@ public class SQLiteDatabase extends SQLiteClosable { mIsWALEnabledLocked = false; mConfigurationLocked.maxConnectionPoolSize = 1; mConfigurationLocked.journalMode = SQLiteGlobal.getDefaultJournalMode(); mConnectionPoolLocked.reconfigure(mConfigurationLocked); } setJournalMode("TRUNCATE"); } /** Loading
core/java/android/database/sqlite/SQLiteDatabaseConfiguration.java +9 −0 Original line number Diff line number Diff line Loading @@ -84,6 +84,13 @@ public final class SQLiteDatabaseConfiguration { */ public Locale locale; /** * The database journal mode. * * Default is {@link SQLiteGlobal#getDefaultJournalMode()}. */ public String journalMode; /** * The custom functions to register. */ Loading @@ -110,6 +117,7 @@ public final class SQLiteDatabaseConfiguration { maxConnectionPoolSize = 1; maxSqlCacheSize = 25; locale = Locale.getDefault(); journalMode = SQLiteGlobal.getDefaultJournalMode(); } /** Loading Loading @@ -146,6 +154,7 @@ public final class SQLiteDatabaseConfiguration { maxConnectionPoolSize = other.maxConnectionPoolSize; maxSqlCacheSize = other.maxSqlCacheSize; locale = other.locale; journalMode = other.journalMode; customFunctions.clear(); customFunctions.addAll(other.customFunctions); } Loading
core/java/android/database/sqlite/SQLiteGlobal.java +41 −0 Original line number Diff line number Diff line Loading @@ -16,6 +16,7 @@ package android.database.sqlite; import android.content.res.Resources; import android.os.StatFs; /** Loading Loading @@ -64,4 +65,44 @@ public final class SQLiteGlobal { return sDefaultPageSize; } } /** * Gets the default journal mode when WAL is not in use. */ public static String getDefaultJournalMode() { return Resources.getSystem().getString( com.android.internal.R.string.db_default_journal_mode); } /** * Gets the journal size limit in bytes. */ public static int getJournalSizeLimit() { return Resources.getSystem().getInteger( com.android.internal.R.integer.db_journal_size_limit); } /** * Gets the database synchronization mode. */ public static String getSyncMode() { return Resources.getSystem().getString( com.android.internal.R.string.db_sync_mode); } /** * Gets the WAL auto-checkpoint integer in database pages. */ public static int getWALAutoCheckpoint() { return Math.max(1, Resources.getSystem().getInteger( com.android.internal.R.integer.db_wal_autocheckpoint)); } /** * Gets the default connection pool size when in WAL mode. */ public static int getWALConnectionPoolSize() { return Math.max(2, Resources.getSystem().getInteger( com.android.internal.R.integer.db_connection_pool_size)); } }
core/jni/android_database_SQLiteConnection.cpp +0 −9 Original line number Diff line number Diff line Loading @@ -128,15 +128,6 @@ static jint nativeOpen(JNIEnv* env, jclass clazz, jstring pathStr, jint openFlag return 0; } // Enable WAL auto-checkpointing after a commit whenever at least one frame is in the log. // This ensures that a checkpoint will occur after each transaction if needed. err = sqlite3_wal_autocheckpoint(db, 1); if (err) { throw_sqlite3_exception(env, db, "Could not enable auto-checkpointing."); sqlite3_close(db); return 0; } // Register custom Android functions. err = register_android_functions(db, UTF16_STORAGE); if (err) { Loading