diff --git a/jOOQ-codegen/src/main/java/org/jooq/util/MatcherStrategy.java b/jOOQ-codegen/src/main/java/org/jooq/util/MatcherStrategy.java index 03e8b83920..4aedf617a7 100644 --- a/jOOQ-codegen/src/main/java/org/jooq/util/MatcherStrategy.java +++ b/jOOQ-codegen/src/main/java/org/jooq/util/MatcherStrategy.java @@ -50,6 +50,7 @@ import org.jooq.tools.StringUtils; import org.jooq.util.jaxb.MatcherRule; import org.jooq.util.jaxb.MatcherTransformType; import org.jooq.util.jaxb.Matchers; +import org.jooq.util.jaxb.MatchersEnumType; import org.jooq.util.jaxb.MatchersFieldType; import org.jooq.util.jaxb.MatchersRoutineType; import org.jooq.util.jaxb.MatchersSchemaType; @@ -132,41 +133,43 @@ public class MatcherStrategy extends DefaultGeneratorStrategy { } private final List schemas(Definition definition) { - if (definition instanceof SchemaDefinition) { + if (definition instanceof SchemaDefinition) return matchers.getSchemas(); - } return emptyList(); } private final List tables(Definition definition) { - if (definition instanceof TableDefinition) { + if (definition instanceof TableDefinition) return matchers.getTables(); - } return emptyList(); } private final List fields(Definition definition) { - if (definition instanceof ColumnDefinition) { + if (definition instanceof ColumnDefinition) return matchers.getFields(); - } return emptyList(); } private final List routines(Definition definition) { - if (definition instanceof RoutineDefinition) { + if (definition instanceof RoutineDefinition) return matchers.getRoutines(); - } return emptyList(); } private final List sequences(Definition definition) { - if (definition instanceof SequenceDefinition) { + if (definition instanceof SequenceDefinition) return matchers.getSequences(); - } + + return emptyList(); + } + + private final List enums(Definition definition) { + if (definition instanceof EnumDefinition) + return matchers.getEnums(); return emptyList(); } @@ -174,9 +177,8 @@ public class MatcherStrategy extends DefaultGeneratorStrategy { private final List split(String result) { List list = new ArrayList(); - for (String string : result.split(",")) { + for (String string : result.split(",")) list.add(string.trim()); - } return list; } @@ -294,6 +296,12 @@ public class MatcherStrategy extends DefaultGeneratorStrategy { return split(result); } + for (MatchersEnumType enums : enums(definition)) { + String result = match(definition, enums.getExpression(), enums.getEnumImplements()); + if (result != null) + return split(result); + } + // Default to standard behaviour return super.getJavaClassImplements(definition, mode); } @@ -327,6 +335,12 @@ public class MatcherStrategy extends DefaultGeneratorStrategy { return result; } + for (MatchersEnumType enums : enums(definition)) { + String result = match(definition, enums.getExpression(), enums.getEnumClass()); + if (result != null) + return result; + } + // Default to standard behaviour return super.getJavaClassName(definition, mode); } diff --git a/jOOQ-manual/src/main/resources/org/jooq/web/manual-3.11.xml b/jOOQ-manual/src/main/resources/org/jooq/web/manual-3.11.xml index b44a05a8bf..583198fc02 100644 --- a/jOOQ-manual/src/main/resources/org/jooq/web/manual-3.11.xml +++ b/jOOQ-manual/src/main/resources/org/jooq/web/manual-3.11.xml @@ -17660,7 +17660,7 @@ public class Book implements java.io.Serializable { - + @@ -17674,8 +17674,7 @@ public class Book implements java.io.Serializable { - + @@ -17707,8 +17706,7 @@ public class Book implements java.io.Serializable {
- + @@ -17723,8 +17721,7 @@ public class Book implements java.io.Serializable { - + @@ -17738,8 +17735,7 @@ public class Book implements java.io.Serializable { - + @@ -17750,6 +17746,19 @@ public class Book implements java.io.Serializable { --> MatcherRule + + + + + + + MY_ENUM + + + --> MatcherRule + com.example.MyOptionalCustomInterface + +
]]> diff --git a/jOOQ-meta/src/main/java/META-INF/sun-jaxb.episode b/jOOQ-meta/src/main/java/META-INF/sun-jaxb.episode index a88eb268f3..5b9e6905b9 100644 --- a/jOOQ-meta/src/main/java/META-INF/sun-jaxb.episode +++ b/jOOQ-meta/src/main/java/META-INF/sun-jaxb.episode @@ -56,6 +56,12 @@ + + + + + + diff --git a/jOOQ-meta/src/main/java/org/jooq/util/jaxb/Matchers.java b/jOOQ-meta/src/main/java/org/jooq/util/jaxb/Matchers.java index 9fcd8032e6..b318f3c2c6 100644 --- a/jOOQ-meta/src/main/java/org/jooq/util/jaxb/Matchers.java +++ b/jOOQ-meta/src/main/java/org/jooq/util/jaxb/Matchers.java @@ -31,7 +31,8 @@ import javax.xml.bind.annotation.XmlType; "tables", "fields", "routines", - "sequences" + "sequences", + "enums" }) @SuppressWarnings({ "all" @@ -55,6 +56,9 @@ public class Matchers implements Serializable @XmlElementWrapper(name = "sequences") @XmlElement(name = "sequence") protected List sequences; + @XmlElementWrapper(name = "enums") + @XmlElement(name = "enum") + protected List enums; public List getSchemas() { if (schemas == null) { @@ -111,6 +115,17 @@ public class Matchers implements Serializable this.sequences = sequences; } + public List getEnums() { + if (enums == null) { + enums = new ArrayList(); + } + return enums; + } + + public void setEnums(List enums) { + this.enums = enums; + } + public Matchers withSchemas(MatchersSchemaType... values) { if (values!= null) { for (MatchersSchemaType value: values) { @@ -216,6 +231,27 @@ public class Matchers implements Serializable return this; } + public Matchers withEnums(MatchersEnumType... values) { + if (values!= null) { + for (MatchersEnumType value: values) { + getEnums().add(value); + } + } + return this; + } + + public Matchers withEnums(Collection values) { + if (values!= null) { + getEnums().addAll(values); + } + return this; + } + + public Matchers withEnums(List enums) { + setEnums(enums); + return this; + } + @Override public String toString() { StringBuilder sb = new StringBuilder(); @@ -244,6 +280,11 @@ public class Matchers implements Serializable sb.append(sequences); sb.append(""); } + if (enums!= null) { + sb.append(""); + sb.append(enums); + sb.append(""); + } return sb.toString(); } @@ -304,6 +345,15 @@ public class Matchers implements Serializable return false; } } + if (enums == null) { + if (other.enums!= null) { + return false; + } + } else { + if (!enums.equals(other.enums)) { + return false; + } + } return true; } @@ -316,6 +366,7 @@ public class Matchers implements Serializable result = ((prime*result)+((fields == null)? 0 :fields.hashCode())); result = ((prime*result)+((routines == null)? 0 :routines.hashCode())); result = ((prime*result)+((sequences == null)? 0 :sequences.hashCode())); + result = ((prime*result)+((enums == null)? 0 :enums.hashCode())); return result; } diff --git a/jOOQ-meta/src/main/java/org/jooq/util/jaxb/MatchersEnumType.java b/jOOQ-meta/src/main/java/org/jooq/util/jaxb/MatchersEnumType.java new file mode 100644 index 0000000000..03c13740d2 --- /dev/null +++ b/jOOQ-meta/src/main/java/org/jooq/util/jaxb/MatchersEnumType.java @@ -0,0 +1,202 @@ + + + + + + + + +package org.jooq.util.jaxb; + +import java.io.Serializable; +import javax.xml.bind.annotation.XmlAccessType; +import javax.xml.bind.annotation.XmlAccessorType; +import javax.xml.bind.annotation.XmlType; +import javax.xml.bind.annotation.adapters.XmlJavaTypeAdapter; +import org.jooq.util.jaxb.tools.StringAdapter; + + +/** + * Declarative naming strategy configuration for enum names. + * + * + * + */ +@XmlAccessorType(XmlAccessType.FIELD) +@XmlType(name = "MatchersEnumType", propOrder = { + +}) +@SuppressWarnings({ + "all" +}) +public class MatchersEnumType implements Serializable +{ + + private final static long serialVersionUID = 31100L; + @XmlJavaTypeAdapter(StringAdapter.class) + protected String expression; + protected MatcherRule enumClass; + @XmlJavaTypeAdapter(StringAdapter.class) + protected String enumImplements; + + /** + * This sequence matcher applies to all unqualified or qualified enum names matched by this expression. If left empty, this matcher applies to all enums. + * + * @return + * possible object is + * {@link String } + * + */ + public String getExpression() { + return expression; + } + + /** + * Sets the value of the expression property. + * + * @param value + * allowed object is + * {@link String } + * + */ + public void setExpression(String value) { + this.expression = value; + } + + /** + * This rule influences the naming of the generated {@link org.jooq.EnumType} object. + * + * @return + * possible object is + * {@link MatcherRule } + * + */ + public MatcherRule getEnumClass() { + return enumClass; + } + + /** + * Sets the value of the enumClass property. + * + * @param value + * allowed object is + * {@link MatcherRule } + * + */ + public void setEnumClass(MatcherRule value) { + this.enumClass = value; + } + + /** + * This string provides additional interfaces that a generated {@link org.jooq.EnumType} should implement. + * + * @return + * possible object is + * {@link String } + * + */ + public String getEnumImplements() { + return enumImplements; + } + + /** + * Sets the value of the enumImplements property. + * + * @param value + * allowed object is + * {@link String } + * + */ + public void setEnumImplements(String value) { + this.enumImplements = value; + } + + public MatchersEnumType withExpression(String value) { + setExpression(value); + return this; + } + + public MatchersEnumType withEnumClass(MatcherRule value) { + setEnumClass(value); + return this; + } + + public MatchersEnumType withEnumImplements(String value) { + setEnumImplements(value); + return this; + } + + @Override + public String toString() { + StringBuilder sb = new StringBuilder(); + if (expression!= null) { + sb.append(""); + sb.append(expression); + sb.append(""); + } + if (enumClass!= null) { + sb.append(""); + sb.append(enumClass); + sb.append(""); + } + if (enumImplements!= null) { + sb.append(""); + sb.append(enumImplements); + sb.append(""); + } + return sb.toString(); + } + + @Override + public boolean equals(Object that) { + if (this == that) { + return true; + } + if (that == null) { + return false; + } + if (getClass()!= that.getClass()) { + return false; + } + MatchersEnumType other = ((MatchersEnumType) that); + if (expression == null) { + if (other.expression!= null) { + return false; + } + } else { + if (!expression.equals(other.expression)) { + return false; + } + } + if (enumClass == null) { + if (other.enumClass!= null) { + return false; + } + } else { + if (!enumClass.equals(other.enumClass)) { + return false; + } + } + if (enumImplements == null) { + if (other.enumImplements!= null) { + return false; + } + } else { + if (!enumImplements.equals(other.enumImplements)) { + return false; + } + } + return true; + } + + @Override + public int hashCode() { + final int prime = 31; + int result = 1; + result = ((prime*result)+((expression == null)? 0 :expression.hashCode())); + result = ((prime*result)+((enumClass == null)? 0 :enumClass.hashCode())); + result = ((prime*result)+((enumImplements == null)? 0 :enumImplements.hashCode())); + return result; + } + +} diff --git a/jOOQ-meta/src/main/java/org/jooq/util/jaxb/ObjectFactory.java b/jOOQ-meta/src/main/java/org/jooq/util/jaxb/ObjectFactory.java index 8d9bf5b738..3e454257ee 100644 --- a/jOOQ-meta/src/main/java/org/jooq/util/jaxb/ObjectFactory.java +++ b/jOOQ-meta/src/main/java/org/jooq/util/jaxb/ObjectFactory.java @@ -124,6 +124,14 @@ public class ObjectFactory { return new MatchersSequenceType(); } + /** + * Create an instance of {@link MatchersEnumType } + * + */ + public MatchersEnumType createMatchersEnumType() { + return new MatchersEnumType(); + } + /** * Create an instance of {@link MatcherRule } * diff --git a/jOOQ-meta/src/main/resources/xsd/jooq-codegen-3.11.0.xsd b/jOOQ-meta/src/main/resources/xsd/jooq-codegen-3.11.0.xsd index 6f18e6ddb9..4557578d1c 100644 --- a/jOOQ-meta/src/main/resources/xsd/jooq-codegen-3.11.0.xsd +++ b/jOOQ-meta/src/main/resources/xsd/jooq-codegen-3.11.0.xsd @@ -144,6 +144,10 @@ + + + + @@ -314,6 +318,29 @@ + + + + + + + + + + + + + + + + + + + + + + +