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(ASE, CUBRID, DB2, DERBY, FIREBIRD, H2, MYSQL, ORACLE, SQLITE, SQLSERVER, SYBASE) .contains(configuration.dialect())) { 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, MYSQL, ORACLE, SQLITE, SQLSERVER, SYBASE) .contains(configuration.dialect())) { Condition result = r.ge(min).and(r.le(max)); if (not) { result = result.not(); } return (QueryPartInternal) result; } else { return new Native(); } }
private final QueryPartInternal delegate(Configuration ctx) { if (query != null) { return (QueryPartInternal) query; } else { switch (ctx.dialect()) { // [#869] Postgres supports this syntax natively case POSTGRES: { return (QueryPartInternal) array; } // [#869] H2 and HSQLDB can simulate this syntax by unnesting // the array in a subselect case H2: case HSQLDB: // [#1048] All other dialects simulate unnesting of arrays using // UNION ALL-connected subselects default: { return (QueryPartInternal) create(ctx).select().from(table(array)); } } } }
@Override final Field<BigDecimal> getFunction0(Configuration configuration) { switch (configuration.dialect().family()) { case ASE: case CUBRID: case HSQLDB: case INGRES: case MARIADB: case MYSQL: case POSTGRES: case SQLSERVER: case SYBASE: return DSL.exp(argument.mul(two())).sub(one()).div(DSL.exp(argument.mul(two())).add(one())); default: return function("tanh", SQLDataType.NUMERIC, argument); } }
@SuppressWarnings("unchecked") @Override final Field<T> getFunction0(Configuration configuration) { // In any dialect, a single argument is always the greatest if (getArguments().length == 1) { return (Field<T>) getArguments()[0]; } switch (configuration.dialect()) { // This implementation has O(2^n) complexity. Better implementations // are very welcome // [#1049] TODO Fix this! case ASE: case DERBY: case SQLSERVER: case SYBASE: { Field<T> first = (Field<T>) getArguments()[0]; Field<T> other = (Field<T>) getArguments()[1]; if (getArguments().length > 2) { Field<?>[] remaining = new Field[getArguments().length - 2]; System.arraycopy(getArguments(), 2, remaining, 0, remaining.length); return DSL.decode() .when(first.greaterThan(other), DSL.greatest(first, remaining)) .otherwise(DSL.greatest(other, remaining)); } else { return DSL.decode().when(first.greaterThan(other), first).otherwise(other); } } case FIREBIRD: return function("maxvalue", getDataType(), getArguments()); case SQLITE: return function("max", getDataType(), getArguments()); default: return function("greatest", getDataType(), getArguments()); } }
private Table<?> pivot(Configuration configuration) { switch (configuration.dialect()) { /* [pro] xx xx xxxxxx xxx xxxxxx xxxxxxx xxx xxx xxxxx xxxxxx xxxx xxxxxxx xxxx xxxxxxxxxx xxxx xxxxxxxxxx x xxxxxx xxx xxxxxxxxxxxxxxxxxxx x xx [/pro] */ // Some other dialects can simulate it. This implementation is // EXPERIMENTAL and not officially supported default: { return new DefaultPivotTable(); } } }
@Override final Field<String> getFunction0(Configuration configuration) { Field<?>[] args = getArguments(); // [#861] Most dialects don't ship with a two-argument replace function: switch (configuration.dialect().family()) { case ASE: { if (args.length == 2) { return function("str_replace", VARCHAR, args[0], args[1], val(null)); } else { return function("str_replace", VARCHAR, args); } } case DB2: case FIREBIRD: case HSQLDB: case INGRES: case MARIADB: case MYSQL: case POSTGRES: case SQLITE: case SQLSERVER: case SYBASE: { if (args.length == 2) { return function("replace", VARCHAR, args[0], args[1], val("")); } else { return function("replace", VARCHAR, args); } } default: { return function("replace", VARCHAR, args); } } }
@Override public SQLDialect dialect() { return delegate.dialect(); }