[#7415] Add ability for MatcherStrategy to allow for customizing enum class names
This commit is contained in:
parent
44a6049562
commit
d0737ce8e4
@ -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<MatchersSchemaType> schemas(Definition definition) {
|
||||
if (definition instanceof SchemaDefinition) {
|
||||
if (definition instanceof SchemaDefinition)
|
||||
return matchers.getSchemas();
|
||||
}
|
||||
|
||||
return emptyList();
|
||||
}
|
||||
|
||||
private final List<MatchersTableType> tables(Definition definition) {
|
||||
if (definition instanceof TableDefinition) {
|
||||
if (definition instanceof TableDefinition)
|
||||
return matchers.getTables();
|
||||
}
|
||||
|
||||
return emptyList();
|
||||
}
|
||||
|
||||
private final List<MatchersFieldType> fields(Definition definition) {
|
||||
if (definition instanceof ColumnDefinition) {
|
||||
if (definition instanceof ColumnDefinition)
|
||||
return matchers.getFields();
|
||||
}
|
||||
|
||||
return emptyList();
|
||||
}
|
||||
|
||||
private final List<MatchersRoutineType> routines(Definition definition) {
|
||||
if (definition instanceof RoutineDefinition) {
|
||||
if (definition instanceof RoutineDefinition)
|
||||
return matchers.getRoutines();
|
||||
}
|
||||
|
||||
return emptyList();
|
||||
}
|
||||
|
||||
private final List<MatchersSequenceType> sequences(Definition definition) {
|
||||
if (definition instanceof SequenceDefinition) {
|
||||
if (definition instanceof SequenceDefinition)
|
||||
return matchers.getSequences();
|
||||
}
|
||||
|
||||
return emptyList();
|
||||
}
|
||||
|
||||
private final List<MatchersEnumType> enums(Definition definition) {
|
||||
if (definition instanceof EnumDefinition)
|
||||
return matchers.getEnums();
|
||||
|
||||
return emptyList();
|
||||
}
|
||||
@ -174,9 +177,8 @@ public class MatcherStrategy extends DefaultGeneratorStrategy {
|
||||
private final List<String> split(String result) {
|
||||
List<String> list = new ArrayList<String>();
|
||||
|
||||
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);
|
||||
}
|
||||
|
||||
@ -17660,7 +17660,7 @@ public class Book implements java.io.Serializable {
|
||||
<generator>
|
||||
<strategy>
|
||||
<matchers>
|
||||
<!-- Specify 0..n schema matchers in order to provide a naming strategy for objects created from schemas. -->
|
||||
<!-- Specify 0..n schema matchers to provide a strategy for naming objects created from schemas. -->
|
||||
<schemas>
|
||||
<schema>
|
||||
|
||||
@ -17674,8 +17674,7 @@ public class Book implements java.io.Serializable {
|
||||
</schema>
|
||||
</schemas>
|
||||
|
||||
<!-- Specify 0..n table matchers in order to provide a naming strategy for objects
|
||||
created from database tables. -->
|
||||
<!-- Specify 0..n table matchers to provide a strategy for naming objects created from tables. -->
|
||||
<tables>
|
||||
<table>
|
||||
|
||||
@ -17707,8 +17706,7 @@ public class Book implements java.io.Serializable {
|
||||
</table>
|
||||
</tables>
|
||||
|
||||
<!-- Specify 0..n field matchers in order to provide a naming strategy for objects
|
||||
created from table fields. -->
|
||||
<!-- Specify 0..n field matchers to provide a strategy for naming objects created from fields. -->
|
||||
<fields>
|
||||
<field>
|
||||
|
||||
@ -17723,8 +17721,7 @@ public class Book implements java.io.Serializable {
|
||||
</field>
|
||||
</fields>
|
||||
|
||||
<!-- Specify 0..n routine matchers in order to provide a naming strategy for objects
|
||||
created from routines. -->
|
||||
<!-- Specify 0..n routine matchers to provide a strategy for naming objects created from routines. -->
|
||||
<routines>
|
||||
<routine>
|
||||
|
||||
@ -17738,8 +17735,7 @@ public class Book implements java.io.Serializable {
|
||||
</routine>
|
||||
</routines>
|
||||
|
||||
<!-- Specify 0..n sequence matchers in order to provide a naming strategy for objects
|
||||
created from sequences. -->
|
||||
<!-- Specify 0..n sequence matchers to provide a strategy for naming objects created from sequences. -->
|
||||
<sequences>
|
||||
<sequence>
|
||||
|
||||
@ -17750,6 +17746,19 @@ public class Book implements java.io.Serializable {
|
||||
<sequenceIdentifier> --> MatcherRule </sequenceIdentifier>
|
||||
</sequence>
|
||||
</sequences>
|
||||
|
||||
<!-- Specify 0..n enum matchers to provide a strategy for naming objects created from enums. -->
|
||||
<enums>
|
||||
<enum>
|
||||
|
||||
<!-- Match unqualified or qualified enum names. If left empty, this matcher applies to all enums. -->
|
||||
<expression>MY_ENUM</expression>
|
||||
|
||||
<!-- These elements influence the naming of a generated org.jooq.EnumType object. -->
|
||||
<enumClass> --> MatcherRule </enumClass>
|
||||
<enumImplements>com.example.MyOptionalCustomInterface</enumImplements>
|
||||
</enum>
|
||||
</enums>
|
||||
</matchers>
|
||||
</strategy>
|
||||
</generator>]]></xml><html>
|
||||
|
||||
@ -56,6 +56,12 @@
|
||||
<bindings if-exists="true" scd="~tns:MatchersSequenceType">
|
||||
<class ref="org.jooq.util.jaxb.MatchersSequenceType"/>
|
||||
</bindings>
|
||||
<bindings if-exists="true" scd="~tns:MatchersEnumsType">
|
||||
<class ref="org.jooq.util.jaxb.MatchersEnumsType"/>
|
||||
</bindings>
|
||||
<bindings if-exists="true" scd="~tns:MatchersEnumType">
|
||||
<class ref="org.jooq.util.jaxb.MatchersEnumType"/>
|
||||
</bindings>
|
||||
<bindings if-exists="true" scd="~tns:MatcherRule">
|
||||
<class ref="org.jooq.util.jaxb.MatcherRule"/>
|
||||
</bindings>
|
||||
|
||||
@ -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<MatchersSequenceType> sequences;
|
||||
@XmlElementWrapper(name = "enums")
|
||||
@XmlElement(name = "enum")
|
||||
protected List<MatchersEnumType> enums;
|
||||
|
||||
public List<MatchersSchemaType> getSchemas() {
|
||||
if (schemas == null) {
|
||||
@ -111,6 +115,17 @@ public class Matchers implements Serializable
|
||||
this.sequences = sequences;
|
||||
}
|
||||
|
||||
public List<MatchersEnumType> getEnums() {
|
||||
if (enums == null) {
|
||||
enums = new ArrayList<MatchersEnumType>();
|
||||
}
|
||||
return enums;
|
||||
}
|
||||
|
||||
public void setEnums(List<MatchersEnumType> 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<MatchersEnumType> values) {
|
||||
if (values!= null) {
|
||||
getEnums().addAll(values);
|
||||
}
|
||||
return this;
|
||||
}
|
||||
|
||||
public Matchers withEnums(List<MatchersEnumType> 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("</sequences>");
|
||||
}
|
||||
if (enums!= null) {
|
||||
sb.append("<enums>");
|
||||
sb.append(enums);
|
||||
sb.append("</enums>");
|
||||
}
|
||||
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;
|
||||
}
|
||||
|
||||
|
||||
202
jOOQ-meta/src/main/java/org/jooq/util/jaxb/MatchersEnumType.java
Normal file
202
jOOQ-meta/src/main/java/org/jooq/util/jaxb/MatchersEnumType.java
Normal file
@ -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("<expression>");
|
||||
sb.append(expression);
|
||||
sb.append("</expression>");
|
||||
}
|
||||
if (enumClass!= null) {
|
||||
sb.append("<enumClass>");
|
||||
sb.append(enumClass);
|
||||
sb.append("</enumClass>");
|
||||
}
|
||||
if (enumImplements!= null) {
|
||||
sb.append("<enumImplements>");
|
||||
sb.append(enumImplements);
|
||||
sb.append("</enumImplements>");
|
||||
}
|
||||
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;
|
||||
}
|
||||
|
||||
}
|
||||
@ -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 }
|
||||
*
|
||||
|
||||
@ -144,6 +144,10 @@
|
||||
<element name="sequences" type="tns:MatchersSequencesType" minOccurs="0" maxOccurs="1">
|
||||
<annotation><appinfo><jxb:property><jxb:javadoc><![CDATA[Declarative naming strategy configuration for sequence names.]]></jxb:javadoc></jxb:property></appinfo></annotation>
|
||||
</element>
|
||||
|
||||
<element name="enums" type="tns:MatchersEnumsType" minOccurs="0" maxOccurs="1">
|
||||
<annotation><appinfo><jxb:property><jxb:javadoc><![CDATA[Declarative naming strategy configuration for enum names.]]></jxb:javadoc></jxb:property></appinfo></annotation>
|
||||
</element>
|
||||
</sequence>
|
||||
</complexType>
|
||||
|
||||
@ -314,6 +318,29 @@
|
||||
</all>
|
||||
</complexType>
|
||||
|
||||
<complexType name="MatchersEnumsType">
|
||||
<sequence>
|
||||
<element name="enum" type="tns:MatchersEnumType" minOccurs="1" maxOccurs="unbounded"/>
|
||||
</sequence>
|
||||
</complexType>
|
||||
|
||||
<complexType name="MatchersEnumType">
|
||||
<annotation><appinfo><jxb:class><jxb:javadoc><![CDATA[Declarative naming strategy configuration for enum names.]]></jxb:javadoc></jxb:class></appinfo></annotation>
|
||||
<all>
|
||||
<element name="expression" type="string" minOccurs="0" maxOccurs="1">
|
||||
<annotation><appinfo><jxb:property><jxb:javadoc><![CDATA[This sequence matcher applies to all unqualified or qualified enum names matched by this expression. If left empty, this matcher applies to all enums.]]></jxb:javadoc></jxb:property></appinfo></annotation>
|
||||
</element>
|
||||
|
||||
<element name="enumClass" type="tns:MatcherRule" minOccurs="0" maxOccurs="1">
|
||||
<annotation><appinfo><jxb:property><jxb:javadoc><![CDATA[This rule influences the naming of the generated {@link org.jooq.EnumType} object.]]></jxb:javadoc></jxb:property></appinfo></annotation>
|
||||
</element>
|
||||
|
||||
<element name="enumImplements" type="string" minOccurs="0" maxOccurs="1">
|
||||
<annotation><appinfo><jxb:property><jxb:javadoc><![CDATA[This string provides additional interfaces that a generated {@link org.jooq.EnumType} should implement.]]></jxb:javadoc></jxb:property></appinfo></annotation>
|
||||
</element>
|
||||
</all>
|
||||
</complexType>
|
||||
|
||||
<complexType name="MatcherRule">
|
||||
<all>
|
||||
<element name="transform" type="tns:MatcherTransformType" minOccurs="0" maxOccurs="1">
|
||||
|
||||
Loading…
Reference in New Issue
Block a user