private final boolean isExecuteWithOptimisticLocking() { Configuration configuration = configuration(); // This can be null when the current record is detached return configuration != null ? TRUE.equals(configuration.settings().isExecuteWithOptimisticLocking()) : false; }
private final boolean isExecuteWithOptimisticLockingIncludeUnversioned() { Configuration configuration = configuration(); // This can be null when the current record is detached return configuration != null ? !TRUE.equals(configuration.settings().isExecuteWithOptimisticLockingExcludeUnversioned()) : true; }
private final boolean isExecuteWithOptimisticLocking() { Configuration configuration = configuration(); // This can be null when the current record is detached if (configuration != null) { return TRUE.equals(configuration.settings().isExecuteWithOptimisticLocking()); } return false; }
private final int storeUpdate(final Field<?>[] storeFields, final TableField<R, ?>[] keys) { final int[] result = new int[1]; delegate(configuration(), (Record) this, UPDATE) .operate(new RecordOperation<Record, RuntimeException>() { @Override public Record operate(Record record) throws RuntimeException { result[0] = storeUpdate0(storeFields, keys); return record; } }); return result[0]; }
private final int storeUpdate(final TableField<R, ?>[] keys) { final int[] result = new int[1]; delegate(configuration(), (Record) this, UPDATE) .operate(new RecordOperation<Record, RuntimeException>() { @Override public Record operate(Record record) throws RuntimeException { result[0] = storeUpdate0(keys); return record; } }); return result[0]; }
@Override public final int store(final Field<?>... storeFields) { final int[] result = new int[1]; delegate(configuration(), (Record) this, STORE) .operate(new RecordOperation<Record, RuntimeException>() { @Override public Record operate(Record record) throws RuntimeException { result[0] = store0(storeFields); return record; } }); return result[0]; }
private final int storeInsert() { final int[] result = new int[1]; delegate(configuration(), (Record) this, INSERT) .operate(new RecordOperation<Record, RuntimeException>() { @Override public Record operate(Record record) throws RuntimeException { result[0] = storeInsert0(); return record; } }); return result[0]; }
@Override public final int delete() { final int[] result = new int[1]; delegate(configuration(), (Record) this, DELETE) .operate(new RecordOperation<Record, RuntimeException>() { @Override public Record operate(Record record) throws RuntimeException { result[0] = delete0(); return record; } }); return result[0]; }
@Override public final int store() { final int[] result = new int[1]; delegate(configuration(), (Record) this, STORE) .operate(new RecordOperation<Record, RuntimeException>() { @Override public Record operate(Record record) throws RuntimeException { result[0] = store0(); return record; } }); return result[0]; }
@Override public final int delete() { final int[] result = new int[1]; delegate(configuration(), (Record) this, DELETE) .operate(new RecordOperation<Record, RuntimeException>() { @Override public Record operate(Record record) throws RuntimeException { result[0] = delete0(); return record; } }); return result[0]; }
@Override public final R copy() { return Utils.newRecord(getTable(), configuration()) .operate(new RecordOperation<R, RuntimeException>() { @Override public R operate(R copy) throws RuntimeException { // Copy all fields. This marks them all as isChanged, which is important List<TableField<R, ?>> key = getPrimaryKey().getFields(); for (Field<?> field : fields.fields.fields) { // Don't copy key values if (!key.contains(field)) { setValue(copy, field); } } return copy; } /** * Extracted method to ensure generic type safety. */ private final <T> void setValue(Record record, Field<T> field) { record.setValue(field, getValue(field)); } }); }
@Override public final R copy() { // [#3359] The "fetched" flag must be set to false to enforce INSERT statements on // subsequent store() calls - when Settings.updatablePrimaryKeys is set. return Tools.newRecord(false, getTable(), configuration()) .operate(new RecordOperation<R, RuntimeException>() { @Override public R operate(R copy) throws RuntimeException { // Copy all fields. This marks them all as isChanged, which is important List<TableField<R, ?>> key = getPrimaryKey().getFields(); for (Field<?> field : fields.fields.fields) { // Don't copy key values if (!key.contains(field)) { setValue(copy, field); } } return copy; } /** * Extracted method to ensure generic type safety. */ private final <T> void setValue(Record record, Field<T> field) { record.set(field, get(field)); } }); }
@Override public final void refresh(final Field<?>... refreshFields) { SelectQuery<Record> select = create().selectQuery(); select.addSelect(refreshFields); select.addFrom(getTable()); Tools.addConditions(select, this, getPrimaryKey().getFieldsArray()); if (select.execute() == 1) { final AbstractRecord source = (AbstractRecord) select.getResult().get(0); delegate(configuration(), (Record) this, REFRESH) .operate(new RecordOperation<Record, RuntimeException>() { @Override public Record operate(Record record) throws RuntimeException { setValues(refreshFields, source); return record; } }); } else { throw new NoDataFoundException("Exactly one row expected for refresh. Record does not exist in database."); } }
@Override public final void refresh(final Field<?>... f) { SelectQuery<Record> select = create().selectQuery(); select.addSelect(f); select.addFrom(getTable()); Utils.addConditions(select, this, getPrimaryKey().getFieldsArray()); if (select.execute() == 1) { final AbstractRecord source = (AbstractRecord) select.getResult().get(0); delegate(configuration(), (Record) this, REFRESH) .operate(new RecordOperation<Record, RuntimeException>() { @Override public Record operate(Record record) throws RuntimeException { setValues(f, source); return record; } }); } else { throw new InvalidResultException("Exactly one row expected for refresh. Record does not exist in database."); } }