use of org.jooq.QueryPartInternal in project jOOQ by jOOQ.
the class RowInCondition method delegate.
private final QueryPartInternal delegate(Configuration configuration) {
if (asList(DERBY, FIREBIRD, SQLITE).contains(configuration.family())) {
List<Condition> conditions = new ArrayList<Condition>();
for (Row row : right) {
conditions.add(new RowCondition(left, row, EQUALS));
}
Condition result = DSL.or(conditions);
if (comparator == NOT_IN) {
result = result.not();
}
return (QueryPartInternal) result;
} else {
return new Native();
}
}
use of org.jooq.QueryPartInternal in project jOOQ by jOOQ.
the class QueryPartCollectionView method accept.
@Override
public /* non-final */
void accept(Context<?> ctx) {
BitSet rendersContent = new BitSet(size());
int i = 0;
for (T e : this) rendersContent.set(i++, ((QueryPartInternal) e).rendersContent(ctx));
int size = rendersContent.cardinality();
boolean format = ctx.format() && (size >= 2 && !isSimple(ctx) || size > 4);
boolean previousQualify = ctx.qualify();
boolean previousAlreadyIndented = TRUE.equals(ctx.data(DATA_LIST_ALREADY_INDENTED));
boolean indent = format && !previousAlreadyIndented;
if (previousAlreadyIndented)
ctx.data(DATA_LIST_ALREADY_INDENTED, false);
if (qualify != null)
ctx.qualify(qualify);
if (indent)
ctx.formatIndentStart();
if (ctx.separatorRequired())
if (format)
ctx.formatSeparator();
else
ctx.sql(' ');
// Some lists render different SQL when empty
if (size == 0) {
toSQLEmptyList(ctx);
} else {
int j = 0;
int k = 0;
T prev = null;
for (T part : this) {
try {
int j0 = j;
if (!rendersContent.get(j++))
continue;
if (mapper != null)
part = mapper.apply(part, j0);
if (k++ > 0) {
// [#3607] Procedures and functions are not separated by comma
if (!(prev instanceof SeparatedQueryPart && ((SeparatedQueryPart) prev).rendersSeparator()))
ctx.sql(separator);
if (format)
ctx.formatSeparator();
else
ctx.sql(' ');
} else if (indent)
ctx.formatNewLine();
if (indent) {
T t = part;
ctx.data(DATA_LIST_ALREADY_INDENTED, t instanceof QueryPartCollectionView && ((QueryPartCollectionView<?>) t).size() > 1, c -> acceptElement(c, t));
} else
acceptElement(ctx, part);
} finally {
prev = part;
}
}
}
if (indent)
ctx.formatIndentEnd().formatNewLine();
if (qualify != null)
ctx.qualify(previousQualify);
if (previousAlreadyIndented)
ctx.data(DATA_LIST_ALREADY_INDENTED, previousAlreadyIndented);
}
use of org.jooq.QueryPartInternal in project jOOQ by jOOQ.
the class AbstractContext method visit0.
// ------------------------------------------------------------------------
// XXX Context API
// ------------------------------------------------------------------------
private final C visit0(QueryPart part) {
if (part != null) {
QueryPartInternal internal = (QueryPartInternal) part;
// We're declaring fields, but "part" does not declare fields
if (declareFields() && !internal.declaresFields()) {
boolean aliases = declareAliases();
declareFields(false);
visit0(internal);
declareFields(true);
declareAliases(aliases);
} else // We're declaring tables, but "part" does not declare tables
if (declareTables() && !internal.declaresTables()) {
boolean aliases = declareAliases();
declareTables(false);
visit0(internal);
declareTables(true);
declareAliases(aliases);
} else // We're declaring windows, but "part" does not declare windows
if (declareWindows() && !internal.declaresWindows()) {
declareWindows(false);
visit0(internal);
declareWindows(true);
} else // We're declaring cte, but "part" does not declare cte
if (declareCTE() && !internal.declaresCTE()) {
declareCTE(false);
visit0(internal);
declareCTE(true);
} else if (!castModeOverride && castMode() != CastMode.DEFAULT && !internal.generatesCast()) {
CastMode previous = castMode();
castMode(CastMode.DEFAULT);
visit0(internal);
castMode(previous);
} else // We're not declaring, or "part" can declare
{
visit0(internal);
}
}
return (C) this;
}
use of org.jooq.QueryPartInternal 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();
}
}
use of org.jooq.QueryPartInternal in project jOOQ by jOOQ.
the class RowIsNull method delegate.
private final QueryPartInternal delegate(Configuration configuration) {
// Informix doesn't implement the RVE IS NULL predicate.
if (asList(CUBRID, DERBY, FIREBIRD, H2, HSQLDB, MARIADB, MYSQL, SQLITE).contains(configuration.family())) {
List<Condition> conditions = new ArrayList<Condition>();
for (Field<?> field : row.fields()) {
conditions.add(isNull ? field.isNull() : field.isNotNull());
}
Condition result = DSL.and(conditions);
return (QueryPartInternal) result;
} else {
return new Native();
}
}
Aggregations