[jOOQ/jOOQ#15212] Add <genericConverter/> and <genericBinding/> to allow

for passing T and U types to custom Converter and Binding instances
This commit is contained in:
Lukas Eder 2023-06-13 09:58:50 +02:00
parent 97311cafda
commit da073d8de0
4 changed files with 216 additions and 3 deletions

View File

@ -282,11 +282,22 @@ public abstract class AbstractTypedElementDefinition<T extends Definition>
converter = resolver.ref(Converter.class) + ".of" + (!FALSE.equals(c.isNullable()) ? "Nullable" : "") + "(" + resolver.classLiteral(tType) + ", " + resolver.classLiteral(uType) + ", " + c.getFrom() + ", " + c.getTo() + ")";
}
else if (!StringUtils.isBlank(customType.getConverter())) {
converter = customType.getConverter();
if (TRUE.equals(customType.isGenericConverter())) {
String tType = tType(db, resolver, definedType);
converter = resolver.constructorCall(customType.getConverter() + "<" + resolver.ref(tType) + ", " + resolver.ref(uType) + ">") + "(" + resolver.classLiteral(tType) + ", " + resolver.classLiteral(uType) + ")";
}
else
converter = customType.getConverter();
}
if (!StringUtils.isBlank(customType.getBinding()))
binding = customType.getBinding();
if (!StringUtils.isBlank(customType.getBinding())) {
if (TRUE.equals(customType.isGenericBinding())) {
String tType = tType(db, resolver, definedType);
binding = resolver.constructorCall(customType.getBinding() + "<" + resolver.ref(tType) + ", " + resolver.ref(uType) + ">") + "(" + resolver.classLiteral(tType) + ", " + resolver.classLiteral(uType) + ")";
}
else
binding = customType.getBinding();
}
}
@ -415,7 +426,9 @@ public abstract class AbstractTypedElementDefinition<T extends Definition>
else {
return new CustomType()
.withBinding(forcedType.getBinding())
.withGenericBinding(forcedType.isGenericBinding())
.withAutoConverter(forcedType.isAutoConverter())
.withGenericConverter(forcedType.isGenericConverter())
.withEnumConverter(forcedType.isEnumConverter())
.withXmlConverter(forcedType.isXmlConverter())
.withJsonConverter(forcedType.isJsonConverter())

View File

@ -46,6 +46,7 @@ public class CustomType implements Serializable, XMLAppendable
protected Boolean auditUpdateUser;
@XmlJavaTypeAdapter(StringAdapter.class)
protected String converter;
protected Boolean genericConverter;
protected Boolean autoConverter;
protected Boolean enumConverter;
protected Boolean xmlConverter;
@ -53,6 +54,7 @@ public class CustomType implements Serializable, XMLAppendable
protected LambdaConverter lambdaConverter;
@XmlJavaTypeAdapter(StringAdapter.class)
protected String binding;
protected Boolean genericBinding;
/**
* @deprecated Use ForcedType only
@ -248,6 +250,32 @@ public class CustomType implements Serializable, XMLAppendable
this.converter = value;
}
/**
* @deprecated Use ForcedType only
*
* @return
* possible object is
* {@link Boolean }
*
*/
@Deprecated
public Boolean isGenericConverter() {
return genericConverter;
}
/**
* Sets the value of the genericConverter property.
*
* @param value
* allowed object is
* {@link Boolean }
*
*/
@Deprecated
public void setGenericConverter(Boolean value) {
this.genericConverter = value;
}
/**
* @deprecated Use ForcedType only
*
@ -388,6 +416,32 @@ public class CustomType implements Serializable, XMLAppendable
this.binding = value;
}
/**
* @deprecated Use ForcedType only
*
* @return
* possible object is
* {@link Boolean }
*
*/
@Deprecated
public Boolean isGenericBinding() {
return genericBinding;
}
/**
* Sets the value of the genericBinding property.
*
* @param value
* allowed object is
* {@link Boolean }
*
*/
@Deprecated
public void setGenericBinding(Boolean value) {
this.genericBinding = value;
}
/**
* @deprecated Use ForcedType only
*
@ -458,6 +512,11 @@ public class CustomType implements Serializable, XMLAppendable
return this;
}
public CustomType withGenericConverter(Boolean value) {
setGenericConverter(value);
return this;
}
public CustomType withAutoConverter(Boolean value) {
setAutoConverter(value);
return this;
@ -498,6 +557,11 @@ public class CustomType implements Serializable, XMLAppendable
return this;
}
public CustomType withGenericBinding(Boolean value) {
setGenericBinding(value);
return this;
}
@Override
public final void appendTo(XMLBuilder builder) {
builder.append("name", name);
@ -509,12 +573,14 @@ public class CustomType implements Serializable, XMLAppendable
builder.append("auditUpdateTimestamp", auditUpdateTimestamp);
builder.append("auditUpdateUser", auditUpdateUser);
builder.append("converter", converter);
builder.append("genericConverter", genericConverter);
builder.append("autoConverter", autoConverter);
builder.append("enumConverter", enumConverter);
builder.append("xmlConverter", xmlConverter);
builder.append("jsonConverter", jsonConverter);
builder.append("lambdaConverter", lambdaConverter);
builder.append("binding", binding);
builder.append("genericBinding", genericBinding);
}
@Override
@ -617,6 +683,15 @@ public class CustomType implements Serializable, XMLAppendable
return false;
}
}
if (genericConverter == null) {
if (other.genericConverter!= null) {
return false;
}
} else {
if (!genericConverter.equals(other.genericConverter)) {
return false;
}
}
if (autoConverter == null) {
if (other.autoConverter!= null) {
return false;
@ -671,6 +746,15 @@ public class CustomType implements Serializable, XMLAppendable
return false;
}
}
if (genericBinding == null) {
if (other.genericBinding!= null) {
return false;
}
} else {
if (!genericBinding.equals(other.genericBinding)) {
return false;
}
}
return true;
}
@ -687,12 +771,14 @@ public class CustomType implements Serializable, XMLAppendable
result = ((prime*result)+((auditUpdateTimestamp == null)? 0 :auditUpdateTimestamp.hashCode()));
result = ((prime*result)+((auditUpdateUser == null)? 0 :auditUpdateUser.hashCode()));
result = ((prime*result)+((converter == null)? 0 :converter.hashCode()));
result = ((prime*result)+((genericConverter == null)? 0 :genericConverter.hashCode()));
result = ((prime*result)+((autoConverter == null)? 0 :autoConverter.hashCode()));
result = ((prime*result)+((enumConverter == null)? 0 :enumConverter.hashCode()));
result = ((prime*result)+((xmlConverter == null)? 0 :xmlConverter.hashCode()));
result = ((prime*result)+((jsonConverter == null)? 0 :jsonConverter.hashCode()));
result = ((prime*result)+((lambdaConverter == null)? 0 :lambdaConverter.hashCode()));
result = ((prime*result)+((binding == null)? 0 :binding.hashCode()));
result = ((prime*result)+((genericBinding == null)? 0 :genericBinding.hashCode()));
return result;
}

View File

@ -46,6 +46,7 @@ public class ForcedType implements Serializable, XMLAppendable
protected Boolean auditUpdateUser;
@XmlJavaTypeAdapter(StringAdapter.class)
protected String converter;
protected Boolean genericConverter;
protected Boolean autoConverter;
protected Boolean enumConverter;
protected Boolean xmlConverter;
@ -53,6 +54,7 @@ public class ForcedType implements Serializable, XMLAppendable
protected LambdaConverter lambdaConverter;
@XmlJavaTypeAdapter(StringAdapter.class)
protected String binding;
protected Boolean genericBinding;
@XmlJavaTypeAdapter(StringAdapter.class)
protected String excludeExpression;
@XmlJavaTypeAdapter(StringAdapter.class)
@ -306,6 +308,30 @@ public class ForcedType implements Serializable, XMLAppendable
this.converter = value;
}
/**
* Whether the converter is generic, receiving <code>&lt;T, U&gt;</code> type variables as well as <code>Class&lt;T&gt;</class> and <code>Class&lt;U&gt;</class> constructor arguments.
*
* @return
* possible object is
* {@link Boolean }
*
*/
public Boolean isGenericConverter() {
return genericConverter;
}
/**
* Sets the value of the genericConverter property.
*
* @param value
* allowed object is
* {@link Boolean }
*
*/
public void setGenericConverter(Boolean value) {
this.genericConverter = value;
}
/**
* Whether the converter is an {@link org.jooq.impl.AutoConverter}.
*
@ -434,6 +460,30 @@ public class ForcedType implements Serializable, XMLAppendable
this.binding = value;
}
/**
* Whether the binding is generic, receiving <code>&lt;T, U&gt;</code> type variables as well as <code>Class&lt;T&gt;</class> and <code>Class&lt;U&gt;</class> constructor arguments.
*
* @return
* possible object is
* {@link Boolean }
*
*/
public Boolean isGenericBinding() {
return genericBinding;
}
/**
* Sets the value of the genericBinding property.
*
* @param value
* allowed object is
* {@link Boolean }
*
*/
public void setGenericBinding(Boolean value) {
this.genericBinding = value;
}
/**
* A Java regular expression matching columns, parameters, attributes,
* etc. which must not have this type. Excludes match before includes, i.e.
@ -693,6 +743,11 @@ public class ForcedType implements Serializable, XMLAppendable
return this;
}
public ForcedType withGenericConverter(Boolean value) {
setGenericConverter(value);
return this;
}
public ForcedType withAutoConverter(Boolean value) {
setAutoConverter(value);
return this;
@ -731,6 +786,11 @@ public class ForcedType implements Serializable, XMLAppendable
return this;
}
public ForcedType withGenericBinding(Boolean value) {
setGenericBinding(value);
return this;
}
/**
* A Java regular expression matching columns, parameters, attributes,
* etc. which must not have this type. Excludes match before includes, i.e.
@ -840,12 +900,14 @@ public class ForcedType implements Serializable, XMLAppendable
builder.append("auditUpdateTimestamp", auditUpdateTimestamp);
builder.append("auditUpdateUser", auditUpdateUser);
builder.append("converter", converter);
builder.append("genericConverter", genericConverter);
builder.append("autoConverter", autoConverter);
builder.append("enumConverter", enumConverter);
builder.append("xmlConverter", xmlConverter);
builder.append("jsonConverter", jsonConverter);
builder.append("lambdaConverter", lambdaConverter);
builder.append("binding", binding);
builder.append("genericBinding", genericBinding);
builder.append("excludeExpression", excludeExpression);
builder.append("includeExpression", includeExpression);
builder.append("expression", expression);
@ -967,6 +1029,15 @@ public class ForcedType implements Serializable, XMLAppendable
return false;
}
}
if (genericConverter == null) {
if (other.genericConverter!= null) {
return false;
}
} else {
if (!genericConverter.equals(other.genericConverter)) {
return false;
}
}
if (autoConverter == null) {
if (other.autoConverter!= null) {
return false;
@ -1021,6 +1092,15 @@ public class ForcedType implements Serializable, XMLAppendable
return false;
}
}
if (genericBinding == null) {
if (other.genericBinding!= null) {
return false;
}
} else {
if (!genericBinding.equals(other.genericBinding)) {
return false;
}
}
if (excludeExpression == null) {
if (other.excludeExpression!= null) {
return false;
@ -1128,12 +1208,14 @@ public class ForcedType implements Serializable, XMLAppendable
result = ((prime*result)+((auditUpdateTimestamp == null)? 0 :auditUpdateTimestamp.hashCode()));
result = ((prime*result)+((auditUpdateUser == null)? 0 :auditUpdateUser.hashCode()));
result = ((prime*result)+((converter == null)? 0 :converter.hashCode()));
result = ((prime*result)+((genericConverter == null)? 0 :genericConverter.hashCode()));
result = ((prime*result)+((autoConverter == null)? 0 :autoConverter.hashCode()));
result = ((prime*result)+((enumConverter == null)? 0 :enumConverter.hashCode()));
result = ((prime*result)+((xmlConverter == null)? 0 :xmlConverter.hashCode()));
result = ((prime*result)+((jsonConverter == null)? 0 :jsonConverter.hashCode()));
result = ((prime*result)+((lambdaConverter == null)? 0 :lambdaConverter.hashCode()));
result = ((prime*result)+((binding == null)? 0 :binding.hashCode()));
result = ((prime*result)+((genericBinding == null)? 0 :genericBinding.hashCode()));
result = ((prime*result)+((excludeExpression == null)? 0 :excludeExpression.hashCode()));
result = ((prime*result)+((includeExpression == null)? 0 :includeExpression.hashCode()));
result = ((prime*result)+((expression == null)? 0 :expression.hashCode()));

View File

@ -1655,6 +1655,18 @@ This feature is available in the commercial distribution only.]]></jxb:javadoc><
</annotation>
</element>
<element name="genericConverter" type="boolean" minOccurs="0" maxOccurs="1">
<annotation>
<appinfo>
<jxb:property>
<jxb:javadoc><![CDATA[@deprecated Use ForcedType only]]></jxb:javadoc>
</jxb:property>
<annox:annotate target="getter">@java.lang.Deprecated</annox:annotate>
<annox:annotate target="setter">@java.lang.Deprecated</annox:annotate>
</appinfo>
</annotation>
</element>
<element name="autoConverter" type="boolean" minOccurs="0" maxOccurs="1" fixed="true">
<annotation>
<appinfo>
@ -1726,6 +1738,18 @@ This feature is available in the commercial distribution only.]]></jxb:javadoc><
</appinfo>
</annotation>
</element>
<element name="genericBinding" type="boolean" minOccurs="0" maxOccurs="1">
<annotation>
<appinfo>
<jxb:property>
<jxb:javadoc><![CDATA[@deprecated Use ForcedType only]]></jxb:javadoc>
</jxb:property>
<annox:annotate target="getter">@java.lang.Deprecated</annox:annotate>
<annox:annotate target="setter">@java.lang.Deprecated</annox:annotate>
</appinfo>
</annotation>
</element>
</all>
</complexType>
@ -1866,6 +1890,10 @@ This feature is available in the commercial distribution only.]]></jxb:javadoc><
<annotation><appinfo><jxb:property><jxb:javadoc><![CDATA[A converter implementation for the {@link #getUserType()}.]]></jxb:javadoc></jxb:property></appinfo></annotation>
</element>
<element name="genericConverter" type="boolean" minOccurs="0" maxOccurs="1">
<annotation><appinfo><jxb:property><jxb:javadoc><![CDATA[Whether the converter is generic, receiving <code>&lt;T, U&gt;</code> type variables as well as <code>Class&lt;T&gt;</class> and <code>Class&lt;U&gt;</class> constructor arguments.]]></jxb:javadoc></jxb:property></appinfo></annotation>
</element>
<element name="autoConverter" type="boolean" minOccurs="0" maxOccurs="1">
<annotation><appinfo><jxb:property><jxb:javadoc><![CDATA[Whether the converter is an {@link org.jooq.impl.AutoConverter}.]]></jxb:javadoc></jxb:property></appinfo></annotation>
</element>
@ -1890,6 +1918,10 @@ This feature is available in the commercial distribution only.]]></jxb:javadoc><
<annotation><appinfo><jxb:property><jxb:javadoc><![CDATA[A {@link org.jooq.Binding} implementation for the custom type.]]></jxb:javadoc></jxb:property></appinfo></annotation>
</element>
<element name="genericBinding" type="boolean" minOccurs="0" maxOccurs="1">
<annotation><appinfo><jxb:property><jxb:javadoc><![CDATA[Whether the binding is generic, receiving <code>&lt;T, U&gt;</code> type variables as well as <code>Class&lt;T&gt;</class> and <code>Class&lt;U&gt;</class> constructor arguments.]]></jxb:javadoc></jxb:property></appinfo></annotation>
</element>
<element name="excludeExpression" type="string" minOccurs="0" maxOccurs="1">
<annotation><appinfo><jxb:property><jxb:javadoc><![CDATA[A Java regular expression matching columns, parameters, attributes,
etc. which must not have this type. Excludes match before includes, i.e.