本文整理汇总了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);
}
}
示例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);
}
示例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();
}
}
}
示例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);
}
示例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();
}
}
}
示例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);
}
}
示例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();
}
示例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) {
}
}
示例9: ConnectionPropertiesImpl
import java.sql.Connection; //导入方法依赖的package包/类
public ConnectionPropertiesImpl(Connection conn) throws SQLException {
this(conn.getAutoCommit(), conn.isReadOnly(), conn.getTransactionIsolation(),
conn.getCatalog(), conn.getSchema());
}
示例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();
}
}