/** * @return true if this model has been persisted to the database */ public boolean isSaved() { return getRowId() != NO_ID; }
void bindValuesForInsert(Table table, ISQLitePreparedStatement preparedInsert) { LongProperty rowidProperty = getRowIdProperty(); Property<?>[] allProperties = table.getProperties(); ModelAndIndex modelAndIndex = new ModelAndIndex(this); for (Property<?> property : allProperties) { if (property == rowidProperty) { long rowid = getRowId(); if (rowid == TableModel.NO_ID) { preparedInsert.bindNull(modelAndIndex.index); } else { preparedInsert.bindLong(modelAndIndex.index, rowid); } } else { property.accept(valueBindingVisitor, preparedInsert, modelAndIndex); } modelAndIndex.index++; } }
void bindValuesForInsert(Table table, ISQLitePreparedStatement preparedInsert) { LongProperty rowidProperty = getRowIdProperty(); Property<?>[] allProperties = table.getProperties(); ModelAndIndex modelAndIndex = new ModelAndIndex(this); for (Property<?> property : allProperties) { if (property == rowidProperty) { long rowid = getRowId(); if (rowid == TableModel.NO_ID) { preparedInsert.bindNull(modelAndIndex.index); } else { preparedInsert.bindLong(modelAndIndex.index, rowid); } } else { property.accept(valueBindingVisitor, preparedInsert, modelAndIndex); } modelAndIndex.index++; } }
/** * Deprecated alias for {@link #getRowId()} */ @Deprecated public long getId() { return getRowId(); }
/** * 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; }
/** * @return true if this model has been persisted to the database */ public boolean isSaved() { return getRowId() != NO_ID; }
/** * Deprecated alias for {@link #getRowId()} */ @Deprecated public long getId() { return getRowId(); }
/** * 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; }