[jOOQ/jOOQ#10511] Add <embeddableDomains/> to allow for wrapping all

DOMAIN types in embeddables
This commit is contained in:
Lukas Eder 2020-08-20 15:38:48 +02:00
parent c76e505a60
commit bb16438f07
9 changed files with 247 additions and 15 deletions

View File

@ -52,8 +52,10 @@ import static org.jooq.SQLDialect.POSTGRES;
import java.util.ArrayList;
import java.util.List;
// ...
import org.jooq.meta.ArrayDefinition;
import org.jooq.meta.CatalogDefinition;
import org.jooq.meta.ColumnDefinition;
import org.jooq.meta.Definition;
import org.jooq.meta.DomainDefinition;
import org.jooq.meta.EmbeddableDefinition;
@ -160,10 +162,30 @@ public class DefaultGeneratorStrategy extends AbstractGeneratorStrategy {
else if (definition instanceof EmbeddableDefinition)
return ((EmbeddableDefinition) definition).getReferencingOutputName().toUpperCase();
else
return definition.getOutputName().toUpperCase();
}
private String getterSetterSuffix(Definition definition) {
// [#5354] Please forgive me but this is how it works.

View File

@ -531,6 +531,7 @@ public class GenerationTool {
database.setIncludeInvisibleColumns(!FALSE.equals(d.isIncludeInvisibleColumns()));
database.setIncludePrimaryKeys(!FALSE.equals(d.isIncludePrimaryKeys()));
database.setIncludeRoutines(!FALSE.equals(d.isIncludeRoutines()));
database.setIncludeDomains(!FALSE.equals(d.isIncludeDomains()));
database.setIncludeSequences(!FALSE.equals(d.isIncludeSequences()));
database.setIncludeTables(!FALSE.equals(d.isIncludeTables()));
database.setIncludeEmbeddables(!FALSE.equals(d.isIncludeEmbeddables()));
@ -549,6 +550,7 @@ public class GenerationTool {
database.setConfiguredEmbeddables(d.getEmbeddables());
database.setEmbeddablePrimaryKeys(TRUE.equals(g.getDatabase().isEmbeddablePrimaryKeys()));
database.setEmbeddableUniqueKeys(TRUE.equals(g.getDatabase().isEmbeddableUniqueKeys()));
database.setEmbeddableDomains(TRUE.equals(g.getDatabase().isEmbeddableDomains()));
database.setLogSlowQueriesAfterSeconds(defaultIfNull(g.getDatabase().getLogSlowQueriesAfterSeconds(), 5));
database.setLogSlowResultsAfterSeconds(defaultIfNull(g.getDatabase().getLogSlowResultsAfterSeconds(), 5));

View File

@ -1248,7 +1248,8 @@ public class JavaGenerator extends AbstractGenerator {
for (TableDefinition table : database.getTables(schema)) {
try {
generateRecord(table);
} catch (Exception e) {
}
catch (Exception e) {
log.error("Error while generating table record " + table, e);
}
}
@ -1260,7 +1261,7 @@ public class JavaGenerator extends AbstractGenerator {
protected void generateRecord(TableDefinition table) {
JavaWriter out = newJavaWriter(getFile(table, Mode.RECORD));
log.info("Generating record", out.file().getName());
generateRecord(table, out);
generateRecord0(table, out);
closeJavaWriter(out);
}
@ -1395,7 +1396,6 @@ public class JavaGenerator extends AbstractGenerator {
if (tableUdtOrEmbeddable instanceof TableDefinition) {
generateRecordSetter(column, i, out);
generateRecordGetter(column, i, out);

View File

@ -39,6 +39,7 @@
package org.jooq.meta;
import static java.lang.Boolean.TRUE;
import static java.util.Arrays.asList;
import static org.jooq.Log.Level.ERROR;
import static org.jooq.SQLDialect.CUBRID;
import static org.jooq.SQLDialect.FIREBIRD;
@ -143,6 +144,7 @@ public abstract class AbstractDatabase implements Database {
private boolean includePackageUDTs = true;
private boolean includePackageConstants = true;
private boolean includeUDTs = true;
private boolean includeDomains = true;
private boolean includeSequences = true;
private boolean includeIndexes = true;
private boolean includeCheckConstraints = true;
@ -159,6 +161,7 @@ public abstract class AbstractDatabase implements Database {
private String[] syntheticIdentities;
private boolean embeddablePrimaryKeys = false;
private boolean embeddableUniqueKeys = false;
private boolean embeddableDomains = false;
private boolean supportsUnsignedTypes;
private boolean integerDisplayWidths;
private boolean ignoreProcedureReturnValues;
@ -1030,6 +1033,16 @@ public abstract class AbstractDatabase implements Database {
this.includeUDTs = includeUDTs;
}
@Override
public final boolean getIncludeDomains() {
return includeDomains;
}
@Override
public final void setIncludeDomains(boolean includeDomains) {
this.includeDomains = includeDomains;
}
@Override
public final boolean getIncludeSequences() {
return includeSequences;
@ -1490,7 +1503,7 @@ public abstract class AbstractDatabase implements Database {
}
@Override
public final List<SequenceDefinition> getSequences(SchemaDefinition schema) {
public final List<SequenceDefinition> getSequences() {
if (sequences == null) {
sequences = new ArrayList<>();
@ -1509,10 +1522,15 @@ public abstract class AbstractDatabase implements Database {
log.info("Sequences excluded");
}
return sequences;
}
@Override
public final List<SequenceDefinition> getSequences(SchemaDefinition schema) {
if (sequencesBySchema == null)
sequencesBySchema = new LinkedHashMap<>();
return filterSchema(sequences, schema, sequencesBySchema);
return filterSchema(getSequences(), schema, sequencesBySchema);
}
@Override
@ -1842,6 +1860,23 @@ public abstract class AbstractDatabase implements Database {
this.embeddableUniqueKeys = embeddableUniqueKeys;
}
@Override
public boolean embeddableDomains() {
return embeddableDomains;
}
@SuppressWarnings("unused")
@Override
public void setEmbeddableDomains(boolean embeddableDomains) {
if (embeddableDomains)
log.info("Commercial feature", "Embeddable domains are a commercial only feature. Please consider upgrading to the jOOQ Professional Edition");
this.embeddableDomains = embeddableDomains;
}
@Override
public final List<EmbeddableDefinition> getEmbeddables() {
if (embeddables == null) {
@ -2005,6 +2040,37 @@ public abstract class AbstractDatabase implements Database {
@ -2050,25 +2116,34 @@ public abstract class AbstractDatabase implements Database {
}
@Override
public final List<DomainDefinition> getDomains(SchemaDefinition schema) {
public final List<DomainDefinition> getDomains() {
if (domains == null) {
domains = new ArrayList<>();
onError(ERROR, "Error while fetching domains", new ExceptionRunnable() {
@Override
public void run() throws Exception {
List<DomainDefinition> e = getDomains0();
if (getIncludeDomains()) {
onError(ERROR, "Error while fetching domains", new ExceptionRunnable() {
@Override
public void run() throws Exception {
List<DomainDefinition> e = getDomains0();
domains = sort(filterExcludeInclude(e));
log.info("Domains fetched", fetchedSize(e, domains));
}
});
domains = sort(filterExcludeInclude(e));
log.info("Domains fetched", fetchedSize(e, domains));
}
});
}
else
log.info("Domains excluded");
}
return domains;
}
@Override
public final List<DomainDefinition> getDomains(SchemaDefinition schema) {
if (domainsBySchema == null)
domainsBySchema = new LinkedHashMap<>();
return filterSchema(domains, schema, domainsBySchema);
return filterSchema(getDomains(), schema, domainsBySchema);
}
@Override

View File

@ -335,4 +335,9 @@ public abstract class AbstractTypedElementDefinition<T extends Definition>
return null;
}
@Override
public final DomainDefinition getDomain() {
return getDatabase().getDomain(getSchema(), getDefinedType().getQualifiedUserType());
}
}

View File

@ -94,6 +94,11 @@ public interface Database extends AutoCloseable {
*/
Relations getRelations();
/**
* The sequences contained in this database.
*/
List<SequenceDefinition> getSequences();
/**
* The sequences contained in this database.
*/
@ -214,6 +219,11 @@ public interface Database extends AutoCloseable {
*/
EnumDefinition getEnum(SchemaDefinition schema, Name name, boolean ignoreCase);
/**
* The domain UDTs defined in this database.
*/
List<DomainDefinition> getDomains();
/**
* The domain UDTs defined in this database.
*/
@ -489,6 +499,16 @@ public interface Database extends AutoCloseable {
*/
boolean getIncludeIndexes();
/**
* whether domains should be included.
*/
void setIncludeDomains(boolean includeDomains);
/**
* whether domains should be included.
*/
boolean getIncludeDomains();
/**
* whether sequences should be included.
*/
@ -918,6 +938,16 @@ public interface Database extends AutoCloseable {
*/
void setEmbeddableUniqueKeys(boolean embeddableUniqueKeys);
/**
* Whether embeddable types for domains should be generated.
*/
boolean embeddableDomains();
/**
* Whether embeddable types for domains should be generated.
*/
void setEmbeddableDomains(boolean embeddableDomains);
/**
* Get the dialect for this database.
*/

View File

@ -64,4 +64,10 @@ public interface TypedElementDefinition<T extends Definition> extends Definition
* The container that contains this typed element.
*/
T getContainer();
/**
* The column / parameter / attribute domain type, or <code>null</code>, if
* it does not reference a domain.
*/
DomainDefinition getDomain();
}

View File

@ -70,6 +70,8 @@ public class Database implements Serializable, XMLAppendable
@XmlElement(defaultValue = "true")
protected Boolean includeUDTs = true;
@XmlElement(defaultValue = "true")
protected Boolean includeDomains = true;
@XmlElement(defaultValue = "true")
protected Boolean includeSequences = true;
@XmlElement(defaultValue = "true")
protected Boolean includeIndexes = true;
@ -137,6 +139,8 @@ public class Database implements Serializable, XMLAppendable
protected Boolean embeddablePrimaryKeys = false;
@XmlElement(defaultValue = "false")
protected Boolean embeddableUniqueKeys = false;
@XmlElement(defaultValue = "false")
protected Boolean embeddableDomains = false;
@XmlElement(defaultValue = "true")
protected Boolean forceIntegerTypesOnZeroScaleDecimals = true;
protected Boolean tableValuedFunctions;
@ -641,6 +645,30 @@ public class Database implements Serializable, XMLAppendable
this.includeUDTs = value;
}
/**
* This flag indicates whether domains should be included in output produced by this database
*
* @return
* possible object is
* {@link Boolean }
*
*/
public Boolean isIncludeDomains() {
return includeDomains;
}
/**
* Sets the value of the includeDomains property.
*
* @param value
* allowed object is
* {@link Boolean }
*
*/
public void setIncludeDomains(Boolean value) {
this.includeDomains = value;
}
/**
* This flag indicates whether sequences should be included in output produced by this database
*
@ -1407,6 +1435,30 @@ public class Database implements Serializable, XMLAppendable
this.embeddableUniqueKeys = value;
}
/**
* Whether wrapper types should be generated for domain types.
*
* @return
* possible object is
* {@link Boolean }
*
*/
public Boolean isEmbeddableDomains() {
return embeddableDomains;
}
/**
* Sets the value of the embeddableDomains property.
*
* @param value
* allowed object is
* {@link Boolean }
*
*/
public void setEmbeddableDomains(Boolean value) {
this.embeddableDomains = value;
}
/**
* Historically, zero-scale decimal types are generated as their most appropriate, corresponding integer type (e.g. NUMBER(2, 0) and less: Byte). This allows for turning off this feature. In case of conflict between this rule and actual {@link #getForcedTypes()}, the latter will win.
*
@ -1781,6 +1833,11 @@ public class Database implements Serializable, XMLAppendable
return this;
}
public Database withIncludeDomains(Boolean value) {
setIncludeDomains(value);
return this;
}
public Database withIncludeSequences(Boolean value) {
setIncludeSequences(value);
return this;
@ -2051,6 +2108,11 @@ public class Database implements Serializable, XMLAppendable
return this;
}
public Database withEmbeddableDomains(Boolean value) {
setEmbeddableDomains(value);
return this;
}
public Database withForceIntegerTypesOnZeroScaleDecimals(Boolean value) {
setForceIntegerTypesOnZeroScaleDecimals(value);
return this;
@ -2250,6 +2312,7 @@ public class Database implements Serializable, XMLAppendable
builder.append("includePackageUDTs", includePackageUDTs);
builder.append("includePackageConstants", includePackageConstants);
builder.append("includeUDTs", includeUDTs);
builder.append("includeDomains", includeDomains);
builder.append("includeSequences", includeSequences);
builder.append("includeIndexes", includeIndexes);
builder.append("includePrimaryKeys", includePrimaryKeys);
@ -2279,6 +2342,7 @@ public class Database implements Serializable, XMLAppendable
builder.append("orderProvider", orderProvider);
builder.append("embeddablePrimaryKeys", embeddablePrimaryKeys);
builder.append("embeddableUniqueKeys", embeddableUniqueKeys);
builder.append("embeddableDomains", embeddableDomains);
builder.append("forceIntegerTypesOnZeroScaleDecimals", forceIntegerTypesOnZeroScaleDecimals);
builder.append("tableValuedFunctions", tableValuedFunctions);
builder.append("logSlowQueriesAfterSeconds", logSlowQueriesAfterSeconds);
@ -2455,6 +2519,15 @@ public class Database implements Serializable, XMLAppendable
return false;
}
}
if (includeDomains == null) {
if (other.includeDomains!= null) {
return false;
}
} else {
if (!includeDomains.equals(other.includeDomains)) {
return false;
}
}
if (includeSequences == null) {
if (other.includeSequences!= null) {
return false;
@ -2716,6 +2789,15 @@ public class Database implements Serializable, XMLAppendable
return false;
}
}
if (embeddableDomains == null) {
if (other.embeddableDomains!= null) {
return false;
}
} else {
if (!embeddableDomains.equals(other.embeddableDomains)) {
return false;
}
}
if (forceIntegerTypesOnZeroScaleDecimals == null) {
if (other.forceIntegerTypesOnZeroScaleDecimals!= null) {
return false;
@ -2838,6 +2920,7 @@ public class Database implements Serializable, XMLAppendable
result = ((prime*result)+((includePackageUDTs == null)? 0 :includePackageUDTs.hashCode()));
result = ((prime*result)+((includePackageConstants == null)? 0 :includePackageConstants.hashCode()));
result = ((prime*result)+((includeUDTs == null)? 0 :includeUDTs.hashCode()));
result = ((prime*result)+((includeDomains == null)? 0 :includeDomains.hashCode()));
result = ((prime*result)+((includeSequences == null)? 0 :includeSequences.hashCode()));
result = ((prime*result)+((includeIndexes == null)? 0 :includeIndexes.hashCode()));
result = ((prime*result)+((includePrimaryKeys == null)? 0 :includePrimaryKeys.hashCode()));
@ -2867,6 +2950,7 @@ public class Database implements Serializable, XMLAppendable
result = ((prime*result)+((orderProvider == null)? 0 :orderProvider.hashCode()));
result = ((prime*result)+((embeddablePrimaryKeys == null)? 0 :embeddablePrimaryKeys.hashCode()));
result = ((prime*result)+((embeddableUniqueKeys == null)? 0 :embeddableUniqueKeys.hashCode()));
result = ((prime*result)+((embeddableDomains == null)? 0 :embeddableDomains.hashCode()));
result = ((prime*result)+((forceIntegerTypesOnZeroScaleDecimals == null)? 0 :forceIntegerTypesOnZeroScaleDecimals.hashCode()));
result = ((prime*result)+((tableValuedFunctions == null)? 0 :tableValuedFunctions.hashCode()));
result = ((prime*result)+((logSlowQueriesAfterSeconds == null)? 0 :logSlowQueriesAfterSeconds.hashCode()));

View File

@ -617,6 +617,10 @@ Excludes match before includes, i.e. excludes have a higher priority.]]></jxb:ja
<annotation><appinfo><jxb:property><jxb:javadoc><![CDATA[This flag indicates whether udts should be included in output produced by this database]]></jxb:javadoc></jxb:property></appinfo></annotation>
</element>
<element name="includeDomains" type="boolean" default="true" minOccurs="0" maxOccurs="1">
<annotation><appinfo><jxb:property><jxb:javadoc><![CDATA[This flag indicates whether domains should be included in output produced by this database]]></jxb:javadoc></jxb:property></appinfo></annotation>
</element>
<element name="includeSequences" type="boolean" default="true" minOccurs="0" maxOccurs="1">
<annotation><appinfo><jxb:property><jxb:javadoc><![CDATA[This flag indicates whether sequences should be included in output produced by this database]]></jxb:javadoc></jxb:property></appinfo></annotation>
</element>
@ -848,6 +852,10 @@ This comparator can be used to influence the order of any object that is produce
<element name="embeddableUniqueKeys" type="boolean" default="false" minOccurs="0" maxOccurs="1">
<annotation><appinfo><jxb:property><jxb:javadoc><![CDATA[Whether wrapper types should be generated for unique key columns, and for their referencing foreign keys.]]></jxb:javadoc></jxb:property></appinfo></annotation>
</element>
<element name="embeddableDomains" type="boolean" default="false" minOccurs="0" maxOccurs="1">
<annotation><appinfo><jxb:property><jxb:javadoc><![CDATA[Whether wrapper types should be generated for domain types.]]></jxb:javadoc></jxb:property></appinfo></annotation>
</element>
<element name="customTypes" type="tns:CustomTypes" minOccurs="0" maxOccurs="1">
<annotation>