List of usage examples for java.sql Connection TRANSACTION_READ_UNCOMMITTED
int TRANSACTION_READ_UNCOMMITTED
To view the source code for java.sql Connection TRANSACTION_READ_UNCOMMITTED.
Click Source Link
From source file:com.amazon.carbonado.repo.jdbc.LoggingConnection.java
public void setTransactionIsolation(int level) throws SQLException { String levelStr;// ww w . ja v a2 s . c o m switch (level) { default: levelStr = String.valueOf(level); break; case Connection.TRANSACTION_NONE: levelStr = "TRANSACTION_NONE"; break; case Connection.TRANSACTION_READ_UNCOMMITTED: levelStr = "TRANSACTION_READ_UNCOMMITTED"; break; case Connection.TRANSACTION_READ_COMMITTED: levelStr = "TRANSACTION_READ_COMMITTED"; break; case Connection.TRANSACTION_REPEATABLE_READ: levelStr = "TRANSACTION_REPEATABLE_READ"; break; case Connection.TRANSACTION_SERIALIZABLE: levelStr = "TRANSACTION_SERIALIZABLE"; break; } mLog.debug("Connection.setTransactionIsolation(" + levelStr + ')'); mCon.setTransactionIsolation(level); }
From source file:com.oltpbenchmark.WorkloadConfiguration.java
public void setIsolationMode(String mode) { if (mode.equals("TRANSACTION_SERIALIZABLE")) this.isolationMode = Connection.TRANSACTION_SERIALIZABLE; else if (mode.equals("TRANSACTION_READ_COMMITTED")) this.isolationMode = Connection.TRANSACTION_READ_COMMITTED; else if (mode.equals("TRANSACTION_REPEATABLE_READ")) this.isolationMode = Connection.TRANSACTION_REPEATABLE_READ; else if (mode.equals("TRANSACTION_READ_UNCOMMITTED")) this.isolationMode = Connection.TRANSACTION_READ_UNCOMMITTED; else if (!mode.isEmpty()) System.out.println("Indefined isolation mode, set to default [TRANSACTION_SERIALIZABLE]"); }
From source file:com.feedzai.commons.sql.abstraction.engine.impl.OracleEngine.java
/** * Overrides {@link com.feedzai.commons.sql.abstraction.engine.AbstractDatabaseEngine#setTransactionIsolation()} This is because * Oracle does not support READ_UNCOMMITTED e REPEATABLE_READ. * * @throws SQLException If a database access error occurs. */// w ww . j a va2 s . c o m @Override protected void setTransactionIsolation() throws SQLException { int isolation = properties.getIsolationLevel(); if (isolation == Connection.TRANSACTION_READ_UNCOMMITTED) { isolation = Connection.TRANSACTION_READ_COMMITTED; } if (isolation == Connection.TRANSACTION_REPEATABLE_READ) { isolation = Connection.TRANSACTION_SERIALIZABLE; } conn.setTransactionIsolation(isolation); }
From source file:lucee.commons.io.res.type.datasource.DatasourceResourceProvider.java
private Core getCore(ConnectionData data) throws PageException { Core core = (Core) cores.get(data.datasourceName); if (core == null) { DatasourceConnection dc = getManager().getConnection(ThreadLocalPageContext.get(), data.getDatasourceName(), data.getUsername(), data.getPassword()); try {/*from w w w. j a va 2 s. com*/ dc.getConnection().setAutoCommit(false); dc.getConnection().setTransactionIsolation(Connection.TRANSACTION_READ_UNCOMMITTED); if ("com.microsoft.jdbc.sqlserver.SQLServerDriver".equals(dc.getDatasource().getClazz().getName())) core = new MSSQL(dc, data.getPrefix()); else if ("com.microsoft.sqlserver.jdbc.SQLServerDriver" .equals(dc.getDatasource().getClazz().getName())) core = new MSSQL(dc, data.getPrefix()); else if ("net.sourceforge.jtds.jdbc.Driver".equals(dc.getDatasource().getClazz().getName())) core = new MSSQL(dc, data.getPrefix()); else if ("org.gjt.mm.mysql.Driver".equals(dc.getDatasource().getClazz().getName())) core = new MySQL(dc, data.getPrefix()); else throw new ApplicationException( "there is no DatasourceResource driver for this database [" + data.getPrefix() + "]"); cores.put(data.datasourceName, core); } catch (SQLException e) { throw new DatabaseException(e, dc); } finally { release(dc); //manager.releaseConnection(CONNECTION_ID,dc); } } return core; }
From source file:it.cnr.icar.eric.server.persistence.rdb.SQLPersistenceManagerImpl.java
@SuppressWarnings("unused") private SQLPersistenceManagerImpl() { loadUsernamePassword();/* w ww .j a va 2 s . co m*/ constructDatabaseURL(); // define transaction isolation if ("TRANSACTION_READ_COMMITTED".equalsIgnoreCase( RegistryProperties.getInstance().getProperty("eric.persistence.rdb.transactionIsolation"))) { transactionIsolation = Connection.TRANSACTION_READ_COMMITTED; } else { transactionIsolation = Connection.TRANSACTION_READ_UNCOMMITTED; } useConnectionPool = Boolean.valueOf( RegistryProperties.getInstance().getProperty("eric.persistence.rdb.useConnectionPooling", "true")) .booleanValue(); skipReferenceCheckOnRemove = Boolean.valueOf(RegistryProperties.getInstance() .getProperty("eric.persistence.rdb.skipReferenceCheckOnRemove", "false")).booleanValue(); dumpStackOnQuery = Boolean.valueOf( RegistryProperties.getInstance().getProperty("eric.persistence.rdb.dumpStackOnQuery", "false")) .booleanValue(); boolean debugConnectionPool = Boolean .valueOf(RegistryProperties.getInstance().getProperty("eric.persistence.rdb.pool.debug", "false")) .booleanValue(); // Create JNDI context if (useConnectionPool) { if (!debugConnectionPool) { // Use Container's connection pooling String ericName = RegistryProperties.getInstance().getProperty("eric.name", "eric"); String envName = "java:comp/env"; String dataSourceName = "jdbc/" + ericName + "-registry"; Context ctx = null; try { ctx = new InitialContext(); if (null == ctx) { log.info(ServerResourceBundle.getInstance().getString("message.UnableToGetInitialContext")); } } catch (NamingException e) { log.info(ServerResourceBundle.getInstance().getString("message.UnableToGetInitialContext"), e); ctx = null; } if (null != ctx) { try { ctx = (Context) ctx.lookup(envName); if (null == ctx) { log.info(ServerResourceBundle.getInstance().getString( "message.UnableToGetJNDIContextForDataSource", new Object[] { envName })); } } catch (NamingException e) { log.info( ServerResourceBundle.getInstance().getString( "message.UnableToGetJNDIContextForDataSource", new Object[] { envName }), e); ctx = null; } } if (null != ctx) { try { ds = (DataSource) ctx.lookup(dataSourceName); if (null == ds) { log.info(ServerResourceBundle.getInstance().getString( "message.UnableToGetJNDIContextForDataSource", new Object[] { envName + "/" + dataSourceName })); } } catch (NamingException e) { log.info(ServerResourceBundle.getInstance().getString( "message.UnableToGetJNDIContextForDataSource", new Object[] { envName + "/" + dataSourceName }), e); ds = null; } } if (null != ds) { // Create a test connection to make sure all is well with // DataSource Connection connection = null; try { connection = ds.getConnection(); } catch (Exception e) { log.info(ServerResourceBundle.getInstance().getString( "message.UnableToCreateTestConnectionForDataSource", new Object[] { envName + "/" + dataSourceName }), e); ds = null; } finally { if (connection != null) { try { connection.close(); } catch (Exception e1) { // Do nothing. connection = null; } } } } } if (ds == null) { // No DataSource available so create our own ConnectionPool loadDatabaseDriver(); createConnectionPool(); } } else { loadDatabaseDriver(); } }
From source file:AIR.Common.DB.AbstractDLL.java
public MultiDataResultSet executeStatement(SQLConnection connection, String queryTemplate, SqlParametersMaps parameters, boolean useNoLock) throws ReturnStatusException { final String messageTemplate = "Exception %1$s executing query. Template is \"%2$s\". Final query is \"%3$s\". Exception message: %4$s."; String reformulatedQuery = reformulateQueryWithParametersSubstitution(queryTemplate, parameters); MultiDataResultSet results = null;/*w w w . j a v a2s . c o m*/ logQuery(reformulatedQuery); int currentTransactionIsolation = -1; PreparedStatement st = null; try { st = connection.prepareStatement(reformulatedQuery); if (useNoLock) { // if (not supported )then throw DBLockNotSupportedException DatabaseMetaData dbMetaData = connection.getMetaData(); if (dbMetaData.supportsTransactionIsolationLevel(Connection.TRANSACTION_READ_UNCOMMITTED) == false) throw new DBLockNotSupportedException( String.format("Select NoLock DB unsupported on %1$s", connection.getCatalog())); // TODO shiva confirm if nolock() is same as // TRANSACTION_READ_UNCOMMITTED. currentTransactionIsolation = connection.getTransactionIsolation(); connection.setTransactionIsolation(Connection.TRANSACTION_READ_UNCOMMITTED); } @SuppressWarnings("unused") boolean gotResultSet = st.execute(); results = new MultiDataResultSet(st); } catch (SQLException ex) { _logger.error(String.format(messageTemplate, "SQLException", queryTemplate, reformulatedQuery, ex.getMessage()), ex); throw new ReturnStatusException(ex); // TODO Shiva throw a ReturnStatusException here instead. Discuss // first. } catch (Exception ex) { _logger.error(String.format(messageTemplate, ex.getClass().getName(), queryTemplate, reformulatedQuery, ex.getMessage()), ex); throw new ReturnStatusException(ex); } finally { try { if (currentTransactionIsolation != -1) connection.setTransactionIsolation(currentTransactionIsolation); } catch (SQLException ex) { _logger.error(String.format(messageTemplate, "SQLException", queryTemplate, reformulatedQuery, ex.getMessage())); throw new ReturnStatusException(ex); } finally { try { st.close(); } catch (Throwable t) { } } } return results; }
From source file:com.glaf.core.jdbc.connection.TomcatJdbcConnectionProvider.java
protected void parsePoolProperties(PoolConfiguration poolProperties, Properties properties) { String value = null;/* ww w. j ava2s. co m*/ value = properties.getProperty(ConnectionConstants.PROP_DEFAULTAUTOCOMMIT); if (value != null) { poolProperties.setDefaultAutoCommit(Boolean.valueOf(value)); } value = properties.getProperty(ConnectionConstants.PROP_DEFAULTREADONLY); if (value != null) { poolProperties.setDefaultReadOnly(Boolean.valueOf(value)); } value = properties.getProperty(ConnectionConstants.PROP_DEFAULTTRANSACTIONISOLATION); if (value != null) { int level = ConnectionConstants.UNKNOWN_TRANSACTIONISOLATION; if ("NONE".equalsIgnoreCase(value)) { level = Connection.TRANSACTION_NONE; } else if ("READ_COMMITTED".equalsIgnoreCase(value)) { level = Connection.TRANSACTION_READ_COMMITTED; } else if ("READ_UNCOMMITTED".equalsIgnoreCase(value)) { level = Connection.TRANSACTION_READ_UNCOMMITTED; } else if ("REPEATABLE_READ".equalsIgnoreCase(value)) { level = Connection.TRANSACTION_REPEATABLE_READ; } else if ("SERIALIZABLE".equalsIgnoreCase(value)) { level = Connection.TRANSACTION_SERIALIZABLE; } else { try { level = Integer.parseInt(value); } catch (NumberFormatException e) { System.err.println("Could not parse defaultTransactionIsolation: " + value); System.err.println("WARNING: defaultTransactionIsolation not set"); System.err.println("using default value of database driver"); level = ConnectionConstants.UNKNOWN_TRANSACTIONISOLATION; } } poolProperties.setDefaultTransactionIsolation(level); } value = properties.getProperty(ConnectionConstants.PROP_DEFAULTCATALOG); if (value != null) { poolProperties.setDefaultCatalog(value); } value = properties.getProperty(ConnectionConstants.PROP_MAXACTIVE); if (value != null && StringUtils.isNumeric(value)) { poolProperties.setMaxActive(Integer.parseInt(value)); } value = properties.getProperty(ConnectionConstants.PROP_MAXIDLE); if (value != null && StringUtils.isNumeric(value)) { poolProperties.setMaxIdle(Integer.parseInt(value)); } value = properties.getProperty(ConnectionConstants.PROP_MINIDLE); if (value != null && StringUtils.isNumeric(value)) { poolProperties.setMinIdle(Integer.parseInt(value)); } value = properties.getProperty(ConnectionConstants.PROP_INITIALSIZE); if (value != null && StringUtils.isNumeric(value)) { poolProperties.setInitialSize(Integer.parseInt(value)); } value = properties.getProperty(ConnectionConstants.PROP_MAXWAIT); if (value != null && StringUtils.isNumeric(value)) { poolProperties.setMaxWait(Integer.parseInt(value)); } value = properties.getProperty(ConnectionConstants.PROP_TESTONBORROW); if (value != null) { poolProperties.setTestOnBorrow(Boolean.valueOf(value).booleanValue()); } value = properties.getProperty(ConnectionConstants.PROP_TESTONRETURN); if (value != null) { poolProperties.setTestOnReturn(Boolean.valueOf(value).booleanValue()); } value = properties.getProperty(ConnectionConstants.PROP_TESTONCONNECT); if (value != null) { poolProperties.setTestOnConnect(Boolean.valueOf(value).booleanValue()); } value = properties.getProperty(ConnectionConstants.PROP_TIMEBETWEENEVICTIONRUNSMILLIS); if (value != null && StringUtils.isNumeric(value)) { poolProperties.setTimeBetweenEvictionRunsMillis(Integer.parseInt(value)); } value = properties.getProperty(ConnectionConstants.PROP_NUMTESTSPEREVICTIONRUN); if (value != null && StringUtils.isNumeric(value)) { poolProperties.setNumTestsPerEvictionRun(Integer.parseInt(value)); } value = properties.getProperty(ConnectionConstants.PROP_MINEVICTABLEIDLETIMEMILLIS); if (value != null && StringUtils.isNumeric(value)) { poolProperties.setMinEvictableIdleTimeMillis(Integer.parseInt(value)); } value = properties.getProperty(ConnectionConstants.PROP_TESTWHILEIDLE); if (value != null) { poolProperties.setTestWhileIdle(Boolean.valueOf(value).booleanValue()); } value = properties.getProperty(ConnectionConstants.PROP_VALIDATOR_CLASS_NAME); if (value != null) { poolProperties.setValidatorClassName(value); } value = properties.getProperty(ConnectionConstants.PROP_VALIDATIONINTERVAL); if (value != null && StringUtils.isNumeric(value)) { poolProperties.setValidationInterval(Long.parseLong(value)); } value = properties.getProperty(ConnectionConstants.PROP_ACCESSTOUNDERLYINGCONNECTIONALLOWED); if (value != null) { poolProperties.setAccessToUnderlyingConnectionAllowed(Boolean.valueOf(value).booleanValue()); } value = properties.getProperty(ConnectionConstants.PROP_REMOVEABANDONED); if (value != null) { poolProperties.setRemoveAbandoned(Boolean.valueOf(value).booleanValue()); } value = properties.getProperty(ConnectionConstants.PROP_REMOVEABANDONEDTIMEOUT); if (value != null && StringUtils.isNumeric(value)) { poolProperties.setRemoveAbandonedTimeout(Integer.parseInt(value)); } value = properties.getProperty(ConnectionConstants.PROP_LOGABANDONED); if (value != null) { poolProperties.setLogAbandoned(Boolean.valueOf(value).booleanValue()); } if (poolProperties.getUsername() != null) { poolProperties.getDbProperties().setProperty("user", poolProperties.getUsername()); } if (poolProperties.getPassword() != null) { poolProperties.getDbProperties().setProperty("password", poolProperties.getPassword()); } value = properties.getProperty(ConnectionConstants.PROP_INITSQL); if (value != null) { poolProperties.setInitSQL(value); } value = properties.getProperty(ConnectionConstants.PROP_INTERCEPTORS); if (value != null) { poolProperties.setJdbcInterceptors(value); } value = properties.getProperty(ConnectionConstants.PROP_JMX_ENABLED); if (value != null) { poolProperties.setJmxEnabled(Boolean.parseBoolean(value)); } value = properties.getProperty(ConnectionConstants.PROP_FAIR_QUEUE); if (value != null) { poolProperties.setFairQueue(Boolean.parseBoolean(value)); } value = properties.getProperty(ConnectionConstants.PROP_USE_EQUALS); if (value != null) { poolProperties.setUseEquals(Boolean.parseBoolean(value)); } value = properties.getProperty(ConnectionConstants.PROP_ABANDONWHENPERCENTAGEFULL); if (value != null && StringUtils.isNumeric(value)) { poolProperties.setAbandonWhenPercentageFull(Integer.parseInt(value)); } value = properties.getProperty(ConnectionConstants.PROP_MAXAGE); if (value != null && StringUtils.isNumeric(value)) { poolProperties.setMaxAge(Long.parseLong(value)); } value = properties.getProperty(ConnectionConstants.PROP_USE_CON_LOCK); if (value != null) { poolProperties.setUseLock(Boolean.parseBoolean(value)); } value = properties.getProperty(ConnectionConstants.PROP_SUSPECT_TIMEOUT); if (value != null && StringUtils.isNumeric(value)) { poolProperties.setSuspectTimeout(Integer.parseInt(value)); } value = properties.getProperty(ConnectionConstants.PROP_ALTERNATE_USERNAME_ALLOWED); if (value != null) { poolProperties.setAlternateUsernameAllowed(Boolean.parseBoolean(value)); } }
From source file:lucee.commons.io.res.type.datasource.DatasourceResourceProvider.java
private DatasourceConnection getDatasourceConnection(ConnectionData data, boolean autoCommit) throws PageException { DatasourceConnection dc = getManager().getConnection(ThreadLocalPageContext.get(), data.getDatasourceName(), data.getUsername(), data.getPassword()); try {/*from w ww . j a v a2 s . co m*/ dc.getConnection().setAutoCommit(autoCommit); dc.getConnection().setTransactionIsolation(Connection.TRANSACTION_READ_UNCOMMITTED); } catch (SQLException e) { throw new DatabaseException(e, dc); } return dc; }
From source file:com.feedzai.commons.sql.abstraction.engine.configuration.PdbProperties.java
/** * Gets the isolation level./*from w ww . j a v a 2 s. c om*/ * * @return The isolation level. */ public int getIsolationLevel() { final Optional<IsolationLevel> e = Enums.getIfPresent(IsolationLevel.class, getProperty(ISOLATION_LEVEL).toUpperCase()); if (!e.isPresent()) { throw new DatabaseEngineRuntimeException(ISOLATION_LEVEL + " must be set and be one of the following: " + EnumSet.allOf(IsolationLevel.class)); } switch (e.get()) { case READ_UNCOMMITTED: return Connection.TRANSACTION_READ_UNCOMMITTED; case READ_COMMITTED: return Connection.TRANSACTION_READ_COMMITTED; case REPEATABLE_READ: return Connection.TRANSACTION_REPEATABLE_READ; case SERIALIZABLE: return Connection.TRANSACTION_SERIALIZABLE; default: // Never happens. throw new DatabaseEngineRuntimeException("New isolation level?!" + e.get()); } }
From source file:io.vitess.jdbc.VitessMySQLDatabaseMetadata.java
public boolean supportsTransactionIsolationLevel(int level) throws SQLException { switch (level) { case Connection.TRANSACTION_READ_COMMITTED: case Connection.TRANSACTION_READ_UNCOMMITTED: case Connection.TRANSACTION_REPEATABLE_READ: case Connection.TRANSACTION_SERIALIZABLE: return true; default://from w w w. j a v a 2s. co m return false; } }