[jOOQ/jOOQ#17683] Add an additional code generation flag to turn off many-to-many relationship generation

This commit is contained in:
Lukas Eder 2024-11-27 16:20:17 +01:00
parent bdec0019fd
commit 800b4e6dd8
6 changed files with 81 additions and 2 deletions

View File

@ -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();

View File

@ -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)

View File

@ -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.

View File

@ -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<ManyToManyKeyDefinition> manyToManyKeys = table.getManyToManyKeys();
Map<TableDefinition, Long> pathCountsManytoMany = manyToManyKeys.stream().collect(groupingBy(d -> d.getForeignKey2().getReferencedTable(), counting()));

View File

@ -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()));

View File

@ -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>