當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。