From 95bc88e5fe10198066dbfa7f631ad804e001fc07 Mon Sep 17 00:00:00 2001 From: Lukas Eder Date: Fri, 13 May 2022 09:21:23 +0200 Subject: [PATCH] [jOOQ/jOOQ#13069] Added --- .../org/jooq/codegen/AbstractGenerator.java | 22 +++ .../java/org/jooq/codegen/GenerationTool.java | 4 + .../main/java/org/jooq/codegen/Generator.java | 24 +++ .../java/org/jooq/codegen/JavaGenerator.java | 158 ++++++++++++++++++ .../java/org/jooq/meta/jaxb/Generate.java | 88 ++++++++++ .../org/jooq/meta/xsd/jooq-codegen-3.17.0.xsd | 12 ++ .../main/java/org/jooq/impl/TableImpl.java | 74 ++++++++ 7 files changed, 382 insertions(+) diff --git a/jOOQ-codegen/src/main/java/org/jooq/codegen/AbstractGenerator.java b/jOOQ-codegen/src/main/java/org/jooq/codegen/AbstractGenerator.java index 2f647e3e03..1d0b1a8380 100644 --- a/jOOQ-codegen/src/main/java/org/jooq/codegen/AbstractGenerator.java +++ b/jOOQ-codegen/src/main/java/org/jooq/codegen/AbstractGenerator.java @@ -70,6 +70,8 @@ abstract class AbstractGenerator implements Generator { boolean generateRelations = true; boolean generateImplicitJoinPathsToOne = true; boolean generateImplicitJoinPathsAsKotlinProperties = true; + boolean generateExistsConvenienceOneToMany = true; + boolean generateExistsConvenienceManyToMany = true; boolean generateRowConvenienceToOne = true; boolean generateMultisetConvenienceOneToMany = true; boolean generateMultisetConvenienceManyToMany = true; @@ -307,6 +309,26 @@ abstract class AbstractGenerator implements Generator { this.generateImplicitJoinPathsAsKotlinProperties = generateImplicitJoinPathsAsKotlinProperties; } + @Override + public boolean generateExistsConvenienceOneToMany() { + return generateExistsConvenienceOneToMany && generateRelations(); + } + + @Override + public void setGenerateExistsConvenienceOneToMany(boolean generateExistsConvenienceOneToMany) { + this.generateExistsConvenienceOneToMany = generateExistsConvenienceOneToMany; + } + + @Override + public boolean generateExistsConvenienceManyToMany() { + return generateExistsConvenienceManyToMany && generateRelations(); + } + + @Override + public void setGenerateExistsConvenienceManyToMany(boolean generateExistsConvenienceManyToMany) { + this.generateExistsConvenienceManyToMany = generateExistsConvenienceManyToMany; + } + @Override public boolean generateRowConvenienceToOne() { return generateRowConvenienceToOne && generateRelations(); diff --git a/jOOQ-codegen/src/main/java/org/jooq/codegen/GenerationTool.java b/jOOQ-codegen/src/main/java/org/jooq/codegen/GenerationTool.java index 846a950168..e49a60decb 100644 --- a/jOOQ-codegen/src/main/java/org/jooq/codegen/GenerationTool.java +++ b/jOOQ-codegen/src/main/java/org/jooq/codegen/GenerationTool.java @@ -720,6 +720,10 @@ public class GenerationTool { generator.setGenerateImplicitJoinPathsToOne(g.getGenerate().isImplicitJoinPathsToOne()); if (g.getGenerate().isImplicitJoinPathsAsKotlinProperties() != null) generator.setGenerateImplicitJoinPathsAsKotlinProperties(g.getGenerate().isImplicitJoinPathsAsKotlinProperties()); + if (g.getGenerate().isExistsConvenienceOneToMany() != null) + generator.setGenerateExistsConvenienceOneToMany(g.getGenerate().isExistsConvenienceOneToMany()); + if (g.getGenerate().isExistsConvenienceManyToMany() != null) + generator.setGenerateExistsConvenienceManyToMany(g.getGenerate().isExistsConvenienceManyToMany()); if (g.getGenerate().isRowConvenienceToOne() != null) generator.setGenerateRowConvenienceToOne(g.getGenerate().isRowConvenienceToOne()); if (g.getGenerate().isMultisetConvenienceOneToMany() != null) diff --git a/jOOQ-codegen/src/main/java/org/jooq/codegen/Generator.java b/jOOQ-codegen/src/main/java/org/jooq/codegen/Generator.java index 1b0bdadddb..b4eda1a9b5 100644 --- a/jOOQ-codegen/src/main/java/org/jooq/codegen/Generator.java +++ b/jOOQ-codegen/src/main/java/org/jooq/codegen/Generator.java @@ -142,6 +142,30 @@ public interface Generator { */ void setGenerateImplicitJoinPathsAsKotlinProperties(boolean generateImplicitJoinPathsAsKotlinProperties); + /** + * Whether EXISTS convenience syntax for one-to-many + * relationships should be generated. + */ + boolean generateExistsConvenienceOneToMany(); + + /** + * Whether EXISTS convenience syntax for one-to-many + * relationships should be generated. + */ + void setGenerateExistsConvenienceOneToMany(boolean generateExistsConvenienceOneToMany); + + /** + * Whether EXISTS convenience syntax for many-to-many + * relationships should be generated. + */ + boolean generateExistsConvenienceManyToMany(); + + /** + * Whether EXISTS convenience syntax for many-to-many + * relationships should be generated. + */ + void setGenerateExistsConvenienceManyToMany(boolean generateExistsConvenienceManyToMany); + /** * Whether ROW convenience syntax for to-one relationships * should be generated. diff --git a/jOOQ-codegen/src/main/java/org/jooq/codegen/JavaGenerator.java b/jOOQ-codegen/src/main/java/org/jooq/codegen/JavaGenerator.java index 5489f642fc..597a3b90d1 100644 --- a/jOOQ-codegen/src/main/java/org/jooq/codegen/JavaGenerator.java +++ b/jOOQ-codegen/src/main/java/org/jooq/codegen/JavaGenerator.java @@ -95,6 +95,7 @@ import java.util.stream.Stream; import org.jooq.AggregateFunction; import org.jooq.Catalog; import org.jooq.Check; +import org.jooq.Condition; import org.jooq.Configuration; import org.jooq.Constants; import org.jooq.DataType; @@ -6523,6 +6524,163 @@ public class JavaGenerator extends AbstractGenerator { + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/jOOQ-meta/src/main/java/org/jooq/meta/jaxb/Generate.java b/jOOQ-meta/src/main/java/org/jooq/meta/jaxb/Generate.java index b39f0c7677..22e7d9cafc 100644 --- a/jOOQ-meta/src/main/java/org/jooq/meta/jaxb/Generate.java +++ b/jOOQ-meta/src/main/java/org/jooq/meta/jaxb/Generate.java @@ -43,6 +43,10 @@ public class Generate implements Serializable, XMLAppendable @XmlElement(defaultValue = "true") protected Boolean implicitJoinPathsAsKotlinProperties = true; @XmlElement(defaultValue = "true") + protected Boolean existsConvenienceOneToMany = true; + @XmlElement(defaultValue = "true") + protected Boolean existsConvenienceManyToMany = true; + @XmlElement(defaultValue = "true") protected Boolean rowConvenienceToOne = true; @XmlElement(defaultValue = "true") protected Boolean multisetConvenienceOneToMany = true; @@ -389,6 +393,58 @@ public class Generate implements Serializable, XMLAppendable this.implicitJoinPathsAsKotlinProperties = value; } + /** + * Generate EXISTS convenience syntax for one-to-many relationships. + *

+ * This feature is available in the commercial distribution only. + * + * @return + * possible object is + * {@link Boolean } + * + */ + public Boolean isExistsConvenienceOneToMany() { + return existsConvenienceOneToMany; + } + + /** + * Sets the value of the existsConvenienceOneToMany property. + * + * @param value + * allowed object is + * {@link Boolean } + * + */ + public void setExistsConvenienceOneToMany(Boolean value) { + this.existsConvenienceOneToMany = value; + } + + /** + * Generate EXISTS convenience syntax for many-to-many relationships. A many-to-many relationship is achieved when a child table has 2 non-nullable foreign keys that are part of a unique key. + *

+ * This feature is available in the commercial distribution only. + * + * @return + * possible object is + * {@link Boolean } + * + */ + public Boolean isExistsConvenienceManyToMany() { + return existsConvenienceManyToMany; + } + + /** + * Sets the value of the existsConvenienceManyToMany property. + * + * @param value + * allowed object is + * {@link Boolean } + * + */ + public void setExistsConvenienceManyToMany(Boolean value) { + this.existsConvenienceManyToMany = value; + } + /** * Generate ROW convenience syntax for to-one relationships. *

@@ -2608,6 +2664,16 @@ public class Generate implements Serializable, XMLAppendable return this; } + public Generate withExistsConvenienceOneToMany(Boolean value) { + setExistsConvenienceOneToMany(value); + return this; + } + + public Generate withExistsConvenienceManyToMany(Boolean value) { + setExistsConvenienceManyToMany(value); + return this; + } + public Generate withRowConvenienceToOne(Boolean value) { setRowConvenienceToOne(value); return this; @@ -3130,6 +3196,8 @@ public class Generate implements Serializable, XMLAppendable builder.append("implicitJoinPathsToOne", implicitJoinPathsToOne); builder.append("implicitJoinPathsUseTableNameForUnambiguousFKs", implicitJoinPathsUseTableNameForUnambiguousFKs); builder.append("implicitJoinPathsAsKotlinProperties", implicitJoinPathsAsKotlinProperties); + builder.append("existsConvenienceOneToMany", existsConvenienceOneToMany); + builder.append("existsConvenienceManyToMany", existsConvenienceManyToMany); builder.append("rowConvenienceToOne", rowConvenienceToOne); builder.append("multisetConvenienceOneToMany", multisetConvenienceOneToMany); builder.append("multisetConvenienceManyToMany", multisetConvenienceManyToMany); @@ -3298,6 +3366,24 @@ public class Generate implements Serializable, XMLAppendable return false; } } + if (existsConvenienceOneToMany == null) { + if (other.existsConvenienceOneToMany!= null) { + return false; + } + } else { + if (!existsConvenienceOneToMany.equals(other.existsConvenienceOneToMany)) { + return false; + } + } + if (existsConvenienceManyToMany == null) { + if (other.existsConvenienceManyToMany!= null) { + return false; + } + } else { + if (!existsConvenienceManyToMany.equals(other.existsConvenienceManyToMany)) { + return false; + } + } if (rowConvenienceToOne == null) { if (other.rowConvenienceToOne!= null) { return false; @@ -4148,6 +4234,8 @@ public class Generate implements Serializable, XMLAppendable result = ((prime*result)+((implicitJoinPathsToOne == null)? 0 :implicitJoinPathsToOne.hashCode())); result = ((prime*result)+((implicitJoinPathsUseTableNameForUnambiguousFKs == null)? 0 :implicitJoinPathsUseTableNameForUnambiguousFKs.hashCode())); result = ((prime*result)+((implicitJoinPathsAsKotlinProperties == null)? 0 :implicitJoinPathsAsKotlinProperties.hashCode())); + result = ((prime*result)+((existsConvenienceOneToMany == null)? 0 :existsConvenienceOneToMany.hashCode())); + result = ((prime*result)+((existsConvenienceManyToMany == null)? 0 :existsConvenienceManyToMany.hashCode())); result = ((prime*result)+((rowConvenienceToOne == null)? 0 :rowConvenienceToOne.hashCode())); result = ((prime*result)+((multisetConvenienceOneToMany == null)? 0 :multisetConvenienceOneToMany.hashCode())); result = ((prime*result)+((multisetConvenienceManyToMany == null)? 0 :multisetConvenienceManyToMany.hashCode())); diff --git a/jOOQ-meta/src/main/resources/org/jooq/meta/xsd/jooq-codegen-3.17.0.xsd b/jOOQ-meta/src/main/resources/org/jooq/meta/xsd/jooq-codegen-3.17.0.xsd index 3d88d443d4..8bf8d5759d 100644 --- a/jOOQ-meta/src/main/resources/org/jooq/meta/xsd/jooq-codegen-3.17.0.xsd +++ b/jOOQ-meta/src/main/resources/org/jooq/meta/xsd/jooq-codegen-3.17.0.xsd @@ -1760,6 +1760,18 @@ This flag allows for turning off this default behaviour.]]> + + EXISTS convenience syntax for one-to-many relationships. +

+This feature is available in the commercial distribution only.]]> + + + + EXISTS convenience syntax for many-to-many relationships. A many-to-many relationship is achieved when a child table has 2 non-nullable foreign keys that are part of a unique key. +

+This feature is available in the commercial distribution only.]]> + + ROW convenience syntax for to-one relationships.

diff --git a/jOOQ/src/main/java/org/jooq/impl/TableImpl.java b/jOOQ/src/main/java/org/jooq/impl/TableImpl.java index 454cca61ce..2d74578401 100644 --- a/jOOQ/src/main/java/org/jooq/impl/TableImpl.java +++ b/jOOQ/src/main/java/org/jooq/impl/TableImpl.java @@ -57,12 +57,15 @@ import static org.jooq.SQLDialect.MYSQL; import static org.jooq.SQLDialect.POSTGRES; import static org.jooq.SQLDialect.YUGABYTEDB; import static org.jooq.impl.DSL.and; +import static org.jooq.impl.DSL.exists; import static org.jooq.impl.DSL.falseCondition; import static org.jooq.impl.DSL.multiset; import static org.jooq.impl.DSL.multisetAgg; +import static org.jooq.impl.DSL.one; import static org.jooq.impl.DSL.row; import static org.jooq.impl.DSL.select; import static org.jooq.impl.DSL.selectFrom; +import static org.jooq.impl.DSL.selectOne; import static org.jooq.impl.DSL.val; import static org.jooq.impl.DefaultMetaProvider.meta; import static org.jooq.impl.DerivedTable.NO_SUPPORT_CORRELATED_DERIVED_TABLE; @@ -387,6 +390,77 @@ implements throw new DataAccessException("The many-to-many MULTISET convenience feature is available in the commercial jOOQ distribution only. Please consider upgrading to the jOOQ Professional Edition or jOOQ Enterprise Edition."); } + /** + * Create a MULTISET one-to-many child table expression from + * this table. + */ + @org.jooq.Internal + @NotNull + protected Condition oneToManyExists( + ForeignKey path, + Function, ? extends TableLike> f + ) { + if (CONFIG.commercial()) { + + + + + + + + + + + + + + + + + + + + } + + throw new DataAccessException("The one-to-many EXISTS convenience feature is available in the commercial jOOQ distribution only. Please consider upgrading to the jOOQ Professional Edition or jOOQ Enterprise Edition."); + } + + /** + * Create a MULTISET many-to-many child table expression from + * this table. + */ + @org.jooq.Internal + @NotNull + protected Condition manyToManyExists( + ForeignKey path1, + ForeignKey path2, + Function, ? extends TableLike> f + ) { + if (CONFIG.commercial()) { + + + + + + + + + + + + + + + + + + + + } + + throw new DataAccessException("The many-to-many EXISTS convenience feature is available in the commercial jOOQ distribution only. Please consider upgrading to the jOOQ Professional Edition or jOOQ Enterprise Edition."); + } +