/** * Deprecated alias for {@link #getRowIdProperty()} */ @Deprecated public LongProperty getIdProperty() { return getRowIdProperty(); } }
protected <TYPE extends TableModel> SquidCursor<TYPE> fetchItemById(Class<TYPE> modelClass, long id, Property<?>... properties) { Table table = getTable(modelClass); return fetchFirstItem(modelClass, table.getRowIdProperty().eq(id), properties); }
/** * 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; }
/** * Same as {@link #updateRow(TableModel)} with the ability to specify a ConflictAlgorithm for handling constraint * violations * * @param item the model to save * @param conflictAlgorithm the conflict algorithm to use * @return true if success, false otherwise */ protected final boolean updateRow(TableModel item, TableStatement.ConflictAlgorithm conflictAlgorithm) { if (!item.isModified()) { // nothing changed return true; } if (!item.isSaved()) { return false; } Class<? extends TableModel> modelClass = item.getClass(); Table table = getTable(modelClass); Update update = Update.table(table).fromTemplate(item).where(table.getRowIdProperty().eq(item.getRowId())); if (conflictAlgorithm != null) { update.onConflict(conflictAlgorithm); } boolean result = updateInternal(update) > 0; if (result) { notifyForTable(DataChangedNotifier.DBOperation.UPDATE, item, table, item.getRowId()); item.markSaved(); } return result; }
public void testPrimaryKeyModelsWithRowId() { assertNotNull(TestMultiColumnKey.ROWID); // Really just asserting at compile time that this exists assertNotNull(TestNonIntegerPrimaryKey.ROWID); // Really just asserting at compile time that this exists assertEquals(TestMultiColumnKey.TABLE.getRowIdProperty(), TestMultiColumnKey.ROWID); assertEquals(TestMultiColumnKey.PROPERTIES[0], TestMultiColumnKey.ROWID); assertEquals(TestNonIntegerPrimaryKey.TABLE.getRowIdProperty(), TestNonIntegerPrimaryKey.ROWID); assertEquals(TestNonIntegerPrimaryKey.PROPERTIES[0], TestNonIntegerPrimaryKey.ROWID); }
/** * Deprecated alias for {@link #getRowIdProperty()} */ @Deprecated public LongProperty getIdProperty() { return getRowIdProperty(); } }
TableModelName expectedTableModelName = new TableModelName(modelClass, "testModelAlias"); if (testModelAlias instanceof Table) { LongProperty testModelAliasId = ((Table) testModelAlias).getRowIdProperty(); String idName = testModelAlias instanceof VirtualTable ? "rowid" : "_id"; assertEquals("testModelAlias." + idName, testModelAliasId.getQualifiedExpression());
protected <TYPE extends TableModel> SquidCursor<TYPE> fetchItemById(Class<TYPE> modelClass, long id, Property<?>... properties) { Table table = getTable(modelClass); return fetchFirstItem(modelClass, table.getRowIdProperty().eq(id), properties); }
/** * 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; }
/** * Same as {@link #updateRow(TableModel)} with the ability to specify a ConflictAlgorithm for handling constraint * violations * * @param item the model to save * @param conflictAlgorithm the conflict algorithm to use * @return true if success, false otherwise */ protected final boolean updateRow(TableModel item, TableStatement.ConflictAlgorithm conflictAlgorithm) { if (!item.isModified()) { // nothing changed return true; } if (!item.isSaved()) { return false; } Class<? extends TableModel> modelClass = item.getClass(); Table table = getTable(modelClass); Update update = Update.table(table).fromTemplate(item).where(table.getRowIdProperty().eq(item.getRowId())); if (conflictAlgorithm != null) { update.onConflict(conflictAlgorithm); } boolean result = updateInternal(update) > 0; if (result) { notifyForTable(DataChangedNotifier.DBOperation.UPDATE, item, table, item.getRowId()); item.markSaved(); } return result; }