Here is my model classes that are persisted in sqlite db using ORMLITE.
public class Site{
...
...
Collection<Visit> visits;
}
public class Visit{
...
...
Collection<Pic> pics;
}
public class Pic{
...
...
}
Now in one view i add,edit or delete from these three tables. There is a button in my view to cancel the changes(add,edit,delete). So i need to rollback to previous state of the db.
How can i achieve this roll back to a certain state of the three tables using ormlite with android?
I have read in ormlite docs about DAO.SetAutoCommit() and startThreadConnection() methods. I think i can do it by using this two. But cant figure it out how to use them. Please suggest me how to do it.
Here is my DBHelper Class:
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;
}
.....
.....