protected static final PreparedStatement prepareStatement(final Connection connection, final String sql, final int resultSetType, final int resultSetConcurrency) throws SQLException { try { return connection.prepareStatement(sql, resultSetType, resultSetConcurrency); } catch(final SQLException x) { try { return connection.prepareStatement(sql); } catch(final SQLException x2) { x.addSuppressed(x2); throw x; } } }
/** * SQLExceptions thrown from batch executions have errors * in a {@link SQLException#getNextException()} chain, which * doesn't print out when you log them. Convert them to be * {@link Throwable#addSuppressed(Throwable)} exceptions, * which do print out with common logging frameworks. * * @param e the exception * @return the 'suppressed' munged exception change */ static SQLException mungeBatchException(SQLException e) { for (SQLException next = e.getNextException(); next != null; next = next.getNextException()) { e.addSuppressed(next); } return e; } }
@Override @SuppressWarnings("PMD.DoNotThrowExceptionInFinally") public void close() { SQLException exception = null; try { List<Cleanable> cleanables = new ArrayList<>(this.cleanables); this.cleanables.clear(); Collections.reverse(cleanables); for (Cleanable cleanable : cleanables) { try { cleanable.close(); } catch (SQLException e) { if (exception == null) { exception = e; } else { exception.addSuppressed(e); } } } } finally { if (exception != null) { throw new CloseException("Exception thrown while cleaning StatementContext", exception); } } }
first.addSuppressed(e); throw first;
/** * Log an exception and convert it to a SQL exception if required. * * @param ex the exception * @return the SQL exception object */ protected SQLException logAndConvert(Throwable ex) { SQLException e = null; try { e = DbException.toSQLException(ex); if (trace == null) { DbException.traceThrowable(e); } else { int errorCode = e.getErrorCode(); if (errorCode >= 23000 && errorCode < 24000) { trace.info(e, "exception"); } else { trace.error(e, "exception"); } } } catch(Throwable ignore) { if (e == null) { e = new SQLException("", "HY000", ex); } e.addSuppressed(ignore); } return e; }
/** * Returns a ResultIterable backed by the given result set supplier, mapper, and context. * * @param supplier result set supplier * @param mapper row mapper * @param ctx statement context * @param <T> the mapped type * @return the result iterable */ static <T> ResultIterable<T> of(Supplier<ResultSet> supplier, RowMapper<T> mapper, StatementContext ctx) { return () -> { try { return new ResultSetResultIterator<>(supplier.get(), mapper, ctx); } catch (SQLException e) { try { ctx.close(); } catch (Exception e1) { e.addSuppressed(e1); } throw new ResultSetException("Unable to iterator result set", e, ctx); } }; }
/** * Executes the update, returning the result obtained from the given {@link ResultProducer}. * * @param <R> the result type * @param producer the result producer. * @return value returned by the result producer. */ public <R> R execute(ResultProducer<R> producer) { try { return producer.produce(this::internalExecute, getContext()); } catch (SQLException e) { try { close(); } catch (Exception e1) { e.addSuppressed(e1); } throw new UnableToProduceResultException("Could not produce statement result", e, getContext()); } }
/** * Executes the query, returning the result obtained from the given {@link ResultProducer}. * * @param <R> the type of the result * @param producer the result producer. * @return value returned by the result producer. */ public <R> R execute(ResultProducer<R> producer) { try { return producer.produce(this::internalExecute, getContext()); } catch (SQLException e) { try { close(); } catch (Exception e1) { e.addSuppressed(e1); } throw new UnableToProduceResultException(e, getContext()); } }
/** * Executes the batch, returning the result obtained from the given {@link ResultProducer}. * * @param <R> the type of the result * @param producer the result producer. * @return value returned by the result producer. */ public <R> R execute(ResultProducer<R> producer) { try { return producer.produce(() -> internalBatchExecute().stmt, getContext()); } catch (SQLException e) { try { close(); } catch (Exception e1) { e.addSuppressed(e1); } throw new UnableToProduceResultException("Exception producing batch result", e, getContext()); } }
e.addSuppressed(ex); e.addSuppressed(ex);
stmt.close(); } catch (SQLException e1) { e.addSuppressed(e1);
public static SQLException withAllSQLExceptions( SQLException sqlEx ) { SQLException next = sqlEx.getNextException(); while( next != null ) { sqlEx.addSuppressed( next ); next = next.getNextException(); } return sqlEx; }
public static SQLException withAllSQLExceptions( SQLException sqlEx ) { SQLException next = sqlEx.getNextException(); while( next != null ) { sqlEx.addSuppressed( next ); next = next.getNextException(); } return sqlEx; }
protected static final PreparedStatement prepareStatement(final Connection connection, final String sql, final int resultSetType, final int resultSetConcurrency) throws SQLException { try { return connection.prepareStatement(sql, resultSetType, resultSetConcurrency); } catch(final SQLException x) { try { return connection.prepareStatement(sql); } catch(final SQLException x2) { x.addSuppressed(x2); throw x; } } }
public static SQLException close(final Connection connection, final SQLException exception) { if (connection == null) { return exception; } try { // if (connection.isClosed()) { // return exception; // } connection.close(); return exception; } catch (final SQLException sqlException) { if (exception == null) { return sqlException; } exception.addSuppressed(sqlException); return exception; } }
public static SQLException close(final Statement statement, final SQLException exception) { if (statement == null) { return exception; } try { // if (statement.isClosed()) { // return exception; // } statement.close(); return exception; } catch (final SQLException sqlException) { if (exception == null) { return sqlException; } exception.addSuppressed(sqlException); return exception; } }
/** * SQLExceptions thrown from batch executions have errors * in a {@link SQLException#getNextException()} chain, which * doesn't print out when you log them. Convert them to be * {@link Throwable#addSuppressed(Throwable)} exceptions, * which do print out with common logging frameworks. */ static SQLException mungeBatchException(SQLException e) { for (SQLException next = e.getNextException(); next != null; next = next.getNextException()) { e.addSuppressed(next); } return e; } }
private RuntimeException handleSqlException(SQLException e) { try { close(); } catch (Exception closeException) { e.addSuppressed(closeException); } return Throwables.propagate(e); } }
@Override public void clearSchema(Connection c) { try (Statement s = c.createStatement()) { LOG.log(Level.FINEST, "Dropping schema objects: START"); s.execute("DROP ALL OBJECTS"); LOG.log(Level.FINEST, "Dropping schema objects: END"); LOG.log(Level.FINEST, "Committing: START"); c.commit(); LOG.log(Level.FINEST, "Committing: END"); } catch (SQLException e) { try { c.rollback(); } catch (SQLException e1) { e.addSuppressed(e1); } throw new RuntimeException(e); } }