use of org.springframework.jdbc.core.support.AbstractLobCreatingPreparedStatementCallback 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.core.support.AbstractLobCreatingPreparedStatementCallback 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