remove public API setConnectionPoolSize()

because connection pool size is now settable by modifying config.xml
of the device.

Change-Id: I973cc11d7dc10c8d95ab83e2f691068f6019fa33
This commit is contained in:
Vasu Nori
2010-09-27 12:32:57 -07:00
parent c18ac6ef84
commit ffe06127f6
4 changed files with 84 additions and 149 deletions

View File

@@ -66018,7 +66018,7 @@
return="boolean"
abstract="false"
native="false"
synchronized="true"
synchronized="false"
static="false"
final="false"
deprecated="not deprecated"
@@ -66600,19 +66600,6 @@
<exception name="SQLException" type="android.database.SQLException">
</exception>
</method>
<method name="setConnectionPoolSize"
return="void"
abstract="false"
native="false"
synchronized="false"
static="false"
final="false"
deprecated="not deprecated"
visibility="public"
>
<parameter name="size" type="int">
</parameter>
</method>
<method name="setLocale"
return="void"
abstract="false"
@@ -247887,7 +247874,7 @@
deprecated="not deprecated"
visibility="public"
>
<parameter name="fileName" type="java.lang.String">
<parameter name="path" type="java.lang.String">
</parameter>
<exception name="FileNotFoundException" type="java.io.FileNotFoundException">
</exception>
@@ -248010,7 +247997,7 @@
deprecated="not deprecated"
visibility="public"
>
<parameter name="filename" type="java.lang.String">
<parameter name="path" type="java.lang.String">
</parameter>
<exception name="FileNotFoundException" type="java.io.FileNotFoundException">
</exception>
@@ -248022,7 +248009,7 @@
deprecated="not deprecated"
visibility="public"
>
<parameter name="filename" type="java.lang.String">
<parameter name="path" type="java.lang.String">
</parameter>
<parameter name="append" type="boolean">
</parameter>
@@ -248693,7 +248680,7 @@
deprecated="not deprecated"
visibility="public"
>
<parameter name="b" type="byte[]">
<parameter name="buffer" type="byte[]">
</parameter>
<parameter name="offset" type="int">
</parameter>
@@ -283770,9 +283757,9 @@
>
<parameter name="dst" type="byte[]">
</parameter>
<parameter name="off" type="int">
<parameter name="dstOffset" type="int">
</parameter>
<parameter name="len" type="int">
<parameter name="byteCount" type="int">
</parameter>
</method>
<method name="get"
@@ -284016,9 +284003,9 @@
>
<parameter name="src" type="byte[]">
</parameter>
<parameter name="off" type="int">
<parameter name="srcOffset" type="int">
</parameter>
<parameter name="len" type="int">
<parameter name="byteCount" type="int">
</parameter>
</method>
<method name="put"
@@ -284255,7 +284242,7 @@
</parameter>
<parameter name="start" type="int">
</parameter>
<parameter name="len" type="int">
<parameter name="byteCount" type="int">
</parameter>
</method>
</class>
@@ -284488,9 +284475,9 @@
>
<parameter name="dst" type="char[]">
</parameter>
<parameter name="off" type="int">
<parameter name="dstOffset" type="int">
</parameter>
<parameter name="len" type="int">
<parameter name="charCount" type="int">
</parameter>
</method>
<method name="get"
@@ -284588,9 +284575,9 @@
>
<parameter name="src" type="char[]">
</parameter>
<parameter name="off" type="int">
<parameter name="srcOffset" type="int">
</parameter>
<parameter name="len" type="int">
<parameter name="charCount" type="int">
</parameter>
</method>
<method name="put"
@@ -284719,7 +284706,7 @@
</parameter>
<parameter name="start" type="int">
</parameter>
<parameter name="len" type="int">
<parameter name="charCount" type="int">
</parameter>
</method>
<method name="wrap"
@@ -284880,9 +284867,9 @@
>
<parameter name="dst" type="double[]">
</parameter>
<parameter name="off" type="int">
<parameter name="dstOffset" type="int">
</parameter>
<parameter name="len" type="int">
<parameter name="doubleCount" type="int">
</parameter>
</method>
<method name="get"
@@ -284969,9 +284956,9 @@
>
<parameter name="src" type="double[]">
</parameter>
<parameter name="off" type="int">
<parameter name="srcOffset" type="int">
</parameter>
<parameter name="len" type="int">
<parameter name="doubleCount" type="int">
</parameter>
</method>
<method name="put"
@@ -285040,7 +285027,7 @@
</parameter>
<parameter name="start" type="int">
</parameter>
<parameter name="len" type="int">
<parameter name="doubleCount" type="int">
</parameter>
</method>
</class>
@@ -285171,9 +285158,9 @@
>
<parameter name="dst" type="float[]">
</parameter>
<parameter name="off" type="int">
<parameter name="dstOffset" type="int">
</parameter>
<parameter name="len" type="int">
<parameter name="floatCount" type="int">
</parameter>
</method>
<method name="get"
@@ -285260,9 +285247,9 @@
>
<parameter name="src" type="float[]">
</parameter>
<parameter name="off" type="int">
<parameter name="srcOffset" type="int">
</parameter>
<parameter name="len" type="int">
<parameter name="floatCount" type="int">
</parameter>
</method>
<method name="put"
@@ -285331,7 +285318,7 @@
</parameter>
<parameter name="start" type="int">
</parameter>
<parameter name="len" type="int">
<parameter name="floatCount" type="int">
</parameter>
</method>
</class>
@@ -285462,9 +285449,9 @@
>
<parameter name="dst" type="int[]">
</parameter>
<parameter name="off" type="int">
<parameter name="dstOffset" type="int">
</parameter>
<parameter name="len" type="int">
<parameter name="intCount" type="int">
</parameter>
</method>
<method name="get"
@@ -285551,9 +285538,9 @@
>
<parameter name="src" type="int[]">
</parameter>
<parameter name="off" type="int">
<parameter name="srcOffset" type="int">
</parameter>
<parameter name="len" type="int">
<parameter name="intCount" type="int">
</parameter>
</method>
<method name="put"
@@ -285622,7 +285609,7 @@
</parameter>
<parameter name="start" type="int">
</parameter>
<parameter name="len" type="int">
<parameter name="intCount" type="int">
</parameter>
</method>
</class>
@@ -285770,9 +285757,9 @@
>
<parameter name="dst" type="long[]">
</parameter>
<parameter name="off" type="int">
<parameter name="dstOffset" type="int">
</parameter>
<parameter name="len" type="int">
<parameter name="longCount" type="int">
</parameter>
</method>
<method name="get"
@@ -285859,9 +285846,9 @@
>
<parameter name="src" type="long[]">
</parameter>
<parameter name="off" type="int">
<parameter name="srcOffset" type="int">
</parameter>
<parameter name="len" type="int">
<parameter name="longCount" type="int">
</parameter>
</method>
<method name="put"
@@ -285930,7 +285917,7 @@
</parameter>
<parameter name="start" type="int">
</parameter>
<parameter name="len" type="int">
<parameter name="longCount" type="int">
</parameter>
</method>
</class>
@@ -286120,9 +286107,9 @@
>
<parameter name="dst" type="short[]">
</parameter>
<parameter name="off" type="int">
<parameter name="dstOffset" type="int">
</parameter>
<parameter name="len" type="int">
<parameter name="shortCount" type="int">
</parameter>
</method>
<method name="get"
@@ -286209,9 +286196,9 @@
>
<parameter name="src" type="short[]">
</parameter>
<parameter name="off" type="int">
<parameter name="srcOffset" type="int">
</parameter>
<parameter name="len" type="int">
<parameter name="shortCount" type="int">
</parameter>
</method>
<method name="put"
@@ -286280,7 +286267,7 @@
</parameter>
<parameter name="start" type="int">
</parameter>
<parameter name="len" type="int">
<parameter name="shortCount" type="int">
</parameter>
</method>
</class>

View File

@@ -246,16 +246,14 @@ import java.util.Random;
}
}
/* package */ void setMaxPoolSize(int size) {
synchronized(mParentDbObj) {
mMaxPoolSize = size;
}
/** only used for testing purposes. */
/* package */ synchronized void setMaxPoolSize(int size) {
mMaxPoolSize = size;
}
/* package */ int getMaxPoolSize() {
synchronized(mParentDbObj) {
return mMaxPoolSize;
}
/** only used for testing purposes. */
/* package */ synchronized int getMaxPoolSize() {
return mMaxPoolSize;
}
/** only used for testing purposes. */

View File

@@ -1048,14 +1048,16 @@ public class SQLiteDatabase extends SQLiteClosable {
* Close the database.
*/
public void close() {
if (!isOpen()) {
return; // already closed
}
if (Log.isLoggable(TAG, Log.DEBUG)) {
Log.i(TAG, "closing db: " + mPath + " (connection # " + mConnectionNum);
}
lock();
try {
// some other thread could have closed this database while I was waiting for lock.
// check the database state
if (!isOpen()) {
return;
}
closeClosable();
// finalize ALL statements queued up so far
closePendingStatements();
@@ -2102,7 +2104,7 @@ public class SQLiteDatabase extends SQLiteClosable {
return;
}
if (!isCacheFullWarningLogged() && mCompiledQueries.size() == mMaxSqlCacheSize) {
if (!mCacheFullWarning && mCompiledQueries.size() == mMaxSqlCacheSize) {
/*
* cache size of {@link #mMaxSqlCacheSize} is not enough for this app.
* log a warning.
@@ -2110,7 +2112,7 @@ public class SQLiteDatabase extends SQLiteClosable {
*/
Log.w(TAG, "Reached MAX size for compiled-sql statement cache for database " +
getPath() + ". Use setMaxSqlCacheSize() to increase cachesize. ");
setCacheFullWarningLogged();
mCacheFullWarning = true;
}
/* add the given SQLiteCompiledSql compiledStatement to cache.
* no need to worry about the cache size - because {@link #mCompiledQueries}
@@ -2134,14 +2136,16 @@ public class SQLiteDatabase extends SQLiteClosable {
* From the compiledQueries cache, returns the compiled-statement-id for the given SQL.
* Returns null, if not found in the cache.
*/
/* package */ synchronized SQLiteCompiledSql getCompiledStatementForSql(String sql) {
SQLiteCompiledSql compiledStatement = mCompiledQueries.get(sql);
if (compiledStatement == null) {
mNumCacheMisses++;
return null;
/* package */ SQLiteCompiledSql getCompiledStatementForSql(String sql) {
synchronized (mCompiledQueries) {
SQLiteCompiledSql compiledStatement = mCompiledQueries.get(sql);
if (compiledStatement == null) {
mNumCacheMisses++;
return null;
}
mNumCacheHits++;
return compiledStatement;
}
mNumCacheHits++;
return compiledStatement;
}
/**
@@ -2159,7 +2163,7 @@ public class SQLiteDatabase extends SQLiteClosable {
* the value set with previous setMaxSqlCacheSize() call.
*/
public void setMaxSqlCacheSize(int cacheSize) {
synchronized(this) {
synchronized(mCompiledQueries) {
if (cacheSize > MAX_SQL_CACHE_SIZE || cacheSize < 0) {
throw new IllegalStateException("expected value between 0 and " + MAX_SQL_CACHE_SIZE);
} else if (cacheSize < mMaxSqlCacheSize) {
@@ -2176,14 +2180,6 @@ public class SQLiteDatabase extends SQLiteClosable {
}
}
private synchronized boolean isCacheFullWarningLogged() {
return mCacheFullWarning;
}
private synchronized void setCacheFullWarningLogged() {
mCacheFullWarning = true;
}
private synchronized int getCacheHitNum() {
return mNumCacheHits;
}
@@ -2279,26 +2275,28 @@ public class SQLiteDatabase extends SQLiteClosable {
*
* @return true if write-ahead-logging is set. false otherwise
*/
public synchronized boolean enableWriteAheadLogging() {
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 (getAttachedDbs().size() > 1) {
if (Log.isLoggable(TAG, Log.DEBUG)) {
Log.d(TAG,
"this database: " + mPath + " has attached databases. can't enable WAL.");
public boolean enableWriteAheadLogging() {
synchronized(this) {
if (mPath.equalsIgnoreCase(MEMORY_DB_PATH)) {
Log.i(TAG, "can't enable WAL for memory databases.");
return false;
}
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 (getAttachedDbs().size() > 1) {
if (Log.isLoggable(TAG, Log.DEBUG)) {
Log.d(TAG,
"this database: " + mPath + " has attached databases. can't enable WAL.");
}
return false;
}
if (mConnectionPool == null) {
mConnectionPool = new DatabaseConnectionPool(this);
setJournalMode(mPath, "WAL");
}
return true;
}
if (mConnectionPool == null) {
mConnectionPool = new DatabaseConnectionPool(this);
setJournalMode(mPath, "WAL");
}
return true;
}
/**
@@ -2338,32 +2336,6 @@ public class SQLiteDatabase extends SQLiteClosable {
}
}
/**
* Sets the database connection handle pool size to the given value.
* Database connection handle pool is enabled when the app calls
* {@link #enableWriteAheadLogging()}.
* <p>
* The default connection handle pool is set by the system by taking into account various
* aspects of the device, such as memory, number of cores etc. It is recommended that
* applications use the default pool size set by the system.
*
* @param size the value the connection handle pool size should be set to.
*/
public void setConnectionPoolSize(int size) {
synchronized(this) {
if (mConnectionPool == null) {
throw new IllegalStateException("connection pool not enabled");
}
int i = mConnectionPool.getMaxPoolSize();
if (size < i) {
throw new IllegalArgumentException(
"cannot set max pool size to a value less than the current max value(=" +
i + ")");
}
mConnectionPool.setMaxPoolSize(size);
}
}
/* package */ SQLiteDatabase createPoolConnection(short connectionNum) {
SQLiteDatabase db = openDatabase(mPath, mFactory, mFlags, mErrorHandler, connectionNum);
db.mParentConnObj = this;

View File

@@ -135,28 +135,6 @@ public class SQLiteDatabaseTest extends AndroidTestCase {
c.close();
}
@SmallTest
public void testSetConnectionPoolSize() {
mDatabase.enableWriteAheadLogging();
// can't set pool size to zero
try {
mDatabase.setConnectionPoolSize(0);
fail("IllegalStateException expected");
} catch (IllegalArgumentException e) {
assertTrue(e.getMessage().contains("less than the current max value"));
}
// set pool size to a valid value
mDatabase.setConnectionPoolSize(10);
assertEquals(10, mDatabase.mConnectionPool.getMaxPoolSize());
// can't set pool size to < the value above
try {
mDatabase.setConnectionPoolSize(1);
fail("IllegalStateException expected");
} catch (IllegalArgumentException e) {
assertTrue(e.getMessage().contains("less than the current max value"));
}
}
/**
* a transaction should be started before a standalone-update/insert/delete statement
*/
@@ -299,7 +277,7 @@ public class SQLiteDatabaseTest extends AndroidTestCase {
if (useWal) {
// set up connection pool
mDatabase.enableWriteAheadLogging();
mDatabase.setConnectionPoolSize(i + 1);
mDatabase.mConnectionPool.setMaxPoolSize(i + 1);
} else {
mDatabase.disableWriteAheadLogging();
}