/** Helper method for wrapping quick calls that don't appreciate being interrupted. * Passes all exceptions and errors back to the client. * Runs in another thread - do not acquire connections from within the callable (it will fail). * N.B. (DCohen) Despite the claim in the previous line, there is code that acquires connections from within the callable successfully. * Unclear why this is bad. * * Should only use low-level type stuff. * * This method takes a connection, which the callable intends to use, * essentially declaring that the child thread now owns * this connection. */ public static <T> T runUninterruptably( final Callable<T> callable, String threadString, final @Nullable Connection connection) throws PalantirSqlException { return runUninterruptably( BasicSQL.DEFAULT_EXECUTE_EXECUTOR.get(), callable, threadString, connection); }
private <T> T runUninterruptablyInternal(final PreparedStatement ps, final ResultSetVisitor<T> visitor, final FinalSQLString sql, final AutoClose autoClose, @Nullable Integer fetchSize) throws PalantirInterruptedException, PalantirSqlException { if (Thread.currentThread().isInterrupted()) { SqlLoggers.CANCEL_LOGGER.debug("interrupted prior to executing uninterruptable SQL call"); throw new PalantirInterruptedException("interrupted prior to executing uninterruptable SQL call"); } return BasicSQLUtils.runUninterruptably(executeStatementExecutor, () -> { if (fetchSize != null) { ps.setFetchSize(fetchSize); } ResultSet rs = null; try { rs = ps.executeQuery(); return visitor.visit(rs); } finally { if (rs != null && autoClose == AutoClose.TRUE) { rs.close(); } } }, sql.toString(), /* We no longer have a connection to worry about */ null); }
PreparedStatement updateInternal(final Connection c, final FinalSQLString sql, final Object vs[], final AutoClose autoClose) throws PalantirSqlException { if (SqlLoggers.LOGGER.isTraceEnabled()) { SqlLoggers.LOGGER.trace("SQL update interval query: {}", sql.getQuery()); } return BasicSQLUtils.runUninterruptably (executeStatementExecutor, () -> { return wrapPreparedStatement(c, sql, vs, ps -> { PreparedStatements.execute(ps); return ps; }, "update", autoClose); //$NON-NLS-1$ }, sql.toString(), c); }
protected PreparedStatement execute(final Connection c, final FinalSQLString sql, final Object vs[], final AutoClose autoClose) throws PalantirSqlException { if (SqlLoggers.LOGGER.isTraceEnabled()) { SqlLoggers.LOGGER.trace("SQL execution query: {}", sql.getQuery()); } return BasicSQLUtils.runUninterruptably (executeStatementExecutor, () -> { return wrapPreparedStatement(c, sql, vs, ps -> { PreparedStatements.execute(ps); return ps; }, "execute", autoClose); //$NON-NLS-1$ }, sql.toString(), c); }
protected int insertOneCountRowsInternal(final Connection c, final FinalSQLString sql, final Object... vs) throws PalantirSqlException { if (SqlLoggers.LOGGER.isTraceEnabled()) { SqlLoggers.LOGGER.trace("SQL insert one count rows internal query: {}", sql.getQuery()); } return BasicSQLUtils.runUninterruptably (executeStatementExecutor, () -> { return wrapPreparedStatement(c, sql, vs, ps -> { PreparedStatements.execute(ps); return PreparedStatements.getUpdateCount(ps); }, "insertOne"); //$NON-NLS-1$ }, sql.toString(), c); }
SqlLoggers.LOGGER.trace("SQL update many query: {}", sql.getQuery()); BasicSQLUtils.runUninterruptably (executeStatementExecutor, (Callable<Void>) () -> { List<BlobHandler> cleanups = Lists.newArrayList(); PreparedStatement ps = null;
SqlLoggers.LOGGER.trace("SQL insert many query: {}", sql.getQuery()); return BasicSQLUtils.runUninterruptably (executeStatementExecutor, () -> { int[] inserted = null; PreparedStatement ps = null;
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(); } }
/** Helper method for wrapping quick calls that don't appreciate being interrupted. * Passes all exceptions and errors back to the client. * Runs in another thread - do not acquire connections from within the callable (it will fail). * N.B. (DCohen) Despite the claim in the previous line, there is code that acquires connections from within the callable successfully. * Unclear why this is bad. * * Should only use low-level type stuff. * * This method takes a connection, which the callable intends to use, * essentially declaring that the child thread now owns * this connection. */ public static <T> T runUninterruptably( final Callable<T> callable, String threadString, final @Nullable Connection connection) throws PalantirSqlException { return runUninterruptably( BasicSQL.DEFAULT_EXECUTE_EXECUTOR.get(), callable, threadString, connection); }
private <T> T runUninterruptablyInternal(final PreparedStatement ps, final ResultSetVisitor<T> visitor, final FinalSQLString sql, final AutoClose autoClose, @Nullable Integer fetchSize) throws PalantirInterruptedException, PalantirSqlException { if (Thread.currentThread().isInterrupted()) { SqlLoggers.CANCEL_LOGGER.debug("interrupted prior to executing uninterruptable SQL call"); throw new PalantirInterruptedException("interrupted prior to executing uninterruptable SQL call"); } return BasicSQLUtils.runUninterruptably(executeStatementExecutor, () -> { if (fetchSize != null) { ps.setFetchSize(fetchSize); } ResultSet rs = null; try { rs = ps.executeQuery(); return visitor.visit(rs); } finally { if (rs != null && autoClose == AutoClose.TRUE) { rs.close(); } } }, sql.toString(), /* We no longer have a connection to worry about */ null); }
PreparedStatement updateInternal(final Connection c, final FinalSQLString sql, final Object vs[], final AutoClose autoClose) throws PalantirSqlException { if (SqlLoggers.LOGGER.isTraceEnabled()) { SqlLoggers.LOGGER.trace("SQL update interval query: {}", sql.getQuery()); } return BasicSQLUtils.runUninterruptably (executeStatementExecutor, () -> { return wrapPreparedStatement(c, sql, vs, ps -> { PreparedStatements.execute(ps); return ps; }, "update", autoClose); //$NON-NLS-1$ }, sql.toString(), c); }
protected PreparedStatement execute(final Connection c, final FinalSQLString sql, final Object vs[], final AutoClose autoClose) throws PalantirSqlException { if (SqlLoggers.LOGGER.isTraceEnabled()) { SqlLoggers.LOGGER.trace("SQL execution query: {}", sql.getQuery()); } return BasicSQLUtils.runUninterruptably (executeStatementExecutor, () -> { return wrapPreparedStatement(c, sql, vs, ps -> { PreparedStatements.execute(ps); return ps; }, "execute", autoClose); //$NON-NLS-1$ }, sql.toString(), c); }
protected int insertOneCountRowsInternal(final Connection c, final FinalSQLString sql, final Object... vs) throws PalantirSqlException { if (SqlLoggers.LOGGER.isTraceEnabled()) { SqlLoggers.LOGGER.trace("SQL insert one count rows internal query: {}", sql.getQuery()); } return BasicSQLUtils.runUninterruptably (executeStatementExecutor, () -> { return wrapPreparedStatement(c, sql, vs, ps -> { PreparedStatements.execute(ps); return PreparedStatements.getUpdateCount(ps); }, "insertOne"); //$NON-NLS-1$ }, sql.toString(), c); }
SqlLoggers.LOGGER.trace("SQL update many query: {}", sql.getQuery()); BasicSQLUtils.runUninterruptably (executeStatementExecutor, (Callable<Void>) () -> { List<BlobHandler> cleanups = Lists.newArrayList(); PreparedStatement ps = null;
SqlLoggers.LOGGER.trace("SQL insert many query: {}", sql.getQuery()); return BasicSQLUtils.runUninterruptably (executeStatementExecutor, () -> { int[] inserted = null; PreparedStatement ps = null;
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(); } }