use of org.jooq.Field in project jOOQ by jOOQ.
the class DAOImpl method records.
private /* non-final */
List<R> records(Collection<P> objects, boolean forUpdate) {
List<R> result = new ArrayList<R>();
Field<?>[] pk = pk();
for (P object : objects) {
// [#2536] Upon store(), insert(), update(), delete(), returned values in the record
// are copied back to the relevant POJO using the RecordListener SPI
DSLContext ctx = using(!FALSE.equals(configuration.settings().isReturnRecordToPojo()) ? configuration.derive(providers(configuration.recordListenerProviders(), object)) : configuration);
R record = ctx.newRecord(table, object);
if (forUpdate && pk != null)
for (Field<?> field : pk) record.changed(field, false);
Tools.resetChangedOnNotNull(record);
result.add(record);
}
return result;
}
use of org.jooq.Field in project jOOQ by jOOQ.
the class InformationSchemaExport method exportTable0.
private static final void exportTable0(Configuration configuration, InformationSchema result, Table<?> t, Set<Table<?>> includedTables) {
org.jooq.util.xml.jaxb.Table it = new org.jooq.util.xml.jaxb.Table();
if (!StringUtils.isBlank(t.getCatalog().getName()))
it.setTableCatalog(t.getCatalog().getName());
if (!StringUtils.isBlank(t.getSchema().getName()))
it.setTableSchema(t.getSchema().getName());
it.setTableName(t.getName());
result.getTables().add(it);
Field<?>[] fields = t.fields();
for (int i = 0; i < fields.length; i++) {
Field<?> f = fields[i];
Column ic = new Column();
if (!StringUtils.isBlank(t.getCatalog().getName()))
ic.setTableCatalog(t.getCatalog().getName());
if (!StringUtils.isBlank(t.getSchema().getName()))
ic.setTableSchema(t.getSchema().getName());
ic.setTableName(t.getName());
ic.setColumnName(f.getName());
ic.setDataType(f.getDataType().getTypeName(configuration));
if (f.getDataType().hasLength())
ic.setCharacterMaximumLength(f.getDataType().length());
if (f.getDataType().hasPrecision())
ic.setNumericPrecision(f.getDataType().precision());
if (f.getDataType().hasScale())
ic.setNumericScale(f.getDataType().scale());
ic.setColumnDefault(DSL.using(configuration).render(f.getDataType().defaultValue()));
ic.setIsNullable(f.getDataType().nullable());
ic.setOrdinalPosition(i + 1);
result.getColumns().add(ic);
}
for (UniqueKey<?> key : t.getKeys()) exportKey0(result, t, key, key.isPrimary() ? PRIMARY_KEY : UNIQUE);
for (ForeignKey<?, ?> fk : t.getReferences()) if (includedTables.contains(fk.getKey().getTable()))
exportKey0(result, t, fk, FOREIGN_KEY);
}
use of org.jooq.Field in project jOOQ by jOOQ.
the class AbstractRoutine method executeSelectFromPOSTGRES.
private final int executeSelectFromPOSTGRES() {
DSLContext create = create(configuration);
List<Field<?>> fields = new ArrayList<Field<?>>();
if (returnParameter != null)
fields.add(DSL.field(DSL.name(getName()), returnParameter.getDataType()));
for (Parameter<?> p : outParameters) fields.add(DSL.field(DSL.name(p.getName()), p.getDataType()));
Result<?> result = create.select(fields).from("{0}", asField()).fetch();
int i = 0;
if (returnParameter != null)
outValues.put(returnParameter, returnParameter.getDataType().convert(result.getValue(0, i++)));
for (Parameter<?> p : outParameters) outValues.put(p, p.getDataType().convert(result.getValue(0, i++)));
return 0;
}
use of org.jooq.Field in project jOOQ by jOOQ.
the class InsertQueryImpl method matchByPrimaryKey.
/**
* Produce a {@link Condition} that matches existing rows by the inserted or
* updated primary key values.
*/
@SuppressWarnings("unchecked")
private final Condition matchByPrimaryKey(FieldMapForInsert map) {
Condition condition = null;
for (Field<?> f : table.getPrimaryKey().getFields()) {
Field<Object> field = (Field<Object>) f;
Field<Object> value = (Field<Object>) map.get(field);
Condition other = field.equal(value);
condition = (condition == null) ? other : condition.and(other);
}
return condition;
}
use of org.jooq.Field in project jOOQ by jOOQ.
the class RowCondition method delegate.
private final QueryPartInternal delegate(Configuration configuration) {
SQLDialect dialect = configuration.dialect();
// Regular comparison predicate emulation
if (asList(EQUALS, NOT_EQUALS).contains(comparator) && asList(DERBY, FIREBIRD, SQLITE).contains(dialect.family())) {
List<Condition> conditions = new ArrayList<Condition>();
Field<?>[] leftFields = left.fields();
Field<?>[] rightFields = right.fields();
for (int i = 0; i < leftFields.length; i++) {
conditions.add(leftFields[i].equal((Field) rightFields[i]));
}
Condition result = DSL.and(conditions);
if (comparator == NOT_EQUALS) {
result = result.not();
}
return (QueryPartInternal) result;
} else // Ordering comparison predicate emulation
if (asList(GREATER, GREATER_OR_EQUAL, LESS, LESS_OR_EQUAL).contains(comparator) && asList(DERBY, CUBRID, FIREBIRD, SQLITE).contains(dialect.family())) {
// The order component of the comparator (stripping the equal component)
Comparator order = (comparator == GREATER) ? GREATER : (comparator == GREATER_OR_EQUAL) ? GREATER : (comparator == LESS) ? LESS : (comparator == LESS_OR_EQUAL) ? LESS : null;
// [#2658] The factored order component of the comparator (enforcing the equal component)
Comparator factoredOrder = (comparator == GREATER) ? GREATER_OR_EQUAL : (comparator == GREATER_OR_EQUAL) ? GREATER_OR_EQUAL : (comparator == LESS) ? LESS_OR_EQUAL : (comparator == LESS_OR_EQUAL) ? LESS_OR_EQUAL : null;
// Whether the comparator has an equal component
boolean equal = (comparator == GREATER_OR_EQUAL) || (comparator == LESS_OR_EQUAL);
// The following algorithm emulates the equivalency of these expressions:
// (A, B, C) > (X, Y, Z)
// (A > X) OR (A = X AND B > Y) OR (A = X AND B = Y AND C > Z)
List<Condition> outer = new ArrayList<Condition>();
Field<?>[] leftFields = left.fields();
Field<?>[] rightFields = right.fields();
for (int i = 0; i < leftFields.length; i++) {
List<Condition> inner = new ArrayList<Condition>();
for (int j = 0; j < i; j++) {
inner.add(leftFields[j].equal((Field) rightFields[j]));
}
inner.add(leftFields[i].compare(order, (Field) rightFields[i]));
outer.add(DSL.and(inner));
}
if (equal) {
outer.add(new RowCondition(left, right, Comparator.EQUALS));
}
Condition result = DSL.or(outer);
// (A >= X) AND ((A > X) OR (A = X AND B > Y) OR (A = X AND B = Y AND C > Z))
if (leftFields.length > 1) {
result = leftFields[0].compare(factoredOrder, (Field) rightFields[0]).and(result);
}
return (QueryPartInternal) result;
} else {
return new Native();
}
}
Aggregations