@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; }
@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; }
@Override public int update(Field<?>... storeFields) { return storeUpdate(storeFields, getPrimaryKey().getFieldsArray()); }
@Override public final int update() { return storeUpdate(getPrimaryKey().getFieldsArray()); }
private final Collection<Field<?>> getReturning() { Collection<Field<?>> result = new LinkedHashSet<Field<?>>(); Identity<R, ?> identity = getTable().getIdentity(); if (identity != null) { result.add(identity.getField()); } result.addAll(getPrimaryKey().getFields()); return result; }
@Override @SuppressWarnings({ "rawtypes", "unchecked" }) public Record key() { RecordImpl result = new RecordImpl(getPrimaryKey().getFields()); result.setValues(result.fields.fields.fields, this); return result; }
@Override @SuppressWarnings({ "rawtypes", "unchecked" }) public Record key() { RecordImpl result = new RecordImpl(getPrimaryKey().getFields()); result.setValues(result.fields.fields.fields, this); return result; }
private final int store0(Field<?>[] storeFields) { TableField<R, ?>[] keys = getPrimaryKey().getFieldsArray(); boolean executeUpdate = false; // [#2764] If primary key values are allowed to be changed, // inserting is only possible without prior loading of pk values if (updatablePrimaryKeys(settings(this))) { executeUpdate = fetched; } else { for (TableField<R, ?> field : keys) { // If any primary key value is null or changed if (changed(field) || // [#3237] or if a NOT NULL primary key value is null, then execute an INSERT (field.getDataType().nullable() == false && get(field) == null)) { executeUpdate = false; break; } // Otherwise, updates are possible executeUpdate = true; } } int result = 0; if (executeUpdate) { result = storeUpdate(storeFields, keys); } else { result = storeInsert(storeFields); } return result; }
private final int store0() { TableField<R, ?>[] keys = getPrimaryKey().getFieldsArray(); boolean executeUpdate = false;
private final int delete0() { TableField<R, ?>[] keys = getPrimaryKey().getFieldsArray(); try { DeleteQuery<R> delete1 = create().deleteQuery(getTable()); Utils.addConditions(delete1, this, keys); if (isExecuteWithOptimisticLocking()) { // [#1596] Add additional conditions for version and/or timestamp columns if (isTimestampOrVersionAvailable()) { addConditionForVersionAndTimestamp(delete1); } // [#1547] Try fetching the Record again first, and compare this // Record's original values with the ones in the database else { checkIfChanged(keys); } } int result = delete1.execute(); checkIfChanged(result, null, null); return result; } // [#673] If store() is called after delete(), a new INSERT should // be executed and the record should be recreated finally { changed(true); } }
@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."); } }
private final int delete0() { TableField<R, ?>[] keys = getPrimaryKey().getFieldsArray(); try { DeleteQuery<R> delete1 = create().deleteQuery(getTable()); Tools.addConditions(delete1, this, keys); if (isExecuteWithOptimisticLocking()) { // [#1596] Add additional conditions for version and/or timestamp columns if (isTimestampOrVersionAvailable()) { addConditionForVersionAndTimestamp(delete1); } // [#1547] Try fetching the Record again first, and compare this // Record's original values with the ones in the database // [#5384] Do this only if the exclusion flag for unversioned records is off else if (isExecuteWithOptimisticLockingIncludeUnversioned()) { checkIfChanged(keys); } } int result = delete1.execute(); checkIfChanged(result, null, null); return result; } // [#673] [#3363] If store() is called after delete(), a new INSERT should // be executed and the record should be recreated finally { changed(true); fetched = false; } }
@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."); } }