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


Java Connection.isReadOnly方法代码示例

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


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

示例1: getConnection

import java.sql.Connection; //导入方法依赖的package包/类
/**
 * @return a Connection instance that can be used to connect to the
 * given database, if a previously-opened connection is available in
 * the cache. Returns null if none is available in the map.
 */
public synchronized Connection getConnection(String connectStr,
    String username) throws SQLException {
  CacheKey key = new CacheKey(connectStr, username);
  Connection cached = connectionMap.get(key);
  if (null != cached) {
    connectionMap.remove(key);
    if (cached.isReadOnly()) {
      // Read-only mode? Don't want it.
      cached.close();
    }

    if (cached.isClosed()) {
      // This connection isn't usable.
      return null;
    }

    cached.rollback(); // Reset any transaction state.
    cached.clearWarnings();

    LOG.debug("Got cached connection for " + key);
  }

  return cached;
}
 
开发者ID:BriData,项目名称:DBus,代码行数:30,代码来源:OracleManager.java

示例2: connectionInit

import java.sql.Connection; //导入方法依赖的package包/类
/**
    * Put the Connection in auto-commit mode and in read only false
    * @param connection	the JDBC Connection to init
    * @throws SQLException	if any SQL Exception occurs
    */
   public static void connectionInit(Connection connection) throws SQLException {
	
// Make sure Connection extracted from the pool is always on autocommit mode
// This avoid for client side to send a connection.getAutoCommit() before 
// starting working.
// This is anyway mandatory for C# as all Connections are per default
// auto commit mode.
if (!connection.getAutoCommit()) {
    connection.rollback();
    connection.setAutoCommit(true);
}

// Make sure we are not in read only. Don't trap Exception because of
// Drivers not supporting this call
if (connection.isReadOnly()) {
    try {
	connection.setReadOnly(false);
    } catch (Exception e) {
	// Ignore
	System.err.println(e.toString());
    }
}
   }
 
开发者ID:kawansoft,项目名称:aceql-http,代码行数:29,代码来源:ConnectionUtil.java

示例3: 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

示例4: 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

示例5: 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

示例6: prepare

import java.sql.Connection; //导入方法依赖的package包/类
public boolean prepare(){
    try {
        if (status.getTransaction() instanceof JdbcTransactionObjectSupport) {
            JdbcTransactionObjectSupport support = (JdbcTransactionObjectSupport) status.getTransaction();
            ConnectionHolder holder = support.getConnectionHolder();
            Connection con = holder.getConnection();
            return !con.isClosed() && !con.isReadOnly();
        }
    }catch (Exception e){
    }
    return false;
}
 
开发者ID:zhangkewei,项目名称:dubbo-transaction,代码行数:13,代码来源:DBTransaction.java

示例7: testRemoteConnectionProperties

import java.sql.Connection; //导入方法依赖的package包/类
@Test public void testRemoteConnectionProperties() throws Exception {
  ConnectionSpec.getDatabaseLock().lock();
  try (AvaticaConnection conn = (AvaticaConnection) DriverManager.getConnection(url)) {
    String id = conn.id;
    final Map<String, ConnectionPropertiesImpl> m = ((RemoteMeta) getMeta(conn)).propsMap;
    assertFalse("remote connection map should start ignorant", m.containsKey(id));
    // force creating a connection object on the remote side.
    try (final Statement stmt = conn.createStatement()) {
      assertTrue("creating a statement starts a local object.", m.containsKey(id));
      assertTrue(stmt.execute("select count(1) from EMP"));
    }
    Connection remoteConn = getConnection(FullyRemoteJdbcMetaFactory.getInstance(), id);
    final boolean defaultRO = remoteConn.isReadOnly();
    final boolean defaultAutoCommit = remoteConn.getAutoCommit();
    final String defaultCatalog = remoteConn.getCatalog();
    final String defaultSchema = remoteConn.getSchema();
    conn.setReadOnly(!defaultRO);
    assertTrue("local changes dirty local state", m.get(id).isDirty());
    assertEquals("remote connection has not been touched", defaultRO, remoteConn.isReadOnly());
    conn.setAutoCommit(!defaultAutoCommit);
    assertEquals("remote connection has not been touched",
        defaultAutoCommit, remoteConn.getAutoCommit());

    // further interaction with the connection will force a sync
    try (final Statement stmt = conn.createStatement()) {
      assertEquals(!defaultAutoCommit, remoteConn.getAutoCommit());
      assertFalse("local values should be clean", m.get(id).isDirty());
    }
  } finally {
    ConnectionSpec.getDatabaseLock().unlock();
  }
}
 
开发者ID:apache,项目名称:calcite-avatica,代码行数:33,代码来源:RemoteMetaTest.java

示例8: from

import java.sql.Connection; //导入方法依赖的package包/类
public static ConnectionProps from(Connection connection) {
    try {
        return new ConnectionProps(connection.isReadOnly(), Isolation.of(connection.getTransactionIsolation()));
    } catch (SQLException e) {
        throw new CallException(e);
    }
}
 
开发者ID:mhewedy,项目名称:spwrap,代码行数:8,代码来源:ConnectionProps.java

示例9: testReadOnly56

import java.sql.Connection; //导入方法依赖的package包/类
public void testReadOnly56() throws Exception {
    if (versionMeetsMinimum(5, 6, 5)) {
        try {
            Connection notLocalState = getConnectionWithProps("profileSql=true");

            for (int i = 0; i < 2; i++) {
                StandardLogger.startLoggingToBuffer();
                notLocalState.setReadOnly(true);
                assertTrue(StandardLogger.getBuffer().toString().indexOf("set session transaction read only") != -1);
                notLocalState.createStatement().execute("set session transaction read write");
                assertFalse(notLocalState.isReadOnly());
            }

            for (int i = 0; i < 2; i++) {
                StandardLogger.startLoggingToBuffer();
                notLocalState.setReadOnly(false);
                assertTrue(StandardLogger.getBuffer().toString().indexOf("set session transaction read write") != -1);
                notLocalState.createStatement().execute("set session transaction read only");
                assertTrue(notLocalState.isReadOnly());
            }

            Connection localState = getConnectionWithProps("profileSql=true,useLocalSessionState=true");

            String txReadOnlyName = versionMeetsMinimum(8, 0, 3) ? "transaction_read_only" : "tx_read_only";

            for (int i = 0; i < 2; i++) {
                StandardLogger.startLoggingToBuffer();
                localState.setReadOnly(true);
                if (i == 0) {
                    assertTrue(StandardLogger.getBuffer().toString().indexOf("set session transaction read only") != -1);
                } else {
                    assertTrue(StandardLogger.getBuffer().toString().indexOf("set session transaction read only") == -1);
                }
                StandardLogger.startLoggingToBuffer();
                localState.isReadOnly();
                assertTrue(StandardLogger.getBuffer().toString().indexOf("select @@session." + txReadOnlyName) == -1);
            }

            Connection noOptimization = getConnectionWithProps("profileSql=true,readOnlyPropagatesToServer=false");

            for (int i = 0; i < 2; i++) {
                StandardLogger.startLoggingToBuffer();
                noOptimization.setReadOnly(true);
                assertTrue(StandardLogger.getBuffer().toString().indexOf("set session transaction read only") == -1);
                StandardLogger.startLoggingToBuffer();
                noOptimization.isReadOnly();
                assertTrue(StandardLogger.getBuffer().toString().indexOf("select @@session." + txReadOnlyName) == -1);
            }
        } finally {
            StandardLogger.dropBuffer();
        }
    }
}
 
开发者ID:bragex,项目名称:the-vigilantes,代码行数:54,代码来源:ConnectionTest.java

示例10: testReadOnly56

import java.sql.Connection; //导入方法依赖的package包/类
public void testReadOnly56() throws Exception {
    if (versionMeetsMinimum(5, 6, 5)) {
        try {
            Connection notLocalState = getConnectionWithProps("profileSql=true");

            for (int i = 0; i < 2; i++) {
                StandardLogger.startLoggingToBuffer();
                notLocalState.setReadOnly(true);
                assertTrue(StandardLogger.getBuffer().toString().indexOf("set session transaction read only") != -1);
                notLocalState.createStatement().execute("set session transaction read write");
                assertFalse(notLocalState.isReadOnly());
            }

            for (int i = 0; i < 2; i++) {
                StandardLogger.startLoggingToBuffer();
                notLocalState.setReadOnly(false);
                assertTrue(StandardLogger.getBuffer().toString().indexOf("set session transaction read write") != -1);
                notLocalState.createStatement().execute("set session transaction read only");
                assertTrue(notLocalState.isReadOnly());
            }

            Connection localState = getConnectionWithProps("profileSql=true,useLocalSessionState=true");

            for (int i = 0; i < 2; i++) {
                StandardLogger.startLoggingToBuffer();
                localState.setReadOnly(true);
                if (i == 0) {
                    assertTrue(StandardLogger.getBuffer().toString().indexOf("set session transaction read only") != -1);
                } else {
                    assertTrue(StandardLogger.getBuffer().toString().indexOf("set session transaction read only") == -1);
                }
                StandardLogger.startLoggingToBuffer();
                localState.isReadOnly();
                assertTrue(StandardLogger.getBuffer().toString().indexOf("select @@session.tx_read_only") == -1);
            }

            Connection noOptimization = getConnectionWithProps("profileSql=true,readOnlyPropagatesToServer=false");

            for (int i = 0; i < 2; i++) {
                StandardLogger.startLoggingToBuffer();
                noOptimization.setReadOnly(true);
                assertTrue(StandardLogger.getBuffer().toString().indexOf("set session transaction read only") == -1);
                StandardLogger.startLoggingToBuffer();
                noOptimization.isReadOnly();
                assertTrue(StandardLogger.getBuffer().toString().indexOf("select @@session.tx_read_only") == -1);
            }
        } finally {
            StandardLogger.dropBuffer();
        }
    }
}
 
开发者ID:JuanJoseFJ,项目名称:ProyectoPacientes,代码行数:52,代码来源:ConnectionTest.java

示例11: 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


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