Ejemplo n.º 1
0
 @Override
 public int deleteAll(Class<?> claxx) {
   acquireReference();
   try {
     SQLiteDatabase db = mHelper.getWritableDatabase();
     SQLStatement stmt = SQLBuilder.buildDeleteAllSql(claxx);
     int num = stmt.execDelete(db);
     // 删除关系映射
     final MapInfo mapTable = SQLBuilder.buildDelAllMappingSql(claxx);
     if (mapTable != null && !mapTable.isEmpty()) {
       Transaction.execute(
           db,
           new Worker<Boolean>() {
             @Override
             public Boolean doTransaction(SQLiteDatabase db) throws Exception {
               if (mapTable.delOldRelationSQL != null) {
                 for (SQLStatement st : mapTable.delOldRelationSQL) {
                   long rowId = st.execDelete(db);
                   if (Log.isPrint) {
                     Log.i(TAG, "Exec delete mapping success, nums: " + rowId);
                   }
                 }
               }
               return true;
             }
           });
     }
     return num;
   } catch (Exception e) {
     e.printStackTrace();
   } finally {
     releaseReference();
   }
   return SQLStatement.NONE;
 }
Ejemplo n.º 2
0
 /** 删除从[start,end]的数据 此方法暂不会删除关联映射表里的关系数据 */
 @Override
 public int delete(Class<?> claxx, long start, long end, String orderAscColumn) {
   acquireReference();
   try {
     if (start < 0 || end < start) {
       throw new RuntimeException("start must >=0 and smaller than end");
     }
     if (start != 0) {
       start -= 1;
     }
     end = end == Integer.MAX_VALUE ? -1 : end - start;
     SQLStatement stmt = SQLBuilder.buildDeleteSql(claxx, start, end, orderAscColumn);
     return stmt.execDelete(mHelper.getWritableDatabase());
   } catch (Exception e) {
     e.printStackTrace();
   } finally {
     releaseReference();
   }
   return SQLStatement.NONE;
 }