當前位置: 首頁>>代碼示例>>Java>>正文


Java Connection.setTransactionIsolation方法代碼示例

本文整理匯總了Java中java.sql.Connection.setTransactionIsolation方法的典型用法代碼示例。如果您正苦於以下問題:Java Connection.setTransactionIsolation方法的具體用法?Java Connection.setTransactionIsolation怎麽用?Java Connection.setTransactionIsolation使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在java.sql.Connection的用法示例。


在下文中一共展示了Connection.setTransactionIsolation方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: procWithResultTwo

import java.sql.Connection; //導入方法依賴的package包/類
public static void procWithResultTwo(Connection conn, Integer[] intparam,
                                     ResultSet[] resultparamOne,
                                     ResultSet[] resultparamTwo)
                                     throws SQLException {

    conn.setTransactionIsolation(Connection.TRANSACTION_READ_COMMITTED);

    Statement st = conn.createStatement();
    ResultSet rs = st.executeQuery(
        "select count(*) from information_schema.columns where table_name='LOB_IDS' and table_schema='SYSTEM_LOBS'");

    if (rs.next()) {
        intparam[0] = rs.getInt(1);

        rs.close();
    }

    resultparamOne[0] = st.executeQuery(
        "select table_schema, table_name from information_schema.tables where table_name='LOB_IDS' and table_schema='SYSTEM_LOBS'");
    resultparamTwo[0] = st.executeQuery(
        "select table_schema, table_name from information_schema.tables where table_name='LOBS' and table_schema='SYSTEM_LOBS'");
}
 
開發者ID:Julien35,項目名稱:dev-courses,代碼行數:23,代碼來源:TestStoredProcedure.java

示例2: setTI

import java.sql.Connection; //導入方法依賴的package包/類
static public void setTI(Connection c, String tiString)
        throws SQLException {
    int i = -1;
    if (tiString.equals("TRANSACTION_READ_UNCOMMITTED"))
        i = Connection.TRANSACTION_READ_UNCOMMITTED;
    if (tiString.equals("TRANSACTION_READ_COMMITTED"))
        i = Connection.TRANSACTION_READ_COMMITTED;
    if (tiString.equals("TRANSACTION_REPEATABLE_READ"))
        i = Connection.TRANSACTION_REPEATABLE_READ;
    if (tiString.equals("TRANSACTION_SERIALIZABLE"))
        i = Connection.TRANSACTION_SERIALIZABLE;
    if (tiString.equals("TRANSACTION_NONE"))
        i = Connection.TRANSACTION_NONE;
    if (i < 0) {
        throw new SQLException(
                "Trans. isol. value not supported by "
                + RCData.class.getName() + ": " + tiString);
    }
    c.setTransactionIsolation(i);
}
 
開發者ID:parabuild-ci,項目名稱:parabuild-ci,代碼行數:21,代碼來源:RCData.java

示例3: setTI

import java.sql.Connection; //導入方法依賴的package包/類
/**
 * Set Transaction Isolation level on the specified JDBC Connection
 */
public static void setTI(Connection c, String tiString)
        throws SQLException {
    int i = -1;
    if (tiString.equals("TRANSACTION_READ_UNCOMMITTED"))
        i = Connection.TRANSACTION_READ_UNCOMMITTED;
    if (tiString.equals("TRANSACTION_READ_COMMITTED"))
        i = Connection.TRANSACTION_READ_COMMITTED;
    if (tiString.equals("TRANSACTION_REPEATABLE_READ"))
        i = Connection.TRANSACTION_REPEATABLE_READ;
    if (tiString.equals("TRANSACTION_SERIALIZABLE"))
        i = Connection.TRANSACTION_SERIALIZABLE;
    if (tiString.equals("TRANSACTION_NONE"))
        i = Connection.TRANSACTION_NONE;
    if (i < 0) {
        throw new SQLException(
                "Trans. isol. value not supported by "
                + RCData.class.getName() + ": " + tiString);
    }
    c.setTransactionIsolation(i);
}
 
開發者ID:Julien35,項目名稱:dev-courses,代碼行數:24,代碼來源:RCData.java

示例4: resetConnectionAfterTransaction

import java.sql.Connection; //導入方法依賴的package包/類
/**
 * 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, 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);
	}
}
 
開發者ID:lamsfoundation,項目名稱:lams,代碼行數:32,代碼來源:DataSourceUtils.java

示例5: recreateConn

import java.sql.Connection; //導入方法依賴的package包/類
private Connection recreateConn(Connection conn) throws SQLException {

    	log.debug("recreating conn xid="+getStr4XidLocal());
    	if(conn!=null){
    		try {
				conn.close();
			} catch (SQLException e) {
				e.printStackTrace();
			}
    		conn=null;
    	}
		Connection connection=DriverManager.getConnection(url, username, password); 
		connection.setAutoCommit(false);
		connection.setTransactionIsolation(level);

		return connection;
    }
 
開發者ID:jeffreyning,項目名稱:nh-micro,代碼行數:18,代碼來源:MicroXaDataSource.java

示例6: createConnection

import java.sql.Connection; //導入方法依賴的package包/類
public Connection createConnection() throws SQLException {
    Connection connection = driver.connect( configuration.jdbcUrl(), jdbcProperties );
    connection.setAutoCommit( configuration.autoCommit() );
    if ( configuration.jdbcTransactionIsolation().isDefined() ) {
        connection.setTransactionIsolation( configuration.jdbcTransactionIsolation().level() );
    }
    if ( configuration.initialSql() != null && !configuration.initialSql().isEmpty() ) {
        try ( Statement statement = connection.createStatement() ) {
            statement.execute( configuration.initialSql() );
        }
    }
    return connection;
}
 
開發者ID:agroal,項目名稱:agroal,代碼行數:14,代碼來源:ConnectionFactory.java

示例7: timeBatch

import java.sql.Connection; //導入方法依賴的package包/類
private long timeBatch(Connection c, int numberOfRows) throws SQLException {
    this.pstmt = c.prepareStatement("INSERT INTO testBug41532(ID, S1, S2, S3, D1, D2, D3, N1, N2, N3) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?)"
            + " ON DUPLICATE KEY UPDATE S1 = VALUES(S1), S2 = VALUES(S2), S3 = VALUES(S3), D1 = VALUES(D1), D2 ="
            + " VALUES(D2), D3 = VALUES(D3), N1 = N1 + VALUES(N1), N2 = N2 + VALUES(N2), N2 = N2 + VALUES(N2)");
    c.setAutoCommit(false);
    c.setTransactionIsolation(Connection.TRANSACTION_READ_COMMITTED);
    Date d1 = new Date(currentTimeMillis());
    Date d2 = new Date(currentTimeMillis() + 1000000);
    Date d3 = new Date(currentTimeMillis() + 1250000);

    for (int i = 0; i < numberOfRows; i++) {
        this.pstmt.setObject(1, new Integer(i), Types.INTEGER);
        this.pstmt.setObject(2, String.valueOf(i), Types.VARCHAR);
        this.pstmt.setObject(3, String.valueOf(i * 0.1), Types.VARCHAR);
        this.pstmt.setObject(4, String.valueOf(i / 3), Types.VARCHAR);
        this.pstmt.setObject(5, new Timestamp(d1.getTime()), Types.TIMESTAMP);
        this.pstmt.setObject(6, new Timestamp(d2.getTime()), Types.TIMESTAMP);
        this.pstmt.setObject(7, new Timestamp(d3.getTime()), Types.TIMESTAMP);
        this.pstmt.setObject(8, new BigDecimal(i + 0.1), Types.DECIMAL);
        this.pstmt.setObject(9, new BigDecimal(i * 0.1), Types.DECIMAL);
        this.pstmt.setObject(10, new BigDecimal(i / 3), Types.DECIMAL);
        this.pstmt.addBatch();
    }
    long startTime = currentTimeMillis();
    this.pstmt.executeBatch();
    c.commit();
    long stopTime = currentTimeMillis();

    this.rs = this.conn.createStatement().executeQuery("SELECT COUNT(*) FROM testBug41532");
    assertTrue(this.rs.next());
    assertEquals(numberOfRows, this.rs.getInt(1));

    return stopTime - startTime;
}
 
開發者ID:JuanJoseFJ,項目名稱:ProyectoPacientes,代碼行數:35,代碼來源:StatementRegressionTest.java

示例8: setDefaults

import java.sql.Connection; //導入方法依賴的package包/類
public void setDefaults(Connection connection) throws SQLException {

        connection.setHoldability(this.holdability);

        if (this.transactionIsolation != Connection.TRANSACTION_NONE) {
            connection.setTransactionIsolation(this.transactionIsolation);
        }
        connection.setAutoCommit(this.isAutoCommit);
        connection.setReadOnly(this.isReadOnly);
        connection.setCatalog(this.catalog);
    }
 
開發者ID:s-store,項目名稱:sstore-soft,代碼行數:12,代碼來源:ConnectionDefaults.java

示例9: getConnection

import java.sql.Connection; //導入方法依賴的package包/類
protected Connection getConnection() throws DatabaseAccessException {

        Connection connection = super.getConnection();
        try {
            connection.setTransactionIsolation(Connection.TRANSACTION_READ_UNCOMMITTED);
        } catch (SQLException e) {
            // Not a big deal, we will not read the entities which are in the process
            // of being inserted, but the transaction is still not completed
        }
        return connection;
    }
 
開發者ID:Axway,項目名稱:ats-framework,代碼行數:12,代碼來源:SQLServerDbReadAccess.java

示例10: doGetConnection

import java.sql.Connection; //導入方法依賴的package包/類
/**
 * Applies the current isolation level value and read-only flag
 * to the returned Connection.
 * @see #getCurrentIsolationLevel()
 * @see #getCurrentReadOnlyFlag()
 */
@Override
protected Connection doGetConnection(String username, 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;
}
 
開發者ID:lamsfoundation,項目名稱:lams,代碼行數:20,代碼來源:IsolationLevelDataSourceAdapter.java

示例11: init

import java.sql.Connection; //導入方法依賴的package包/類
public void init() throws Exception{
	for(int i=0;i<minSize;i++){
		Connection connection=DriverManager.getConnection(url, username, password); 
		count.incrementAndGet();
		connection.setAutoCommit(false);
		connection.setTransactionIsolation(level);	
		pool.add(connection);
	}
	if(delayToRollFlag){
		MicroConnDelayHandler microDelayHandler=new MicroConnDelayHandler();
		microDelayHandler.dataSourceId=dataSourceId;
		microExpireCache.setMicroDelayHandler(microDelayHandler);
		microExpireCache.init();
	}
}
 
開發者ID:jeffreyning,項目名稱:nh-micro,代碼行數:16,代碼來源:MicroXaDataSource.java

示例12: wrapConnectionAndMarkAsInUse

import java.sql.Connection; //導入方法依賴的package包/類
private Connection wrapConnectionAndMarkAsInUse(
        PooledConnection pooledConnection) throws SQLException {

    pooledConnection = assureValidConnection(pooledConnection);

    Connection conn = pooledConnection.getConnection();

    if (doResetAutoCommit) {
        conn.setAutoCommit(isAutoCommit);
    }

    if (doResetReadOnly) {
        conn.setReadOnly(isReadOnly);
    }

    if (doResetTransactionIsolation) {
        conn.setTransactionIsolation(transactionIsolation);
        /* TESING ONLY!!
        System.err.println("<<<<<<<<< ISO LVL => " + transactionIsolation
        + " >>>>>>>>>>>>");
        */
    }

    if (doResetCatalog) {
        conn.setCatalog(catalog);
        /* TESTING ONLY!
        System.err.println("<<<<<<<<< CAT => " + catalog
        + " >>>>>>>>>>>>");
        */
    }

    if (validationQuery != null) {

        // End-to-end test before return the Connection.
        java.sql.ResultSet rs = null;

        try {
            rs = conn.createStatement().executeQuery(validationQuery);

            if (!rs.next()) {
                throw new SQLException("0 rows returned");
            }
        } catch (SQLException se) {
            closePhysically(pooledConnection,
                            "Closing non-validating pooledConnection.");

            throw new SQLException("Validation query failed: "
                                   + se.getMessage());
        } finally {
            if (rs != null) {
                rs.close();
            }
        }
    }
    this.connectionsInUse.add(pooledConnection);

    SessionConnectionWrapper sessionWrapper =
        new SessionConnectionWrapper(pooledConnection.getConnection());

    this.sessionConnectionWrappers.put(pooledConnection, sessionWrapper);

    return sessionWrapper;
}
 
開發者ID:s-store,項目名稱:sstore-soft,代碼行數:64,代碼來源:ManagedPoolDataSource.java

示例13: makeConnection

import java.sql.Connection; //導入方法依賴的package包/類
/**
 * Create a connection to the database; usually used only from within
 * getConnection(), which enforces a singleton guarantee around the
 * Connection object.
 *
 * Oracle-specific driver uses READ_COMMITTED which is the weakest
 * semantics Oracle supports.
 */
protected Connection makeConnection() throws SQLException {

  Connection connection;
  String driverClass = getDriverClass();

  try {
    Class.forName(driverClass);
  } catch (ClassNotFoundException cnfe) {
    throw new RuntimeException("Could not load db driver class: "
        + driverClass);
  }

  String username = options.getUsername();
  String password = options.getPassword();
  String connectStr = options.getConnectString();

  try {
    connection = CACHE.getConnection(connectStr, username);
  } catch (SQLException e) {
    connection = null;
    LOG.debug("Cached connecion has expired.");
  }

  if (null == connection) {
    // Couldn't pull one from the cache. Get a new one.
    LOG.debug("Creating a new connection for "
            + connectStr + ", using username: " + username);
    Properties connectionParams = options.getConnectionParams();
    if (connectionParams != null && connectionParams.size() > 0) {
      LOG.debug("User specified connection params. "
                + "Using properties specific API for making connection.");

      Properties props = new Properties();
      if (username != null) {
        props.put("user", username);
      }

      if (password != null) {
        props.put("password", password);
      }

      props.putAll(connectionParams);
      connection = DriverManager.getConnection(connectStr, props);
    } else {
      LOG.debug("No connection paramenters specified. "
              + "Using regular API for making connection.");
      if (username == null) {
        connection = DriverManager.getConnection(connectStr);
      } else {
        connection = DriverManager.getConnection(
                            connectStr, username, password);
      }
    }
  }

  // We only use this for metadata queries. Loosest semantics are okay.
  connection.setTransactionIsolation(Connection.TRANSACTION_READ_COMMITTED);

  // Setting session time zone
  setSessionTimeZone(connection);

  // Rest of the Sqoop code expects that the connection will have be running
  // without autoCommit, so we need to explicitly set it to false. This is
  // usually done directly by SqlManager in the makeConnection method, but
  // since we are overriding it, we have to do it ourselves.
  connection.setAutoCommit(false);

  return connection;
}
 
開發者ID:aliyun,項目名稱:aliyun-maxcompute-data-collectors,代碼行數:78,代碼來源:OracleManager.java

示例14: getConnection

import java.sql.Connection; //導入方法依賴的package包/類
public Connection getConnection() throws SQLException {
	final Connection c = ds.getConnection();
	if (isolation!=null) c.setTransactionIsolation( isolation.intValue() );
	if ( c.getAutoCommit() ) c.setAutoCommit(false);
	return c;
}
 
開發者ID:parabuild-ci,項目名稱:parabuild-ci,代碼行數:7,代碼來源:DBCPConnectionProvider.java

示例15: getConnection

import java.sql.Connection; //導入方法依賴的package包/類
private Connection getConnection() throws SQLException {
    Connection conn = dataSource.getPooledConnection().getConnection();
    conn.setTransactionIsolation(Connection.
                                 TRANSACTION_READ_COMMITTED);
    return conn;
}
 
開發者ID:xuraylei,項目名稱:fresco_floodlight,代碼行數:7,代碼來源:JavaDBStorageEngine.java


注:本文中的java.sql.Connection.setTransactionIsolation方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。