@Override public synchronized void close() { if (sharedConnection != null) { try { sharedConnection.getUnderlyingConnection().close(); } catch (SQLException e) { log.error("Error occurred closing the underlying connection", e); } finally { sharedConnection = null; } } } }
private static void closeSql(SqlConnection conn) { Connection underlyingConnection = conn.getUnderlyingConnection(); if (underlyingConnection != null) { try { underlyingConnection.close(); } catch (Exception e) { log.debug("Error occurred trying to close the sql connection", e); } } }
private <T> T run(Function<SqlConnection, T> runner) { SqlConnection conn = connections.get(); try { return runner.apply(conn); } finally { try { conn.getUnderlyingConnection().close(); } catch (Exception e) { log.debug("Error occurred trying to close the connection", e); } } }
private SqlConnection getCompactionConnection() { SqlConnection sqlConnection = conns.get(); try { int originalNetworkTimeout = sqlConnection.getUnderlyingConnection().getNetworkTimeout(); int newNetworkMillis = Ints.saturatedCast(config.compactionConnectionTimeout()); log.info("Increased sql socket read timeout from {} to {}", SafeArg.of("originalNetworkTimeoutMillis", originalNetworkTimeout), SafeArg.of("newNetworkTimeoutMillis", newNetworkMillis)); sqlConnection.getUnderlyingConnection().setNetworkTimeout(compactionTimeoutExecutor, newNetworkMillis); } catch (SQLException e) { log.warn("Failed to increase socket read timeout for the connection. Encountered an exception:", e); } return sqlConnection; } }
} finally { try { Connection conn = freshConn.getUnderlyingConnection(); if (conn != null) { conn.close();
private <T> void runWriteForceAutocommit(TableReference tableRef, Function<DbWriteTable, T> runner) { try (ConnectionSupplier conns = new ConnectionSupplier(connections)) { SqlConnection conn = conns.get(); boolean autocommit; try { autocommit = conn.getUnderlyingConnection().getAutoCommit(); } catch (PalantirSqlException | SQLException e1) { throw Throwables.rewrapAndThrowUncheckedException(e1); } if (!autocommit) { runWriteFreshConnection(conns, tableRef, runner); } else { runner.apply(dbTables.createWrite(tableRef, conns)); } } }
@Before public void setup() { SqlConnection mockConnection = mock(SqlConnection.class); when(connectionSupplier.get()).thenReturn(mockConnection); AgnosticResultSet resultSet = mock(AgnosticResultSet.class); when(mockConnection.selectResultSetUnregisteredQuery(startsWith("SELECT table_size FROM"), anyObject())) .thenReturn(resultSet); AgnosticResultRow row = mock(AgnosticResultRow.class); when(row.getInteger(eq("table_size"))).thenReturn(TableValueStyle.OVERFLOW.getId()); doReturn(ImmutableList.of(row)).when(resultSet).rows(); when(mockConnection.getUnderlyingConnection()).thenReturn(mock(Connection.class)); }
@Before public void setup() { connectionSupplier = mock(ConnectionSupplier.class); oracleTableNameUnmapper = new OracleTableNameUnmapper(); SqlConnection sqlConnection = mock(SqlConnection.class); Connection connection = mock(Connection.class); when(sqlConnection.getUnderlyingConnection()).thenReturn(connection); when(connectionSupplier.get()).thenReturn(sqlConnection); resultSet = mock(AgnosticResultSet.class); when(sqlConnection .selectResultSetUnregisteredQuery( startsWith("SELECT short_table_name FROM atlasdb_table_names WHERE table_name"), anyObject())) .thenReturn(resultSet); }
log.info("Got connection for deleteAllTimestamps on table {}: {}, autocommit={}", shortTableName, conn.getUnderlyingConnection(), conn.getUnderlyingConnection().getAutoCommit()); } catch (PalantirSqlException | SQLException e) {
log.info("Got connection for delete on table {}: {}, autocommit={}", shortTableName, conn.getUnderlyingConnection(), conn.getUnderlyingConnection().getAutoCommit()); } catch (PalantirSqlException | SQLException e) {
private static void closeSql(SqlConnection conn) { Connection underlyingConnection = conn.getUnderlyingConnection(); if (underlyingConnection != null) { try { underlyingConnection.close(); } catch (Exception e) { log.debug("Error occurred trying to close the sql connection", e); } } }
@Override public synchronized void close() { if (sharedConnection != null) { try { sharedConnection.getUnderlyingConnection().close(); } catch (SQLException e) { log.error("Error occurred closing the underlying connection", e); } finally { sharedConnection = null; } } } }
private <T> T run(Function<SqlConnection, T> runner) { SqlConnection conn = connections.get(); try { return runner.apply(conn); } finally { try { conn.getUnderlyingConnection().close(); } catch (Exception e) { log.debug("Error occurred trying to close the connection", e); } } }
private SqlConnection getCompactionConnection() { SqlConnection sqlConnection = conns.get(); try { int originalNetworkTimeout = sqlConnection.getUnderlyingConnection().getNetworkTimeout(); int newNetworkMillis = Ints.saturatedCast(config.compactionConnectionTimeout()); log.info("Increased sql socket read timeout from {} to {}", SafeArg.of("originalNetworkTimeoutMillis", originalNetworkTimeout), SafeArg.of("newNetworkTimeoutMillis", newNetworkMillis)); sqlConnection.getUnderlyingConnection().setNetworkTimeout(compactionTimeoutExecutor, newNetworkMillis); } catch (SQLException e) { log.warn("Failed to increase socket read timeout for the connection. Encountered an exception:", e); } return sqlConnection; } }
} finally { try { Connection conn = freshConn.getUnderlyingConnection(); if (conn != null) { conn.close();
private <T> void runWriteForceAutocommit(TableReference tableRef, Function<DbWriteTable, T> runner) { try (ConnectionSupplier conns = new ConnectionSupplier(connections)) { SqlConnection conn = conns.get(); boolean autocommit; try { autocommit = conn.getUnderlyingConnection().getAutoCommit(); } catch (PalantirSqlException | SQLException e1) { throw Throwables.rewrapAndThrowUncheckedException(e1); } if (!autocommit) { runWriteFreshConnection(conns, tableRef, runner); } else { runner.apply(dbTables.createWrite(tableRef, conns)); } } }
log.info("Got connection for delete on table {}: {}, autocommit={}", shortTableName, conn.getUnderlyingConnection(), conn.getUnderlyingConnection().getAutoCommit()); } catch (PalantirSqlException | SQLException e) {
log.info("Got connection for deleteAllTimestamps on table {}: {}, autocommit={}", shortTableName, conn.getUnderlyingConnection(), conn.getUnderlyingConnection().getAutoCommit()); } catch (PalantirSqlException | SQLException e) {