[#6944] Add a way to specify what object type a <forcedType/> should match

This commit is contained in:
lukaseder 2019-02-21 10:02:37 +01:00
parent d8f06d6b1c
commit c154c58c57
5 changed files with 131 additions and 0 deletions

View File

@ -221,6 +221,12 @@
</bindings>
<bindings if-exists="true" scd="~tns:ForcedTypeObjectType">
<typesafeEnumClass ref="org.jooq.meta.jaxb.ForcedTypeObjectType"/>
</bindings>
<bindings if-exists="true" scd="~tns:RegexFlag">
<typesafeEnumClass ref="org.jooq.meta.jaxb.RegexFlag"/>

View File

@ -78,6 +78,7 @@ import org.jooq.meta.jaxb.CatalogMappingType;
import org.jooq.meta.jaxb.CustomType;
import org.jooq.meta.jaxb.EnumType;
import org.jooq.meta.jaxb.ForcedType;
import org.jooq.meta.jaxb.ForcedTypeObjectType;
import org.jooq.meta.jaxb.Nullability;
import org.jooq.meta.jaxb.RegexFlag;
import org.jooq.meta.jaxb.SchemaMappingType;
@ -1406,6 +1407,15 @@ public abstract class AbstractDatabase implements Database {
String expression = StringUtils.defaultIfNull(forcedType.getExpressions(), forcedType.getExpression());
String types = forcedType.getTypes();
Nullability nullability = forcedType.getNullability();
ForcedTypeObjectType objectType = forcedType.getObjectType();
if ( (objectType != null && objectType != ForcedTypeObjectType.ALL)
&& ((objectType == ForcedTypeObjectType.ATTRIBUTE && !(definition instanceof AttributeDefinition))
|| (objectType == ForcedTypeObjectType.COLUMN && !(definition instanceof ColumnDefinition))
|| (objectType == ForcedTypeObjectType.ELEMENT && !(definition instanceof ArrayDefinition))
|| (objectType == ForcedTypeObjectType.PARAMETER && !(definition instanceof ParameterDefinition))
|| (objectType == ForcedTypeObjectType.SEQUENCE && !(definition instanceof SequenceDefinition))))
continue forcedTypeLoop;
if ( (nullability != null && nullability != Nullability.ALL)
&& ((nullability == Nullability.NOT_NULL && definedType.isNullable())

View File

@ -53,6 +53,9 @@ public class ForcedType implements Serializable
@XmlElement(defaultValue = "ALL")
@XmlSchemaType(name = "string")
protected Nullability nullability = Nullability.ALL;
@XmlElement(defaultValue = "ALL")
@XmlSchemaType(name = "string")
protected ForcedTypeObjectType objectType = ForcedTypeObjectType.ALL;
/**
* The name (in {@link org.jooq.impl.SQLDataType}) to force any matches to
@ -276,6 +279,30 @@ public class ForcedType implements Serializable
this.nullability = value;
}
/**
* Whether this forced type should apply to all object types, or only to specific ones
*
* @return
* possible object is
* {@link ForcedTypeObjectType }
*
*/
public ForcedTypeObjectType getObjectType() {
return objectType;
}
/**
* Sets the value of the objectType property.
*
* @param value
* allowed object is
* {@link ForcedTypeObjectType }
*
*/
public void setObjectType(ForcedTypeObjectType value) {
this.objectType = value;
}
public ForcedType withName(String value) {
setName(value);
return this;
@ -321,6 +348,11 @@ public class ForcedType implements Serializable
return this;
}
public ForcedType withObjectType(ForcedTypeObjectType value) {
setObjectType(value);
return this;
}
@Override
public String toString() {
StringBuilder sb = new StringBuilder();
@ -369,6 +401,11 @@ public class ForcedType implements Serializable
sb.append(nullability);
sb.append("</nullability>");
}
if (objectType!= null) {
sb.append("<objectType>");
sb.append(objectType);
sb.append("</objectType>");
}
return sb.toString();
}
@ -465,6 +502,15 @@ public class ForcedType implements Serializable
return false;
}
}
if (objectType == null) {
if (other.objectType!= null) {
return false;
}
} else {
if (!objectType.equals(other.objectType)) {
return false;
}
}
return true;
}
@ -481,6 +527,7 @@ public class ForcedType implements Serializable
result = ((prime*result)+((expressions == null)? 0 :expressions.hashCode()));
result = ((prime*result)+((types == null)? 0 :types.hashCode()));
result = ((prime*result)+((nullability == null)? 0 :nullability.hashCode()));
result = ((prime*result)+((objectType == null)? 0 :objectType.hashCode()));
return result;
}

View File

@ -0,0 +1,53 @@
package org.jooq.meta.jaxb;
import javax.xml.bind.annotation.XmlEnum;
import javax.xml.bind.annotation.XmlType;
/**
* <p>Java class for ForcedTypeObjectType.
*
* <p>The following schema fragment specifies the expected content contained within this class.
* <p>
* <pre>
* &lt;simpleType name="ForcedTypeObjectType"&gt;
* &lt;restriction base="{http://www.w3.org/2001/XMLSchema}string"&gt;
* &lt;enumeration value="ALL"/&gt;
* &lt;enumeration value="ATTRIBUTE"/&gt;
* &lt;enumeration value="COLUMN"/&gt;
* &lt;enumeration value="ELEMENT"/&gt;
* &lt;enumeration value="PARAMETER"/&gt;
* &lt;enumeration value="SEQUENCE"/&gt;
* &lt;/restriction&gt;
* &lt;/simpleType&gt;
* </pre>
*
*/
@XmlType(name = "ForcedTypeObjectType")
@XmlEnum
public enum ForcedTypeObjectType {
ALL,
ATTRIBUTE,
COLUMN,
ELEMENT,
PARAMETER,
SEQUENCE;
public String value() {
return name();
}
public static ForcedTypeObjectType fromValue(String v) {
return valueOf(v);
}
}

View File

@ -873,9 +873,24 @@ type. If provided, both "expression" and "types" must match.]]></jxb:javadoc></j
<element name="nullability" type="tns:Nullability" default="ALL" minOccurs="0" maxOccurs="1">
<annotation><appinfo><jxb:property><jxb:javadoc><![CDATA[Whether this forced type should apply to nullable / non-nullable / all columns]]></jxb:javadoc></jxb:property></appinfo></annotation>
</element>
<element name="objectType" type="tns:ForcedTypeObjectType" default="ALL" minOccurs="0" maxOccurs="1">
<annotation><appinfo><jxb:property><jxb:javadoc><![CDATA[Whether this forced type should apply to all object types, or only to specific ones]]></jxb:javadoc></jxb:property></appinfo></annotation>
</element>
</all>
</complexType>
<simpleType name="ForcedTypeObjectType">
<restriction base="string">
<enumeration value="ALL"/>
<enumeration value="ATTRIBUTE"/>
<enumeration value="COLUMN"/>
<enumeration value="ELEMENT"/>
<enumeration value="PARAMETER"/>
<enumeration value="SEQUENCE"/>
</restriction>
</simpleType>
<complexType name="Generate">
<annotation><appinfo><jxb:class><jxb:javadoc><![CDATA[Options strictly related to generated code.]]></jxb:javadoc></jxb:class></appinfo></annotation>
<all>