From cc77a2746de07fc0c9f05c33b47e1619e4b735fa Mon Sep 17 00:00:00 2001 From: lukaseder Date: Fri, 21 Apr 2017 11:40:59 +0200 Subject: [PATCH] [#6094] Support Oracle's PARTITION BY prefixed OUTER JOIN --- jOOQ/src/main/java/org/jooq/Table.java | 16 + .../java/org/jooq/TableOuterJoinStep.java | 598 ++++++++++++++++++ .../java/org/jooq/TablePartitionByStep.java | 5 +- .../java/org/jooq/impl/AbstractTable.java | 13 + .../main/java/org/jooq/impl/JoinTable.java | 69 +- .../org/jooq/impl/PartitionJoinTable.java | 246 +++++++ 6 files changed, 924 insertions(+), 23 deletions(-) create mode 100644 jOOQ/src/main/java/org/jooq/TableOuterJoinStep.java create mode 100644 jOOQ/src/main/java/org/jooq/impl/PartitionJoinTable.java diff --git a/jOOQ/src/main/java/org/jooq/Table.java b/jOOQ/src/main/java/org/jooq/Table.java index 1047d5c15c..852c3ab6f3 100644 --- a/jOOQ/src/main/java/org/jooq/Table.java +++ b/jOOQ/src/main/java/org/jooq/Table.java @@ -756,6 +756,22 @@ public interface Table extends TableLike { @Support TableOnStep innerJoin(Name name); + + + + + + + + + + + + + + + + /** * LEFT OUTER JOIN a table to this table. *

diff --git a/jOOQ/src/main/java/org/jooq/TableOuterJoinStep.java b/jOOQ/src/main/java/org/jooq/TableOuterJoinStep.java new file mode 100644 index 0000000000..e46f4e2d35 --- /dev/null +++ b/jOOQ/src/main/java/org/jooq/TableOuterJoinStep.java @@ -0,0 +1,598 @@ +/* + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + * Other licenses: + * ----------------------------------------------------------------------------- + * Commercial licenses for this work are available. These replace the above + * ASL 2.0 and offer limited warranties, support, maintenance, and commercial + * database integrations. + * + * For more information, please visit: http://www.jooq.org/licenses + * + * + * + * + * + * + * + * + * + * + * + * + * + */ +package org.jooq; + +// ... +// ... +import static org.jooq.SQLDialect.CUBRID; +// ... +import static org.jooq.SQLDialect.DERBY; +import static org.jooq.SQLDialect.FIREBIRD; +import static org.jooq.SQLDialect.H2; +// ... +import static org.jooq.SQLDialect.HSQLDB; +// ... +// ... +import static org.jooq.SQLDialect.MARIADB; +import static org.jooq.SQLDialect.MYSQL; +// ... +import static org.jooq.SQLDialect.POSTGRES; +// ... +// ... +// ... + +import org.jooq.impl.DSL; + +/** + * An intermediate type for the construction of a partitioned + * {@link SQLDialect#ORACLE} OUTER JOIN clause. + *

+ * This step allows for adding Oracle-specific PARTITION BY clauses + * to the left of an OUTER JOIN keyword. See the Oracle + * documentation for more details here: https://docs.oracle.com/database/121/SQLRF/statements_10002.htm#BABBCHJA + * + * @author Lukas Eder + */ +public interface TableOuterJoinStep { + + /** + * LEFT OUTER JOIN a table to this table. + *

+ * A synonym for {@link #leftOuterJoin(TableLike)}. + * + * @see #leftOuterJoin(TableLike) + */ + @Support + TableOnStep leftJoin(TableLike table); + + /** + * LEFT OUTER JOIN a table to this table. + *

+ * A synonym for {@link #leftOuterJoin(String)}. + *

+ * 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#table(SQL) + * @see #leftOuterJoin(SQL) + * @see SQL + */ + @Support + @PlainSQL + TableOnStep leftJoin(SQL sql); + + /** + * LEFT OUTER JOIN a table to this table. + *

+ * A synonym for {@link #leftOuterJoin(String)}. + *

+ * 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#table(String) + * @see #leftOuterJoin(String) + * @see SQL + */ + @Support + @PlainSQL + TableOnStep leftJoin(String sql); + + /** + * LEFT OUTER JOIN a table to this table. + *

+ * A synonym for {@link #leftOuterJoin(String, Object...)}. + *

+ * 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#table(String, Object...) + * @see DSL#sql(String, Object...) + * @see #leftOuterJoin(String, Object...) + * @see SQL + */ + @Support + @PlainSQL + TableOnStep leftJoin(String sql, Object... bindings); + + /** + * LEFT OUTER JOIN a table to this table. + *

+ * A synonym for {@link #leftOuterJoin(String, QueryPart...)}. + *

+ * 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#table(String, QueryPart...) + * @see DSL#sql(String, QueryPart...) + * @see #leftOuterJoin(String, QueryPart...) + * @see SQL + */ + @Support + @PlainSQL + TableOnStep leftJoin(String sql, QueryPart... parts); + + /** + * LEFT OUTER JOIN a table to this table. + *

+ * A synonym for {@link #leftOuterJoin(Name)}. + * + * @see DSL#table(Name) + * @see #leftOuterJoin(Name) + */ + @Support + TableOnStep leftJoin(Name name); + + /** + * LEFT OUTER JOIN a table to this table. + */ + @Support + TableOnStep leftOuterJoin(TableLike table); + + /** + * LEFT OUTER JOIN a table to this 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#table(SQL) + * @see SQL + */ + @Support + @PlainSQL + TableOnStep leftOuterJoin(SQL sql); + + /** + * LEFT OUTER JOIN a table to this 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#table(String) + * @see SQL + */ + @Support + @PlainSQL + TableOnStep leftOuterJoin(String sql); + + /** + * LEFT OUTER JOIN a table to this 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#table(String, Object...) + * @see DSL#sql(String, Object...) + * @see SQL + */ + @Support + @PlainSQL + TableOnStep leftOuterJoin(String sql, Object... bindings); + + /** + * LEFT OUTER JOIN a table to this 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#table(String, QueryPart...) + * @see DSL#sql(String, QueryPart...) + * @see SQL + */ + @Support + @PlainSQL + TableOnStep leftOuterJoin(String sql, QueryPart... parts); + + /** + * LEFT OUTER JOIN a table to this table. + * + * @see DSL#table(Name) + * @see SQL + */ + @Support + TableOnStep leftOuterJoin(Name name); + + /** + * RIGHT OUTER JOIN a table to this table. + *

+ * A synonym for {@link #rightOuterJoin(TableLike)}. + *

+ * This is only possible where the underlying RDBMS supports it. + * + * @see #rightOuterJoin(TableLike) + */ + @Support({ CUBRID, DERBY, FIREBIRD, H2, HSQLDB, MARIADB, MYSQL, POSTGRES }) + TableOnStep rightJoin(TableLike table); + + /** + * RIGHT OUTER JOIN a table to this table. + *

+ * A synonym for {@link #rightOuterJoin(String)}. + *

+ * This is only possible where the underlying RDBMS supports it. + *

+ * 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#table(SQL) + * @see #rightOuterJoin(SQL) + * @see SQL + */ + @Support({ CUBRID, DERBY, FIREBIRD, H2, HSQLDB, MARIADB, MYSQL, POSTGRES }) + @PlainSQL + TableOnStep rightJoin(SQL sql); + + /** + * RIGHT OUTER JOIN a table to this table. + *

+ * A synonym for {@link #rightOuterJoin(String)}. + *

+ * This is only possible where the underlying RDBMS supports it. + *

+ * 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#table(String) + * @see #rightOuterJoin(String) + * @see SQL + */ + @Support({ CUBRID, DERBY, FIREBIRD, H2, HSQLDB, MARIADB, MYSQL, POSTGRES }) + @PlainSQL + TableOnStep rightJoin(String sql); + + /** + * RIGHT OUTER JOIN a table to this table. + *

+ * A synonym for {@link #rightOuterJoin(String, Object...)}. + *

+ * This is only possible where the underlying RDBMS supports it. + *

+ * 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#table(String, Object...) + * @see DSL#sql(String, Object...) + * @see #rightOuterJoin(String, Object...) + * @see SQL + */ + @Support({ CUBRID, DERBY, FIREBIRD, H2, HSQLDB, MARIADB, MYSQL, POSTGRES }) + @PlainSQL + TableOnStep rightJoin(String sql, Object... bindings); + + /** + * RIGHT OUTER JOIN a table to this table. + *

+ * A synonym for {@link #rightOuterJoin(String, QueryPart...)}. + *

+ * This is only possible where the underlying RDBMS supports it + *

+ * 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#table(String, QueryPart...) + * @see DSL#sql(String, QueryPart...) + * @see #rightOuterJoin(String, QueryPart...) + * @see SQL + */ + @Support({ CUBRID, DERBY, FIREBIRD, H2, HSQLDB, MARIADB, MYSQL, POSTGRES }) + @PlainSQL + TableOnStep rightJoin(String sql, QueryPart... parts); + + /** + * RIGHT OUTER JOIN a table to this table. + *

+ * A synonym for {@link #rightOuterJoin(Name)}. + *

+ * This is only possible where the underlying RDBMS supports it + * + * @see DSL#table(Name) + * @see #rightOuterJoin(Name) + */ + @Support({ CUBRID, DERBY, FIREBIRD, H2, HSQLDB, MARIADB, MYSQL, POSTGRES }) + TableOnStep rightJoin(Name name); + + /** + * RIGHT OUTER JOIN a table to this table. + *

+ * This is only possible where the underlying RDBMS supports it + */ + @Support({ CUBRID, DERBY, FIREBIRD, H2, HSQLDB, MARIADB, MYSQL, POSTGRES }) + TableOnStep rightOuterJoin(TableLike table); + + /** + * RIGHT OUTER JOIN a table to this table. + *

+ * This is only possible where the underlying RDBMS supports it + *

+ * 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#table(SQL) + * @see SQL + */ + @Support({ CUBRID, DERBY, FIREBIRD, H2, HSQLDB, MARIADB, MYSQL, POSTGRES }) + @PlainSQL + TableOnStep rightOuterJoin(SQL sql); + + /** + * RIGHT OUTER JOIN a table to this table. + *

+ * This is only possible where the underlying RDBMS supports it + *

+ * 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#table(String) + * @see SQL + */ + @Support({ CUBRID, DERBY, FIREBIRD, H2, HSQLDB, MARIADB, MYSQL, POSTGRES }) + @PlainSQL + TableOnStep rightOuterJoin(String sql); + + /** + * RIGHT OUTER JOIN a table to this table. + *

+ * This is only possible where the underlying RDBMS supports it + *

+ * 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#table(String, Object...) + * @see DSL#sql(String, Object...) + * @see SQL + */ + @Support({ CUBRID, DERBY, FIREBIRD, H2, HSQLDB, MARIADB, MYSQL, POSTGRES }) + @PlainSQL + TableOnStep rightOuterJoin(String sql, Object... bindings); + + /** + * RIGHT OUTER JOIN a table to this table. + *

+ * This is only possible where the underlying RDBMS supports it + *

+ * 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#table(String, QueryPart...) + * @see DSL#sql(String, QueryPart...) + * @see SQL + */ + @Support({ CUBRID, DERBY, FIREBIRD, H2, HSQLDB, MARIADB, MYSQL, POSTGRES }) + @PlainSQL + TableOnStep rightOuterJoin(String sql, QueryPart... parts); + + /** + * RIGHT OUTER JOIN a table to this table. + *

+ * This is only possible where the underlying RDBMS supports it + * + * @see DSL#table(Name) + */ + @Support({ CUBRID, DERBY, FIREBIRD, H2, HSQLDB, MARIADB, MYSQL, POSTGRES }) + TableOnStep rightOuterJoin(Name name); + + /** + * FULL OUTER JOIN a table to this table. + *

+ * A synonym for {@link #fullOuterJoin(TableLike)}. + */ + @Support({ FIREBIRD, HSQLDB, POSTGRES }) + TableOnStep fullJoin(TableLike table); + + /** + * FULL OUTER JOIN a table to this table. + *

+ * A synonym for {@link #fullOuterJoin(SQL)}. + *

+ * 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! + */ + @Support({ FIREBIRD, HSQLDB, POSTGRES }) + @PlainSQL + TableOnStep fullJoin(SQL sql); + + /** + * FULL OUTER JOIN a table to this table. + *

+ * A synonym for {@link #fullOuterJoin(String)}. + *

+ * 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! + */ + @Support({ FIREBIRD, HSQLDB, POSTGRES }) + @PlainSQL + TableOnStep fullJoin(String sql); + + /** + * FULL OUTER JOIN a table to this table. + *

+ * A synonym for {@link #fullOuterJoin(String, Object...)}. + *

+ * 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! + */ + @Support({ FIREBIRD, HSQLDB, POSTGRES }) + @PlainSQL + TableOnStep fullJoin(String sql, Object... bindings); + + /** + * FULL OUTER JOIN a table to this table. + *

+ * A synonym for {@link #fullOuterJoin(String, QueryPart...)}. + *

+ * 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! + */ + @Support({ FIREBIRD, HSQLDB, POSTGRES }) + @PlainSQL + TableOnStep fullJoin(String sql, QueryPart... parts); + + /** + * FULL OUTER JOIN a table to this table. + *

+ * A synonym for {@link #fullOuterJoin(Name)}. + */ + @Support({ FIREBIRD, HSQLDB, POSTGRES }) + TableOnStep fullJoin(Name name); + + /** + * FULL OUTER JOIN a table to this table. + *

+ * This is only possible where the underlying RDBMS supports it + */ + @Support({ FIREBIRD, HSQLDB, POSTGRES }) + TableOnStep fullOuterJoin(TableLike table); + + /** + * FULL OUTER JOIN a table to this table. + *

+ * This is only possible where the underlying RDBMS supports it + *

+ * 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#table(SQL) + * @see SQL + */ + @Support({ FIREBIRD, HSQLDB, POSTGRES }) + @PlainSQL + TableOnStep fullOuterJoin(SQL sql); + + /** + * FULL OUTER JOIN a table to this table. + *

+ * This is only possible where the underlying RDBMS supports it + *

+ * 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#table(String) + * @see SQL + */ + @Support({ FIREBIRD, HSQLDB, POSTGRES }) + @PlainSQL + TableOnStep fullOuterJoin(String sql); + + /** + * FULL OUTER JOIN a table to this table. + *

+ * This is only possible where the underlying RDBMS supports it + *

+ * 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#table(String, Object...) + * @see DSL#sql(String, Object...) + * @see SQL + */ + @Support({ FIREBIRD, HSQLDB, POSTGRES }) + @PlainSQL + TableOnStep fullOuterJoin(String sql, Object... bindings); + + /** + * FULL OUTER JOIN a table to this table. + *

+ * This is only possible where the underlying RDBMS supports it + *

+ * 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#table(String, QueryPart...) + * @see DSL#sql(String, QueryPart...) + * @see SQL + */ + @Support({ FIREBIRD, HSQLDB, POSTGRES }) + @PlainSQL + TableOnStep fullOuterJoin(String sql, QueryPart... parts); + + /** + * FULL OUTER JOIN a table to this table. + *

+ * This is only possible where the underlying RDBMS supports it + * + * @see DSL#table(Name) + */ + @Support({ FIREBIRD, HSQLDB, POSTGRES }) + TableOnStep fullOuterJoin(Name name); +} diff --git a/jOOQ/src/main/java/org/jooq/TablePartitionByStep.java b/jOOQ/src/main/java/org/jooq/TablePartitionByStep.java index 6e520a0fbd..30a31a36e3 100644 --- a/jOOQ/src/main/java/org/jooq/TablePartitionByStep.java +++ b/jOOQ/src/main/java/org/jooq/TablePartitionByStep.java @@ -45,9 +45,8 @@ import java.util.Collection; * This step allows for adding Oracle-specific PARTITION BY clauses * to the right of an OUTER JOIN keyword. See the Oracle * documentation for more details here: http://docs.oracle.com/cd/B28359_01/server.111/b28286/queries006.htm# - * i2054062 + * "https://docs.oracle.com/database/121/SQLRF/statements_10002.htm#BABBCHJA" + * >https://docs.oracle.com/database/121/SQLRF/statements_10002.htm#BABBCHJA * * @author Lukas Eder */ diff --git a/jOOQ/src/main/java/org/jooq/impl/AbstractTable.java b/jOOQ/src/main/java/org/jooq/impl/AbstractTable.java index 5dc2f7f328..566931f807 100644 --- a/jOOQ/src/main/java/org/jooq/impl/AbstractTable.java +++ b/jOOQ/src/main/java/org/jooq/impl/AbstractTable.java @@ -89,6 +89,7 @@ import org.jooq.TableField; import org.jooq.TableLike; import org.jooq.TableOnStep; import org.jooq.TableOptionalOnStep; +import org.jooq.TableOuterJoinStep; import org.jooq.TablePartitionByStep; import org.jooq.UniqueKey; // ... @@ -928,6 +929,18 @@ abstract class AbstractTable extends AbstractQueryPart impleme return innerJoin(table(name)); } + + + + + + + + + + + + @Override public final TablePartitionByStep leftJoin(TableLike table) { return leftOuterJoin(table); diff --git a/jOOQ/src/main/java/org/jooq/impl/JoinTable.java b/jOOQ/src/main/java/org/jooq/impl/JoinTable.java index 2ee41d87aa..896d9a72bf 100644 --- a/jOOQ/src/main/java/org/jooq/impl/JoinTable.java +++ b/jOOQ/src/main/java/org/jooq/impl/JoinTable.java @@ -91,6 +91,7 @@ import static org.jooq.impl.Tools.DataKey.DATA_COLLECT_SEMI_ANTI_JOIN; import java.util.ArrayList; import java.util.Collection; +import java.util.Collections; import java.util.List; import org.jooq.Clause; @@ -110,8 +111,8 @@ import org.jooq.Table; import org.jooq.TableField; import org.jooq.TableLike; import org.jooq.TableOnConditionStep; -import org.jooq.TableOnStep; import org.jooq.TableOptionalOnStep; +import org.jooq.TableOuterJoinStep; import org.jooq.exception.DataAccessException; /** @@ -119,7 +120,11 @@ import org.jooq.exception.DataAccessException; * * @author Lukas Eder */ -final class JoinTable extends AbstractTable implements TableOptionalOnStep, TableOnConditionStep { +final class JoinTable extends AbstractTable +implements + TableOuterJoinStep, + TableOptionalOnStep, + TableOnConditionStep { /** * Generated UID @@ -129,18 +134,32 @@ final class JoinTable extends AbstractTable implements TableOptionalOnSt private final Table lhs; private final Table rhs; - private final QueryPartList> rhsPartitionBy; + + + + private final JoinType type; private final ConditionProviderImpl condition; private final QueryPartList> using; JoinTable(TableLike lhs, TableLike rhs, JoinType type) { + + + + + + super("join"); this.lhs = lhs.asTable(); this.rhs = rhs.asTable(); - this.rhsPartitionBy = new QueryPartList>(); + + + + + + this.type = type; this.condition = new ConditionProviderImpl(); @@ -169,13 +188,10 @@ final class JoinTable extends AbstractTable implements TableOptionalOnSt Keyword keyword = translatedType.toKeyword(); - if (translatedType == CROSS_APPLY && ctx.family() == POSTGRES) { + if (translatedType == CROSS_APPLY && ctx.family() == POSTGRES) keyword = K_CROSS_JOIN_LATERAL; - } - else if (translatedType == OUTER_APPLY && ctx.family() == POSTGRES) { + else if (translatedType == OUTER_APPLY && ctx.family() == POSTGRES) keyword = K_LEFT_OUTER_JOIN_LATERAL; - } - @@ -185,6 +201,18 @@ final class JoinTable extends AbstractTable implements TableOptionalOnSt toSQLTable(ctx, lhs); + + + + + + + + + + + + switch (translatedType) { case LEFT_SEMI_JOIN: case LEFT_ANTI_JOIN: @@ -220,17 +248,18 @@ final class JoinTable extends AbstractTable implements TableOptionalOnSt toSQLTable(ctx, rhs); - // [#1645] The Oracle PARTITION BY clause can be put to the right of an - // OUTER JOINed table - if (!rhsPartitionBy.isEmpty()) { - ctx.formatSeparator() - .start(TABLE_JOIN_PARTITION_BY) - .visit(K_PARTITION_BY) - .sql(" (") - .visit(rhsPartitionBy) - .sql(')') - .end(TABLE_JOIN_PARTITION_BY); - } + + + + + + + + + + + + // CROSS JOIN and NATURAL JOIN do not have any condition clauses if (!asList(CROSS_JOIN, diff --git a/jOOQ/src/main/java/org/jooq/impl/PartitionJoinTable.java b/jOOQ/src/main/java/org/jooq/impl/PartitionJoinTable.java new file mode 100644 index 0000000000..8079153ee8 --- /dev/null +++ b/jOOQ/src/main/java/org/jooq/impl/PartitionJoinTable.java @@ -0,0 +1,246 @@ +/* + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + * Other licenses: + * ----------------------------------------------------------------------------- + * Commercial licenses for this work are available. These replace the above + * ASL 2.0 and offer limited warranties, support, maintenance, and commercial + * database integrations. + * + * For more information, please visit: http://www.jooq.org/licenses + * + * + * + * + * + * + * + * + * + * + * + * + * + */ +package org.jooq.impl; + +import static org.jooq.JoinType.FULL_OUTER_JOIN; +import static org.jooq.JoinType.LEFT_OUTER_JOIN; +import static org.jooq.JoinType.RIGHT_OUTER_JOIN; +import static org.jooq.impl.DSL.table; + +import java.util.Collection; + +import org.jooq.Field; +import org.jooq.Name; +import org.jooq.QueryPart; +import org.jooq.Record; +import org.jooq.SQL; +import org.jooq.Table; +import org.jooq.TableLike; +import org.jooq.TableOnStep; +import org.jooq.TableOuterJoinStep; + +/** + * @author Lukas Eder + */ +final class PartitionJoinTable implements TableOuterJoinStep { + + private final Table lhs; + private final Collection> lhsPartitionBy; + + PartitionJoinTable(Table lhs, Collection> lhsPartitionBy) { + this.lhs = lhs; + this.lhsPartitionBy = lhsPartitionBy; + } + + @Override + public final TableOnStep leftJoin(TableLike table) { + return leftOuterJoin(table); + } + + @Override + public final TableOnStep leftJoin(SQL sql) { + return leftOuterJoin(sql); + } + + @Override + public final TableOnStep leftJoin(String sql) { + return leftOuterJoin(sql); + } + + @Override + public final TableOnStep leftJoin(String sql, Object... bindings) { + return leftOuterJoin(sql, bindings); + } + + @Override + public final TableOnStep leftJoin(String sql, QueryPart... parts) { + return leftOuterJoin(sql, parts); + } + + @Override + public final TableOnStep leftJoin(Name name) { + return leftOuterJoin(name); + } + + @Override + public final TableOnStep leftOuterJoin(TableLike table) { + return new JoinTable(lhs, table, LEFT_OUTER_JOIN, lhsPartitionBy); + } + + @Override + public final TableOnStep leftOuterJoin(SQL sql) { + return leftOuterJoin(table(sql)); + } + + @Override + public final TableOnStep leftOuterJoin(String sql) { + return leftOuterJoin(table(sql)); + } + + @Override + public final TableOnStep leftOuterJoin(String sql, Object... bindings) { + return leftOuterJoin(table(sql, bindings)); + } + + @Override + public final TableOnStep leftOuterJoin(String sql, QueryPart... parts) { + return leftOuterJoin(table(sql, parts)); + } + + @Override + public final TableOnStep leftOuterJoin(Name name) { + return leftOuterJoin(table(name)); + } + + @Override + public final TableOnStep rightJoin(TableLike table) { + return rightOuterJoin(table); + } + + @Override + public final TableOnStep rightJoin(SQL sql) { + return rightOuterJoin(sql); + } + + @Override + public final TableOnStep rightJoin(String sql) { + return rightOuterJoin(sql); + } + + @Override + public final TableOnStep rightJoin(String sql, Object... bindings) { + return rightOuterJoin(sql, bindings); + } + + @Override + public final TableOnStep rightJoin(String sql, QueryPart... parts) { + return rightOuterJoin(sql, parts); + } + + @Override + public final TableOnStep rightJoin(Name name) { + return rightOuterJoin(name); + } + + @Override + public final TableOnStep rightOuterJoin(TableLike table) { + return new JoinTable(lhs, table, RIGHT_OUTER_JOIN, lhsPartitionBy); + } + + @Override + public final TableOnStep rightOuterJoin(SQL sql) { + return rightOuterJoin(table(sql)); + } + + @Override + public final TableOnStep rightOuterJoin(String sql) { + return rightOuterJoin(table(sql)); + } + + @Override + public final TableOnStep rightOuterJoin(String sql, Object... bindings) { + return rightOuterJoin(table(sql, bindings)); + } + + @Override + public final TableOnStep rightOuterJoin(String sql, QueryPart... parts) { + return rightOuterJoin(table(sql, parts)); + } + + @Override + public final TableOnStep rightOuterJoin(Name name) { + return rightOuterJoin(table(name)); + } + + @Override + public final TableOnStep fullJoin(TableLike table) { + return fullOuterJoin(table); + } + + @Override + public final TableOnStep fullJoin(SQL sql) { + return fullOuterJoin(sql); + } + + @Override + public final TableOnStep fullJoin(String sql) { + return fullOuterJoin(sql); + } + + @Override + public final TableOnStep fullJoin(String sql, Object... bindings) { + return fullOuterJoin(sql, bindings); + } + + @Override + public final TableOnStep fullJoin(String sql, QueryPart... parts) { + return fullOuterJoin(sql, parts); + } + + @Override + public final TableOnStep fullJoin(Name name) { + return fullOuterJoin(name); + } + + @Override + public final TableOnStep fullOuterJoin(TableLike table) { + return new JoinTable(lhs, table, FULL_OUTER_JOIN, lhsPartitionBy); + } + + @Override + public final TableOnStep fullOuterJoin(SQL sql) { + return fullOuterJoin(table(sql)); + } + + @Override + public final TableOnStep fullOuterJoin(String sql) { + return fullOuterJoin(table(sql)); + } + + @Override + public final TableOnStep fullOuterJoin(String sql, Object... bindings) { + return fullOuterJoin(table(sql, bindings)); + } + + @Override + public final TableOnStep fullOuterJoin(String sql, QueryPart... parts) { + return fullOuterJoin(table(sql, parts)); + } + + @Override + public final TableOnStep fullOuterJoin(Name name) { + return fullOuterJoin(table(name)); + } +}