add warning in finalizer. deprecate protected members.

finalizer shoudl not be called ever. add a warning to say that.
adeprecate a few members in SQLiteProgram.java. they should not
have had protected access level. shoudl be package.
This commit is contained in:
Vasu Nori
2010-03-01 14:47:47 -08:00
parent d2b41b6e7d
commit 14b60e747c
3 changed files with 28 additions and 6 deletions

View File

@@ -28,6 +28,8 @@ import android.util.Log;
*/
/* package */ class SQLiteCompiledSql {
private static final String TAG = "SQLiteCompiledSql";
/** The database this program is compiled against. */
/* package */ SQLiteDatabase mDatabase;
@@ -44,11 +46,17 @@ import android.util.Log;
*/
/* package */ int nStatement = 0;
/** the following are for debugging purposes */
private String mSqlStmt = null;
private Throwable mStackTrace = null;
/** when in cache and is in use, this member is set */
private boolean mInUse = false;
/* package */ SQLiteCompiledSql(SQLiteDatabase db, String sql) {
mDatabase = db;
mSqlStmt = sql;
mStackTrace = new Exception().fillInStackTrace();
this.nHandle = db.mNativeHandle;
compile(sql, true);
}
@@ -115,8 +123,15 @@ import android.util.Log;
* Make sure that the native resource is cleaned up.
*/
@Override
protected void finalize() {
releaseSqlStatement();
protected void finalize() throws Throwable {
try {
if (nStatement == 0) return;
// finalizer should NEVER get called
Log.w(TAG, "finalizer should never be called. sql: " + mSqlStmt, mStackTrace);
releaseSqlStatement();
} finally {
super.finalize();
}
}
/**

View File

@@ -21,7 +21,10 @@ package android.database.sqlite;
*/
public abstract class SQLiteProgram extends SQLiteClosable {
/** The database this program is compiled against. */
/** The database this program is compiled against.
* @deprecated do not use this
*/
@Deprecated
protected SQLiteDatabase mDatabase;
/** The SQL used to create this query */
@@ -30,7 +33,9 @@ public abstract class SQLiteProgram extends SQLiteClosable {
/**
* Native linkage, do not modify. This comes from the database and should not be modified
* in here or in the native code.
* @deprecated do not use this
*/
@Deprecated
protected int nHandle = 0;
/**
@@ -41,7 +46,9 @@ public abstract class SQLiteProgram extends SQLiteClosable {
/**
* SQLiteCompiledSql statement id is populated with the corresponding object from the above
* member. This member is used by the native_bind_* methods
* @deprecated do not use this
*/
@Deprecated
protected int nStatement = 0;
/* package */ SQLiteProgram(SQLiteDatabase db, String sql) {