List of usage examples for java.sql Connection getTransactionIsolation
int getTransactionIsolation() throws SQLException;
Connection
object's current transaction isolation level. From source file:net.unicon.mercury.fac.rdbms.RdbmsMessageFactory.java
protected ConnState beginTransaction(Connection conn, boolean serialized) throws SQLException { ConnState rslt = new ConnState(); if (serialized) { rslt.isoLevel = conn.getTransactionIsolation(); conn.setTransactionIsolation(Connection.TRANSACTION_SERIALIZABLE); }/*from w w w. ja va2 s .com*/ rslt.autoCommit = conn.getAutoCommit(); conn.setAutoCommit(false); return rslt; }
From source file:org.apache.ode.utils.DbIsolation.java
/** * Set Ode-specific isolation level on the connection, if needed. *//*from ww w .j a v a 2 s . co m*/ public static void setIsolationLevel(Connection c) throws SQLException { try { if (_isolationLevel != 0 && c.getTransactionIsolation() != _isolationLevel) { if (__log.isDebugEnabled()) __log.debug("Set isolation level to " + _isolationLevel); c.setTransactionIsolation(_isolationLevel); } } catch (Exception e) { if (__log.isDebugEnabled()) __log.debug("Error while setting isolation level to " + _isolationLevel, e); } }
From source file:org.apache.ode.utils.LoggingDataSourceWrapper.java
public Connection getConnection() throws SQLException { Connection conn = new LoggingConnectionWrapper(_wrapped.getConnection(), _log); if (shouldPrint()) print("getConnection (tx=" + conn.getTransactionIsolation() + ")"); return conn;/*from ww w . j a va 2 s. c o m*/ }
From source file:org.apache.ode.utils.LoggingDataSourceWrapper.java
public Connection getConnection(String username, String password) throws SQLException { Connection conn = new LoggingConnectionWrapper(_wrapped.getConnection(username, password), _log); if (shouldPrint()) print("getConnection (tx=" + conn.getTransactionIsolation() + ")"); return conn;/* w w w .j a v a 2 s.c o m*/ }
From source file:org.apache.ode.utils.LoggingInterceptor.java
public Object invoke(Object proxy, Method method, Object[] args) throws Throwable { try {/*from w w w .j a va2 s. com*/ if (method.getDeclaringClass() == DataSource.class && "getConnection".equals(method.getName())) { Connection conn = (Connection) method.invoke(_delegate, args); print("getConnection (tx=" + conn.getTransactionIsolation() + ")"); return Proxy.newProxyInstance(_delegate.getClass().getClassLoader(), new Class[] { Connection.class }, new LoggingInterceptor<Connection>(conn, _log)); } else if (method.getDeclaringClass() == Connection.class && Statement.class.isAssignableFrom(method.getReturnType())) { Statement stmt = (Statement) method.invoke(_delegate, args); print(method, args); return Proxy.newProxyInstance(_delegate.getClass().getClassLoader(), new Class[] { method.getReturnType() }, new LoggingInterceptor<Statement>(stmt, _log)); } else { print(method, args); return method.invoke(_delegate, args); } } catch (InvocationTargetException e) { throw e.getTargetException(); } }
From source file:org.apache.openjpa.jdbc.sql.DBDictionary.java
/** * This method is called when the dictionary first sees any connection. * It is used to initialize dictionary metadata if needed. If you * override this method, be sure to call * <code>super.connectedConfiguration</code>. *//*w w w . ja v a 2s . co m*/ public void connectedConfiguration(Connection conn) throws SQLException { if (!connected) { DatabaseMetaData metaData = null; try { metaData = conn.getMetaData(); databaseProductName = nullSafe(metaData.getDatabaseProductName()); databaseProductVersion = nullSafe(metaData.getDatabaseProductVersion()); setMajorVersion(metaData.getDatabaseMajorVersion()); setMinorVersion(metaData.getDatabaseMinorVersion()); try { // JDBC3-only method, so it might throw an // AbstractMethodError int JDBCMajorVersion = metaData.getJDBCMajorVersion(); isJDBC3 = JDBCMajorVersion >= 3; isJDBC4 = JDBCMajorVersion >= 4; } catch (Throwable t) { // ignore if not JDBC3 } } catch (Exception e) { if (log.isTraceEnabled()) log.trace(e.toString(), e); } if (log.isTraceEnabled()) { log.trace(DBDictionaryFactory.toString(metaData)); if (isJDBC3) { try { log.trace(_loc.get("connection-defaults", new Object[] { conn.getAutoCommit(), conn.getHoldability(), conn.getTransactionIsolation() })); } catch (Throwable t) { log.trace("Unable to trace connection settings", t); } } } // Configure the naming utility if (supportsDelimitedIdentifiers == null) // not explicitly set configureNamingUtil(metaData); // Auto-detect generated keys retrieval support unless user specified it. if (supportsGetGeneratedKeys == null) { supportsGetGeneratedKeys = (isJDBC3) ? metaData.supportsGetGeneratedKeys() : false; } if (log.isInfoEnabled()) { log.info(_loc.get("dict-info", new Object[] { metaData.getDatabaseProductName(), getMajorVersion(), getMinorVersion(), metaData.getDriverName(), metaData.getDriverVersion() })); } } connected = true; }
From source file:org.apache.slide.store.impl.rdbms.JDBCStore.java
protected Connection getNewConnection() throws SQLException { Connection connection; if (useDbcpPooling) { try {/* www. ja v a2 s. c o m*/ connection = DriverManager.getConnection(DBCP_URL + ":" + dbcpPoolName); } catch (SQLException e) { getLogger().log("Could not create connection. Reason: " + e, LOG_CHANNEL, Logger.EMERGENCY); throw e; } } else { try { connection = DriverManager.getConnection(url, user, password); } catch (SQLException e) { getLogger().log("Could not create connection. Reason: " + e, LOG_CHANNEL, Logger.EMERGENCY); throw e; } try { if (connection.getTransactionIsolation() != isolationLevel) { connection.setTransactionIsolation(isolationLevel); } } catch (SQLException e) { getLogger().log("Could not set isolation level '" + isolationLevelToString(isolationLevel) + "'. Reason: " + e, LOG_CHANNEL, Logger.WARNING); } if (connection.getAutoCommit()) { connection.setAutoCommit(false); } } return connection; }
From source file:org.artifactory.storage.db.util.JdbcHelper.java
/** * @return A transaction aware connection *//* w w w . j a v a2 s .c o m*/ private Connection getConnection() throws SQLException { Connection connection = DataSourceUtils.doGetConnection(dataSource); if (Connection.TRANSACTION_READ_COMMITTED != connection.getTransactionIsolation()) { connection.setTransactionIsolation(Connection.TRANSACTION_READ_COMMITTED); } return connection; }
From source file:org.cloudgraph.rdb.service.RDBGraphService.java
public int count(Query query) { if (query == null) throw new IllegalArgumentException("expected non-null 'query' argument"); validate(query);//from w w w . ja va2 s .c o m if (log.isDebugEnabled()) { log(query); } Connection con = null; try { if (log.isDebugEnabled()) log.debug("getting connection"); con = ProviderManager.instance().getConnection(); if (con.getAutoCommit()) { if (log.isDebugEnabled()) log.debug("turning off connection autocommit for count query"); con.setAutoCommit(false); } RDBMSVendorName vendor = PlasmaRuntime.getInstance() .getRDBMSProviderVendor(DataAccessProviderName.JDBC); switch (vendor) { case ORACLE: con.setTransactionIsolation(Connection.TRANSACTION_READ_COMMITTED); break; case MYSQL: con.setTransactionIsolation(Connection.TRANSACTION_NONE); // Oracle // does // not // support break; default: } // TODO: make transaction isolation configurable if (log.isDebugEnabled()) log.debug( "using transaction isolation level " + con.getTransactionIsolation() + " for count query"); } catch (SQLException e2) { if (con != null) try { if (log.isDebugEnabled()) log.debug("closing connection"); con.close(); } catch (SQLException e) { log.error(e.getMessage(), e); } throw new DataAccessException(e2); } GraphQuery dispatcher = new GraphQuery(con); try { return dispatcher.count(query); } finally { if (con != null) try { if (log.isDebugEnabled()) log.debug("closing connection"); con.close(); } catch (SQLException e) { log.error(e.getMessage(), e); } } }
From source file:org.cloudgraph.rdb.service.RDBGraphService.java
public int[] count(Query[] queries) { if (queries == null) throw new IllegalArgumentException("expected non-null 'queries' argument"); Connection con = null; try {/* w w w . j a v a 2 s .c o m*/ if (log.isDebugEnabled()) log.debug("getting connection"); con = ProviderManager.instance().getConnection(); if (con.getAutoCommit()) { if (log.isDebugEnabled()) log.debug("turning off connection autocommit for multi count query"); con.setAutoCommit(false); } // TODO: make transaction isolation configurable RDBMSVendorName vendor = PlasmaRuntime.getInstance() .getRDBMSProviderVendor(DataAccessProviderName.JDBC); switch (vendor) { case ORACLE: con.setTransactionIsolation(Connection.TRANSACTION_READ_COMMITTED); break; case MYSQL: con.setTransactionIsolation(Connection.TRANSACTION_READ_COMMITTED); break; default: } if (log.isDebugEnabled()) log.debug("using transaction isolation level " + con.getTransactionIsolation() + " for multi count query"); } catch (SQLException e2) { if (con != null) try { if (log.isDebugEnabled()) log.debug("closing connection"); con.close(); } catch (SQLException e) { log.error(e.getMessage(), e); } throw new DataAccessException(e2); } GraphQuery dispatcher = new GraphQuery(con); int[] counts = new int[queries.length]; try { for (int i = 0; i < queries.length; i++) counts[i] = dispatcher.count(queries[i]); return counts; } finally { if (con != null) try { if (log.isDebugEnabled()) log.debug("closing connection"); con.close(); } catch (SQLException e) { log.error(e.getMessage(), e); } } }