/** * Add a {@link Criterion} to the HAVING clause of this query. Multiple calls will combine all the criterions with * AND. * * @param criterion the Criterion to add to the HAVING clause * @return this Query object, to allow chaining method calls */ public Query having(Criterion criterion) { if (criterion == null) { return this; } if (immutable) { return fork().having(criterion); } if (this.havings == null) { this.havings = new ArrayList<>(); } this.havings.add(criterion); invalidateCompileCache(); return this; }
/** * Set the {@link SqlTable table} this query selects from * * @param table the table to select from * @return this Query object, to allow chaining method calls */ public Query from(SqlTable<?> table) { if (immutable) { return fork().from(table); } if (this.table != table) { this.table = table; if (selectAllCache != null) { selectAllCache.clear(); } invalidateCompileCache(); } return this; }
/** * Add a {@link Criterion} to the WHERE clause of this query. Multiple calls will combine all the criterions with * AND. * * @param criterion the Criterion to add to the WHERE clause * @return this Query object, to allow chaining method calls */ public Query where(Criterion criterion) { if (criterion == null) { return this; } if (immutable) { return fork().where(criterion); } if (criterions == null) { criterions = new ArrayList<>(); } criterions.add(criterion); invalidateCompileCache(); return this; }
/** * Add more {@link Field Fields} to be selected * * @param fields the additional Fields to be selected * @return this Query object, to allow chaining method calls */ public Query selectMore(List<Field<?>> fields) { if (immutable) { return fork().selectMore(fields); } if (!isEmpty(fields)) { if (this.fields == null) { this.fields = new ArrayList<>(fields); } else { this.fields.addAll(fields); } if (selectAllCache != null) { selectAllCache.clear(); } invalidateCompileCache(); } return this; }
/** * Add a {@link Join} to this query * * @param joins one or more joins to apply to this query * @return this Query object, to allow chaining method calls */ public Query join(Join... joins) { if (immutable) { return fork().join(joins); } if (this.joins == null) { this.joins = new ArrayList<>(); } SquidUtilities.addAll(this.joins, joins); if (selectAllCache != null) { selectAllCache.clear(); } invalidateCompileCache(); return this; }
/** * Add a GROUP BY clause (or an additional grouping term) to this query * * @param fields one or more Fields to group on * @return this Query object, to allow chaining method calls */ public Query groupBy(Field<?>... fields) { if (immutable) { return fork().groupBy(fields); } if (this.groupByFields == null) { this.groupByFields = new ArrayList<>(); } SquidUtilities.addAll(this.groupByFields, fields); invalidateCompileCache(); return this; }
/** * Add an ORDER BY clause (or an additional ordering term) to this query * * @param orders one or more ordering terms * @return this Query object, to allow chaining method calls */ public Query orderBy(Order... orders) { if (immutable) { return fork().orderBy(orders); } if (this.orders == null) { this.orders = new ArrayList<>(); } SquidUtilities.addAll(this.orders, orders); invalidateCompileCache(); return this; }
/** * Form a compound select with the given query using the INTERSECT operator * * @param query a Query object to append with the INTERSECT operator * @return this Query object, to allow chaining method calls * @see <a href="http://www.sqlite.org/lang_select.html#compound">http://www.sqlite.org/lang_select.html#compound</a> */ public Query intersect(Query query) { if (immutable) { return fork().intersect(query); } addCompoundSelect(CompoundSelect.intersect(query)); return this; }
/** * Form a compound select with the given query using the EXCEPT operator * * @param query a Query object to append with the EXCEPT operator * @return this Query object, to allow chaining method calls * @see <a href="http://www.sqlite.org/lang_select.html#compound">http://www.sqlite.org/lang_select.html#compound</a> */ public Query except(Query query) { if (immutable) { return fork().except(query); } addCompoundSelect(CompoundSelect.except(query)); return this; }
/** * Form a compound select with the given query using the UNION operator * * @param query a Query object to append with the UNION operator * @return this Query object, to allow chaining method calls * @see <a href="http://www.sqlite.org/lang_select.html#compound">http://www.sqlite.org/lang_select.html#compound</a> */ public Query union(Query query) { if (immutable) { return fork().union(query); } addCompoundSelect(CompoundSelect.union(query)); return this; }
/** * Form a compound select with the given query using the UNION ALL operator * * @param query a Query object to append with the UNION ALL operator * @return this Query object, to allow chaining method calls * @see <a href="http://www.sqlite.org/lang_select.html#compound">http://www.sqlite.org/lang_select.html#compound</a> */ public Query unionAll(Query query) { if (immutable) { return fork().unionAll(query); } addCompoundSelect(CompoundSelect.unionAll(query)); return this; }
/** * Add more {@link Field Fields} to be selected * * @param fields the additional Fields to be selected * @return this Query object, to allow chaining method calls */ public Query selectMore(Field<?>... fields) { if (immutable) { return fork().selectMore(fields); } if (!isEmpty(fields)) { if (this.fields == null) { this.fields = new ArrayList<>(); } SquidUtilities.addAll(this.fields, fields); if (selectAllCache != null) { selectAllCache.clear(); } invalidateCompileCache(); } return this; }
/** * Set the limit of this statement as a SQL expression; e.g. a {@link Function} or the result of * {@link #asFunction()} to use a subquery. Use {@link #NO_LIMIT} to remove the limit. * * @param limit the maximum number of rows this query should return * @return this Query object, to allow chaining method calls */ public Query limit(Field<Integer> limit) { if (limit == null) { limit = NO_LIMIT; } if (immutable) { return fork().limit(limit); } if (!this.limit.equals(limit)) { this.limit = limit; invalidateCompileCache(); } return this; }
/** * Set the limit of this statement as a SQL expression; e.g. a {@link Function} or the result of * {@link #asFunction()} to use a subquery. Use {@link #NO_LIMIT} for limit to remove the limit. Use * {@link #NO_OFFSET} for offset to remove the offset. * * @param limit the maximum number of rows this query should return * @param offset the number of rows this query should skip * @return this Query object, to allow chaining method calls */ public Query limit(Field<Integer> limit, Field<Integer> offset) { if (limit == null) { limit = NO_LIMIT; } if (offset == null) { offset = NO_OFFSET; } if (immutable) { return fork().limit(limit, offset); } if (!this.limit.equals(limit) || !this.offset.equals(offset)) { this.limit = limit; this.offset = offset; invalidateCompileCache(); } return this; }
public void testFork() { Query base = Query.select().from(Employee.TABLE).limit(1); Query fork = base.fork().limit(2); base.limit(3); assertFalse(base == fork); assertEquals(Field.field("3"), base.getLimit()); assertEquals(Field.field("2"), fork.getLimit()); assertEquals(base.getTable(), fork.getTable()); }
/** * Add a GROUP BY clause (or an additional grouping term) to this query * * @param fields one or more Fields to group on * @return this Query object, to allow chaining method calls */ public Query groupBy(Field<?>... fields) { if (immutable) { return fork().groupBy(fields); } if (this.groupByFields == null) { this.groupByFields = new ArrayList<>(); } SquidUtilities.addAll(this.groupByFields, fields); invalidateCompileCache(); return this; }
/** * Form a compound select with the given query using the INTERSECT operator * * @param query a Query object to append with the INTERSECT operator * @return this Query object, to allow chaining method calls * @see <a href="http://www.sqlite.org/lang_select.html#compound">http://www.sqlite.org/lang_select.html#compound</a> */ public Query intersect(Query query) { if (immutable) { return fork().intersect(query); } addCompoundSelect(CompoundSelect.intersect(query)); return this; }
/** * Form a compound select with the given query using the EXCEPT operator * * @param query a Query object to append with the EXCEPT operator * @return this Query object, to allow chaining method calls * @see <a href="http://www.sqlite.org/lang_select.html#compound">http://www.sqlite.org/lang_select.html#compound</a> */ public Query except(Query query) { if (immutable) { return fork().except(query); } addCompoundSelect(CompoundSelect.except(query)); return this; }
/** * Form a compound select with the given query using the UNION operator * * @param query a Query object to append with the UNION operator * @return this Query object, to allow chaining method calls * @see <a href="http://www.sqlite.org/lang_select.html#compound">http://www.sqlite.org/lang_select.html#compound</a> */ public Query union(Query query) { if (immutable) { return fork().union(query); } addCompoundSelect(CompoundSelect.union(query)); return this; }
/** * Form a compound select with the given query using the UNION ALL operator * * @param query a Query object to append with the UNION ALL operator * @return this Query object, to allow chaining method calls * @see <a href="http://www.sqlite.org/lang_select.html#compound">http://www.sqlite.org/lang_select.html#compound</a> */ public Query unionAll(Query query) { if (immutable) { return fork().unionAll(query); } addCompoundSelect(CompoundSelect.unionAll(query)); return this; }