Skip to content

Commit

Permalink
[#17683] Add an additional code generation flag to turn off many-to-m…
Browse files Browse the repository at this point in the history
…any relationship generation
  • Loading branch information
lukaseder committed Nov 27, 2024
1 parent bdec001 commit 800b4e6
Show file tree
Hide file tree
Showing 6 changed files with 81 additions and 2 deletions.
16 changes: 16 additions & 0 deletions jOOQ-codegen/src/main/java/org/jooq/codegen/AbstractGenerator.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -357,6 +358,21 @@ public void setGenerateImplicitJoinPathsToMany(boolean generateImplicitJoinPaths
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();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -751,6 +751,8 @@ else if (schema.getOutputSchema() == null)
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)
Expand Down
12 changes: 12 additions & 0 deletions jOOQ-codegen/src/main/java/org/jooq/codegen/Generator.java
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8089,8 +8089,7 @@ else if (kotlin) {
}
}

// [#17681] The to-one path of the ManyToManyKeyDefinition.foreignKey2 property must be available
if (generateImplicitJoinPathsToOne()) {
if (generateImplicitJoinPathsManyToMany()) {
List<ManyToManyKeyDefinition> manyToManyKeys = table.getManyToManyKeys();
Map<TableDefinition, Long> pathCountsManytoMany = manyToManyKeys.stream().collect(groupingBy(d -> d.getForeignKey2().getReferencedTable(), counting()));

Expand Down
46 changes: 46 additions & 0 deletions jOOQ-meta/src/main/java/org/jooq/meta/jaxb/Generate.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -451,6 +453,30 @@ public void setImplicitJoinPathsToMany(Boolean value) {
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.
*
Expand Down Expand Up @@ -3594,6 +3620,15 @@ public Generate withImplicitJoinPathsToMany(Boolean value) {
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.
*
Expand Down Expand Up @@ -4843,6 +4878,7 @@ public final void appendTo(XMLBuilder builder) {
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);
Expand Down Expand Up @@ -5045,6 +5081,15 @@ public boolean equals(Object that) {
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;
Expand Down Expand Up @@ -6201,6 +6246,7 @@ public int hashCode() {
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()));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2550,6 +2550,10 @@ This is a prerequisite for various advanced features]]></jxb:javadoc></jxb:prope
<element name="implicitJoinPathsToMany" type="boolean" default="true" minOccurs="0" maxOccurs="1">
<annotation><appinfo><jxb:property><jxb:javadoc><![CDATA[Generate implicit join path constructors on generated tables for incoming foreign key relationships (to-many relationships)]]></jxb:javadoc></jxb:property></appinfo></annotation>
</element>

<element name="implicitJoinPathsManyToMany" type="boolean" default="true" minOccurs="0" maxOccurs="1">
<annotation><appinfo><jxb:property><jxb:javadoc><![CDATA[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.]]></jxb:javadoc></jxb:property></appinfo></annotation>
</element>

<element name="implicitJoinPathTableSubtypes" type="boolean" default="true" minOccurs="0" maxOccurs="1">
<annotation><appinfo><jxb:property><jxb:javadoc><![CDATA[Generate implicit join path table subtypes implementing {@link org.jooq.Path} for increased JOIN convenience.]]></jxb:javadoc></jxb:property></appinfo></annotation>
Expand Down

0 comments on commit 800b4e6

Please sign in to comment.