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 104210e4a6..efa2d061ef 100644 --- a/jOOQ-codegen/src/main/java/org/jooq/codegen/AbstractGenerator.java +++ b/jOOQ-codegen/src/main/java/org/jooq/codegen/AbstractGenerator.java @@ -76,6 +76,7 @@ abstract class AbstractGenerator implements Generator { boolean generateUDTPaths = true; boolean generateImplicitJoinPathsToOne = true; boolean generateImplicitJoinPathsToMany = true; + boolean generateImplicitJoinPathsManyToMany = true; boolean generateImplicitJoinPathTableSubtypes = true; boolean generateImplicitJoinPathUnusedConstructors = true; boolean generateImplicitJoinPathsAsKotlinProperties = true; @@ -357,6 +358,21 @@ abstract class AbstractGenerator implements Generator { this.generateImplicitJoinPathsToMany = generateImplicitJoinPathsToMany; } + @Override + public boolean generateImplicitJoinPathsManyToMany() { + + // [#17681] The to-one path of the ManyToManyKeyDefinition.foreignKey2 property must be available + return generateImplicitJoinPathsToMany + && generateImplicitJoinPathsToOne() + && generateImplicitJoinPathsToMany() + && generateRelations(); + } + + @Override + public void setGenerateImplicitJoinPathsManyToMany(boolean generateImplicitJoinPathsManyToMany) { + this.generateImplicitJoinPathsManyToMany = generateImplicitJoinPathsManyToMany; + } + @Override public boolean generateImplicitJoinPathTableSubtypes() { return generateImplicitJoinPathTableSubtypes && 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 ab44ff8139..b9026ecd63 100644 --- a/jOOQ-codegen/src/main/java/org/jooq/codegen/GenerationTool.java +++ b/jOOQ-codegen/src/main/java/org/jooq/codegen/GenerationTool.java @@ -751,6 +751,8 @@ public class GenerationTool { generator.setGenerateImplicitJoinPathsToOne(g.getGenerate().isImplicitJoinPathsToOne()); if (g.getGenerate().isImplicitJoinPathsToMany() != null) generator.setGenerateImplicitJoinPathsToMany(g.getGenerate().isImplicitJoinPathsToMany()); + if (g.getGenerate().isImplicitJoinPathsManyToMany() != null) + generator.setGenerateImplicitJoinPathsManyToMany(g.getGenerate().isImplicitJoinPathsManyToMany()); if (g.getGenerate().isImplicitJoinPathTableSubtypes() != null) generator.setGenerateImplicitJoinPathTableSubtypes(g.getGenerate().isImplicitJoinPathTableSubtypes()); if (g.getGenerate().isImplicitJoinPathUnusedConstructors() != 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 f2d4b5065c..3d770b98c1 100644 --- a/jOOQ-codegen/src/main/java/org/jooq/codegen/Generator.java +++ b/jOOQ-codegen/src/main/java/org/jooq/codegen/Generator.java @@ -160,6 +160,18 @@ public interface Generator { */ void setGenerateImplicitJoinPathsToMany(boolean generateImplicitJoinPathsToMany); + /** + * Whether implicit join path constructors on generated tables for + * many-to-many relationships should be generated. + */ + boolean generateImplicitJoinPathsManyToMany(); + + /** + * Whether implicit join path constructors on generated tables for + * many-to-many relationships should be generated. + */ + void setGenerateImplicitJoinPathsManyToMany(boolean generateImplicitJoinPathsManyToMany); + /** * Whether to generate implicit join path table subtypes implementing * {@link Path} for increased JOIN convenience. 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 38c843b382..1429b1025a 100644 --- a/jOOQ-codegen/src/main/java/org/jooq/codegen/JavaGenerator.java +++ b/jOOQ-codegen/src/main/java/org/jooq/codegen/JavaGenerator.java @@ -8089,8 +8089,7 @@ public class JavaGenerator extends AbstractGenerator { } } - // [#17681] The to-one path of the ManyToManyKeyDefinition.foreignKey2 property must be available - if (generateImplicitJoinPathsToOne()) { + if (generateImplicitJoinPathsManyToMany()) { List manyToManyKeys = table.getManyToManyKeys(); Map pathCountsManytoMany = manyToManyKeys.stream().collect(groupingBy(d -> d.getForeignKey2().getReferencedTable(), counting())); 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 82d74815ba..e4d0e9ef05 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,8 @@ public class Generate implements Serializable, XMLAppendable @XmlElement(defaultValue = "true") protected Boolean implicitJoinPathsToMany = true; @XmlElement(defaultValue = "true") + protected Boolean implicitJoinPathsManyToMany = true; + @XmlElement(defaultValue = "true") protected Boolean implicitJoinPathTableSubtypes = true; @XmlElement(defaultValue = "false") protected Boolean implicitJoinPathUnusedConstructors = false; @@ -451,6 +453,30 @@ public class Generate implements Serializable, XMLAppendable this.implicitJoinPathsToMany = value; } + /** + * Generate implicit join path constructors on generated tables for many-to-many relationships. This turns off implicitly, if either of the other path generations are turned off. + * + * @return + * possible object is + * {@link Boolean } + * + */ + public Boolean isImplicitJoinPathsManyToMany() { + return implicitJoinPathsManyToMany; + } + + /** + * Generate implicit join path constructors on generated tables for many-to-many relationships. This turns off implicitly, if either of the other path generations are turned off. + * + * @param value + * allowed object is + * {@link Boolean } + * + */ + public void setImplicitJoinPathsManyToMany(Boolean value) { + this.implicitJoinPathsManyToMany = value; + } + /** * Generate implicit join path table subtypes implementing {@link org.jooq.Path} for increased JOIN convenience. * @@ -3594,6 +3620,15 @@ public class Generate implements Serializable, XMLAppendable return this; } + /** + * Generate implicit join path constructors on generated tables for many-to-many relationships. This turns off implicitly, if either of the other path generations are turned off. + * + */ + public Generate withImplicitJoinPathsManyToMany(Boolean value) { + setImplicitJoinPathsManyToMany(value); + return this; + } + /** * Generate implicit join path table subtypes implementing {@link org.jooq.Path} for increased JOIN convenience. * @@ -4843,6 +4878,7 @@ public class Generate implements Serializable, XMLAppendable builder.append("udtPaths", udtPaths); builder.append("implicitJoinPathsToOne", implicitJoinPathsToOne); builder.append("implicitJoinPathsToMany", implicitJoinPathsToMany); + builder.append("implicitJoinPathsManyToMany", implicitJoinPathsManyToMany); builder.append("implicitJoinPathTableSubtypes", implicitJoinPathTableSubtypes); builder.append("implicitJoinPathUnusedConstructors", implicitJoinPathUnusedConstructors); builder.append("implicitJoinPathsUseTableNameForUnambiguousFKs", implicitJoinPathsUseTableNameForUnambiguousFKs); @@ -5045,6 +5081,15 @@ public class Generate implements Serializable, XMLAppendable return false; } } + if (implicitJoinPathsManyToMany == null) { + if (other.implicitJoinPathsManyToMany!= null) { + return false; + } + } else { + if (!implicitJoinPathsManyToMany.equals(other.implicitJoinPathsManyToMany)) { + return false; + } + } if (implicitJoinPathTableSubtypes == null) { if (other.implicitJoinPathTableSubtypes!= null) { return false; @@ -6201,6 +6246,7 @@ public class Generate implements Serializable, XMLAppendable result = ((prime*result)+((udtPaths == null)? 0 :udtPaths.hashCode())); result = ((prime*result)+((implicitJoinPathsToOne == null)? 0 :implicitJoinPathsToOne.hashCode())); result = ((prime*result)+((implicitJoinPathsToMany == null)? 0 :implicitJoinPathsToMany.hashCode())); + result = ((prime*result)+((implicitJoinPathsManyToMany == null)? 0 :implicitJoinPathsManyToMany.hashCode())); result = ((prime*result)+((implicitJoinPathTableSubtypes == null)? 0 :implicitJoinPathTableSubtypes.hashCode())); result = ((prime*result)+((implicitJoinPathUnusedConstructors == null)? 0 :implicitJoinPathUnusedConstructors.hashCode())); result = ((prime*result)+((implicitJoinPathsUseTableNameForUnambiguousFKs == null)? 0 :implicitJoinPathsUseTableNameForUnambiguousFKs.hashCode())); diff --git a/jOOQ-meta/src/main/resources/org/jooq/meta/xsd/jooq-codegen-3.20.0.xsd b/jOOQ-meta/src/main/resources/org/jooq/meta/xsd/jooq-codegen-3.20.0.xsd index e0d3786385..bc5cb6e5b6 100644 --- a/jOOQ-meta/src/main/resources/org/jooq/meta/xsd/jooq-codegen-3.20.0.xsd +++ b/jOOQ-meta/src/main/resources/org/jooq/meta/xsd/jooq-codegen-3.20.0.xsd @@ -2550,6 +2550,10 @@ This is a prerequisite for various advanced features]]> + + + +