diff options
| author | Vasu Nori <vnori@google.com> | 2010-09-27 18:29:18 -0700 |
|---|---|---|
| committer | Android (Google) Code Review <android-gerrit@google.com> | 2010-09-27 18:29:18 -0700 |
| commit | 9b8a51e9d34fe3ed7f980956be97463685949138 (patch) | |
| tree | 62c57b17c8d0d45dc31bbccf42d4d3dd340f7e47 /core/java/android | |
| parent | eb1817844f9f508e1acf155ad98fb19d58ecaaef (diff) | |
| parent | 587423afb52f65db28498a9f2378cccbd2e823c8 (diff) | |
Merge "fix this: closing database twice fails with IllegalStateException"
Diffstat (limited to 'core/java/android')
3 files changed, 19 insertions, 12 deletions
diff --git a/core/java/android/database/sqlite/DatabaseConnectionPool.java b/core/java/android/database/sqlite/DatabaseConnectionPool.java index 8adc9c578dca..39a9d23c0220 100644 --- a/core/java/android/database/sqlite/DatabaseConnectionPool.java +++ b/core/java/android/database/sqlite/DatabaseConnectionPool.java @@ -93,7 +93,7 @@ import java.util.Random; poolObj = mPool.get(0); } else { for (int i = 0; i < mMaxPoolSize; i++) { - if (mPool.get(i).mDb.isSqlInStatementCache(sql)) { + if (mPool.get(i).mDb.isInStatementCache(sql)) { poolObj = mPool.get(i); break; } @@ -119,7 +119,7 @@ import java.util.Random; // there are free connections available. pick one // preferably a connection caching the pre-compiled statement of the given SQL for (int i = 0; i < poolSize; i++) { - if (mPool.get(i).isFree() && mPool.get(i).mDb.isSqlInStatementCache(sql)) { + if (mPool.get(i).isFree() && mPool.get(i).mDb.isInStatementCache(sql)) { poolObj = mPool.get(i); break; } diff --git a/core/java/android/database/sqlite/SQLiteDatabase.java b/core/java/android/database/sqlite/SQLiteDatabase.java index 6882ea2116cd..7ab5d82936fb 100644 --- a/core/java/android/database/sqlite/SQLiteDatabase.java +++ b/core/java/android/database/sqlite/SQLiteDatabase.java @@ -1048,6 +1048,9 @@ public class SQLiteDatabase extends SQLiteClosable { * Close the database. */ public void close() { + if (!isOpen()) { + return; + } if (Log.isLoggable(TAG, Log.DEBUG)) { Log.i(TAG, "closing db: " + mPath + " (connection # " + mConnectionNum); } @@ -2174,12 +2177,18 @@ public class SQLiteDatabase extends SQLiteClosable { } } - /* package */ boolean isSqlInStatementCache(String sql) { + /* package */ boolean isInStatementCache(String sql) { synchronized (mCompiledQueries) { return mCompiledQueries.containsKey(sql); } } + /* package */ boolean isInStatementCache(SQLiteCompiledSql sqliteCompiledSql) { + synchronized (mCompiledQueries) { + return mCompiledQueries.containsValue(sqliteCompiledSql); + } + } + private synchronized int getCacheHitNum() { return mNumCacheHits; } diff --git a/core/java/android/database/sqlite/SQLiteProgram.java b/core/java/android/database/sqlite/SQLiteProgram.java index 4747a9e9fd1a..e78e35ab4ba2 100644 --- a/core/java/android/database/sqlite/SQLiteProgram.java +++ b/core/java/android/database/sqlite/SQLiteProgram.java @@ -188,15 +188,13 @@ public abstract class SQLiteProgram extends SQLiteClosable { // this SQL statement was never in cache mCompiledSql.releaseSqlStatement(); } else { - synchronized(mDatabase.mCompiledQueries) { - if (!mDatabase.mCompiledQueries.containsValue(mCompiledSql)) { - // it is NOT in compiled-sql cache. i.e., responsibility of - // releasing this statement is on me. - mCompiledSql.releaseSqlStatement(); - } else { - // it is in compiled-sql cache. reset its CompiledSql#mInUse flag - mCompiledSql.release(); - } + if (!mDatabase.isInStatementCache(mCompiledSql)) { + // it is NOT in compiled-sql cache. i.e., responsibility of + // releasing this statement is on me. + mCompiledSql.releaseSqlStatement(); + } else { + // it is in compiled-sql cache. reset its CompiledSql#mInUse flag + mCompiledSql.release(); } } mCompiledSql = null; |
