当前位置: 首页>>代码示例>>Java>>正文


Java Connection.getTransactionIsolation方法代码示例

本文整理汇总了Java中java.sql.Connection.getTransactionIsolation方法的典型用法代码示例。如果您正苦于以下问题:Java Connection.getTransactionIsolation方法的具体用法?Java Connection.getTransactionIsolation怎么用?Java Connection.getTransactionIsolation使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在java.sql.Connection的用法示例。


在下文中一共展示了Connection.getTransactionIsolation方法的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: setTransactionIsolationLevel

import java.sql.Connection; //导入方法依赖的package包/类
@Override
public int setTransactionIsolationLevel(int isolationLevel)
{
    Connection connection = template.getConnection();
    if (connection == null)
    {
        throw new NullPointerException("There is no current connection");
    }
    try
    {
        if (!connection.getMetaData().supportsTransactionIsolationLevel(isolationLevel))
        {
            throw new IllegalStateException("Transaction isolation level not supported: " + isolationLevel);
        }
        int isolationLevelWas = connection.getTransactionIsolation();
        connection.setTransactionIsolation(isolationLevel);
        return isolationLevelWas;
    }
    catch (SQLException e)
    {
        throw new IllegalStateException("Failed to set transaction isolation level: " + isolationLevel, e);
    }
}
 
开发者ID:Alfresco,项目名称:alfresco-repository,代码行数:24,代码来源:ControlDAOImpl.java

示例2: testUseLocalSessionState

import java.sql.Connection; //导入方法依赖的package包/类
/**
 * Tests whether or not the configuration 'useLocalSessionState' actually
 * prevents non-needed 'set autocommit=', 'set session transaction isolation
 * ...' and 'show variables like tx_isolation' queries.
 * 
 * @throws Exception
 *             if the test fails.
 */
public void testUseLocalSessionState() throws Exception {
    Properties props = new Properties();

    props.setProperty("useLocalSessionState", "true");
    props.setProperty("profileSQL", "true");
    props.setProperty("logFactory", "com.mysql.jdbc.log.StandardLogger");

    Connection conn1 = getConnectionWithProps(props);
    conn1.setAutoCommit(true);
    conn1.setTransactionIsolation(Connection.TRANSACTION_REPEATABLE_READ);

    StandardLogger.startLoggingToBuffer();

    conn1.setAutoCommit(true);
    conn1.setTransactionIsolation(Connection.TRANSACTION_REPEATABLE_READ);
    conn1.getTransactionIsolation();

    String logAsString = StandardLogger.getBuffer().toString();
    String txIsolationName = versionMeetsMinimum(4, 0, 3) && !versionMeetsMinimum(8, 0, 3) ? "tx_isolation" : "transaction_isolation";

    assertTrue(logAsString.indexOf("SET SESSION") == -1 && logAsString.indexOf("SHOW VARIABLES LIKE '" + txIsolationName + "'") == -1
            && logAsString.indexOf("SET autocommit=") == -1);
}
 
开发者ID:bragex,项目名称:the-vigilantes,代码行数:32,代码来源:ConnectionTest.java

示例3: testBug27655

import java.sql.Connection; //导入方法依赖的package包/类
/**
 * Tests fix for BUG#27655 - getTransactionIsolation() uses
 * "SHOW VARIABLES LIKE" which is very inefficient on MySQL-5.0+
 * 
 * @throws Exception
 */
public void testBug27655() throws Exception {
    Properties props = new Properties();
    props.setProperty("profileSQL", "true");
    props.setProperty("logger", "StandardLogger");
    StandardLogger.startLoggingToBuffer();

    Connection loggedConn = null;

    try {
        loggedConn = getConnectionWithProps(props);
        loggedConn.getTransactionIsolation();

        if (versionMeetsMinimum(8, 0, 3)) {
            assertEquals(-1, StandardLogger.getBuffer().toString().indexOf("SHOW VARIABLES LIKE 'transaction_isolation'"));
        } else if (versionMeetsMinimum(4, 0, 3)) {
            assertEquals(-1, StandardLogger.getBuffer().toString().indexOf("SHOW VARIABLES LIKE 'tx_isolation'"));
        }
    } finally {
        StandardLogger.dropBuffer();
        if (loggedConn != null) {
            loggedConn.close();
        }
    }
}
 
开发者ID:bragex,项目名称:the-vigilantes,代码行数:31,代码来源:ConnectionRegressionTest.java

示例4: testUseLocalSessionState

import java.sql.Connection; //导入方法依赖的package包/类
/**
 * Tests whether or not the configuration 'useLocalSessionState' actually
 * prevents non-needed 'set autocommit=', 'set session transaction isolation
 * ...' and 'show variables like tx_isolation' queries.
 * 
 * @throws Exception
 *             if the test fails.
 */
public void testUseLocalSessionState() throws Exception {
    Properties props = new Properties();

    props.setProperty("useLocalSessionState", "true");
    props.setProperty("profileSQL", "true");
    props.setProperty("logFactory", "com.mysql.jdbc.log.StandardLogger");

    Connection conn1 = getConnectionWithProps(props);
    conn1.setAutoCommit(true);
    conn1.setTransactionIsolation(Connection.TRANSACTION_REPEATABLE_READ);

    StandardLogger.startLoggingToBuffer();

    conn1.setAutoCommit(true);
    conn1.setTransactionIsolation(Connection.TRANSACTION_REPEATABLE_READ);
    conn1.getTransactionIsolation();

    String logAsString = StandardLogger.getBuffer().toString();

    assertTrue(logAsString.indexOf("SET SESSION") == -1 && logAsString.indexOf("SHOW VARIABLES LIKE 'tx_isolation'") == -1
            && logAsString.indexOf("SET autocommit=") == -1);
}
 
开发者ID:JuanJoseFJ,项目名称:ProyectoPacientes,代码行数:31,代码来源:ConnectionTest.java

示例5: testBug27655

import java.sql.Connection; //导入方法依赖的package包/类
/**
 * Tests fix for BUG#27655 - getTransactionIsolation() uses
 * "SHOW VARIABLES LIKE" which is very inefficient on MySQL-5.0+
 * 
 * @throws Exception
 */
public void testBug27655() throws Exception {
    Properties props = new Properties();
    props.setProperty("profileSQL", "true");
    props.setProperty("logger", "StandardLogger");
    StandardLogger.startLoggingToBuffer();

    Connection loggedConn = null;

    try {
        loggedConn = getConnectionWithProps(props);
        loggedConn.getTransactionIsolation();

        if (versionMeetsMinimum(4, 0, 3)) {
            assertEquals(-1, StandardLogger.getBuffer().toString().indexOf("SHOW VARIABLES LIKE 'tx_isolation'"));
        }
    } finally {
        StandardLogger.dropBuffer();
        if (loggedConn != null) {
            loggedConn.close();
        }
    }
}
 
开发者ID:JuanJoseFJ,项目名称:ProyectoPacientes,代码行数:29,代码来源:ConnectionRegressionTest.java

示例6: getConnection

import java.sql.Connection; //导入方法依赖的package包/类
/**
 * {@inheritDoc}
 *
 * @param datasourceName 取得するコネクションのデータソース名
 *
 * @see jp.co.future.uroborosql.connection.ConnectionSupplier#getConnection(java.lang.String)
 */
@Override
public Connection getConnection(final String datasourceName) {
	try {
		DataSource ds = dsMap.computeIfAbsent(datasourceName, DataSourceConnectionSupplierImpl::getNewDataSource);
		final Connection connection;
		synchronized (ds) {
			connection = ds.getConnection();
		}
		boolean autoCommit = getAutoCommit(datasourceName);
		if (connection.getAutoCommit() != autoCommit) {
			connection.setAutoCommit(autoCommit);
		}
		boolean readOnly = getReadOnly(datasourceName);
		if (connection.isReadOnly() != readOnly) {
			connection.setReadOnly(readOnly);
		}
		int transactionIsolation = getTransactionIsolation(datasourceName);
		if (transactionIsolation > 0 && connection.getTransactionIsolation() != transactionIsolation) {
			connection.setTransactionIsolation(transactionIsolation);
		}
		return connection;
	} catch (SQLException ex) {
		throw new UroborosqlRuntimeException("Connection[" + datasourceName + "] can not be acquired.", ex);
	}
}
 
开发者ID:future-architect,项目名称:uroborosql,代码行数:33,代码来源:DataSourceConnectionSupplierImpl.java

示例7: ConnectionDefaults

import java.sql.Connection; //导入方法依赖的package包/类
public ConnectionDefaults(Connection connection) throws SQLException {

        this.holdability          = connection.getHoldability();
        this.transactionIsolation = connection.getTransactionIsolation();
        this.isAutoCommit         = connection.getAutoCommit();
        this.isReadOnly           = connection.isReadOnly();
        this.catalog              = connection.getCatalog();
    }
 
开发者ID:s-store,项目名称:sstore-soft,代码行数:9,代码来源:ConnectionDefaults.java

示例8: ConnectionWrapper

import java.sql.Connection; //导入方法依赖的package包/类
/**
   * Creates a connection wrapper that adds the ability to cache prepared statements.
   *
   * @param connection
   * @param cacheSize
   */
  public ConnectionWrapper(Connection connection, int cacheSize) {
this.connection = connection;
caching = false;
maxCacheSize = cacheSize <= 0 ? 0 : cacheSize;
if (maxCacheSize > 0) {
	caching = true;
	pStmtCache = new HashMap<>(maxCacheSize * 2);
}
      try {
          isolationLevel = connection.getTransactionIsolation();
          isolationCachingEnabled = true;
      } catch (SQLException e) {
      }
  }
 
开发者ID:ops4j,项目名称:org.ops4j.pax.transx,代码行数:21,代码来源:ConnectionWrapper.java

示例9: ConnectionPropertiesImpl

import java.sql.Connection; //导入方法依赖的package包/类
public ConnectionPropertiesImpl(Connection conn) throws SQLException {
  this(conn.getAutoCommit(), conn.isReadOnly(), conn.getTransactionIsolation(),
      conn.getCatalog(), conn.getSchema());
}
 
开发者ID:apache,项目名称:calcite-avatica,代码行数:5,代码来源:ConnectionPropertiesImpl.java

示例10: checkDefaultConnectionProperties

import java.sql.Connection; //导入方法依赖的package包/类
/**
 * Check the default connection properties (auto-commit, transaction isolation),
 * keeping them to be able to expose them correctly without fetching an actual
 * JDBC Connection from the target DataSource.
 * <p>This will be invoked once on startup, but also for each retrieval of a
 * target Connection. If the check failed on startup (because the database was
 * down), we'll lazily retrieve those settings.
 * @param con the Connection to use for checking
 * @throws SQLException if thrown by Connection methods
 */
protected synchronized void checkDefaultConnectionProperties(Connection con) throws SQLException {
	if (this.defaultAutoCommit == null) {
		this.defaultAutoCommit = con.getAutoCommit();
	}
	if (this.defaultTransactionIsolation == null) {
		this.defaultTransactionIsolation = con.getTransactionIsolation();
	}
}
 
开发者ID:lamsfoundation,项目名称:lams,代码行数:19,代码来源:LazyConnectionDataSourceProxy.java


注:本文中的java.sql.Connection.getTransactionIsolation方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。