@Override public final Connection acquire() { Connection local = localTxConnection.get(); if (local == null) return delegateConnectionProvider.acquire(); else return local; }
@Override public final void release(Connection connection) { if (connection instanceof MockConnectionWrapper) delegate.release(((MockConnectionWrapper) connection).connection); else throw new IllegalArgumentException("Argument connection must be a MockConnectionWrapper"); }
@Override public void rollback(Savepoint savepoint) { try { Connection connection = jooqConf.connectionProvider().acquire(); connection.rollback(savepoint); } catch (SQLException ex) { //TODO: Change exception throw new RuntimeException(ex); } }
@Override public final void release(Connection connection) { Connection local = localTxConnection.get(); if (local == null) delegateConnectionProvider.release(connection); else if (local != connection) throw new IllegalStateException( "A different connection was released than the thread-bound one that was expected"); } }
@Override public void rollback() { try { Connection connection = jooqConf.connectionProvider().acquire(); connection.rollback(); } catch (SQLException ex) { //TODO: Change exception throw new RuntimeException(ex); } }
@Override public final void close() throws SQLException { Connection connection = getDelegate(); if (connection != null) { connectionProvider.release(connection); } }
private final DatabaseMetaData meta() { if (meta == null) { ConnectionProvider provider = configuration.connectionProvider(); Connection connection = null; try { connection = provider.acquire(); meta = connection.getMetaData(); } catch (SQLException e) { throw new DataAccessException("Error while accessing DatabaseMetaData", e); } finally { if (connection != null) { provider.release(connection); } } } return meta; }
@Override public void releaseSavepoint(Savepoint savepoint) { try { Connection connection = jooqConf.connectionProvider().acquire(); connection.releaseSavepoint(savepoint); } catch (SQLException ex) { //TODO: Change exception throw new RuntimeException(ex); } }
@Override public final void close() throws SQLException { Connection connection = getDelegate(); if (connection != null) { connectionProvider.release(connection); } }
@Override @SuppressFBWarnings( value = "OBL_UNSATISFIED_OBLIGATION", justification = "False positive: https://sourceforge.net/p/findbugs/bugs/1021/") public long getDatabaseSize() { ConnectionProvider connectionProvider = getDsl().configuration().connectionProvider(); Connection connection = connectionProvider.acquire(); try (PreparedStatement ps = connection.prepareStatement("SELECT sum(data_length + index_length) FROM information_schema.tables")) { //ps.setString(1, getMeta().getDatabaseName()); ResultSet rs = ps.executeQuery(); rs.next(); return rs.getLong(1); } catch (SQLException ex) { //TODO: Change exception throw new RuntimeException(ex); } finally { connectionProvider.release(connection); } }
@Override public void commit() { try { Connection connection = jooqConf.connectionProvider().acquire(); connection.commit(); } catch (SQLException ex) { //TODO: Change exception throw new RuntimeException(ex); } }
@Override public final void close() throws SQLException { repeatedSQL.clear(); configuration.connectionProvider().release(getDelegate()); }
@SuppressFBWarnings("SQL_PREPARED_STATEMENT_GENERATED_FROM_NONCONSTANT_STRING") @Override protected void createSequence(String escapedSchemaName, String seqName) throws SQLException { Connection c = getDsl().configuration().connectionProvider().acquire(); String query = "CALL " + TorodbSchema.TORODB_SCHEMA + ".create_sequence(?,?)"; try (PreparedStatement ps = c.prepareStatement(query)) { ps.setString(1, escapedSchemaName); ps.setString(2, seqName); ps.execute(); } finally { getDsl().configuration().connectionProvider().release(c); } }
@Override public Savepoint setSavepoint() { try { Connection connection = jooqConf.connectionProvider().acquire(); return connection.setSavepoint(); } catch (SQLException ex) { //TODO: Change exception throw new RuntimeException(ex); } }
@Override public final void close() throws SQLException { configuration.connectionProvider().release(getDelegate()); } }
@SuppressFBWarnings("SQL_PREPARED_STATEMENT_GENERATED_FROM_NONCONSTANT_STRING") private void createSchema(DSLContext dsl, DatabaseInterface databaseInterface) throws SQLException { Connection c = dsl.configuration().connectionProvider().acquire(); try (PreparedStatement ps = c.prepareStatement(databaseInterface.createSchemaStatement(TORODB_SCHEMA))) { ps.executeUpdate(); } try (PreparedStatement ps = c.prepareStatement(databaseInterface.getCollectionsTable().getSQLCreationStatement(databaseInterface))) { ps.execute(); } finally { dsl.configuration().connectionProvider().release(c); } }
@Override public final Connection acquire() { return new MockConnectionWrapper(delegate.acquire()); }
/** * Ensure an <code>autoCommit</code> value on the connection, if it was set * to <code>true</code>, originally. */ private final void brace(Configuration configuration, boolean start) { DefaultConnectionProvider connection = connection(configuration); try { boolean autoCommit = autoCommit(configuration); // Transactions cannot run with autoCommit = true. Change the value for // the duration of a transaction if (autoCommit == true) connection.setAutoCommit(!start); } // [#3718] Chances are that the above JDBC interactions throw additional exceptions // try-finally will ensure that the ConnectionProvider.release() call is made finally { if (!start) { connectionProvider.release(connection.connection); configuration.data().remove(DATA_DEFAULT_TRANSACTION_PROVIDER_CONNECTION); } } }