Refine search
private void resetConnection() { if (supportsTransaction) { try { connection.setAutoCommit(true); // restore default isolation level if (previousIsolationLevel != -1) { connection.setTransactionIsolation(previousIsolationLevel); } } catch (SQLException ignored) { } } } }
@Override @SuppressWarnings("UnnecessaryUnboxing") public Connection getConnection() throws SQLException { final Connection c = ds.getConnection(); if ( isolation != null && !isolation.equals( c.getTransactionIsolation() ) ) { c.setTransactionIsolation( isolation.intValue() ); } if ( c.getAutoCommit() != autocommit ) { c.setAutoCommit( autocommit ); } return c; }
@Override public Connection getConnection() throws SQLException { // get a connection from the pool (thru DriverManager, cfr. Proxool doc) final Connection c = DriverManager.getConnection( proxoolAlias ); // set the Transaction Isolation if defined if ( isolation != null ) { c.setTransactionIsolation( isolation ); } // toggle autoCommit to false if set if ( c.getAutoCommit() != autocommit ) { c.setAutoCommit( autocommit ); } // return the connection return c; }
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(); }
private Connection createReadUncommittedConnection() throws SQLException { Connection connection = db.getDataSource().getConnection(); connection.setAutoCommit(false); if (connection.getMetaData().supportsTransactionIsolationLevel(Connection.TRANSACTION_READ_UNCOMMITTED)) { connection.setTransactionIsolation(Connection.TRANSACTION_READ_UNCOMMITTED); } return connection; }
this.target.setTransactionIsolation(this.transactionIsolation); this.target.setAutoCommit(this.autoCommit);
@Override public Connection getConnection() { Connection conn; try { if (username != null) { conn = DriverManager.getConnection(url, username, password); } else { conn = DriverManager.getConnection(url); } if (isolation != null) { conn.setTransactionIsolation(isolation.intValue()); } if (autoCommit != null) { conn.setAutoCommit(autoCommit.booleanValue()); } } catch (SQLException sex) { throw new DbSqlException("Connection not found", sex); } return conn; }
private Connection getDbConn(int isolationLevel, DataSource connPool) throws SQLException { int rc = doRetryOnConnPool ? 10 : 1; Connection dbConn = null; while (true) { try { dbConn = connPool.getConnection(); dbConn.setAutoCommit(false); dbConn.setTransactionIsolation(isolationLevel); return dbConn; } catch (SQLException e){ closeDbConn(dbConn); if ((--rc) <= 0) throw e; LOG.error("There is a problem with a connection from the pool, retrying(rc=" + rc + "): " + getMessage(e), e); } } }
/** * Attempts to restore the auto commit and transaction isolation connection * attributes of the wrapped connection to their original values (if they * were overwritten). */ public void restoreOriginalAtributes() { try { if (overwroteOriginalAutoCommitValue) { conn.setAutoCommit(originalAutoCommitValue); } } catch (Throwable t) { getLog().warn("Failed restore connection's original auto commit setting.", t); } try { if (overwroteOriginalTxIsolationValue) { conn.setTransactionIsolation(originalTxIsolationValue); } } catch (Throwable t) { getLog().warn("Failed restore connection's original transaction isolation setting.", t); } }
private static Connection createConnection(String connectionString, boolean readOnly) { try { Connection connection = DriverManager.getConnection(connectionString); connection.setAutoCommit(false); connection.setReadOnly(readOnly); // We use UNCOMMITTED read to enable operations to alter the database and continue // with those changes, but still roll back the database if something goes wrong later. connection.setTransactionIsolation(Connection.TRANSACTION_READ_UNCOMMITTED); // Test and create tables if (!tablesExist(connection)) { createTables(connection); } return connection; } catch (Exception e) { if (e.getCause() != null) { if (e.getCause().getMessage().contains("Database lock acquisition failure")) { throw new RuntimeException("Another process is using the database.", e); } } throw new RuntimeException("Cannot create new connection; database down?", e); } }
/** * Attempts to restore the auto commit and transaction isolation connection * attributes of the wrapped connection to their original values (if they * were overwritten). */ public void restoreOriginalAtributes() { try { if (overwroteOriginalAutoCommitValue) { conn.setAutoCommit(originalAutoCommitValue); } } catch (Throwable t) { getLog().warn("Failed restore connection's original auto commit setting.", t); } try { if (overwroteOriginalTxIsolationValue) { conn.setTransactionIsolation(originalTxIsolationValue); } } catch (Throwable t) { getLog().warn("Failed restore connection's original transaction isolation setting.", t); } }
/** * Return true if the transaction of the given txnId is open. * @param conf HiveConf * @param txnId transaction id to search for * @return * @throws Exception */ public static boolean isOpenOrAbortedTransaction(Configuration conf, long txnId) throws Exception { Connection conn = null; PreparedStatement stmt = null; ResultSet rs = null; try { conn = getConnection(conf); conn.setAutoCommit(false); conn.setTransactionIsolation(Connection.TRANSACTION_READ_COMMITTED); stmt = conn.prepareStatement("SELECT txn_id FROM TXNS WHERE txn_id = ?"); stmt.setLong(1, txnId); rs = stmt.executeQuery(); if (!rs.next()) { return false; } else { return true; } } finally { closeResources(conn, stmt, rs); } }
/** * 关闭事务,清理现场 */ @Override public void close() { ComboException ce = new ComboException(); for (ConnInfo cInfo : list) { try { // 试图恢复旧的事务级别 if (!cInfo.conn.isClosed()) { if (cInfo.restoreIsoLevel) cInfo.conn.setTransactionIsolation(cInfo.oldLevel); if (cInfo.restoreAutoCommit) cInfo.conn.setAutoCommit(true); } } catch (Throwable e) {} finally { try { cInfo.conn.close(); } catch (Exception e) { ce.add(e); } } } // 清除数据源记录 list.clear(); }
public void initPhysicalConnection(Connection conn, Map<String, Object> variables, Map<String, Object> globalVariables) throws SQLException { if (conn.getAutoCommit() != defaultAutoCommit) { conn.setAutoCommit(defaultAutoCommit); conn.setTransactionIsolation(getDefaultTransactionIsolation());
conn = dataSrc.getConnection(); conn.setAutoCommit(false); conn.setTransactionIsolation(TRANSACTION_READ_COMMITTED);
@Override public Connection createConnection() { final Connection conn = makeConnection( url, connectionProps ); if ( conn == null ) { throw new HibernateException( "Unable to make JDBC Connection [" + url + "]" ); } try { if ( isolation != null ) { conn.setTransactionIsolation( isolation ); } } catch (SQLException e) { throw convertSqlException( "Unable to set transaction isolation (" + isolation + ")", e ); } try { if ( conn.getAutoCommit() != autoCommit ) { conn.setAutoCommit( autoCommit ); } } catch (SQLException e) { throw convertSqlException( "Unable to set auto-commit (" + autoCommit + ")", e ); } return conn; }
conn = dataSrc.getConnection(); conn.setAutoCommit(false); conn.setTransactionIsolation(TRANSACTION_READ_COMMITTED);
/** * Opens a transaction. */ protected void openTx() { if (connection == null) { connection = connectionProvider.getConnection(); } txActive = true; try { connection.setAutoCommit(false); if (txMode.getIsolation() != DbTransactionMode.ISOLATION_DEFAULT) { connection.setTransactionIsolation(txMode.getIsolation()); } connection.setReadOnly(txMode.isReadOnly()); } catch (SQLException sex) { throw new DbSqlException("Open TX failed", sex); } }
/** * 开启事务 * * @param transLevel * 事务级别 * @see java.sql.Connection * @return 原对象 * @throws DaoException * 如果已经开启过事务 */ public NutTxDao begin(int transLevel) throws DaoException { if (this.conn != null) throw new DaoException("NutTxDao has been begined!!"); id = R.UU32(); if (debug) log.debugf("begin level=%d id=%s", transLevel, id); try { this.conn = dataSource.getConnection(); this.conn.setTransactionIsolation(transLevel); if (this.conn.getAutoCommit() == true) { this.conn.setAutoCommit(false); _autoCommit = true; } setSavepoint(id); } catch (SQLException e) { throw new DaoException(e); } return this; }
if (connection.getAutoCommit() != autoCommit) { LOG.trace("Setting auto commit to {} on connection {}", autoCommit, connection); connection.setAutoCommit(autoCommit); connection.setTransactionIsolation(transactionIsolation); } catch (Throwable e) {