use of java.sql.Clob in project jOOQ by jOOQ.
the class DefaultBinding method set.
@Override
public void set(BindingSetSQLOutputContext<U> ctx) throws SQLException {
Configuration configuration = ctx.configuration();
T value = converter.to(ctx.value());
if (value == null) {
ctx.output().writeObject(null);
} else if (type == Blob.class) {
ctx.output().writeBlob((Blob) value);
} else if (type == Boolean.class) {
ctx.output().writeBoolean((Boolean) value);
} else if (type == BigInteger.class) {
ctx.output().writeBigDecimal(new BigDecimal((BigInteger) value));
} else if (type == BigDecimal.class) {
ctx.output().writeBigDecimal((BigDecimal) value);
} else if (type == Byte.class) {
ctx.output().writeByte((Byte) value);
} else if (type == byte[].class) {
// Use reflection to avoid dependency on OJDBC
if (isLob) {
Blob blob = null;
try {
blob = on("oracle.sql.BLOB").call("createTemporary", on(ctx.output()).call("getSTRUCT").call("getJavaSqlConnection").get(), false, on("oracle.sql.BLOB").get("DURATION_SESSION")).get();
blob.setBytes(1, (byte[]) value);
ctx.output().writeBlob(blob);
} finally {
DefaultExecuteContext.register(blob);
}
} else {
ctx.output().writeBytes((byte[]) value);
}
} else if (type == Clob.class) {
ctx.output().writeClob((Clob) value);
} else if (type == Date.class) {
Date date = (Date) value;
ctx.output().writeDate(date);
} else if (type == Double.class) {
ctx.output().writeDouble((Double) value);
} else if (type == Float.class) {
ctx.output().writeFloat((Float) value);
} else if (type == Integer.class) {
ctx.output().writeInt((Integer) value);
} else if (type == Long.class) {
ctx.output().writeLong((Long) value);
} else if (type == Short.class) {
ctx.output().writeShort((Short) value);
} else if (type == String.class) {
// Use reflection to avoid dependency on OJDBC
if (isLob) {
Clob clob = null;
try {
clob = on("oracle.sql.CLOB").call("createTemporary", on(ctx.output()).call("getSTRUCT").call("getJavaSqlConnection").get(), false, on("oracle.sql.CLOB").get("DURATION_SESSION")).get();
clob.setString(1, (String) value);
ctx.output().writeClob(clob);
} finally {
DefaultExecuteContext.register(clob);
}
} else {
ctx.output().writeString((String) value);
}
} else if (type == Time.class) {
ctx.output().writeTime((Time) value);
} else if (type == Timestamp.class) {
ctx.output().writeTimestamp((Timestamp) value);
} else if (type == YearToMonth.class) {
ctx.output().writeString(value.toString());
} else if (type == DayToSecond.class) {
ctx.output().writeString(value.toString());
} else // }
if (UNumber.class.isAssignableFrom(type)) {
ctx.output().writeString(value.toString());
} else if (type == UUID.class) {
ctx.output().writeString(value.toString());
} else if (EnumType.class.isAssignableFrom(type)) {
ctx.output().writeString(((EnumType) value).getLiteral());
} else if (UDTRecord.class.isAssignableFrom(type)) {
ctx.output().writeObject((UDTRecord<?>) value);
} else {
throw new UnsupportedOperationException("Type " + type + " is not supported");
}
}
use of java.sql.Clob in project pinot by linkedin.
the class SqlQueryBuilder method createInsertStatement.
public PreparedStatement createInsertStatement(Connection conn, String tableName, AbstractEntity entity) throws Exception {
if (!insertSqlMap.containsKey(tableName)) {
String insertSql = generateInsertSql(tableName, entityMappingHolder.columnInfoPerTable.get(tableName.toLowerCase()));
insertSqlMap.put(tableName, insertSql);
LOG.debug(insertSql);
}
String sql = insertSqlMap.get(tableName);
PreparedStatement preparedStatement = conn.prepareStatement(sql, Statement.RETURN_GENERATED_KEYS);
LinkedHashMap<String, ColumnInfo> columnInfoMap = entityMappingHolder.columnInfoPerTable.get(tableName);
int parameterIndex = 1;
for (ColumnInfo columnInfo : columnInfoMap.values()) {
if (columnInfo.field != null && !AUTO_UPDATE_COLUMN_SET.contains(columnInfo.columnNameInDB.toLowerCase())) {
Object val = columnInfo.field.get(entity);
LOG.debug("Setting value: {} for:{} sqlType:{}", val, columnInfo.columnNameInDB, columnInfo.sqlType);
if (val != null) {
if (columnInfo.sqlType == Types.CLOB) {
Clob clob = conn.createClob();
clob.setString(1, val.toString());
preparedStatement.setClob(parameterIndex++, clob);
} else if (columnInfo.sqlType == Types.TIMESTAMP) {
preparedStatement.setObject(parameterIndex++, val, columnInfo.sqlType);
} else {
preparedStatement.setObject(parameterIndex++, val.toString(), columnInfo.sqlType);
}
} else {
preparedStatement.setNull(parameterIndex++, columnInfo.sqlType);
}
}
}
return preparedStatement;
}
use of java.sql.Clob in project mybatis-3 by mybatis.
the class ClobTypeHandler method getNullableResult.
@Override
public String getNullableResult(ResultSet rs, String columnName) throws SQLException {
String value = "";
Clob clob = rs.getClob(columnName);
if (clob != null) {
int size = (int) clob.length();
value = clob.getSubString(1, size);
}
return value;
}
use of java.sql.Clob in project mybatis-3 by mybatis.
the class ClobTypeHandler method getNullableResult.
@Override
public String getNullableResult(CallableStatement cs, int columnIndex) throws SQLException {
String value = "";
Clob clob = cs.getClob(columnIndex);
if (clob != null) {
int size = (int) clob.length();
value = clob.getSubString(1, size);
}
return value;
}
use of java.sql.Clob in project mybatis-3 by mybatis.
the class NClobTypeHandler method getNullableResult.
@Override
public String getNullableResult(ResultSet rs, String columnName) throws SQLException {
String value = "";
Clob clob = rs.getClob(columnName);
if (clob != null) {
int size = (int) clob.length();
value = clob.getSubString(1, size);
}
return value;
}
Aggregations