[#3369] Render CAST(? AS DATE) for java.sql.Timestamp bind values that are bound to Oracle DATE columns
This commit is contained in:
parent
a5afce8508
commit
ef39b04e18
@ -1082,18 +1082,14 @@ public class JavaGenerator extends AbstractGenerator {
|
||||
final String attrId = getStrategy().getJavaIdentifier(attribute);
|
||||
final String attrName = attribute.getName();
|
||||
final String attrComment = StringUtils.defaultString(attribute.getComment());
|
||||
final String attrConverterType = attribute.getType().getConverter();
|
||||
final List<String> converters = list(
|
||||
attribute.getType().getConverter(),
|
||||
attribute.getType().getBinding()
|
||||
);
|
||||
|
||||
out.tab(1).javadoc("The attribute <code>%s</code>.%s", attribute.getQualifiedOutputName(), defaultIfBlank(" " + attrComment, ""));
|
||||
|
||||
if (attrConverterType != null) {
|
||||
out.tab(1).println("public static final %s<%s, %s> %s = createField(\"%s\", %s, %s, \"%s\", new %s());",
|
||||
UDTField.class, recordType, attrType, attrId, attrName, attrTypeRef, udtId, escapeString(""), attrConverterType);
|
||||
}
|
||||
else {
|
||||
out.tab(1).println("public static final %s<%s, %s> %s = createField(\"%s\", %s, %s, \"%s\");",
|
||||
UDTField.class, recordType, attrType, attrId, attrName, attrTypeRef, udtId, escapeString(""));
|
||||
}
|
||||
out.tab(1).println("public static final %s<%s, %s> %s = createField(\"%s\", %s, %s, \"%s\"[[before=, ][new %s()]]);",
|
||||
UDTField.class, recordType, attrType, attrId, attrName, attrTypeRef, udtId, escapeString(""), converters);
|
||||
}
|
||||
|
||||
// [#799] Oracle UDT's can have member procedures
|
||||
@ -1310,7 +1306,10 @@ public class JavaGenerator extends AbstractGenerator {
|
||||
xxxxx xxxxxxxxxxxx xxxxxxxxxx x xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx xxxxxxxxxxxxx
|
||||
xxxxx xxxxxx xxxxxxxxx x xxxxxxxxxxxxxxxxxxxxxx
|
||||
xxxxx xxxxxx xxxxxxxx x xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
|
||||
xxxxx xxxxxx xxxxxxxxxxxxxxxxxxxx x xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
|
||||
xxxxx xxxxxxxxxxxx xxxxxxxxxx x xxxxx
|
||||
xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
|
||||
xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
|
||||
xx
|
||||
|
||||
xxxxxxxxxx xxx x xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx xxxxxxxxxxxxxx
|
||||
xxxxxxxxxxxxxxxxx xxxxxx xxxxxxxxxxxxx
|
||||
@ -1325,11 +1324,7 @@ public class JavaGenerator extends AbstractGenerator {
|
||||
xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
|
||||
xxxxxxxxxxxxxxxxxxxxxxxxxx xxxxx xxxxxxxxxxxxxx xxx xxxxxxxxxx xxxxxxxxxxxxxxxxxxxxx
|
||||
|
||||
xx xxxxxxxxxxxxxxxxxxxxx xx xxxxx
|
||||
xxxxxxxxxxxxxxxxxxxxxxxxxxxxx xxxxxxx xxx xxxxxxxxxxxxxx xxx xxxxxxxx xxxxxxxxx xxxxxxxxxx xxxxxxxxxxxxxxx xxxxxxxxxxxxxxxxxxxxxx
|
||||
xxxx
|
||||
xxxxxxxxxxxxxxxxxxxxxxxxxxxxx xxxxxxx xxx xxxxxxxxxxxxxxxxx xxxxxxxxx xxxxxxxxxx xxxxxxxxxxxxxxxx
|
||||
|
||||
xxxxxxxxxxxxxxxxxxxxxxxxxxxxx xxxxxxx xxx xxxxxxxxxxxxxxxxxxxxxxx xxxxx xxxxxxxxxx xxxxxxxxx xxxxxxxxxx xxxxxxxxxxxxxxx xxxxxxxxxxxx
|
||||
xxxxxxxxxxxxxxxxxxxxxxxx
|
||||
|
||||
xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx x xxxxx x xxxxxxx x xxx xxx xxxxxx xxxxxx xxxxxxxxxxx xxxxxxxxx xxxxxxxxxxx
|
||||
@ -1349,11 +1344,7 @@ public class JavaGenerator extends AbstractGenerator {
|
||||
|
||||
xxxxxxxxxxxxxxxxxxxxxxxxxx x xxx xxxxxxxxxxxxxxx xxxxxxxx xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
|
||||
xxxxxxxxxxxxxxxxxxxxxxxxxx xxxx xxx xxxxxxxxxxx
|
||||
|
||||
xx xxxxxxxxxxxxxxxxxxxxx xx xxxxx
|
||||
xxxxxxxxxxxxxxxxxxxxxxxxxxxxx xxxxxxx xxx xxx xxxxxxxx xxxxxxxxx xxxxxxxxxx xxxxxxxxxxxxxxx xxxxxxxxxxxxxxxxxxxxxx
|
||||
xxxx
|
||||
xxxxxxxxxxxxxxxxxxxxxxxxxxxxx xxxxxxx xxxxxx xxxxxxxxx xxxxxxxxxx xxxxxxxxxxxxxxxx
|
||||
xxxxxxxxxxxxxxxxxxxxxxxxxxxxx xxxxxxx xxxxxxxxxxxx xxxxx xxxxxxxxxx xxxxxxxxx xxxxxxxxxx xxxxxxxxxxxxxxx xxxxxxxxxxxx
|
||||
|
||||
xxxxxxxxxxxxxxxxxxxxxxxx
|
||||
|
||||
@ -2071,21 +2062,17 @@ public class JavaGenerator extends AbstractGenerator {
|
||||
final String columnId = getStrategy().getJavaIdentifier(column);
|
||||
final String columnName = column.getName();
|
||||
final String columnComment = StringUtils.defaultString(column.getComment());
|
||||
final String columnConverterType = column.getType().getConverter();
|
||||
final List<String> converters = list(
|
||||
column.getType().getConverter(),
|
||||
column.getType().getBinding()
|
||||
);
|
||||
|
||||
String isStatic = generateInstanceFields() ? "" : "static ";
|
||||
String tableRef = generateInstanceFields() ? "this" : getStrategy().getJavaIdentifier(table);
|
||||
|
||||
out.tab(1).javadoc("The column <code>%s</code>.%s", column.getQualifiedOutputName(), defaultIfBlank(" " + columnComment, ""));
|
||||
|
||||
if (columnConverterType != null) {
|
||||
out.tab(1).println("public %sfinal %s<%s, %s> %s = createField(\"%s\", %s, %s, \"%s\", new %s());",
|
||||
isStatic, TableField.class, recordType, columnType, columnId, columnName, columnTypeRef, tableRef, escapeString(columnComment), columnConverterType);
|
||||
}
|
||||
else {
|
||||
out.tab(1).println("public %sfinal %s<%s, %s> %s = createField(\"%s\", %s, %s, \"%s\");",
|
||||
isStatic, TableField.class, recordType, columnType, columnId, columnName, columnTypeRef, tableRef, escapeString(columnComment));
|
||||
}
|
||||
out.tab(1).println("public %sfinal %s<%s, %s> %s = createField(\"%s\", %s, %s, \"%s\"[[before=, ][new %s()]]);",
|
||||
isStatic, TableField.class, recordType, columnType, columnId, columnName, columnTypeRef, tableRef, escapeString(columnComment), converters);
|
||||
}
|
||||
|
||||
// [#1255] With instance fields, the table constructor may
|
||||
@ -2571,9 +2558,14 @@ public class JavaGenerator extends AbstractGenerator {
|
||||
final List<?> returnTypeRef = list((routine.getReturnValue() != null)
|
||||
? getJavaTypeReference(database, routine.getReturnType())
|
||||
: null);
|
||||
final List<?> returnConverterType = list((routine.getReturnValue() != null)
|
||||
final List<?> returnConverterType = list(
|
||||
(routine.getReturnValue() != null)
|
||||
? routine.getReturnType().getConverter()
|
||||
: null);
|
||||
: null,
|
||||
(routine.getReturnValue() != null)
|
||||
? routine.getReturnType().getBinding()
|
||||
: null
|
||||
);
|
||||
final List<String> interfaces = getStrategy().getJavaClassImplements(routine, Mode.DEFAULT);
|
||||
final String schemaId = getStrategy().getFullJavaIdentifier(schema);
|
||||
final List<String> packageId = getStrategy().getFullJavaIdentifiers(routine.getPackage());
|
||||
@ -3377,12 +3369,13 @@ public class JavaGenerator extends AbstractGenerator {
|
||||
return getJavaType(type1).equals(getJavaType(type2));
|
||||
}
|
||||
|
||||
private static final <T> List<T> list(T object) {
|
||||
private static final <T> List<T> list(T... objects) {
|
||||
List<T> result = new ArrayList<T>();
|
||||
|
||||
if (object != null && !"".equals(object)) {
|
||||
result.add(object);
|
||||
}
|
||||
if (objects != null)
|
||||
for (T object : objects)
|
||||
if (object != null && !"".equals(object))
|
||||
result.add(object);
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
@ -131,7 +131,7 @@ abstract class AbstractTypedElementDefinition<T extends Definition>
|
||||
if (dataType != null) {
|
||||
if (dataType.getSQLType() == Types.DATE) {
|
||||
DataType<?> forcedDataType = DefaultDataType.getDataType(db.getDialect(), SQLDataType.TIMESTAMP.getTypeName(), 0, 0);
|
||||
result = new DefaultDataTypeDefinition(db, child.getSchema(), forcedDataType.getTypeName(), 0, 0, 0, result.isNullable(), result.isDefaulted(), null, DateAsTimestampBinding.class.getName());
|
||||
result = new DefaultDataTypeDefinition(db, child.getSchema(), forcedDataType.getTypeName(), 0, 0, 0, result.isNullable(), result.isDefaulted(), null, null, DateAsTimestampBinding.class.getName());
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -141,6 +141,7 @@ abstract class AbstractTypedElementDefinition<T extends Definition>
|
||||
if (forcedType != null) {
|
||||
String type = forcedType.getName();
|
||||
String converter = null;
|
||||
String binding = result.getBinding();
|
||||
|
||||
CustomType customType = customType(db, forcedType.getName());
|
||||
if (customType != null) {
|
||||
@ -148,7 +149,11 @@ abstract class AbstractTypedElementDefinition<T extends Definition>
|
||||
? customType.getType()
|
||||
: customType.getName();
|
||||
|
||||
converter = customType.getConverter();
|
||||
if (!StringUtils.isBlank(customType.getConverter()))
|
||||
converter = customType.getConverter();
|
||||
|
||||
if (!StringUtils.isBlank(customType.getBinding()))
|
||||
binding = customType.getBinding();
|
||||
}
|
||||
|
||||
|
||||
@ -180,7 +185,7 @@ abstract class AbstractTypedElementDefinition<T extends Definition>
|
||||
|
||||
// [#677] SQLDataType matches are actual type-rewrites
|
||||
if (forcedDataType != null) {
|
||||
result = new DefaultDataTypeDefinition(db, child.getSchema(), type, l, p, s, n, d, null, converter);
|
||||
result = new DefaultDataTypeDefinition(db, child.getSchema(), type, l, p, s, n, d, null, converter, binding);
|
||||
}
|
||||
|
||||
// Other forced types are UDT's, enums, etc.
|
||||
@ -189,7 +194,7 @@ abstract class AbstractTypedElementDefinition<T extends Definition>
|
||||
p = result.getPrecision();
|
||||
s = result.getScale();
|
||||
String t = result.getType();
|
||||
result = new DefaultDataTypeDefinition(db, child.getSchema(), t, l, p, s, n, d, type, converter);
|
||||
result = new DefaultDataTypeDefinition(db, child.getSchema(), t, l, p, s, n, d, type, converter, binding);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@ -59,6 +59,12 @@ public interface DataTypeDefinition {
|
||||
*/
|
||||
String getConverter();
|
||||
|
||||
/**
|
||||
* The binding type that is applied to this data type, or
|
||||
* <code>null</code>, if no such binding type is configured.
|
||||
*/
|
||||
String getBinding();
|
||||
|
||||
/**
|
||||
* The type's length.
|
||||
*/
|
||||
|
||||
@ -57,6 +57,7 @@ public class DefaultDataTypeDefinition implements DataTypeDefinition {
|
||||
private final String typeName;
|
||||
private final String udtName;
|
||||
private final String converter;
|
||||
private final String binding;
|
||||
private final boolean nullable;
|
||||
private final boolean defaulted;
|
||||
private final int length;
|
||||
@ -76,6 +77,10 @@ public class DefaultDataTypeDefinition implements DataTypeDefinition {
|
||||
}
|
||||
|
||||
public DefaultDataTypeDefinition(Database database, SchemaDefinition schema, String typeName, Number length, Number precision, Number scale, Boolean nullable, Boolean defaultable, String udtName, String converter) {
|
||||
this(database, schema, typeName, length, precision, scale, nullable, defaultable, udtName, converter, null);
|
||||
}
|
||||
|
||||
public DefaultDataTypeDefinition(Database database, SchemaDefinition schema, String typeName, Number length, Number precision, Number scale, Boolean nullable, Boolean defaultable, String udtName, String converter, String binding) {
|
||||
this.database = database;
|
||||
this.schema = schema;
|
||||
|
||||
@ -83,6 +88,7 @@ public class DefaultDataTypeDefinition implements DataTypeDefinition {
|
||||
this.typeName = typeName == null ? "OTHER" : typeName;
|
||||
this.udtName = udtName;
|
||||
this.converter = converter;
|
||||
this.binding = binding;
|
||||
|
||||
// Some dialects do not distinguish between length and precision...
|
||||
if (length != null && precision != null && length.intValue() != 0 && precision.intValue() != 0) {
|
||||
@ -144,6 +150,11 @@ public class DefaultDataTypeDefinition implements DataTypeDefinition {
|
||||
return converter;
|
||||
}
|
||||
|
||||
@Override
|
||||
public final String getBinding() {
|
||||
return binding;
|
||||
}
|
||||
|
||||
@Override
|
||||
public final int getLength() {
|
||||
return length;
|
||||
|
||||
@ -560,7 +560,10 @@
|
||||
<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" />
|
||||
<element name="converter" type="string" minOccurs="0" maxOccurs="1" />
|
||||
|
||||
<!-- A binding implementation for the custom type -->
|
||||
<element name="binding" type="string" minOccurs="0" maxOccurs="1" />
|
||||
</all>
|
||||
</complexType>
|
||||
|
||||
|
||||
@ -137,35 +137,44 @@ public abstract class AbstractRoutine<T> extends AbstractQueryPart implements Ro
|
||||
// ------------------------------------------------------------------------
|
||||
|
||||
protected AbstractRoutine(String name, Schema schema) {
|
||||
this(name, schema, null, null, (Binding<?, T>) null);
|
||||
this(name, schema, null, null, null, null);
|
||||
}
|
||||
|
||||
protected AbstractRoutine(String name, Schema schema, Package pkg) {
|
||||
this(name, schema, pkg, null, (Binding<?, T>) null);
|
||||
this(name, schema, pkg, null, null, null);
|
||||
}
|
||||
|
||||
protected AbstractRoutine(String name, Schema schema, DataType<T> type) {
|
||||
this(name, schema, null, type, (Binding<?, T>) null);
|
||||
this(name, schema, null, type, null, null);
|
||||
}
|
||||
|
||||
protected AbstractRoutine(String name, Schema schema, DataType<?> type, Converter<?, T> converter) {
|
||||
this(name, schema, type, DefaultBinding.newBinding(converter, type));
|
||||
protected <X> AbstractRoutine(String name, Schema schema, DataType<X> type, Converter<X, T> converter) {
|
||||
this(name, schema, null, type, converter, null);
|
||||
}
|
||||
|
||||
protected AbstractRoutine(String name, Schema schema, DataType<?> type, Binding<?, T> converter) {
|
||||
this(name, schema, null, type, converter);
|
||||
protected <X> AbstractRoutine(String name, Schema schema, DataType<X> type, Binding<X, T> binding) {
|
||||
this(name, schema, null, type, null, binding);
|
||||
}
|
||||
|
||||
|
||||
protected <X, Y> AbstractRoutine(String name, Schema schema, DataType<X> type, Converter<Y, T> converter, Binding<X, Y> binding) {
|
||||
this(name, schema, null, type, converter, binding);
|
||||
}
|
||||
|
||||
protected AbstractRoutine(String name, Schema schema, Package pkg, DataType<T> type) {
|
||||
this(name, schema, pkg, type, (Binding<?, T>) null);
|
||||
this(name, schema, pkg, type, null, null);
|
||||
}
|
||||
|
||||
protected AbstractRoutine(String name, Schema schema, Package pkg, DataType<?> type, Converter<?, T> converter) {
|
||||
this(name, schema, pkg, type, DefaultBinding.newBinding(converter, type));
|
||||
protected <X> AbstractRoutine(String name, Schema schema, Package pkg, DataType<X> type, Converter<X, T> converter) {
|
||||
this(name, schema, pkg, type, converter, null);
|
||||
}
|
||||
|
||||
protected <X> AbstractRoutine(String name, Schema schema, Package pkg, DataType<X> type, Binding<X, T> binding) {
|
||||
this(name, schema, pkg, type, null, binding);
|
||||
}
|
||||
|
||||
@SuppressWarnings({ "unchecked", "rawtypes" })
|
||||
protected AbstractRoutine(String name, Schema schema, Package pkg, DataType<?> type, Binding<?, T> binding) {
|
||||
protected <X, Y> AbstractRoutine(String name, Schema schema, Package pkg, DataType<X> type, Converter<Y, T> converter, Binding<X, Y> binding) {
|
||||
this.parameterIndexes = new HashMap<Parameter<?>, Integer>();
|
||||
|
||||
this.schema = schema;
|
||||
@ -179,9 +188,9 @@ public abstract class AbstractRoutine<T> extends AbstractQueryPart implements Ro
|
||||
this.inValuesDefaulted = new HashSet<Parameter<?>>();
|
||||
this.inValuesNonDefaulted = new HashSet<Parameter<?>>();
|
||||
this.outValues = new HashMap<Parameter<?>, Object>();
|
||||
this.type = binding == null
|
||||
this.type = converter == null && binding == null
|
||||
? (DataType<T>) type
|
||||
: type.asConvertedDataType((Binding) binding);
|
||||
: type.asConvertedDataType(DefaultBinding.newBinding((Converter) converter, type, binding));
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------------
|
||||
@ -761,7 +770,7 @@ public abstract class AbstractRoutine<T> extends AbstractQueryPart implements Ro
|
||||
* @param type The data type of the field
|
||||
*/
|
||||
protected static final <T> Parameter<T> createParameter(String name, DataType<T> type) {
|
||||
return createParameter(name, type, false, (Binding<T, T>) null);
|
||||
return createParameter(name, type, false, null, null);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -774,7 +783,7 @@ public abstract class AbstractRoutine<T> extends AbstractQueryPart implements Ro
|
||||
* {@link Parameter#isDefaulted()}
|
||||
*/
|
||||
protected static final <T> Parameter<T> createParameter(String name, DataType<T> type, boolean isDefaulted) {
|
||||
return createParameter(name, type, isDefaulted, (Binding<T, T>) null);
|
||||
return createParameter(name, type, isDefaulted, null, null);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -787,7 +796,20 @@ public abstract class AbstractRoutine<T> extends AbstractQueryPart implements Ro
|
||||
* {@link Parameter#isDefaulted()}
|
||||
*/
|
||||
protected static final <T, U> Parameter<U> createParameter(String name, DataType<T> type, boolean isDefaulted, Converter<T, U> converter) {
|
||||
return createParameter(name, type, isDefaulted, DefaultBinding.newBinding(converter, type));
|
||||
return createParameter(name, type, isDefaulted, converter, null);
|
||||
}
|
||||
|
||||
/**
|
||||
* Subclasses may call this method to create {@link UDTField} objects that
|
||||
* are linked to this table.
|
||||
*
|
||||
* @param name The name of the field (case-sensitive!)
|
||||
* @param type The data type of the field
|
||||
* @param isDefaulted Whether the parameter is defaulted (see
|
||||
* {@link Parameter#isDefaulted()}
|
||||
*/
|
||||
protected static final <T, U> Parameter<U> createParameter(String name, DataType<T> type, boolean isDefaulted, Binding<T, U> binding) {
|
||||
return createParameter(name, type, isDefaulted, null, binding);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -800,12 +822,13 @@ public abstract class AbstractRoutine<T> extends AbstractQueryPart implements Ro
|
||||
* {@link Parameter#isDefaulted()}
|
||||
*/
|
||||
@SuppressWarnings("unchecked")
|
||||
protected static final <T, U> Parameter<U> createParameter(String name, DataType<T> type, boolean isDefaulted, Binding<T, U> binding) {
|
||||
final DataType<U> actualType = binding == null
|
||||
protected static final <T, X, U> Parameter<U> createParameter(String name, DataType<T> type, boolean isDefaulted, Converter<X, U> converter, Binding<T, X> binding) {
|
||||
final Binding<T, U> actualBinding = DefaultBinding.newBinding(converter, type, binding);
|
||||
final DataType<U> actualType = converter == null && binding == null
|
||||
? (DataType<U>) type
|
||||
: type.asConvertedDataType(binding);
|
||||
: type.asConvertedDataType(actualBinding);
|
||||
|
||||
return new ParameterImpl<U>(name, actualType, isDefaulted, binding);
|
||||
return new ParameterImpl<U>(name, actualType, isDefaulted, actualBinding);
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@ -321,7 +321,7 @@ abstract class AbstractTable<R extends Record> extends AbstractQueryPart impleme
|
||||
* @param type The data type of the field
|
||||
*/
|
||||
protected static final <R extends Record, T> TableField<R, T> createField(String name, DataType<T> type, Table<R> table) {
|
||||
return createField(name, type, table, null, (Binding<T, T>) null);
|
||||
return createField(name, type, table, null, null, null);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -332,7 +332,7 @@ abstract class AbstractTable<R extends Record> extends AbstractQueryPart impleme
|
||||
* @param type The data type of the field
|
||||
*/
|
||||
protected static final <R extends Record, T> TableField<R, T> createField(String name, DataType<T> type, Table<R> table, String comment) {
|
||||
return createField(name, type, table, comment, (Binding<T, T>) null);
|
||||
return createField(name, type, table, comment, null, null);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -343,7 +343,18 @@ abstract class AbstractTable<R extends Record> extends AbstractQueryPart impleme
|
||||
* @param type The data type of the field
|
||||
*/
|
||||
protected static final <R extends Record, T, U> TableField<R, U> createField(String name, DataType<T> type, Table<R> table, String comment, Converter<T, U> converter) {
|
||||
return createField(name, type, table, comment, DefaultBinding.newBinding(converter, type));
|
||||
return createField(name, type, table, comment, converter, null);
|
||||
}
|
||||
|
||||
/**
|
||||
* Subclasses may call this method to create {@link TableField} objects that
|
||||
* are linked to this table.
|
||||
*
|
||||
* @param name The name of the field (case-sensitive!)
|
||||
* @param type The data type of the field
|
||||
*/
|
||||
protected static final <R extends Record, T, U> TableField<R, U> createField(String name, DataType<T> type, Table<R> table, String comment, Binding<T, U> binding) {
|
||||
return createField(name, type, table, comment, null, binding);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -354,12 +365,14 @@ abstract class AbstractTable<R extends Record> extends AbstractQueryPart impleme
|
||||
* @param type The data type of the field
|
||||
*/
|
||||
@SuppressWarnings("unchecked")
|
||||
protected static final <R extends Record, T, U> TableField<R, U> createField(String name, DataType<T> type, Table<R> table, String comment, Binding<T, U> binding) {
|
||||
final DataType<U> actualType = binding == null
|
||||
? (DataType<U>) type
|
||||
: type.asConvertedDataType(binding);
|
||||
protected static final <R extends Record, T, X, U> TableField<R, U> createField(String name, DataType<T> type, Table<R> table, String comment, Converter<X, U> converter, Binding<T, X> binding) {
|
||||
final Binding<T, U> actualBinding = DefaultBinding.newBinding(converter, type, binding);
|
||||
final DataType<U> actualType =
|
||||
converter == null && binding == null
|
||||
? (DataType<U>) type
|
||||
: type.asConvertedDataType(actualBinding);
|
||||
|
||||
final TableFieldImpl<R, U> tableField = new TableFieldImpl<R, U>(name, actualType, table, comment, binding);
|
||||
final TableFieldImpl<R, U> tableField = new TableFieldImpl<R, U>(name, actualType, table, comment, actualBinding);
|
||||
|
||||
// [#1199] The public API of Table returns immutable field lists
|
||||
if (table instanceof TableImpl) {
|
||||
|
||||
@ -89,7 +89,7 @@ xxxxxx xxxxx xxxxxxxxxxxxxxxxxx xxxxxxx xxxxxxxxxxxxx xxxxxxxxxx xxxxxxxxxxxxxx
|
||||
xxxxxxxxxxxxxxxxxxxxxxxxxxx
|
||||
xxxxxxxxxxx
|
||||
xxxxxxxxx xxxxxxxxxxxxxxxxxxxxxx xxxxxxx xxxxxx xxxxx xxxxxxxxxxx xxxxx xxxxxxxxxxxxx xxxxxxxxxxxxxx x
|
||||
xxxxxxxxxxxx xxxxx xxxxxx
|
||||
xxxxxxxxxxxx xxxxx xxxxx xxxxxxxxxxxxx xxx xxxxx xxxxxx
|
||||
x
|
||||
|
||||
xxx
|
||||
@ -101,8 +101,8 @@ xxxxxx xxxxx xxxxxxxxxxxxxxxxxx xxxxxxx xxxxxxxxxxxxx xxxxxxxxxx xxxxxxxxxxxxxx
|
||||
xx
|
||||
xxxxxxxxxxxxxxxxxxxxxxxxxxx
|
||||
xxxxxxxxxxx
|
||||
xxxxxxxxx xxxxxxxxxxxxxxxxxxxxxx xxxxxxx xxxxxx xxxxx xxxxxxxxxxx xxxxx xxxxxxxxxxxxx xxxxxxxxxxxxxx xxxxxxxxxxxx xx xxxxxxxxxx x
|
||||
xxxxxxxxxxxx xxxxx xxxxx xxxxxxxxxxx
|
||||
xxxxxxxxx xxx xxxxxxxxxxxxxxxxxxxxxx xxxxxxx xxxxxx xxxxx xxxxxxxxxxx xxxxx xxxxxxxxxxxxx xxxxxxxxxxxxxx xxxxxxxxxxxx xx xxxxxxxxxx x
|
||||
xxxxxxxxxxxx xxxxx xxxxx xxxxxxxxxx xxxxxx
|
||||
x
|
||||
|
||||
xxx
|
||||
@ -114,36 +114,56 @@ xxxxxx xxxxx xxxxxxxxxxxxxxxxxx xxxxxxx xxxxxxxxxxxxx xxxxxxxxxx xxxxxxxxxxxxxx
|
||||
xx
|
||||
xxxxxxxxxxxxxxxxxxxxxxxxxxx
|
||||
xxxxxxxxxxx
|
||||
xxxxxxxxx xxxxxxxxxxxxxxxxxxxxxx xxxxxxx xxxxxx xxxxx xxxxxxxxxxx xxxxx xxxxxxxxxxxxx xxxxxxxxxxxxxx xxxxxxxxxx xx xxxxxxxx x
|
||||
xxxxxxxxxxxx xxxxx xxxxx xxxxxxxxx
|
||||
xxxxxxxxx xxx xx xxxxxxxxxxxxxxxxxxxxxx xxxxxxx xxxxxx xxxxx xxxxxxxxxxx xxxxx xxxxxxxxxxxxx xxxxxxxxxxxxxx xxxxxxxxxx xx xxxxxxxx x
|
||||
xxxxxxxxxxxx xxxxx xxxxx xxxxxxxxxxxxx xxx xxxxx xxxxxxxxx
|
||||
x
|
||||
|
||||
xxx
|
||||
x xxxxxx xx xxxxx xxxxx xxxxxx
|
||||
x
|
||||
x xxxxxxxxxxx x xxxxx x xxxxxxx x xxx xxx
|
||||
x xxxxxx xxxxxxxxxxxxxxxxxxxxxxxx xxxxxxx xxxxxxxxx xxxxxxxxxxx
|
||||
x xxxxxxxxxxx xxxxxxxx
|
||||
xx
|
||||
xxxxxxxxxxxxxxxxxxxxxxxxxxx
|
||||
xxxxxxxxxxx
|
||||
xxxxxxxxx xxx xx xxxxxxxxxxxxxxxxxxxxxx xxxxxxx xxxxxx xxxxx xxxxxxxxxxx xxxxx xxxxxxxxxxxxx xxxxxxxxxxxxxx xxxxxxxxxxxx xx xxxxxxxxxx xxxxxxxxxx xx xxxxxxxx x
|
||||
xxxxxxxxxxxx xxxxx xxxxx xxxxxxxxxx xxxxxxxxx
|
||||
x
|
||||
|
||||
xxx
|
||||
x xxxxxx xx xxxxx xxxxx xxxxxx
|
||||
xx
|
||||
xxxxxxxxx xxxxxxxxxxxxxxxxxxxxxx xxxxxxx xxxxxx xxxxx xxxxxxxxxxx xxxxx x
|
||||
xxxxxxxxxxxx xxxxx xxxxx xxxxxxxxxxxxx xxx xxxxxx
|
||||
xxxxxxxxxxxx xxxxx xxxxx xxxxxxxxxxxxx xxx xxxxx xxxxxx
|
||||
x
|
||||
|
||||
xxx
|
||||
x xxxxxx xx xxxxx xxxxx xxxxxx
|
||||
xx
|
||||
xxxxxxxxx xxxxxxxxxxxxxxxxxxxxxx xxxxxxx xxxxxx xxxxx xxxxxxxxxxx xxxxx xxxxxxxxxxxx xx xxxxxxxxxx x
|
||||
xxxxxxxxxxxx xxxxx xxxxx xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx xxxxxxx
|
||||
xxxxxxxxx xxx xxxxxxxxxxxxxxxxxxxxxx xxxxxxx xxxxxx xxxxx xxxxxxxxxxx xxxxx xxxxxxxxxxxx xx xxxxxxxxxx x
|
||||
xxxxxxxxxxxx xxxxx xxxxx xxxxxxxxxx xxxxxx
|
||||
x
|
||||
|
||||
xxx
|
||||
x xxxxxx xx xxxxx xxxxx xxxxxx
|
||||
xx
|
||||
xxxxxxxxxxxxxxxxxxx xxxxxxxxxxxx xxxxxxxxxx xx
|
||||
xxxxxxxxx xxxxxxxxxxxxxxxxxxxxxx xxxxxxx xxxxxx xxxxx xxxxxxxxxxx xxxxx xxxxxxxxxx xx xxxxxxxx x
|
||||
xxxxxxxxx xxx xx xxxxxxxxxxxxxxxxxxxxxx xxxxxxx xxxxxx xxxxx xxxxxxxxxxx xxxxx xxxxxxxxxx xx xxxxxxxx x
|
||||
xxxxxxxxxxxx xxxxx xxxxx xxxxxxxxxxxxx xxx xxxxx xxxxxxxxx
|
||||
x
|
||||
|
||||
xxx
|
||||
x xxxxxx xx xxxxx xxxxx xxxxxx
|
||||
xx
|
||||
xxxxxxxxxxxxxxxxxxx xxxxxxxxxxx xx
|
||||
xxxxxxxxx xxx xx xxxxxxxxxxxxxxxxxxxxxx xxxxxxx xxxxxx xxxxx xxxxxxxxxxx xxxxx xxxxxxxxxxxx xx xxxxxxxxxx xxxxxxxxxx xx xxxxxxxx x
|
||||
xxxxxxxxxxxx
|
||||
|
||||
xxxxxxxxxxx x xxxxxxx
|
||||
xxxxxxxxx x xxxxx
|
||||
xxxxxxxxxxxxx x xxxxxxx xx xxxx
|
||||
xxxxxxxxxxxxx x xxxxxxxxx xx xxxx xx xxxxxxx xx xxxx
|
||||
x xxxxxxxxxxxxx xxxx
|
||||
x xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx xxxxxxxxx
|
||||
x xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx xxxxx xxxxxxxxxx
|
||||
|
||||
xx xxxxx xxxx xxxx xxxxxxxxxxxxxx
|
||||
xxxxxxxxx x xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
|
||||
|
||||
@ -41,7 +41,7 @@
|
||||
package org.jooq.impl;
|
||||
|
||||
// ...
|
||||
import static org.jooq.conf.ParamType.INLINED;
|
||||
import static org.jooq.impl.DSL.val;
|
||||
|
||||
import java.sql.SQLException;
|
||||
import java.sql.Timestamp;
|
||||
@ -96,13 +96,10 @@ public class DateAsTimestampBinding implements Binding<Timestamp, Timestamp> {
|
||||
xx xxxx xx xxxx xx xxxxxxx xxxxxxxx xxxxxxxxxx xx xxxx xxxxxxx xx xxxxxxxxx xxx xxxxxxxxxxxxxxxxxxxx
|
||||
xx xxxxx xxxxx xxxxxxx xxxxx xxxxxx
|
||||
xx xxxx xxxxxxxxxxx xxxxx xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
|
||||
xx xxxxxxx xx xxxxxx xx xxxxxxxxxxxxxxxxxx xx xxxxxxxx x
|
||||
xxxxxxxxxxxxxxxxxxxxxx
|
||||
xxxxxxxxx
|
||||
xxxxxxxxxxxxxxxxxxxx
|
||||
xxxxxx xx
|
||||
xxxxxxxxxxxx xxxxxx
|
||||
xxxxxxxxxx
|
||||
xx xxxxxxx xx xxxxxxx x
|
||||
xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
|
||||
xxxxxxxxxxxxxxxxxxxxxxxx
|
||||
xxxxxx xxxxxxxxxxxxxx xxxxxxxxxxxxxxxx
|
||||
x
|
||||
xxxx
|
||||
xx [/pro] */
|
||||
|
||||
@ -103,6 +103,7 @@ import org.jooq.BindingSetStatementContext;
|
||||
import org.jooq.Configuration;
|
||||
import org.jooq.Context;
|
||||
import org.jooq.Converter;
|
||||
import org.jooq.Converters;
|
||||
import org.jooq.DataType;
|
||||
import org.jooq.EnumType;
|
||||
import org.jooq.Field;
|
||||
@ -160,13 +161,72 @@ public class DefaultBinding<T, U> implements Binding<T, U> {
|
||||
}
|
||||
|
||||
@SuppressWarnings({ "rawtypes", "unchecked" })
|
||||
static <T, U> DefaultBinding<T, U> newBinding(Converter<T, U> converter, DataType<?> type) {
|
||||
return new DefaultBinding(
|
||||
converter != null
|
||||
? converter
|
||||
: new IdentityConverter(type.getType()),
|
||||
type.isLob()
|
||||
);
|
||||
static <T, X, U> Binding<T, U> newBinding(final Converter<X, U> converter, final DataType<T> type, final Binding<T, X> binding) {
|
||||
final Binding<T, U> theBinding;
|
||||
|
||||
|
||||
if (converter == null && binding == null) {
|
||||
theBinding = (Binding) new DefaultBinding<T, T>(new IdentityConverter<T>(type.getType()), type.isLob());
|
||||
}
|
||||
else if (converter == null) {
|
||||
theBinding = (Binding) binding;
|
||||
}
|
||||
else if (binding == null) {
|
||||
theBinding = (Binding) new DefaultBinding<X, U>(converter, type.isLob());
|
||||
}
|
||||
else {
|
||||
theBinding = new Binding<T, U>() {
|
||||
|
||||
/**
|
||||
* Generated UID
|
||||
*/
|
||||
private static final long serialVersionUID = 8912340791845209886L;
|
||||
|
||||
final Converter<T, U> theConverter = Converters.of(binding.converter(), converter);
|
||||
|
||||
@Override
|
||||
public Converter<T, U> converter() {
|
||||
return theConverter;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void sql(BindingSQLContext<U> ctx) throws SQLException {
|
||||
binding.sql(ctx.convert(converter));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void register(BindingRegisterContext<U> ctx) throws SQLException {
|
||||
binding.register(ctx.convert(converter));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void set(BindingSetStatementContext<U> ctx) throws SQLException {
|
||||
binding.set(ctx.convert(converter));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void set(BindingSetSQLOutputContext<U> ctx) throws SQLException {
|
||||
binding.set(ctx.convert(converter));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void get(BindingGetResultSetContext<U> ctx) throws SQLException {
|
||||
binding.get(ctx.convert(converter));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void get(BindingGetStatementContext<U> ctx) throws SQLException {
|
||||
binding.get(ctx.convert(converter));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void get(BindingGetSQLInputContext<U> ctx) throws SQLException {
|
||||
binding.get(ctx.convert(converter));
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
return theBinding;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@ -587,7 +587,7 @@ public class DefaultDataType<T> implements DataType<T> {
|
||||
|
||||
@Override
|
||||
public final <U> DataType<U> asConvertedDataType(Converter<? super T, U> converter) {
|
||||
return asConvertedDataType(DefaultBinding.newBinding((Converter) converter, this));
|
||||
return asConvertedDataType(DefaultBinding.newBinding(converter, this, null));
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@ -163,7 +163,7 @@ public class UDTImpl<R extends UDTRecord<R>> extends AbstractQueryPart implement
|
||||
* @param type The data type of the field
|
||||
*/
|
||||
protected static final <R extends UDTRecord<R>, T> UDTField<R, T> createField(String name, DataType<T> type, UDT<R> udt) {
|
||||
return createField(name, type, udt, "", (Binding<T, T>) null);
|
||||
return createField(name, type, udt, "", null, null);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -174,7 +174,7 @@ public class UDTImpl<R extends UDTRecord<R>> extends AbstractQueryPart implement
|
||||
* @param type The data type of the field
|
||||
*/
|
||||
protected static final <R extends UDTRecord<R>, T> UDTField<R, T> createField(String name, DataType<T> type, UDT<R> udt, String comment) {
|
||||
return createField(name, type, udt, comment, (Binding<T, T>) null);
|
||||
return createField(name, type, udt, comment, null, null);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -185,7 +185,18 @@ public class UDTImpl<R extends UDTRecord<R>> extends AbstractQueryPart implement
|
||||
* @param type The data type of the field
|
||||
*/
|
||||
protected static final <R extends UDTRecord<R>, T, U> UDTField<R, U> createField(String name, DataType<T> type, UDT<R> udt, String comment, Converter<T, U> converter) {
|
||||
return createField(name, type, udt, comment, DefaultBinding.newBinding(converter, type));
|
||||
return createField(name, type, udt, comment, converter, null);
|
||||
}
|
||||
|
||||
/**
|
||||
* Subclasses may call this method to create {@link UDTField} objects that
|
||||
* are linked to this table.
|
||||
*
|
||||
* @param name The name of the field (case-sensitive!)
|
||||
* @param type The data type of the field
|
||||
*/
|
||||
protected static final <R extends UDTRecord<R>, T, U> UDTField<R, U> createField(String name, DataType<T> type, UDT<R> udt, String comment, Binding<T, U> binding) {
|
||||
return createField(name, type, udt, comment, null, binding);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -196,12 +207,13 @@ public class UDTImpl<R extends UDTRecord<R>> extends AbstractQueryPart implement
|
||||
* @param type The data type of the field
|
||||
*/
|
||||
@SuppressWarnings("unchecked")
|
||||
protected static final <R extends UDTRecord<R>, T, U> UDTField<R, U> createField(String name, DataType<T> type, UDT<R> udt, String comment, Binding<T, U> binding) {
|
||||
final DataType<U> actualType = binding == null
|
||||
protected static final <R extends UDTRecord<R>, T, X, U> UDTField<R, U> createField(String name, DataType<T> type, UDT<R> udt, String comment, Converter<X, U> converter, Binding<T, X> binding) {
|
||||
final Binding<T, U> actualBinding = DefaultBinding.newBinding(converter, type, binding);
|
||||
final DataType<U> actualType = converter == null && binding == null
|
||||
? (DataType<U>) type
|
||||
: type.asConvertedDataType(binding);
|
||||
: type.asConvertedDataType(actualBinding);
|
||||
|
||||
final UDTFieldImpl<R, U> udtField = new UDTFieldImpl<R, U>(name, actualType, udt, comment, binding);
|
||||
final UDTFieldImpl<R, U> udtField = new UDTFieldImpl<R, U>(name, actualType, udt, comment, actualBinding);
|
||||
|
||||
return udtField;
|
||||
}
|
||||
|
||||
Loading…
Reference in New Issue
Block a user