Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 587423af authored by Vasu Nori's avatar Vasu Nori
Browse files

fix this: closing database twice fails with IllegalStateException

Change-Id: Idda35e49d539845099b377872f9a6f0e0caa4626
parent c63806d8
Loading
Loading
Loading
Loading
+2 −2
Original line number Diff line number Diff line
@@ -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;
                }
+10 −1
Original line number Diff line number Diff line
@@ -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;
    }
+7 −9
Original line number Diff line number Diff line
@@ -188,8 +188,7 @@ public abstract class SQLiteProgram extends SQLiteClosable {
            // this SQL statement was never in cache
            mCompiledSql.releaseSqlStatement();
        } else {
            synchronized(mDatabase.mCompiledQueries) {
                if (!mDatabase.mCompiledQueries.containsValue(mCompiledSql)) {
            if (!mDatabase.isInStatementCache(mCompiledSql)) {
                // it is NOT in compiled-sql cache. i.e., responsibility of
                // releasing this statement is on me.
                mCompiledSql.releaseSqlStatement();
@@ -198,7 +197,6 @@ public abstract class SQLiteProgram extends SQLiteClosable {
                mCompiledSql.release();
            }
        }
        }
        mCompiledSql = null;
        nStatement = 0;
    }