private int executeCountRows(Connection c, FinalSQLString sql, Object... vs) throws PalantirSqlException { PreparedStatement ps = null; try { ps = basicSql.execute(c, sql, vs, AutoClose.FALSE); return PreparedStatements.getUpdateCount(ps); } finally { BasicSQL.closeSilently(ps); } }
static PalantirSqlException handleInterruptions(long startTime, ExecutionException ee) throws PalantirSqlException { SQLException e = getSQLException(ee.getCause()); return handleInterruptions(startTime, e); }
boolean insertManyUnregisteredQuery(Connection c, String sql, Iterable<Object[]> list) throws PalantirSqlException { return basicSql.insertMany( c, SQLString.getUnregisteredQuery(sql), Iterables.toArray(list, Object[].class)); }
private <T> T runCancellably(final PreparedStatement ps, ResultSetVisitor<T> visitor, final FinalSQLString sql, AutoClose autoClose, @Nullable Integer fetchSize) throws PalantirInterruptedException, PalantirSqlException { if (isSqlCancellationDisabled()) { return runUninterruptablyInternal(ps, visitor, sql, autoClose, fetchSize); } else { return runCancellablyInternal(ps, visitor, sql, autoClose, fetchSize); } }
List<BlobHandler> cleanups = Lists.newArrayList(); PreparedStatement ps = null; SqlTimer.Handle timerKey = getSqlTimer().start("updateMany(" + vs.length + ")", sql.getKey(), sql.getQuery()); //$NON-NLS-1$ //$NON-NLS-2$ try { ps = c.prepareStatement(sql.getQuery()); for (int j=0; j < vs[i].length; j++) { Object obj = vs[i][j]; BlobHandler cleanup = setObject(c, ps, j+1, obj); if (cleanup != null) { cleanups.add(cleanup); } catch (SQLException sqle) { SqlLoggers.SQL_EXCEPTION_LOG.debug("Caught SQLException", sqle); throw wrapSQLExceptionWithVerboseLogging(sqle, sql.getQuery(), vs); } finally { closeSilently(ps); timerKey.stop(); for (BlobHandler cleanup : cleanups) {
public static void rollback(Connection c) throws PalantirSqlException { try { c.rollback(); } catch (SQLException e) { throw BasicSQL.handleInterruptions(0, e); } }
private <T> T wrapPreparedStatement(final Connection c, final FinalSQLString query, final Object[] vs, PreparedStatementVisitor<T> visitor, String description, AutoClose autoClose) throws PalantirSqlException, PalantirInterruptedException { SqlTimer.Handle timerKey = getSqlTimer().start(description, query.getKey(), query.getQuery()); PreparedStatement ps = null; try { ps = BasicSQLUtils.runUninterruptably( executeStatementExecutor, () -> createPreparedStatement(c, query.getQuery(), vs), "SQL createPreparedStatement", c); return visitor.visit(ps); } catch (PalantirSqlException sqle) { throw wrapSQLExceptionWithVerboseLogging(sqle, query.getQuery(), vs); } finally { closeSilently(ps, autoClose); timerKey.stop(); } }
"selectList", //$NON-NLS-1$ sql, getSqlTimer(), creationException); } catch (Exception e) { closeSilently(rs); BasicSQLUtils.throwUncheckedIfSQLException(e); throw Throwables.throwUncheckedException(e); return runCancellably(ps, resultSetVisitor, sql, AutoClose.FALSE, fetchSize); } catch (Exception e) { closeSilently(ps); BasicSQLUtils.throwUncheckedIfSQLException(e); throw Throwables.throwUncheckedException(e); return wrapPreparedStatement( c, sql,
void executeUnregisteredQuery(Connection c, String sql, Object... vs) throws PalantirSqlException { basicSql.execute(c, SQLString.getUnregisteredQuery(sql), vs, AutoClose.TRUE); }
protected int updateCountRowsInternal(Connection c, FinalSQLString sql, Object... vs) throws PalantirSqlException { PreparedStatement ps = null; try { ps = updateInternal(c, sql, vs, AutoClose.FALSE); return PreparedStatements.getUpdateCount(ps); } finally { closeSilently(ps); } }
int insertOneCountRowsUnregisteredQuery(Connection c, String sql, Object... vs) throws PalantirSqlException { return basicSql.insertOneCountRowsInternal(c, SQLString.getUnregisteredQuery(sql), vs); }
protected boolean isSqlCancellationDisabled() { return getSqlConfig().isSqlCancellationDisabled(); }
private static SQLException getSQLException(Throwable cause) { if (cause instanceof SQLException) { return (SQLException) cause; } if (cause.getCause() == null || !(cause instanceof PalantirSqlException)) { throw Throwables.rewrapAndThrowUncheckedException(cause); } return getSQLException(cause.getCause()); }
protected static void closeSilently(PreparedStatement ps) { closeSilently(ps, AutoClose.TRUE); }
PreparedStatement ps = null; SqlTimer.Handle timerKey = getSqlTimer().start("insertMany(" + vs.length + ")", sql.getKey(), sql.getQuery()); //$NON-NLS-1$ //$NON-NLS-2$ List<BlobHandler> cleanups = Lists.newArrayList(); try { for (int j=0; j < vs[i].length; j++) { Object obj = vs[i][j]; BlobHandler cleanup = setObject(c, ps, j+1, obj); if (cleanup != null) { cleanups.add(cleanup); } catch (SQLException sqle) { SqlLoggers.SQL_EXCEPTION_LOG.debug("Caught SQLException", sqle); throw wrapSQLExceptionWithVerboseLogging(sqle, sql.getQuery(), vs); } finally { closeSilently(ps); timerKey.stop(); for (BlobHandler cleanup : cleanups) {
public static void commit(Connection c) throws PalantirSqlException { try { c.commit(); } catch (SQLException e) { throw BasicSQL.handleInterruptions(0, e); } } }
private <T> T wrapPreparedStatement(final Connection c, final FinalSQLString query, final Object[] vs, PreparedStatementVisitor<T> visitor, String description, AutoClose autoClose) throws PalantirSqlException, PalantirInterruptedException { SqlTimer.Handle timerKey = getSqlTimer().start(description, query.getKey(), query.getQuery()); PreparedStatement ps = null; try { ps = BasicSQLUtils.runUninterruptably( executeStatementExecutor, () -> createPreparedStatement(c, query.getQuery(), vs), "SQL createPreparedStatement", c); return visitor.visit(ps); } catch (PalantirSqlException sqle) { throw wrapSQLExceptionWithVerboseLogging(sqle, query.getQuery(), vs); } finally { closeSilently(ps, autoClose); timerKey.stop(); } }
"selectList", //$NON-NLS-1$ sql, getSqlTimer(), creationException); } catch (Exception e) { closeSilently(rs); BasicSQLUtils.throwUncheckedIfSQLException(e); throw Throwables.throwUncheckedException(e); return runCancellably(ps, resultSetVisitor, sql, AutoClose.FALSE, fetchSize); } catch (Exception e) { closeSilently(ps); BasicSQLUtils.throwUncheckedIfSQLException(e); throw Throwables.throwUncheckedException(e); return wrapPreparedStatement( c, sql,
private <T> T runCancellably(final PreparedStatement ps, ResultSetVisitor<T> visitor, final FinalSQLString sql, AutoClose autoClose, @Nullable Integer fetchSize) throws PalantirInterruptedException, PalantirSqlException { if (isSqlCancellationDisabled()) { return runUninterruptablyInternal(ps, visitor, sql, autoClose, fetchSize); } else { return runCancellablyInternal(ps, visitor, sql, autoClose, fetchSize); } }
PreparedStatement execute(Connection c, String key, Object... vs) throws PalantirSqlException { return basicSql.execute(c, SQLString.getByKey(key, c), vs, AutoClose.TRUE); }