/** 主动删除其mapping数据 */ @Override public int delete(Object entity) { acquireReference(); try { return SQLBuilder.buildDeleteSql(entity) .execDeleteWithMapping(mHelper.getWritableDatabase(), entity, mTableManager); } catch (Exception e) { e.printStackTrace(); } finally { releaseReference(); } return SQLStatement.NONE; }
/** 删除从[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; }
@Override public int delete(final Collection<?> collection) { acquireReference(); try { if (!Checker.isEmpty(collection)) { EntityTable table = TableManager.getTable(collection.iterator().next()); if (table.key != null) { SQLStatement stmt = SQLBuilder.buildDeleteSql(collection); return stmt.execDeleteCollection( mHelper.getWritableDatabase(), collection, mTableManager); } else { Integer size = Transaction.execute( mHelper.getWritableDatabase(), new Worker<Integer>() { @Override public Integer doTransaction(SQLiteDatabase db) throws Exception { for (Object entity : collection) { SQLBuilder.buildDeleteSql(entity) .execDeleteWithMapping(db, entity, mTableManager); } if (Log.isPrint) { Log.i(TAG, "Exec delete(no primarykey) :" + collection.size()); } return collection.size(); } }); return size == null ? 0 : size; } } } catch (Exception e) { e.printStackTrace(); } finally { releaseReference(); } return SQLStatement.NONE; }