AndroidのOrmLiteに小さな問題があります。
データベースのバージョンをインクリメントするonUpgrade
と、OrmLiteヘルパーで期待どおりにメソッドが呼び出されます。アップグレード後、onCreate
メソッドが呼び出され、次の例外が発生します。
11-24 10:09:45.720: ERROR/AndroidConnectionSource(390): connection saved
com.j256.ormlite.android.AndroidDatabaseConnection@44f0f478 is not the one
being cleared com.j256.ormlite.android.AndroidDatabaseConnection@44f5d310
クリアされた接続が保存された接続と同じでない理由がわかりません。
データベース関数(挿入...)もOrmLiteHelperクラスに入れました。多分これは問題かもしれませんか?!?
ヘルパークラスのスニペット:
public class OrmLiteDBProvider extends OrmLiteSqliteOpenHelper
implements IEntityProvider, IDBProvider {
//snip
@Override
public void onCreate(SQLiteDatabase db, ConnectionSource connectionSource) {
try {
Log.i(OrmLiteDBProvider.class.getName(), "Creating database and tables");
TableUtils.createTable(connectionSource, OrgManaged.class);
} catch (SQLException e) {
Log.e(OrmLiteDBProvider.class.getName(),
"Can't create database and tables", e);
throw new RuntimeException(e);
}
}
@Override
public void onUpgrade(SQLiteDatabase db, ConnectionSource connectionSource,
int oldVersion, int newVersion) {
try {
Log.i(OrmLiteDBProvider.class.getName(),
"Database version changed. Dropping database.");
TableUtils.dropTable(connectionSource, OrgManaged.class, true);
// after we drop the old databases, we create the new ones
onCreate(db);
} catch (SQLException e) {
Log.e(OrmLiteDBProvider.class.getName(), "Can't drop databases", e);
throw new RuntimeException(e);
}
}
それは私が見逃している単純なものだと思います。
よろしくお願いします。