From c2a5dc320f4c17ab3f375e16af93b24ecc7a643b Mon Sep 17 00:00:00 2001 From: lukaseder Date: Tue, 5 Feb 2019 16:28:02 +0100 Subject: [PATCH] [#7312] WIP --- .../src/main/java/org/jooq/conf/Settings.java | 54 +++++++++++++++++++ .../java/org/jooq/impl/SelectQueryImpl.java | 12 ++++- .../resources/xsd/jooq-runtime-3.12.0.xsd | 12 +++++ 3 files changed, 76 insertions(+), 2 deletions(-) diff --git a/jOOQ/src/main/java/org/jooq/conf/Settings.java b/jOOQ/src/main/java/org/jooq/conf/Settings.java index 236aaa12be..c106200eac 100644 --- a/jOOQ/src/main/java/org/jooq/conf/Settings.java +++ b/jOOQ/src/main/java/org/jooq/conf/Settings.java @@ -68,6 +68,8 @@ public class Settings protected Boolean renderScalarSubqueriesForStoredFunctions = false; @XmlElement(defaultValue = "true") protected Boolean renderOrderByRownumberForEmulatedPagination = true; + @XmlElement(defaultValue = "false") + protected Boolean transformTableListsToAnsiJoin = false; @XmlElement(defaultValue = "DEFAULT") @XmlSchemaType(name = "string") protected BackslashEscaping backslashEscaping = BackslashEscaping.DEFAULT; @@ -500,6 +502,38 @@ public class Settings this.renderOrderByRownumberForEmulatedPagination = value; } + /** + * Transform table lists to ANSI join if possible + *

+ * (Very) historically, prior to ANSI join syntax, joins were implemented by listing tables in + * the FROM clause and providing join predicates in the WHERE clause, possibly using vendor specific + * operators like (+) (Oracle, DB2) or *= (SQL Server) for outer join + * support. Migrating such join syntax is tedious. The jOOQ parser can parse the old syntax and + * this flag enables the transformation to ANSI join syntax. + *

+ * This feature is available in the commercial distribution only. + * + * @return + * possible object is + * {@link Boolean } + * + */ + public Boolean isTransformTableListsToAnsiJoin() { + return transformTableListsToAnsiJoin; + } + + /** + * Sets the value of the transformTableListsToAnsiJoin property. + * + * @param value + * allowed object is + * {@link Boolean } + * + */ + public void setTransformTableListsToAnsiJoin(Boolean value) { + this.transformTableListsToAnsiJoin = value; + } + /** * Whether string literals should be escaped with backslash. * @@ -1438,6 +1472,11 @@ public class Settings return this; } + public Settings withTransformTableListsToAnsiJoin(Boolean value) { + setTransformTableListsToAnsiJoin(value); + return this; + } + public Settings withBackslashEscaping(BackslashEscaping value) { setBackslashEscaping(value); return this; @@ -1681,6 +1720,11 @@ public class Settings sb.append(renderOrderByRownumberForEmulatedPagination); sb.append(""); } + if (transformTableListsToAnsiJoin!= null) { + sb.append(""); + sb.append(transformTableListsToAnsiJoin); + sb.append(""); + } if (backslashEscaping!= null) { sb.append(""); sb.append(backslashEscaping); @@ -1988,6 +2032,15 @@ public class Settings return false; } } + if (transformTableListsToAnsiJoin == null) { + if (other.transformTableListsToAnsiJoin!= null) { + return false; + } + } else { + if (!transformTableListsToAnsiJoin.equals(other.transformTableListsToAnsiJoin)) { + return false; + } + } if (backslashEscaping == null) { if (other.backslashEscaping!= null) { return false; @@ -2323,6 +2376,7 @@ public class Settings result = ((prime*result)+((renderFormatting == null)? 0 :renderFormatting.hashCode())); result = ((prime*result)+((renderScalarSubqueriesForStoredFunctions == null)? 0 :renderScalarSubqueriesForStoredFunctions.hashCode())); result = ((prime*result)+((renderOrderByRownumberForEmulatedPagination == null)? 0 :renderOrderByRownumberForEmulatedPagination.hashCode())); + result = ((prime*result)+((transformTableListsToAnsiJoin == null)? 0 :transformTableListsToAnsiJoin.hashCode())); result = ((prime*result)+((backslashEscaping == null)? 0 :backslashEscaping.hashCode())); result = ((prime*result)+((paramType == null)? 0 :paramType.hashCode())); result = ((prime*result)+((paramCastMode == null)? 0 :paramCastMode.hashCode())); diff --git a/jOOQ/src/main/java/org/jooq/impl/SelectQueryImpl.java b/jOOQ/src/main/java/org/jooq/impl/SelectQueryImpl.java index bcf125b983..59592cb3cd 100644 --- a/jOOQ/src/main/java/org/jooq/impl/SelectQueryImpl.java +++ b/jOOQ/src/main/java/org/jooq/impl/SelectQueryImpl.java @@ -1306,15 +1306,24 @@ final class SelectQueryImpl extends AbstractResultQuery imp ; List semiAntiJoinPredicates = null; + ConditionProviderImpl where = getWhere(); if (hasFrom) { Object previousCollect = context.data(DATA_COLLECT_SEMI_ANTI_JOIN, true); Object previousCollected = context.data(DATA_COLLECTED_SEMI_ANTI_JOIN, null); + TableList tablelist = getFrom(); + + + + + + + context.formatSeparator() .visit(K_FROM) .sql(' ') - .visit(getFrom()); + .visit(tablelist); @@ -1338,7 +1347,6 @@ final class SelectQueryImpl extends AbstractResultQuery imp // WHERE clause // ------------ context.start(SELECT_WHERE); - ConditionProviderImpl where = getWhere(); if (TRUE.equals(context.data().get(BooleanDataKey.DATA_SELECT_NO_DATA))) context.formatSeparator() diff --git a/jOOQ/src/main/resources/xsd/jooq-runtime-3.12.0.xsd b/jOOQ/src/main/resources/xsd/jooq-runtime-3.12.0.xsd index e0fcf7ec78..f5ee96d681 100644 --- a/jOOQ/src/main/resources/xsd/jooq-runtime-3.12.0.xsd +++ b/jOOQ/src/main/resources/xsd/jooq-runtime-3.12.0.xsd @@ -101,6 +101,18 @@ jOOQ to not generate the additional ORDER BY clause. For details, see https://github.com/jOOQ/jOOQ/issues/7609.]]> + + +(Very) historically, prior to ANSI join syntax, joins were implemented by listing tables in +the FROM clause and providing join predicates in the WHERE clause, possibly using vendor specific +operators like (+) (Oracle, DB2) or *= (SQL Server) for outer join +support. Migrating such join syntax is tedious. The jOOQ parser can parse the old syntax and +this flag enables the transformation to ANSI join syntax. +

+This feature is available in the commercial distribution only.]]> + +