use of org.springframework.jdbc.support.lob.LobCreator in project otter by alibaba.
the class BitTableIntegration method doPreparedStatement.
private void doPreparedStatement(PreparedStatement ps, final DbDialect dbDialect, final Integer[] columnTypes, final String[] columnValues) throws SQLException {
LobCreator lobCreator = null;
for (int i = 0; i < columnTypes.length; i++) {
int paramIndex = i + 1;
String sqlValue = columnValues[i];
int sqlType = columnTypes[i];
Object param = SqlUtils.stringToSqlValue(sqlValue, sqlType, SqlUtils.isTextType(sqlType), dbDialect.isEmptyStringNulled());
switch(sqlType) {
case Types.CLOB:
if (lobCreator == null) {
lobCreator = dbDialect.getLobHandler().getLobCreator();
}
lobCreator.setClobAsString(ps, paramIndex, (String) param);
break;
case Types.BLOB:
if (lobCreator == null) {
lobCreator = dbDialect.getLobHandler().getLobCreator();
}
lobCreator.setBlobAsBytes(ps, paramIndex, (byte[]) param);
break;
case Types.TIME:
case Types.TIMESTAMP:
case Types.DATE:
ps.setObject(paramIndex, sqlValue);
break;
default:
StatementCreatorUtils.setParameterValue(ps, paramIndex, sqlType, null, param);
break;
}
}
}
use of org.springframework.jdbc.support.lob.LobCreator in project otter by alibaba.
the class DbDialectTest method doPreparedStatement.
private void doPreparedStatement(PreparedStatement ps, final DbDialect dbDialect, final Integer[] columnTypes, final String[] columnValues) throws SQLException {
LobCreator lobCreator = null;
for (int i = 0; i < columnTypes.length; i++) {
int paramIndex = i + 1;
String sqlValue = columnValues[i];
int sqlType = columnTypes[i];
Object param = SqlUtils.stringToSqlValue(sqlValue, sqlType, SqlUtils.isTextType(sqlType), dbDialect.isEmptyStringNulled());
switch(sqlType) {
case Types.CLOB:
if (lobCreator == null) {
lobCreator = dbDialect.getLobHandler().getLobCreator();
}
lobCreator.setClobAsString(ps, paramIndex, (String) param);
break;
case Types.BLOB:
if (lobCreator == null) {
lobCreator = dbDialect.getLobHandler().getLobCreator();
}
lobCreator.setBlobAsBytes(ps, paramIndex, (byte[]) param);
break;
default:
StatementCreatorUtils.setParameterValue(ps, paramIndex, sqlType, null, param);
break;
}
}
}
use of org.springframework.jdbc.support.lob.LobCreator in project otter by alibaba.
the class TimeTableIntegration method doPreparedStatement.
private void doPreparedStatement(PreparedStatement ps, final DbDialect dbDialect, final Integer[] columnTypes, final String[] columnValues) throws SQLException {
LobCreator lobCreator = null;
for (int i = 0; i < columnTypes.length; i++) {
int paramIndex = i + 1;
String sqlValue = columnValues[i];
int sqlType = columnTypes[i];
Object param = SqlUtils.stringToSqlValue(sqlValue, sqlType, SqlUtils.isTextType(sqlType), dbDialect.isEmptyStringNulled());
switch(sqlType) {
case Types.CLOB:
if (lobCreator == null) {
lobCreator = dbDialect.getLobHandler().getLobCreator();
}
lobCreator.setClobAsString(ps, paramIndex, (String) param);
break;
case Types.BLOB:
if (lobCreator == null) {
lobCreator = dbDialect.getLobHandler().getLobCreator();
}
lobCreator.setBlobAsBytes(ps, paramIndex, (byte[]) param);
break;
case Types.TIME:
case Types.TIMESTAMP:
case Types.DATE:
ps.setObject(paramIndex, sqlValue);
break;
default:
StatementCreatorUtils.setParameterValue(ps, paramIndex, sqlType, null, param);
break;
}
}
}
use of org.springframework.jdbc.support.lob.LobCreator in project camel by apache.
the class JdbcAggregationRepository method insertAndUpdateHelper.
protected void insertAndUpdateHelper(final CamelContext camelContext, final String key, final Exchange exchange, String sql, final boolean idComesFirst) throws Exception {
final byte[] data = codec.marshallExchange(camelContext, exchange, allowSerializedHeaders);
jdbcTemplate.execute(sql, new AbstractLobCreatingPreparedStatementCallback(getLobHandler()) {
@Override
protected void setValues(PreparedStatement ps, LobCreator lobCreator) throws SQLException {
int totalParameterIndex = 0;
lobCreator.setBlobAsBytes(ps, ++totalParameterIndex, data);
if (idComesFirst) {
ps.setString(++totalParameterIndex, key);
}
if (storeBodyAsText) {
ps.setString(++totalParameterIndex, exchange.getIn().getBody(String.class));
}
if (hasHeadersToStoreAsText()) {
for (String headerName : headersToStoreAsText) {
String headerValue = exchange.getIn().getHeader(headerName, String.class);
ps.setString(++totalParameterIndex, headerValue);
}
}
if (!idComesFirst) {
ps.setString(++totalParameterIndex, key);
}
}
});
}
use of org.springframework.jdbc.support.lob.LobCreator in project perun by CESNET.
the class Auditer method storeMessageToDb.
/**
* Store the message to the DB.
*
* @param sess
* @param message
*/
public void storeMessageToDb(final PerunSession sess, final String message) {
synchronized (LOCK_DB_TABLE_AUDITER_LOG) {
try {
final int msgId = Utils.getNewId(jdbc, "auditer_log_id_seq");
jdbc.execute("insert into auditer_log (id, msg, actor, created_at, created_by_uid) values (?,?,?," + Compatibility.getSysdate() + ",?)", new AbstractLobCreatingPreparedStatementCallback(lobHandler) {
public void setValues(PreparedStatement ps, LobCreator lobCreator) throws SQLException {
ps.setInt(1, msgId);
lobCreator.setClobAsString(ps, 2, message);
ps.setString(3, sess.getPerunPrincipal().getActor());
ps.setInt(4, sess.getPerunPrincipal().getUserId());
}
});
} catch (RuntimeException e) {
log.error("Cannot store auditer log message ['{}'], exception: {}", message, e);
} catch (InternalErrorException e) {
log.error("Cannot get unique id for new auditer log message ['{}'], exception: {}", message, e);
}
}
}
Aggregations