[#3232] Add optional <type/> configuration to <customType/> in order to specify different converters for the same Java type
This commit is contained in:
parent
06dfaf5a2b
commit
90202fbb90
@ -360,9 +360,14 @@ public abstract class AbstractDatabase implements Database {
|
||||
}
|
||||
|
||||
@Override
|
||||
public final CustomType getConfiguredCustomType(String name) {
|
||||
public final CustomType getConfiguredCustomType(String typeName) {
|
||||
for (CustomType type : configuredCustomTypes) {
|
||||
if (type.getName().equals(name)) {
|
||||
if (type == null || (type.getName() == null && type.getType() == null)) {
|
||||
log.warn("Invalid custom type encountered: " + type);
|
||||
continue;
|
||||
}
|
||||
|
||||
if (StringUtils.equals(type.getType() != null ? type.getType() : type.getName(), typeName)) {
|
||||
return type;
|
||||
}
|
||||
}
|
||||
|
||||
@ -50,6 +50,8 @@ import org.jooq.exception.SQLDialectNotSupportedException;
|
||||
import org.jooq.impl.DefaultDataType;
|
||||
import org.jooq.impl.SQLDataType;
|
||||
import org.jooq.tools.JooqLogger;
|
||||
import org.jooq.tools.StringUtils;
|
||||
import org.jooq.util.jaxb.CustomType;
|
||||
import org.jooq.util.jaxb.ForcedType;
|
||||
|
||||
abstract class AbstractTypedElementDefinition<T extends Definition>
|
||||
@ -128,7 +130,9 @@ abstract class AbstractTypedElementDefinition<T extends Definition>
|
||||
// [#677] Forced types for matching regular expressions
|
||||
ForcedType forcedType = db.getConfiguredForcedType(child, definedType);
|
||||
if (forcedType != null) {
|
||||
log.debug("Forcing type", child + " into " + forcedType.getName());
|
||||
String type = getCustomType(db, forcedType.getName());
|
||||
|
||||
log.info("Forcing type", child + " into " + type);
|
||||
DataType<?> forcedDataType = null;
|
||||
|
||||
String t = result.getType();
|
||||
@ -139,20 +143,35 @@ abstract class AbstractTypedElementDefinition<T extends Definition>
|
||||
boolean d = result.isDefaulted();
|
||||
|
||||
try {
|
||||
forcedDataType = DefaultDataType.getDataType(db.getDialect(), forcedType.getName(), p, s);
|
||||
forcedDataType = DefaultDataType.getDataType(db.getDialect(), type, p, s);
|
||||
} catch (SQLDialectNotSupportedException ignore) {}
|
||||
|
||||
// [#677] SQLDataType matches are actual type-rewrites
|
||||
if (forcedDataType != null) {
|
||||
result = new DefaultDataTypeDefinition(db, child.getSchema(), forcedType.getName(), l, p, s, n, d);
|
||||
result = new DefaultDataTypeDefinition(db, child.getSchema(), type, l, p, s, n, d);
|
||||
}
|
||||
|
||||
// Other forced types are UDT's, enums, etc.
|
||||
else {
|
||||
result = new DefaultDataTypeDefinition(db, child.getSchema(), t, l, p, s, n, d, forcedType.getName());
|
||||
result = new DefaultDataTypeDefinition(db, child.getSchema(), t, l, p, s, n, d, type);
|
||||
}
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
private static String getCustomType(Database db, String name) {
|
||||
for (CustomType type : db.getConfiguredCustomTypes()) {
|
||||
if (name.equals(type.getName())) {
|
||||
if (!StringUtils.isBlank(type.getType())) {
|
||||
return type.getType();
|
||||
}
|
||||
else {
|
||||
return type.getName();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return name;
|
||||
}
|
||||
}
|
||||
|
||||
@ -485,6 +485,11 @@
|
||||
<all>
|
||||
<!-- The name of the custom type -->
|
||||
<element name="name" type="string" minOccurs="1" maxOccurs="1" />
|
||||
|
||||
<!-- The type of the custom type - e.g. java.time.LocalDateTime.
|
||||
For backwards-compatibility reasons, this information is optional. If left undefined,
|
||||
the "type" value will default to the "name" value. -->
|
||||
<element name="type" type="string" minOccurs="0" maxOccurs="1" />
|
||||
|
||||
<!-- A converter implementation for the custom type -->
|
||||
<element name="converter" type="string" minOccurs="1" maxOccurs="1" />
|
||||
|
||||
@ -9,7 +9,7 @@ package org.jooq.test.postgres.generatedclasses.tables;
|
||||
@java.lang.SuppressWarnings({ "all", "unchecked", "rawtypes" })
|
||||
public class T_2781 extends org.jooq.impl.TableImpl<org.jooq.test.postgres.generatedclasses.tables.records.T_2781Record> {
|
||||
|
||||
private static final long serialVersionUID = -56691512;
|
||||
private static final long serialVersionUID = 605276217;
|
||||
|
||||
/**
|
||||
* The singleton instance of <code>public.t_2781</code>
|
||||
@ -27,12 +27,12 @@ public class T_2781 extends org.jooq.impl.TableImpl<org.jooq.test.postgres.gener
|
||||
/**
|
||||
* The column <code>public.t_2781.org</code>.
|
||||
*/
|
||||
public final org.jooq.TableField<org.jooq.test.postgres.generatedclasses.tables.records.T_2781Record, java.lang.String> ORG = createField("org", org.jooq.impl.SQLDataType.CLOB, this, "");
|
||||
public final org.jooq.TableField<org.jooq.test.postgres.generatedclasses.tables.records.T_2781Record, java.lang.String> org_ = createField("org", org.jooq.impl.SQLDataType.CLOB, this, "");
|
||||
|
||||
/**
|
||||
* The column <code>public.t_2781.jooq</code>.
|
||||
*/
|
||||
public final org.jooq.TableField<org.jooq.test.postgres.generatedclasses.tables.records.T_2781Record, java.lang.String> JOOQ = createField("jooq", org.jooq.impl.SQLDataType.CLOB, this, "");
|
||||
public final org.jooq.TableField<org.jooq.test.postgres.generatedclasses.tables.records.T_2781Record, java.lang.String> jooq = createField("jooq", org.jooq.impl.SQLDataType.CLOB, this, "");
|
||||
|
||||
/**
|
||||
* Create a <code>public.t_2781</code> table reference
|
||||
|
||||
@ -9,7 +9,7 @@ package org.jooq.test.postgres.generatedclasses.tables.records;
|
||||
@java.lang.SuppressWarnings({ "all", "unchecked", "rawtypes" })
|
||||
public class T_2781Record extends org.jooq.impl.TableRecordImpl<org.jooq.test.postgres.generatedclasses.tables.records.T_2781Record> implements org.jooq.Record2<java.lang.String, java.lang.String>, org.jooq.test.postgres.generatedclasses.tables.interfaces.IT_2781 {
|
||||
|
||||
private static final long serialVersionUID = -579115035;
|
||||
private static final long serialVersionUID = -1293660246;
|
||||
|
||||
/**
|
||||
* Setter for <code>public.t_2781.org</code>.
|
||||
@ -68,7 +68,7 @@ public class T_2781Record extends org.jooq.impl.TableRecordImpl<org.jooq.test.po
|
||||
*/
|
||||
@Override
|
||||
public org.jooq.Field<java.lang.String> field1() {
|
||||
return org.jooq.test.postgres.generatedclasses.tables.T_2781.T_2781.ORG;
|
||||
return org.jooq.test.postgres.generatedclasses.tables.T_2781.T_2781.org_;
|
||||
}
|
||||
|
||||
/**
|
||||
@ -76,7 +76,7 @@ public class T_2781Record extends org.jooq.impl.TableRecordImpl<org.jooq.test.po
|
||||
*/
|
||||
@Override
|
||||
public org.jooq.Field<java.lang.String> field2() {
|
||||
return org.jooq.test.postgres.generatedclasses.tables.T_2781.T_2781.JOOQ;
|
||||
return org.jooq.test.postgres.generatedclasses.tables.T_2781.T_2781.jooq;
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@ -29,7 +29,8 @@
|
||||
<unsignedTypes>true</unsignedTypes>
|
||||
<customTypes>
|
||||
<customType>
|
||||
<name>org.jooq.test._.converters.Boolean_10</name>
|
||||
<name>B10</name>
|
||||
<type>org.jooq.test._.converters.Boolean_10</type>
|
||||
<converter>org.jooq.test._.converters.Boolean_10_Converter</converter>
|
||||
</customType>
|
||||
<customType>
|
||||
@ -107,7 +108,7 @@
|
||||
<expression>(?i:(.*?.)?T_BOOLEANS.TRUE_FALSE_UC)</expression>
|
||||
</forcedType>
|
||||
<forcedType>
|
||||
<name>org.jooq.test._.converters.Boolean_10</name>
|
||||
<name>B10</name>
|
||||
<expression>(?i:(.*?.)?T_BOOLEANS.ONE_ZERO)</expression>
|
||||
</forcedType>
|
||||
</forcedTypes>
|
||||
|
||||
Loading…
Reference in New Issue
Block a user