@Override public Criterion negate() { Operator contrary = operator.getContrary(); if (contrary != null) { return constructNegatedCriterion(contrary); } return super.negate(); }
/** * Add a left {@link Join} to this query using the USING clause * * @param table the table to join on * @param usingColumns one or more columns to use for the "using" clause * @return this Query object, to allow chaining method calls */ public Query leftJoin(SqlTable<?> table, Property<?>... usingColumns) { return join(Join.left(table, usingColumns)); }
public CompiledStatement resolveToCompiledStatement() { String cacheKey = hasCollectionArgs() ? getCacheKey() : null; int totalArgSize = calculateArgsSizeWithCollectionArgs(); boolean largeArgMode = totalArgSize > SqlStatement.MAX_VARIABLE_NUMBER; return new CompiledStatement(resolveSqlString(cacheKey, largeArgMode), resolveSqlArguments(cacheKey, totalArgSize, largeArgMode), needsValidation); }
/** * Construct a new Select statement that queries all the {@link Field}s of the given subquery * * @param subquery the inner Query object * @param subqueryAlias the name to alias the subquery * @return a new Query object */ public static Query fromSubquery(Query subquery, String subqueryAlias) { SubqueryTable table = subquery.as(subqueryAlias); return Query.select(table.qualifiedFields()).from(table); }
/** * Construct an IntegerProperty represented by the expression "COUNT(field)" or "COUNT(DISTINCT field)" * * @param field the field to count * @param distinct whether to count distinct values only or not */ public static IntegerProperty countProperty(Field<?> field, boolean distinct) { Function<Integer> function = distinct ? Function.countDistinct(field) : Function.count(field); return fromFunction(function, "count"); }
/** * Add an inner {@link Join} to this query using the ON clause * * @param table the table to join on * @param onCriterions one or more criterions to use for the "on" clause * @return this Query object, to allow chaining method calls */ public Query innerJoin(SqlTable<?> table, Criterion... onCriterions) { return join(Join.inner(table, onCriterions)); }
/** * Construct an IntegerProperty represented by the expression "COUNT(1)" */ public static IntegerProperty countProperty() { return fromFunction(Function.count(), "count"); }
@Override public final synchronized CompiledStatement compile(CompileContext compileContext) { if (compiledArgumentResolver == null) { SqlBuilder builder = buildSql(compileContext, true, false); compiledArgumentResolver = new CompiledArgumentResolver(builder); } return compiledArgumentResolver.resolveToCompiledStatement(); }
/** * @return the expression for the function as it would be compiled with the given CompileContext */ public String getExpression(CompileContext forCompileContext) { SqlBuilder builder = new SqlBuilder(forCompileContext, false); appendQualifiedExpression(builder, false); return builder.getSqlString(); }
/** * Construct a StringProperty from a literal value and with the given alias, e.g. "'hello' AS greeting" * * @param literal the literal value * @param selectAs the alias to use. May be null. */ public static StringProperty literal(String literal, String selectAs) { return new StringProperty(null, SqlUtils.sanitizeStringAsLiteral(literal), selectAs, null); }
protected final SqlBuilder buildSql(CompileContext compileContext, boolean withBoundArguments, boolean forSqlValidation) { SqlBuilder builder = new SqlBuilder(compileContext, withBoundArguments); appendToSqlBuilder(builder, forSqlValidation); return builder; }
/** * @return a {@link Criterion} that the field must be equal to the given string, ignoring case. This will only work * for ASCII characters. */ public Criterion eqCaseInsensitive(String value) { if (value == null) { return isNull(); } return new CaseInsensitiveEqualsCriterion(this, Operator.eq, value); }
/** * @return a {@link Criterion} that the field must not be equal to the given value */ public Criterion neq(Object value) { if (value == null) { return isNotNull(); } return new BinaryCriterion(this, Operator.neq, value); }
@Override protected String expressionForComparison() { if (function != null) { return function.expressionForComparison(); } return super.expressionForComparison(); }
/** * @return a {@link Criterion} that the field must be equal to the given value */ public Criterion eq(Object value) { if (value == null) { return isNull(); } return new BinaryCriterion(this, Operator.eq, value); }
/** * @return a {@link Criterion} that the field's value is in the result of the {@link Query}. If the query is null, * this is equivalent to 'IN ()', which will always be false. */ public Criterion in(Query query) { if (query == null) { return in((Collection<?>) null); } return new BinaryCriterion(this, Operator.in, query); }
private Object[] applyArgumentResolver(Object[] args) { ArgumentResolver resolver = compileContext.getArgumentResolver(); Object[] result = new Object[args.length]; for (int i = 0; i < args.length; i++) { result[i] = resolver.resolveArgument(args[i]); } return result; }
/** * Add a left {@link Join} to this query using the ON clause * * @param table the table to join on * @param onCriterions one or more criterions to use for the "on" clause * @return this Query object, to allow chaining method calls */ public Query leftJoin(SqlTable<?> table, Criterion... onCriterions) { return join(Join.left(table, onCriterions)); }
/** * Add an inner {@link Join} to this query using the USING clause * * @param table the table to join on * @param usingColumns one or more columns to use for the "using" clause * @return this Query object, to allow chaining method calls */ public Query innerJoin(SqlTable<?> table, Property<?>... usingColumns) { return join(Join.inner(table, usingColumns)); }