/** * Delete all rows matching the given {@link Criterion} * * @param modelClass model class for the table to delete from * @param where the Criterion to match. Note: passing null will delete all rows! * @return the number of deleted rows */ public int deleteWhere(Class<? extends TableModel> modelClass, Criterion where) { Table table = getTable(modelClass); Delete delete = Delete.from(table); if (where != null) { delete.where(where); } int rowsUpdated = deleteInternal(delete); if (rowsUpdated > 0) { notifyForTable(DataChangedNotifier.DBOperation.DELETE, null, table, TableModel.NO_ID); } return rowsUpdated; }
/** * Delete the row with the given row ID * * @param modelClass the model class corresponding to the table to delete from * @param id the row ID of the record * @return true if delete was successful */ public boolean delete(Class<? extends TableModel> modelClass, long id) { Table table = getTable(modelClass); int rowsUpdated = deleteInternal(Delete.from(table).where(table.getRowIdProperty().eq(id))); if (rowsUpdated > 0) { notifyForTable(DataChangedNotifier.DBOperation.DELETE, null, table, id); } return rowsUpdated > 0; }
@Override public void run() { database.delete(Delete.from(TestModel.TABLE).where(TestModel.LAST_NAME.like("Bos%"))); } };
public void testMissingTriggerEventThrowsIllegalStateException() { Delete delete = Delete.from(TestModel.TABLE).where(TestModel.IS_HAPPY.isFalse()); final Trigger trigger = Trigger.after("trigger").when(TestModel.IS_HAPPY.isFalse()) .perform(delete); testThrowsException(new Runnable() { public void run() { trigger.compile(database.getCompileContext()); } }, IllegalStateException.class); }
public void testDeleteAll() { // check preconditions int numRows = database.countAll(TestModel.class); assertTrue(numRows > 0); // delete from testModels Delete delete = Delete.from(TestModel.TABLE); CompiledStatement compiled = delete.compile(database.getCompileContext()); verifyCompiledSqlArgs(compiled, 0); assertEquals(numRows, database.delete(delete)); numRows = database.countAll(TestModel.class); assertEquals(0, numRows); } }
public void testDeleteWhere() { Criterion criterion = TestModel.LUCKY_NUMBER.lte(0); // check preconditions TestModel shouldBeFound = database.fetchByCriterion(TestModel.class, criterion, TestModel.PROPERTIES); assertNotNull(shouldBeFound); // delete from testModels where testModels.luckyNumber <= 0; Delete delete = Delete.from(TestModel.TABLE).where(criterion); CompiledStatement compiled = delete.compile(database.getCompileContext()); verifyCompiledSqlArgs(compiled, 1, 0); assertEquals(1, database.delete(delete)); int numRows = database.countAll(TestModel.class); assertEquals(3, numRows); TestModel shouldNotBeFound = database.fetchByCriterion(TestModel.class, criterion, TestModel.PROPERTIES); assertNull(shouldNotBeFound); }
/** * Delete all rows matching the given {@link Criterion} * * @param modelClass model class for the table to delete from * @param where the Criterion to match. Note: passing null will delete all rows! * @return the number of deleted rows */ public int deleteWhere(Class<? extends TableModel> modelClass, Criterion where) { Table table = getTable(modelClass); Delete delete = Delete.from(table); if (where != null) { delete.where(where); } int rowsUpdated = deleteInternal(delete); if (rowsUpdated > 0) { notifyForTable(DataChangedNotifier.DBOperation.DELETE, null, table, TableModel.NO_ID); } return rowsUpdated; }
/** * Delete the row with the given row ID * * @param modelClass the model class corresponding to the table to delete from * @param id the row ID of the record * @return true if delete was successful */ public boolean delete(Class<? extends TableModel> modelClass, long id) { Table table = getTable(modelClass); int rowsUpdated = deleteInternal(Delete.from(table).where(table.getRowIdProperty().eq(id))); if (rowsUpdated > 0) { notifyForTable(DataChangedNotifier.DBOperation.DELETE, null, table, id); } return rowsUpdated > 0; }
.perform(update); Delete delete = Delete.from(TriggerTester.TABLE) .where(TriggerTester.ID.eq(Trigger.oldValueOf(TestViewModel.TEST_MODEL_ID))); Trigger deleteInsteadOf = Trigger.insteadOf("view_delete").deleteOn(TestViewModel.VIEW) assertEquals(ename2, triggerValue.getStr2()); database.delete(Delete.from(TestViewModel.VIEW)); assertEquals(0, database.countAll(TriggerTester.class));