Search in sources :

Example 26 with Clob

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");
    }
}
Also used : Blob(java.sql.Blob) Configuration(org.jooq.Configuration) Time(java.sql.Time) LocalTime(java.time.LocalTime) OffsetTime(java.time.OffsetTime) OffsetDateTime(java.time.OffsetDateTime) LocalDateTime(java.time.LocalDateTime) BigDecimal(java.math.BigDecimal) LocalDate(java.time.LocalDate) Date(java.sql.Date) UInteger(org.jooq.types.UInteger) BigInteger(java.math.BigInteger) UNumber(org.jooq.types.UNumber) EnumType(org.jooq.EnumType) UByte(org.jooq.types.UByte) BigInteger(java.math.BigInteger) Clob(java.sql.Clob) UShort(org.jooq.types.UShort) YearToMonth(org.jooq.types.YearToMonth)

Example 27 with Clob

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;
}
Also used : PreparedStatement(java.sql.PreparedStatement) Clob(java.sql.Clob)

Example 28 with Clob

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;
}
Also used : Clob(java.sql.Clob)

Example 29 with Clob

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;
}
Also used : Clob(java.sql.Clob)

Example 30 with Clob

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;
}
Also used : Clob(java.sql.Clob)

Aggregations

Clob (java.sql.Clob)96 FilterChainImpl (com.alibaba.druid.filter.FilterChainImpl)27 Blob (java.sql.Blob)24 SQLException (java.sql.SQLException)20 ResultSet (java.sql.ResultSet)16 NClob (java.sql.NClob)14 MockClob (com.alibaba.druid.mock.MockClob)13 ClobProxy (com.alibaba.druid.proxy.jdbc.ClobProxy)13 MockNClob (com.alibaba.druid.mock.MockNClob)12 NClobProxy (com.alibaba.druid.proxy.jdbc.NClobProxy)12 ResultSetProxyImpl (com.alibaba.druid.proxy.jdbc.ResultSetProxyImpl)12 PreparedStatement (java.sql.PreparedStatement)10 IOException (java.io.IOException)8 InputStream (java.io.InputStream)8 Reader (java.io.Reader)7 Test (org.junit.Test)7 StringReader (java.io.StringReader)6 Connection (java.sql.Connection)6 Timestamp (java.sql.Timestamp)5 CUBRIDOIDProxy (com.cubrid.jdbc.proxy.driver.CUBRIDOIDProxy)4