当前位置: 首页>>代码示例>>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;未经允许,请勿转载。