找到了:
public Savepoint setSavePoint(String name) throws SQLException { try { db.beginTransaction(); logger.trace("{}: save-point set with name {}", this, name); return new OurSavePoint(name); } catch (android.database.SQLException e) { throw SqlExceptionUtil.create("problems beginning transaction " + name, e); } }
db.beginTransaction();是我想要的东西。
接下来还有:
public void commit(Savepoint savepoint) throws SQLException { try { db.setTransactionSuccessful(); db.endTransaction(); if (savepoint == null) { logger.trace("{}: transaction is successfuly ended", this); } else { logger.trace("{}: transaction {} is successfuly ended", this, savepoint.getSavepointName()); } } catch (android.database.SQLException e) { throw SqlExceptionUtil.create("problems commiting transaction " + savepoint.getSavepointName(), e); } }
public void rollback(Savepoint savepoint) throws SQLException { try { // no setTransactionSuccessful() means it is a rollback db.endTransaction(); if (savepoint == null) { logger.trace("{}: transaction is ended, unsuccessfuly", this); } else { logger.trace("{}: transaction {} is ended, unsuccessfuly", this, savepoint.getSavepointName()); } } catch (android.database.SQLException e) { throw SqlExceptionUtil.create("problems rolling back transaction " + savepoint.getSavepointName(), e); }
看到这个写个方法,问题就基本上解决了。
AndroidDatabaseConnection connection = null; String pointName = "pointName"; Savepoint savepoint = null; try { DebugTool.info ( "@@@@@@@@@@@@@@@@@@@@updateFooodTable= " + CommonUtil.getCurrentTime () ); // // beging transaction connection = new AndroidDatabaseConnection ( BaseApplication.SQLiteAccess () .getHelper ( BaseApplication.mAppContext ).getWritableDatabase () , true ); // connection.setAutoCommit ( false ); dao.setAutoCommit ( connection , false ); // dao.startThreadConnection (); savepoint = connection.setSavePoint ( pointName ); for ( Food food : foodList ) { try { dao.createOrUpdate ( food ); } catch ( SQLException e ) { DebugTool .info ( "<!=============updateFooodTable===========SQLException============>" ); } catch ( Exception e ) { DebugTool .info ( "<!=============updateFooodTable===========Exception================>" ); } } ///foodcookmethods // connection.commit ( null ); // dao.commit ( connection ); connection.commit ( savepoint ); DebugTool.info ( "@@@@@@@@@@@@@@@@@@@@updateFooodTable= " + CommonUtil.getCurrentTime () ); } catch ( SQLException e ) { DebugTool .error ( "<!===updateFooodTable====>" ,e); try { connection.rollback ( savepoint ); } catch ( SQLException e1 ) { DebugTool .error ( "<!===updateFooodTable++rollback=SQLException===>" ,e1); } }