I used ormlite for ORM mapping. It seems very useful and I have been using it in the project. It is good to encapsulate the omnipotent Dao interface when the data volume is small. It's a pleasure for me to use it .. Good days are always short, and the server-side database suddenly adds 800 pieces of data !! The Dao. createorupdate method is a tragedy. It takes 40 s !! It's really intolerable !! Then it is natural to think of things to enable ormlite, but find one on the Internet, where it is difficult to use it, and the words should look at the source code better.
Found:
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);}}
See:
db.beginTransaction();
Is what I want.
Next we will see:
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 rollbackdb.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);}
When we see this write method, the problem is basically solved.
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);}}