@SuppressWarnings("unchecked") private /* non-final */ Condition equal(Field<?>[] pk, T id) { if (pk.length == 1) { return ((Field<Object>) pk[0]).equal(pk[0].getDataType().convert(id)); } // [#2573] Composite key T types are of type Record[N] else { return row(pk).equal((Record) id); } }
@SuppressWarnings("unchecked") private /* non-final */ Condition equal(Field<?>[] pk, Collection<T> ids) { if (pk.length == 1) { if (ids.size() == 1) { return equal(pk, ids.iterator().next()); } else { return ((Field<Object>) pk[0]).in(pk[0].getDataType().convert(ids)); } } // [#2573] Composite key T types are of type Record[N] else { return row(pk).in(ids.toArray(EMPTY_RECORD)); } }
private final QueryPartInternal delegate(Configuration configuration) { // These casts are safe for RowImpl RowN r = (RowN) row; RowN min = (RowN) minValue; RowN max = (RowN) maxValue; // These dialects don't support the SYMMETRIC keyword at all if (symmetric && NO_SUPPORT_SYMMETRIC.contains(configuration.family())) { return not ? (QueryPartInternal) r.notBetween(min, max).and(r.notBetween(max, min)) : (QueryPartInternal) r.between(min, max).or(r.between(max, min)); } // These dialects either don't support row value expressions, or they // Can't handle row value expressions with the BETWEEN predicate else if (row.size() > 1 && EMULATE_BETWEEN.contains(configuration.family())) { Condition result = r.ge(min).and(r.le(max)); if (not) result = result.not(); return (QueryPartInternal) result; } else { return new Native(); } }
switch (comparator) { case GREATER: condition = ((RowN) left).gt(row(fields)); break; condition = ((RowN) left).ge(row(fields)); break; condition = ((RowN) left).lt(row(fields)); break; condition = ((RowN) left).le(row(fields)); break; case NOT_EQUALS: default: condition = ((RowN) left).eq(row(fields)); break;
? left instanceof Field ? ((Field) left).compare(comp, DSL.all(parseSelect(ctx, 1))) : ((RowN) left).compare(comp, DSL.all(parseSelect(ctx, ((RowN) left).size()))) : any ? left instanceof Field ? ((Field) left).compare(comp, DSL.any(parseSelect(ctx, 1))) : ((RowN) left).compare(comp, DSL.any(parseSelect(ctx, ((RowN) left).size()))) : left instanceof Field ? ((Field) left).compare(comp, toField(ctx, parseConcat(ctx, null))) : ((RowN) left).compare(comp, parseRow(ctx, ((RowN) left).size(), true)); ? left instanceof Field ? ((Field) left).isNotNull() : ((RowN) left).isNotNull() : left instanceof Field ? ((Field) left).isNull() : ((RowN) left).isNotNull(); RowN right = parseRow(ctx, ((RowN) left).size(), true); return not ? ((RowN) left).isNotDistinctFrom(right) : ((RowN) left).isDistinctFrom(right); ? left instanceof Field ? ((Field) left).notIn(parseSelect(ctx, 1)) : ((RowN) left).notIn(parseSelect(ctx, ((RowN) left).size())) : left instanceof Field ? ((Field) left).in(parseSelect(ctx, 1)) : ((RowN) left).in(parseSelect(ctx, ((RowN) left).size())); else result = not
private static final RowN parseTuple(ParserContext ctx, Integer degree, boolean allowDoubleParens) { parse(ctx, '('); List<? extends FieldOrRow> fieldsOrRows; if (allowDoubleParens) fieldsOrRows = parseFieldsOrRows(ctx); else fieldsOrRows = parseFields(ctx); RowN row; if (fieldsOrRows.size() == 0) row = row(); else if (fieldsOrRows.get(0) instanceof Field) row = row(fieldsOrRows); else if (fieldsOrRows.size() == 1) row = (RowN) fieldsOrRows.get(0); else throw ctx.exception("Unsupported row size"); if (degree != null && row.size() != degree) throw ctx.exception("Expected row of degree: " + degree + ". Got: " + row.size()); parse(ctx, ')'); return row; }
switch (comparator) { case GREATER: condition = ((RowN) left).gt(row(fields)); break; condition = ((RowN) left).ge(row(fields)); break; condition = ((RowN) left).lt(row(fields)); break; condition = ((RowN) left).le(row(fields)); break; case NOT_EQUALS: default: condition = ((RowN) left).eq(row(fields)); break;
public static Table<Record> values(RowN... rows) { Values.assertNotEmpty(rows); int size = rows[0].size();
private final QueryPartInternal delegate(Configuration configuration) { // These casts are safe for RowImpl RowN r = (RowN) row; RowN min = (RowN) minValue; RowN max = (RowN) maxValue; // These dialects don't support the SYMMETRIC keyword at all if (symmetric && asList(CUBRID, DERBY, FIREBIRD, H2, MARIADB, MYSQL, SQLITE).contains(configuration.dialect().family())) { if (not) { return (QueryPartInternal) r.notBetween(min, max).and(r.notBetween(max, min)); } else { return (QueryPartInternal) r.between(min, max).or(r.between(max, min)); } } // These dialects either don't support row value expressions, or they // Can't handle row value expressions with the BETWEEN predicate else if (row.size() > 1 && asList(CUBRID, DERBY, FIREBIRD, MARIADB, MYSQL, SQLITE).contains(configuration.dialect().family())) { Condition result = r.ge(min).and(r.le(max)); if (not) { result = result.not(); } return (QueryPartInternal) result; } else { return new Native(); } }
@SuppressWarnings("unchecked") protected Condition equalKeys(Collection<T> ids){ UniqueKey<?> uk = getTable().getPrimaryKey(); Objects.requireNonNull(uk,()->"No primary key"); /** * Copied from jOOQs DAOImpl#equal-method */ TableField<? extends Record, ?>[] pk = uk.getFieldsArray(); Condition condition; if (pk.length == 1) { if (ids.size() == 1) { condition = equalKey(ids.iterator().next()); }else { condition = pk[0].in(pk[0].getDataType().convert(ids)); } }else { condition = row(pk).in(ids.toArray(new Record[ids.size()])); } return condition; }
@SuppressWarnings("unchecked") public static <R extends UpdatableRecord<R>,T,F> F applyConditionally(T id, Table<R> table, Function<Condition, F> function){ UniqueKey<?> uk = table.getPrimaryKey(); Objects.requireNonNull(uk,()->"No primary key"); /** * Copied from jOOQs DAOImpl#equal-method */ TableField<? extends Record, ?>[] pk = uk.getFieldsArray(); Condition condition; if (pk.length == 1) { condition = ((Field<Object>) pk[0]).equal(pk[0].getDataType().convert(id)); } else { condition = row(pk).equal((Record) id); } return function.apply(condition); }
int size = rows[0].size();
@SuppressWarnings("unchecked") protected Condition equalKeys(Collection<T> ids){ UniqueKey<?> uk = getTable().getPrimaryKey(); Objects.requireNonNull(uk,()->"No primary key"); /** * Copied from jOOQs DAOImpl#equal-method */ TableField<? extends Record, ?>[] pk = uk.getFieldsArray(); Condition condition; if (pk.length == 1) { if (ids.size() == 1) { condition = equalKey(ids.iterator().next()); }else { condition = pk[0].in(pk[0].getDataType().convert(ids)); } }else { condition = row(pk).in(ids.toArray(new Record[ids.size()])); } return condition; }
@SuppressWarnings("unchecked") protected Condition equalKey(T id){ UniqueKey<?> uk = getTable().getPrimaryKey(); Objects.requireNonNull(uk,()->"No primary key"); /** * Copied from jOOQs DAOImpl#equal-method */ TableField<? extends Record, ?>[] pk = uk.getFieldsArray(); Condition condition; if (pk.length == 1) { condition = ((Field<Object>) pk[0]).equal(pk[0].getDataType().convert(id)); } else { condition = row(pk).equal((Record) id); } return condition; }
/** * Do the actual fetching */ @SuppressWarnings("unchecked") private static <R1 extends Record, R2 extends Record> Result<R1> fetch( Collection<? extends R2> records, Table<R1> table, TableField<R1, ?>[] fields1, TableField<R2, ?>[] fields2) { // Use regular predicates if (fields1.length == 1) { return extractDSLContext(records) .selectFrom(table) .where(((Field<Object>) fields1[0]).in(extractValues(records, fields2[0]))) .fetch(); } // Use row value expressions else { return extractDSLContext(records) .selectFrom(table) .where(row(fields1).in(extractRows(records, fields2))) .fetch(); } }
@SuppressWarnings("unchecked") protected Condition equalKey(T id){ UniqueKey<?> uk = getTable().getPrimaryKey(); Objects.requireNonNull(uk,()->"No primary key"); /** * Copied from jOOQs DAOImpl#equal-method */ TableField<? extends Record, ?>[] pk = uk.getFieldsArray(); Condition condition; if (pk.length == 1) { condition = ((Field<Object>) pk[0]).equal(pk[0].getDataType().convert(id)); } else { condition = row(pk).equal((Record) id); } return condition; }
/** * Do the actual fetching */ @SuppressWarnings("unchecked") private static <R1 extends Record, R2 extends Record> Result<R1> fetch( Collection<? extends R2> records, Table<R1> table, TableField<R1, ?>[] fields1, TableField<R2, ?>[] fields2) { // Use regular predicates if (fields1.length == 1) { return extractDSLContext(records) .selectFrom(table) .where(((Field<Object>) fields1[0]).in(extractValues(records, fields2[0]))) .fetch(); } // Use row value expressions else { return extractDSLContext(records) .selectFrom(table) .where(row(fields1).in(extractRows(records, fields2))) .fetch(); } }