これは、ORMLITEを使用してsqlitedbに永続化される私のモデルクラスです。
public class Site{
...
...
Collection<Visit> visits;
}
public class Visit{
...
...
Collection<Pic> pics;
}
public class Pic{
...
...
}
1つのビューで、これら3つのテーブルを追加、編集、または削除します。ビューには、変更(追加、編集、削除)をキャンセルするためのボタンがあります。したがって、dbの以前の状態にロールバックする必要があります。
androidでormliteを使用して、3つのテーブルの特定の状態にこのロールバックを実現するにはどうすればよいですか?
DAO.SetAutoCommit()メソッドとstartThreadConnection()メソッドに関するormliteドキュメントを読みました。この2つでできると思います。しかし、それらの使い方を理解することはできません。やり方を教えてください。
これが私のDBHelperクラスです:
public class DatabaseHelper extends OrmLiteSqliteOpenHelper {
// name of the database file
private static final String DATABASE_NAME = "Test.db";
private static final int DATABASE_VERSION = 1;
private Dao<Site, Integer> siteListDao = null;
private Dao<Visit, Integer> visitDao= null;
private Dao<Pic,Integer> picDao=null;
public DatabaseHelper(Context context) {
super(context, DATABASE_NAME, null, DATABASE_VERSION);
}
@Override
public void onCreate(SQLiteDatabase database,ConnectionSource connectionSource) {
try {
TableUtils.createTable(connectionSource, Site.class);
TableUtils.createTable(connectionSource, Visit.class);
TableUtils.createTable(connectionSource, Pic.class);
} catch (SQLException e) {
Log.e(DatabaseHelper.class.getName(), "Can't create database", e);
throw new RuntimeException(e);
} catch (java.sql.SQLException e) {
e.printStackTrace();
}
}
public Dao<Visit, Integer> getVisitDao() {
if (null == visitDao) {
try {
visitDao = getDao(Visit.class);
}catch (java.sql.SQLException e) {
e.printStackTrace();
}
}
return visitDao;
}
.....
.....