@Override public void execute(final Connection connection) throws SQLException { connection.setReadOnly(readOnly); } });
@Override public void setReadOnly(boolean readOnly) throws SQLException { targetConnection.setReadOnly(readOnly); }
@Override public void setReadOnly(boolean readOnly) throws SQLException { raw.setReadOnly(readOnly); }
@Override public void setReadOnly(boolean readOnly) throws SQLException { connection.setReadOnly(readOnly); }
@Override public void setReadOnly(boolean readOnly) throws SQLException { raw.setReadOnly(readOnly); }
private void close(Connection conn) throws SQLException { if (conn != null) { if (conn.isReadOnly()) { conn.setReadOnly(false); // restore NOT readOnly before return to pool } conn.close(); } }
/** * Reset the given Connection after a transaction, * regarding read-only flag and isolation level. * @param con the Connection to reset * @param previousIsolationLevel the isolation level to restore, if any * @see #prepareConnectionForTransaction */ public static void resetConnectionAfterTransaction(Connection con, @Nullable Integer previousIsolationLevel) { Assert.notNull(con, "No Connection specified"); try { // Reset transaction isolation to previous value, if changed for the transaction. if (previousIsolationLevel != null) { if (logger.isDebugEnabled()) { logger.debug("Resetting isolation level of JDBC Connection [" + con + "] to " + previousIsolationLevel); } con.setTransactionIsolation(previousIsolationLevel); } // Reset read-only flag. if (con.isReadOnly()) { if (logger.isDebugEnabled()) { logger.debug("Resetting read-only flag of JDBC Connection [" + con + "]"); } con.setReadOnly(false); } } catch (Throwable ex) { logger.debug("Could not reset JDBC Connection after transaction", ex); } }
@Override public Connection getConnection(JdbcSplit split) throws SQLException { Connection connection = connectionFactory.openConnection(); try { connection.setReadOnly(true); } catch (SQLException e) { connection.close(); throw e; } return connection; }
public void reset() throws SQLException { // reset default settings if (underlyingReadOnly != defaultReadOnly) { conn.setReadOnly(defaultReadOnly); underlyingReadOnly = defaultReadOnly; } if (underlyingHoldability != defaultHoldability) { conn.setHoldability(defaultHoldability); underlyingHoldability = defaultHoldability; } if (underlyingTransactionIsolation != defaultTransactionIsolation) { conn.setTransactionIsolation(defaultTransactionIsolation); underlyingTransactionIsolation = defaultTransactionIsolation; } if (underlyingAutoCommit != defaultAutoCommit) { conn.setAutoCommit(defaultAutoCommit); underlyingAutoCommit = defaultAutoCommit; } connectionEventListeners.clear(); statementEventListeners.clear(); for (Object item : statementTrace.toArray()) { Statement stmt = (Statement) item; JdbcUtils.close(stmt); } statementTrace.clear(); conn.clearWarnings(); }
/** {@inheritDoc} */ @Override public void setReadOnly(boolean readOnly) throws SQLException { conn.setReadOnly(readOnly); }
/** * Applies the current isolation level value and read-only flag * to the returned Connection. * @see #getCurrentIsolationLevel() * @see #getCurrentReadOnlyFlag() */ @Override protected Connection doGetConnection(@Nullable String username, @Nullable String password) throws SQLException { Connection con = super.doGetConnection(username, password); Boolean readOnlyToUse = getCurrentReadOnlyFlag(); if (readOnlyToUse != null) { con.setReadOnly(readOnlyToUse); } Integer isolationLevelToUse = getCurrentIsolationLevel(); if (isolationLevelToUse != null) { con.setTransactionIsolation(isolationLevelToUse); } return con; }
@Override public T withHandle(Handle handle) throws Exception { final Connection connection = handle.getConnection(); final boolean readOnly = connection.isReadOnly(); connection.setReadOnly(true); try { return handle.inTransaction(callback); } finally { try { connection.setReadOnly(readOnly); } catch (SQLException e) { // at least try to log it so we don't swallow exceptions LOGGER.error(e, "Unable to reset connection read-only state"); } } } }
this.target.setReadOnly(true);
public <T> T execute(boolean isReadOnly, SqlExecutor<T> executor) throws SQLException { Connection conn = null; try { conn = dataSource.getConnection(); if (isReadOnly) { conn.setReadOnly(true); } return executor.run(conn); } finally { close(conn); } }
public <T> T execute(boolean isReadOnly, SqlExecutor<T> executor) throws SQLException { Connection conn = null; try { conn = dataSource.getConnection(); if (isReadOnly) { conn.setReadOnly(true); } return executor.run(conn); } finally { close(conn); } }
@Override public void connection_setReadOnly(ConnectionProxy connection, boolean readOnly) throws SQLException { if (this.pos < filterSize) { nextFilter() .connection_setReadOnly(this, connection, readOnly); return; } connection.getRawObject() .setReadOnly(readOnly); }
@Override public void setReadOnly(boolean readOnly) throws SQLException { TestObjectStoreInitRetry.debugTrace(); _baseConn.setReadOnly(readOnly); }
@Override public void setReadOnly(boolean readOnly) throws SQLException { checkState(); boolean useLocalSessionState = holder.getDataSource().isUseLocalSessionState(); if (useLocalSessionState) { if (readOnly == holder.isUnderlyingReadOnly()) { return; } } try { conn.setReadOnly(readOnly); } catch (SQLException ex) { handleException(ex, null); } holder.setUnderlyingReadOnly(readOnly); }
@Test public void testParticipatingTransactionWithIncompatibleReadOnly() throws Exception { willThrow(new SQLException("read-only not supported")).given(con).setReadOnly(true); tm.setValidateExistingTransaction(true);
verify(connection).setReadOnly(true); verify(connection).setTransactionIsolation(Connection.TRANSACTION_REPEATABLE_READ); verify(connection, times(2)).close();