}
@Override
public void set(BindingSetStatementContext<U> ctx) throws SQLException {
Configuration configuration = ctx.configuration();
SQLDialect dialect = ctx.dialect();
T value = converter.to(ctx.value());
if (log.isTraceEnabled()) {
if (value != null && value.getClass().isArray() && value.getClass() != byte[].class) {
log.trace("Binding variable " + ctx.index(), Arrays.asList((Object[]) value) + " (" + type + ")");
}
else {
log.trace("Binding variable " + ctx.index(), value + " (" + type + ")");
}
}
// Setting null onto a prepared statement is subtly different for every
// SQL dialect. See the following section for details
if (value == null) {
int sqlType = DefaultDataType.getDataType(dialect, type).getSQLType();
/* [pro] xx
xx xxxxxxxxxxxx xxxxx xxxxx xxxx xx xx xxxxx xxxx xxxxx xxxx xxxx
xx xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx x
xxxxxx xxxxxxxx x xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx xxxxxxxxxxxxxxxx
xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx xxxxxxxx xxxxxxxxxx
x
xxxx
xx [/pro] */
// [#1126] Oracle's UDTs need to be bound with their type name
if (UDTRecord.class.isAssignableFrom(type)) {
String typeName = Utils.newRecord(false, (Class<UDTRecord<?>>) type)
.<RuntimeException>operate(null)
.getUDT()
.getName();
ctx.statement().setNull(ctx.index(), sqlType, typeName);
}
// [#1225] [#1227] TODO Put this logic into DataType
// Some dialects have trouble binding binary data as BLOB
else if (asList(POSTGRES).contains(configuration.dialect()) && sqlType == Types.BLOB) {
ctx.statement().setNull(ctx.index(), Types.BINARY);
}
/* [pro] xx
xxxx xx xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx xx xxxxxxx x
xx xxxx xxxxxxxxxx xxxx xx xxxx xxxxxx xxxx xxx xxx xxxxxxxxx xxxxxx
xx xxxxxxxxxxx xxxxx xxxxxxx xxx xxxxxxx
xx xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
xxxxxx xxxxxxxxx x
xxxx xxxxxxxxxxxxx
xxxx xxxxxxxxxxxxxxxx
xxxx xxxxxxxxxxxxxxxxxxxx
xxxx xxxxxxxxxxx
xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx xxxxxxxxxxxxxxx
xxxxxx
xxxxxxxx
xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx xxxxxx
xxxxxx
x
x
xx xxxxxxx xxxxxxx xxx xxx xxxxxx xxxxxx xxxx xxx xxxx xxxxxxxx xxx xxx xxxx xxxxxx
xx xxxxxx xxx xxx xxxxxxx xxxxx
xxxx xx xxxxxxxx xx xxxxxxxxxxxxx xx xxxxxxxxxxx xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx x
xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx xxxxxx
x
xx [/pro] */
// All other types can be set to null if the JDBC type is known
else if (sqlType != Types.OTHER) {
ctx.statement().setNull(ctx.index(), sqlType);
}
/* [pro] xx
xx xxxxxx xxx xxx xxxxxxx xxxxxxx xxxxx xxxxxx xx xxx xx xxxx
xx xxxxxxxxxxx xxx
xxxx xx xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx xx xxxxxxxxxx x
xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx xxxxxxxxx
x
xx xxxxxx xxx xxxxxxx xxxxxxx xxxxx xxx xx xxx xx xxxx xxxxx xxxxxxx
xxxx xx xxxxxxxxxxxxxxxxxxxxxxxx xx xxxxxxx x
xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx xxxxxxxxxxxxxxx
x
xx [/pro] */
// [#729] In the absence of the correct JDBC type, try setObject
else {
ctx.statement().setObject(ctx.index(), null);
}
}
else {
Class<?> actualType = type;
// Try to infer the bind value type from the actual bind value if possible.
if (actualType == Object.class) {
actualType = value.getClass();
}
if (actualType == Blob.class) {
ctx.statement().setBlob(ctx.index(), (Blob) value);
}
else if (actualType == Boolean.class) {
/* [pro] xx
xx xx xxxxxx xxxxxx xxxxxx xx xxxxx xxxxx xxxxx xx xxxxxxxxx xx xxxxxxxxxx xx xxxxxxx xxxxxxx
xx xxxxxxxxxxxxxxxxx xx xxxxxxx
xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx xxxxxxxxx xxxxx x x x xxx
xxxx
xx [/pro] */
ctx.statement().setBoolean(ctx.index(), (Boolean) value);
}
else if (actualType == BigDecimal.class) {
if (asList(SQLITE).contains(dialect.family())) {
ctx.statement().setString(ctx.index(), value.toString());
}
else {
ctx.statement().setBigDecimal(ctx.index(), (BigDecimal) value);
}
}
else if (actualType == BigInteger.class) {
if (asList(SQLITE).contains(dialect.family())) {
ctx.statement().setString(ctx.index(), value.toString());
}
else {
ctx.statement().setBigDecimal(ctx.index(), new BigDecimal((BigInteger) value));
}
}
else if (actualType == Byte.class) {
ctx.statement().setByte(ctx.index(), (Byte) value);
}
else if (actualType == byte[].class) {
ctx.statement().setBytes(ctx.index(), (byte[]) value);
}
else if (actualType == Clob.class) {
ctx.statement().setClob(ctx.index(), (Clob) value);
}
else if (actualType == Double.class) {
ctx.statement().setDouble(ctx.index(), (Double) value);
}
else if (actualType == Float.class) {
ctx.statement().setFloat(ctx.index(), (Float) value);
}
else if (actualType == Integer.class) {
ctx.statement().setInt(ctx.index(), (Integer) value);
}
else if (actualType == Long.class) {
/* [pro] xx
xx xxxxxxxxxxxxxxxxx xx xxxxxxx
xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx xxxxxxxxxxxxxxxxxx
xxxx
xx [/pro] */
ctx.statement().setLong(ctx.index(), (Long) value);
}
else if (actualType == Short.class) {
ctx.statement().setShort(ctx.index(), (Short) value);
}
else if (actualType == String.class) {
ctx.statement().setString(ctx.index(), (String) value);
}
// There is potential for trouble when binding date time as such
// -------------------------------------------------------------
else if (actualType == Date.class) {
if (dialect == SQLITE) {
ctx.statement().setString(ctx.index(), ((Date) value).toString());
}
else {
ctx.statement().setDate(ctx.index(), (Date) value);
}
}
else if (actualType == Time.class) {
if (dialect == SQLITE) {
ctx.statement().setString(ctx.index(), ((Time) value).toString());
}
else {
ctx.statement().setTime(ctx.index(), (Time) value);
}
}
else if (actualType == Timestamp.class) {
if (dialect == SQLITE) {
ctx.statement().setString(ctx.index(), ((Timestamp) value).toString());
}
else {
ctx.statement().setTimestamp(ctx.index(), (Timestamp) value);
}
}
// [#566] Interval data types are best bound as Strings
else if (actualType == YearToMonth.class) {
if (dialect == POSTGRES) {
ctx.statement().setObject(ctx.index(), toPGInterval((YearToMonth) value));
}
else {
ctx.statement().setString(ctx.index(), value.toString());
}
}
else if (actualType == DayToSecond.class) {
if (dialect == POSTGRES) {
ctx.statement().setObject(ctx.index(), toPGInterval((DayToSecond) value));
}
else {
ctx.statement().setString(ctx.index(), value.toString());
}
}
else if (actualType == UByte.class) {
ctx.statement().setShort(ctx.index(), ((UByte) value).shortValue());
}
else if (actualType == UShort.class) {
ctx.statement().setInt(ctx.index(), ((UShort) value).intValue());
}
else if (actualType == UInteger.class) {
/* [pro] xx
xx xxxxxxxxxxxxxxxxx xx xxxxxxx
xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx xxxxxxxxxxxxxxxxxx
xxxx
xx [/pro] */
ctx.statement().setLong(ctx.index(), ((UInteger) value).longValue());
}
else if (actualType == ULong.class) {
/* [pro] xx
xx xxxxxxxxxxxxxxxxx xx xxxxxxx
xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx xxxxxxxxxxxxxxxxxx
xxxx
xx [/pro] */
ctx.statement().setBigDecimal(ctx.index(), new BigDecimal(value.toString()));
}
else if (actualType == UUID.class) {
switch (dialect.family()) {
// [#1624] Some JDBC drivers natively support the
// java.util.UUID data type
case H2:
case POSTGRES: {