diff --git a/jOOQ/src/main/java/org/jooq/Table.java b/jOOQ/src/main/java/org/jooq/Table.java index 1e8d1ec897..be8355ec8f 100644 --- a/jOOQ/src/main/java/org/jooq/Table.java +++ b/jOOQ/src/main/java/org/jooq/Table.java @@ -606,6 +606,161 @@ public interface Table extends TableLike, Named { Table as(Table otherTable, BiFunction, ? super Integer, ? extends Field> aliasFunction); + // ------------------------------------------------------------------------- + // XXX: WHERE clauses on tables + // ------------------------------------------------------------------------- + + /** + * Add a WHERE clause to the table, connecting them with each + * other with {@link Operator#AND}. + *

+ * The resulting table acts like a derived table that projects all of this + * table's columns and filters by the argument {@link Condition}. If + * syntactically reasonable, the derived table may be inlined to the query + * that selects from the resulting table. + */ + @Support + Table where(Condition condition); + + /** + * Add a WHERE clause to the table, connecting them with each + * other with {@link Operator#AND}. + *

+ * The resulting table acts like a derived table that projects all of this + * table's columns and filters by the argument {@link Condition}. If + * syntactically reasonable, the derived table may be inlined to the query + * that selects from the resulting table. + */ + @Support + Table where(Condition... conditions); + + /** + * Add a WHERE clause to the table, connecting them with each + * other with {@link Operator#AND}. + *

+ * The resulting table acts like a derived table that projects all of this + * table's columns and filters by the argument {@link Condition}. If + * syntactically reasonable, the derived table may be inlined to the query + * that selects from the resulting table. + */ + @Support + Table where(Collection conditions); + + /** + * Add a WHERE clause to the table. + *

+ * The resulting table acts like a derived table that projects all of this + * table's columns and filters by the argument {@link Condition}. If + * syntactically reasonable, the derived table may be inlined to the query + * that selects from the resulting table. + */ + @Support + Table where(Field field); + + /** + * Add a WHERE clause to the table. + *

+ * The resulting table acts like a derived table that projects all of this + * table's columns and filters by the argument {@link Condition}. If + * syntactically reasonable, the derived table may be inlined to the query + * that selects from the resulting table. + *

+ * NOTE: When inserting plain SQL into jOOQ objects, you must + * guarantee syntax integrity. You may also create the possibility of + * malicious SQL injection. Be sure to properly use bind variables and/or + * escape literals when concatenated into SQL clauses! + * + * @see DSL#condition(SQL) + * @see SQL + */ + @Support + @PlainSQL + Table where(SQL sql); + + /** + * Add a WHERE clause to the table. + *

+ * The resulting table acts like a derived table that projects all of this + * table's columns and filters by the argument {@link Condition}. If + * syntactically reasonable, the derived table may be inlined to the query + * that selects from the resulting table. + *

+ * NOTE: When inserting plain SQL into jOOQ objects, you must + * guarantee syntax integrity. You may also create the possibility of + * malicious SQL injection. Be sure to properly use bind variables and/or + * escape literals when concatenated into SQL clauses! + * + * @see DSL#condition(String) + * @see SQL + */ + @Support + @PlainSQL + Table where(String sql); + + /** + * Add a WHERE clause to the table. + *

+ * The resulting table acts like a derived table that projects all of this + * table's columns and filters by the argument {@link Condition}. If + * syntactically reasonable, the derived table may be inlined to the query + * that selects from the resulting table. + *

+ * NOTE: When inserting plain SQL into jOOQ objects, you must + * guarantee syntax integrity. You may also create the possibility of + * malicious SQL injection. Be sure to properly use bind variables and/or + * escape literals when concatenated into SQL clauses! + * + * @see DSL#condition(String, Object...) + * @see DSL#sql(String, Object...) + * @see SQL + */ + @Support + @PlainSQL + Table where(String sql, Object... bindings); + + /** + * Add a WHERE clause to the table. + *

+ * The resulting table acts like a derived table that projects all of this + * table's columns and filters by the argument {@link Condition}. If + * syntactically reasonable, the derived table may be inlined to the query + * that selects from the resulting table. + *

+ * NOTE: When inserting plain SQL into jOOQ objects, you must + * guarantee syntax integrity. You may also create the possibility of + * malicious SQL injection. Be sure to properly use bind variables and/or + * escape literals when concatenated into SQL clauses! + * + * @see DSL#condition(String, QueryPart...) + * @see DSL#sql(String, QueryPart...) + * @see SQL + */ + @Support + @PlainSQL + Table where(String sql, QueryPart... parts); + + /** + * Add a WHERE EXISTS clause to the table. + *

+ * The resulting table acts like a derived table that projects all of this + * table's columns and filters by the argument {@link Condition}. If + * syntactically reasonable, the derived table may be inlined to the query + * that selects from the resulting table. + */ + @Support + Table whereExists(Select select); + + /** + * Add a WHERE NOT EXISTS clause to the table. + *

+ * The resulting table acts like a derived table that projects all of this + * table's columns and filters by the argument {@link Condition}. If + * syntactically reasonable, the derived table may be inlined to the query + * that selects from the resulting table. + */ + @Support + Table whereNotExists(Select select); + // ------------------------------------------------------------------------- // XXX: JOIN clauses on tables // ------------------------------------------------------------------------- diff --git a/jOOQ/src/main/java/org/jooq/impl/AbstractTable.java b/jOOQ/src/main/java/org/jooq/impl/AbstractTable.java index 190643d393..71eaf3be60 100644 --- a/jOOQ/src/main/java/org/jooq/impl/AbstractTable.java +++ b/jOOQ/src/main/java/org/jooq/impl/AbstractTable.java @@ -51,7 +51,11 @@ import static org.jooq.JoinType.NATURAL_RIGHT_OUTER_JOIN; import static org.jooq.JoinType.OUTER_APPLY; import static org.jooq.JoinType.RIGHT_OUTER_JOIN; import static org.jooq.JoinType.STRAIGHT_JOIN; +import static org.jooq.impl.DSL.condition; +import static org.jooq.impl.DSL.exists; // ... +import static org.jooq.impl.DSL.notExists; +import static org.jooq.impl.DSL.selectFrom; import static org.jooq.impl.DSL.table; import static org.jooq.impl.DSL.val; import static org.jooq.impl.Tools.EMPTY_FIELD; @@ -90,6 +94,7 @@ import org.jooq.RecordType; import org.jooq.Row; import org.jooq.SQL; import org.jooq.Schema; +import org.jooq.Select; import org.jooq.Table; import org.jooq.TableField; import org.jooq.TableLike; @@ -461,9 +466,6 @@ abstract class AbstractTable extends AbstractNamed implements return Collections.emptyList(); } - /** - * {@inheritDoc} - */ @Override public final List> getReferencesFrom(Table other) { return other.getReferencesTo(this); @@ -479,9 +481,6 @@ abstract class AbstractTable extends AbstractNamed implements return Collections.emptyList(); } - /** - * {@inheritDoc} - */ @SuppressWarnings("unchecked") @Override public final List> getReferencesTo(Table other) { @@ -1003,6 +1002,60 @@ abstract class AbstractTable extends AbstractNamed implements return (TableOnStep) join(table, LEFT_ANTI_JOIN); } + // ------------------------------------------------------------------------ + // XXX: WHERE API + // ------------------------------------------------------------------------ + + @Override + public /* non-final */ Table where(Condition condition) { + return table(selectFrom(this).where(condition)).as(this); + } + + @Override + public /* non-final */ Table where(Condition... conditions) { + return table(selectFrom(this).where(conditions)).as(this); + } + + @Override + public /* non-final */ Table where(Collection conditions) { + return table(selectFrom(this).where(conditions)).as(this); + } + + @Override + public /* non-final */ Table where(Field field) { + return where(condition(field)); + } + + @Override + public /* non-final */ Table where(SQL sql) { + return where(condition(sql)); + } + + @Override + public /* non-final */ Table where(String sql) { + return where(condition(sql)); + } + + @Override + public /* non-final */ Table where(String sql, Object... bindings) { + return where(condition(sql, bindings)); + } + + @Override + public /* non-final */ Table where(String sql, QueryPart... parts) { + return where(condition(sql, parts)); + } + + @Override + public /* non-final */ Table whereExists(Select select) { + return where(exists(select)); + } + + @Override + public /* non-final */ Table whereNotExists(Select select) { + return where(notExists(select)); + } + // ------------------------------------------------------------------------ // XXX: JOIN API // ------------------------------------------------------------------------