protected <T> T executeCallback(IConnectionCallback<T> callback) { try { return callback.execute(this.connection); } catch (SQLException ex) { throw this.jdbcSqlTemplate.translate(ex); } }
public long insertWithGeneratedKey(String sql, String column, String sequenceName, Object[] args, int[] types) { try { return jdbcSqlTemplate.insertWithGeneratedKey(connection, sql, column, sequenceName, args, types); } catch (SQLException ex) { throw jdbcSqlTemplate.translate(ex); } }
@Override public SqlException translate(String message, Throwable ex) { if (ex instanceof SQLException) { if (((SQLException)ex).getErrorCode() == 335544336) { throw new ConcurrencySqlException(message, ex); } } return super.translate(message, ex); }
public void commit() { if (connection != null) { try { if (pstmt != null && inBatchMode) { flush(); } connection.commit(); } catch (SQLException ex) { throw jdbcSqlTemplate.translate(ex); } } }
public void prepare(String sql) { try { if (this.markers.size() > 0) { throw new IllegalStateException( "Cannot prepare a new batch before the last batch has been flushed."); } JdbcSqlTemplate.close(pstmt); if (log.isDebugEnabled()) { log.debug("Preparing: {}", sql); } pstmt = connection.prepareStatement(sql); psql = sql; } catch (SQLException ex) { throw jdbcSqlTemplate.translate(ex); } }
public int flush() { int rowsUpdated = 0; if (markers.size() > 0 && pstmt != null) { try { int[] updates = pstmt.executeBatch(); for (int i : updates) { rowsUpdated += normalizeUpdateCount(i); } markers.clear(); } catch (BatchUpdateException ex) { removeMarkersThatWereSuccessful(ex); throw jdbcSqlTemplate.translate(ex); } catch (SQLException ex) { throw jdbcSqlTemplate.translate(ex); } } return rowsUpdated; }
protected void init() { if (this.connection != null) { close(); } try { this.connection = jdbcSqlTemplate.getDataSource().getConnection(); this.oldAutoCommitValue = this.connection.getAutoCommit(); this.connection.setAutoCommit(false); SqlUtils.addSqlTransaction(this); } catch (SQLException ex) { close(); throw jdbcSqlTemplate.translate(ex); } }
public <T> T execute(IConnectionCallback<T> callback) { Connection c = null; try { c = getConnection(); return callback.execute(c); } catch (SQLException ex) { throw translate(ex); } finally { close(c); } }
public T next() { try { while (rs!=null && rs.next()) { Row row = getMapForRow(rs, sqlTemplate.getSettings().isReadStringsAsBytes()); T value = mapper.mapRow(row); if (value != null) { return value; } } return null; } catch (SQLException ex) { throw sqlTemplate.translate(ex); } }
boolean isSequenceCreate = statement.toLowerCase().trim().startsWith("create sequence"); if (resultsListener != null) { resultsListener.sqlErrored(statement, translate(statement, ex), statementCount, isDrop, isSequenceCreate);
public int addRow(Object marker, Object[] args, int[] argTypes) { int rowsUpdated = 0; try { if (log.isDebugEnabled()) { log.debug("Adding {} {}", ArrayUtils.toString(args), inBatchMode ? " in batch mode" : ""); } if (args != null) { jdbcSqlTemplate.setValues(pstmt, args, argTypes, jdbcSqlTemplate.getLobHandler().getDefaultHandler()); } if (inBatchMode) { if (marker == null) { marker = new Integer(markers.size() + 1); } markers.add(marker); pstmt.addBatch(); if (markers.size() >= jdbcSqlTemplate.getSettings().getBatchSize()) { rowsUpdated = flush(); } } else { pstmt.execute(); rowsUpdated = pstmt.getUpdateCount(); } } catch (SQLException ex) { throw jdbcSqlTemplate.translate(ex); } return rowsUpdated; }