public ISqlTransaction startSqlTransaction() { return new JdbcSqlTransaction(this); }
public int execute(final String sql) { return executeCallback(new IConnectionCallback<Integer>() { public Integer execute(Connection con) throws SQLException { Statement stmt = null; ResultSet rs = null; try { logSql(sql, null); stmt = con.createStatement(); if (stmt.execute(sql)) { rs = stmt.getResultSet(); while (rs.next()) { } } return stmt.getUpdateCount(); } finally { JdbcSqlTemplate.close(rs); JdbcSqlTemplate.close(stmt); } } }); }
@Override public void open(DataContext context) { super.open(context); try { JdbcSqlTransaction jdbcTransaction = (JdbcSqlTransaction) transaction; Connection conn = jdbcExtractor.getNativeConnection(jdbcTransaction.getConnection()); copyManager = new CopyManager((BaseConnection) conn); } catch (Exception ex) { throw getPlatform().getSqlTemplate().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; }
public Integer execute(Connection con) throws SQLException { Statement stmt = null; ResultSet rs = null; try { logSql(sql, null); stmt = con.createStatement(); if (stmt.execute(sql)) { rs = stmt.getResultSet(); while (rs.next()) { } } return stmt.getUpdateCount(); } finally { JdbcSqlTemplate.close(rs); JdbcSqlTemplate.close(stmt); } } });
public void commit() { if (connection != null) { try { if (pstmt != null && inBatchMode) { flush(); } connection.commit(); } catch (SQLException ex) { throw jdbcSqlTemplate.translate(ex); } } }
public int queryForInt(String sql, Object... args) { Integer val = queryForObject(sql, Integer.class, args); if (val == null) { val = Integer.MIN_VALUE; } return val; }
public JdbcSqlTransaction(JdbcSqlTemplate jdbcSqlTemplate) { this.jdbcSqlTemplate = jdbcSqlTemplate; this.init(); }
protected void removeMarkersThatWereSuccessful(BatchUpdateException ex) { int[] updateCounts = ex.getUpdateCounts(); Iterator<Object> it = markers.iterator(); int index = 0; while (it.hasNext()) { it.next(); if (updateCounts.length > index && normalizeUpdateCount(updateCounts[index]) > 0) { it.remove(); } index++; } }
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> List<T> query(String sql, ISqlRowMapper<T> mapper, Map<String, Object> namedParams) { ParsedSql parsedSql = NamedParameterUtils.parseSqlStatement(sql); String newSql = NamedParameterUtils.substituteNamedParameters(parsedSql, namedParams); Object[] params = NamedParameterUtils.buildValueArray(parsedSql, namedParams); return query(newSql, mapper, params, null); }
if (rowArrays.size() > 0) { JdbcSqlTransaction jdbcTransaction = (JdbcSqlTransaction) transaction; Connection c = jdbcTransaction.getConnection(); Connection oracleConnection = jdbcExtractor.getNativeConnection(c);
public Integer execute(Connection con) throws SQLException { PreparedStatement stmt = null; ResultSet rs = null; try { logSql(sql, args); stmt = con.prepareStatement(sql); if (args != null && args.length > 0) { jdbcSqlTemplate.setValues(stmt, args); } if (stmt.execute()) { rs = stmt.getResultSet(); while (rs.next()) { } } return stmt.getUpdateCount(); } finally { JdbcSqlTemplate.close(rs); JdbcSqlTemplate.close(stmt); } } });
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; }
public long queryForLong(String sql, Object... args) { Long val = queryForObject(sql, Long.class, args); if (val == null) { val = Long.MIN_VALUE; } return val; }
public Integer execute(Connection con) throws SQLException { PreparedStatement stmt = null; ResultSet rs = null; try { logSql(sql, args); stmt = con.prepareStatement(sql); jdbcSqlTemplate.setValues(stmt, args, types, jdbcSqlTemplate.getLobHandler().getDefaultHandler()); if (stmt.execute()) { rs = stmt.getResultSet(); while (rs.next()) { } } return stmt.getUpdateCount(); } finally { JdbcSqlTemplate.close(rs); JdbcSqlTemplate.close(stmt); } } });
public int prepareAndExecute(final String sql, final Object[] args, final int[] types) { return executeCallback(new IConnectionCallback<Integer>() { public Integer execute(Connection con) throws SQLException { PreparedStatement stmt = null; ResultSet rs = null; try { logSql(sql, args); stmt = con.prepareStatement(sql); jdbcSqlTemplate.setValues(stmt, args, types, jdbcSqlTemplate.getLobHandler().getDefaultHandler()); if (stmt.execute()) { rs = stmt.getResultSet(); while (rs.next()) { } } return stmt.getUpdateCount(); } finally { JdbcSqlTemplate.close(rs); JdbcSqlTemplate.close(stmt); } } }); }
public T execute(Connection con) throws SQLException { T result = null; Statement stmt = null; ResultSet rs = null; try { logSql(sql, args); if (args != null && args.length > 0) { PreparedStatement ps = con.prepareStatement(sql); stmt = ps; stmt.setQueryTimeout(jdbcSqlTemplate.getSettings().getQueryTimeout()); jdbcSqlTemplate.setValues(ps, args); rs = ps.executeQuery(); } else { stmt = con.createStatement(); stmt.setQueryTimeout(jdbcSqlTemplate.getSettings().getQueryTimeout()); rs = stmt.executeQuery(sql); } if (rs.next()) { result = jdbcSqlTemplate.getObjectFromResultSet(rs, clazz); } } finally { JdbcSqlTemplate.close(rs); JdbcSqlTemplate.close(stmt); } return result; } });
public <T> List<T> query(final String sql, final ISqlRowMapper<T> mapper, final Object[] args, final int[] types) { return executeCallback(new IConnectionCallback<List<T>>() { public List<T> execute(Connection c) throws SQLException { PreparedStatement st = null; ResultSet rs = null; try { logSql(sql, args); st = c.prepareStatement(sql); st.setQueryTimeout(jdbcSqlTemplate.getSettings().getQueryTimeout()); if (args != null) { jdbcSqlTemplate.setValues(st, args, types, jdbcSqlTemplate.getLobHandler().getDefaultHandler()); } st.setFetchSize(jdbcSqlTemplate.getSettings().getFetchSize()); rs = st.executeQuery(); List<T> list = new ArrayList<T>(); while (rs.next()) { Row row = JdbcSqlReadCursor.getMapForRow(rs, jdbcSqlTemplate.getSettings().isReadStringsAsBytes()); T value = mapper.mapRow(row); list.add(value); } return list; } finally { JdbcSqlTemplate.close(rs); JdbcSqlTemplate.close(st); } } }); }