List of usage examples for java.sql Connection TRANSACTION_READ_COMMITTED
int TRANSACTION_READ_COMMITTED
To view the source code for java.sql Connection TRANSACTION_READ_COMMITTED.
Click Source Link
From source file:org.mybatis.guice.datasource.dbcp.SharedPoolDataSourceProviderTest.java
@Test public void get() throws Throwable { final boolean autoCommit = true; final int loginTimeout = 10; final boolean defaultReadOnly = true; final int defaultTransactionIsolation = Connection.TRANSACTION_READ_COMMITTED; final String description = "test_description"; final int minEvictableIdleTimeMillis = 30; final int numTestsPerEvictionRun = 40; final boolean rollbackAfterValidation = true; final boolean testOnBorrow = true; final boolean testOnReturn = true; final boolean testWhileIdle = true; final int timeBetweenEvictionRunsMillis = 50; final String validationQuery = "SELECT 1"; final int maxActive = 60; final int maxIdle = 70; final int maxWait = 80; Injector injector = Guice.createInjector(new AbstractModule() { @Override// w w w . j av a 2 s . c om protected void configure() { bind(ConnectionPoolDataSource.class).toInstance(connectionPoolDataSource); bindConstant().annotatedWith(Names.named("JDBC.autoCommit")).to(autoCommit); bindConstant().annotatedWith(Names.named("JDBC.loginTimeout")).to(loginTimeout); bindConstant().annotatedWith(Names.named("DBCP.defaultReadOnly")).to(defaultReadOnly); bindConstant().annotatedWith(Names.named("DBCP.defaultTransactionIsolation")) .to(defaultTransactionIsolation); bindConstant().annotatedWith(Names.named("DBCP.description")).to(description); bindConstant().annotatedWith(Names.named("DBCP.minEvictableIdleTimeMillis")) .to(minEvictableIdleTimeMillis); bindConstant().annotatedWith(Names.named("DBCP.numTestsPerEvictionRun")).to(numTestsPerEvictionRun); bindConstant().annotatedWith(Names.named("DBCP.rollbackAfterValidation")) .to(rollbackAfterValidation); bindConstant().annotatedWith(Names.named("DBCP.testOnBorrow")).to(testOnBorrow); bindConstant().annotatedWith(Names.named("DBCP.testOnReturn")).to(testOnReturn); bindConstant().annotatedWith(Names.named("DBCP.testWhileIdle")).to(testWhileIdle); bindConstant().annotatedWith(Names.named("DBCP.timeBetweenEvictionRunsMillis")) .to(timeBetweenEvictionRunsMillis); bindConstant().annotatedWith(Names.named("DBCP.validationQuery")).to(validationQuery); bindConstant().annotatedWith(Names.named("DBCP.maxActive")).to(maxActive); bindConstant().annotatedWith(Names.named("DBCP.maxIdle")).to(maxIdle); bindConstant().annotatedWith(Names.named("DBCP.maxWait")).to(maxWait); } }); SharedPoolDataSourceProvider provider = injector.getInstance(SharedPoolDataSourceProvider.class); SharedPoolDataSource dataSource = (SharedPoolDataSource) provider.get(); assertEquals(connectionPoolDataSource, dataSource.getConnectionPoolDataSource()); assertEquals(autoCommit, dataSource.isDefaultAutoCommit()); assertEquals(defaultReadOnly, dataSource.isDefaultReadOnly()); assertEquals(defaultTransactionIsolation, dataSource.getDefaultTransactionIsolation()); assertEquals(description, dataSource.getDescription()); assertEquals(loginTimeout, dataSource.getLoginTimeout()); assertEquals(minEvictableIdleTimeMillis, dataSource.getMinEvictableIdleTimeMillis()); assertEquals(numTestsPerEvictionRun, dataSource.getNumTestsPerEvictionRun()); assertEquals(rollbackAfterValidation, dataSource.isRollbackAfterValidation()); assertEquals(testOnBorrow, dataSource.isTestOnBorrow()); assertEquals(testOnReturn, dataSource.isTestOnReturn()); assertEquals(testWhileIdle, dataSource.isTestWhileIdle()); assertEquals(timeBetweenEvictionRunsMillis, dataSource.getTimeBetweenEvictionRunsMillis()); assertEquals(validationQuery, dataSource.getValidationQuery()); assertEquals(maxActive, dataSource.getMaxActive()); assertEquals(maxIdle, dataSource.getMaxIdle()); assertEquals(maxWait, dataSource.getMaxWait()); }
From source file:org.pivotal.sqlfire.HibernateTransactionalBatchInsertsTest.java
protected static Properties createHibernateConfigurationSettings() { Properties hibernateConfigurationSettings = new Properties(); hibernateConfigurationSettings.setProperty("hibernate.dialect", "com.vmware.sqlfire.hibernate.SQLFireDialect"); hibernateConfigurationSettings.setProperty("hibernate.show_sql", "true"); hibernateConfigurationSettings.setProperty("hibernate.cache.provider_class", "org.hibernate.cache.NoCacheProvider"); //hibernateConfigurationSettings.setProperty("hibernate.connection.autocommit", "false"); hibernateConfigurationSettings.setProperty("hibernate.connection.isolation", String.valueOf(Connection.TRANSACTION_READ_COMMITTED)); hibernateConfigurationSettings.setProperty("hibernate.connection.driver_class", "com.vmware.sqlfire.jdbc.ClientDriver"); hibernateConfigurationSettings.setProperty("hibernate.connection.url", "jdbc:sqlfire://localhost:1529/"); hibernateConfigurationSettings.setProperty("hibernate.connection.username", "app"); hibernateConfigurationSettings.setProperty("hibernate.connection.password", "app"); hibernateConfigurationSettings.setProperty("hibernate.connection.pool_size", "1"); hibernateConfigurationSettings.setProperty("hibernate.hbm2ddl.auto", "update"); hibernateConfigurationSettings.setProperty("hibernate.hbm2ddl.import_files", "/data/source/schema/create-user-table.sqlf.ddl.sql"); return hibernateConfigurationSettings; }
From source file:org.mybatis.guice.datasource.dbcp.PerUserPoolDataSourceProviderTest.java
@Test public void get() throws Throwable { final boolean autoCommit = true; final int loginTimeout = 10; final boolean defaultReadOnly = true; final int defaultTransactionIsolation = Connection.TRANSACTION_READ_COMMITTED; final String description = "test_description"; final int minEvictableIdleTimeMillis = 20; final int numTestsPerEvictionRun = 30; final boolean rollbackAfterValidation = true; final boolean testOnBorrow = true; final boolean testOnReturn = true; final boolean testWhileIdle = true; final int timeBetweenEvictionRunsMillis = 40; final String validationQuery = "SELECT 1"; final int maxActive = 50; final int maxIdle = 60; final int maxWait = 70; Injector injector = Guice.createInjector(new AbstractModule() { @Override/*ww w . j a v a 2s. c om*/ protected void configure() { bind(ConnectionPoolDataSource.class).toInstance(connectionPoolDataSource); bindConstant().annotatedWith(Names.named("JDBC.autoCommit")).to(autoCommit); bindConstant().annotatedWith(Names.named("JDBC.loginTimeout")).to(loginTimeout); bindConstant().annotatedWith(Names.named("DBCP.defaultReadOnly")).to(defaultReadOnly); bindConstant().annotatedWith(Names.named("DBCP.defaultTransactionIsolation")) .to(defaultTransactionIsolation); bindConstant().annotatedWith(Names.named("DBCP.description")).to(description); bindConstant().annotatedWith(Names.named("DBCP.minEvictableIdleTimeMillis")) .to(minEvictableIdleTimeMillis); bindConstant().annotatedWith(Names.named("DBCP.numTestsPerEvictionRun")).to(numTestsPerEvictionRun); bindConstant().annotatedWith(Names.named("DBCP.rollbackAfterValidation")) .to(rollbackAfterValidation); bindConstant().annotatedWith(Names.named("DBCP.testOnBorrow")).to(testOnBorrow); bindConstant().annotatedWith(Names.named("DBCP.testOnReturn")).to(testOnReturn); bindConstant().annotatedWith(Names.named("DBCP.testWhileIdle")).to(testWhileIdle); bindConstant().annotatedWith(Names.named("DBCP.timeBetweenEvictionRunsMillis")) .to(timeBetweenEvictionRunsMillis); bindConstant().annotatedWith(Names.named("DBCP.validationQuery")).to(validationQuery); bindConstant().annotatedWith(Names.named("DBCP.maxActive")).to(maxActive); bindConstant().annotatedWith(Names.named("DBCP.maxIdle")).to(maxIdle); bindConstant().annotatedWith(Names.named("DBCP.maxWait")).to(maxWait); } }); PerUserPoolDataSourceProvider provider = injector.getInstance(PerUserPoolDataSourceProvider.class); PerUserPoolDataSource dataSource = (PerUserPoolDataSource) provider.get(); assertEquals(connectionPoolDataSource, dataSource.getConnectionPoolDataSource()); assertEquals(autoCommit, dataSource.isDefaultAutoCommit()); assertEquals(loginTimeout, dataSource.getLoginTimeout()); assertEquals(defaultReadOnly, dataSource.isDefaultReadOnly()); assertEquals(defaultTransactionIsolation, dataSource.getDefaultTransactionIsolation()); assertEquals(description, dataSource.getDescription()); assertEquals(minEvictableIdleTimeMillis, dataSource.getMinEvictableIdleTimeMillis()); assertEquals(numTestsPerEvictionRun, dataSource.getNumTestsPerEvictionRun()); assertEquals(rollbackAfterValidation, dataSource.isRollbackAfterValidation()); assertEquals(testOnBorrow, dataSource.isTestOnBorrow()); assertEquals(testOnReturn, dataSource.isTestOnReturn()); assertEquals(testWhileIdle, dataSource.isTestWhileIdle()); assertEquals(timeBetweenEvictionRunsMillis, dataSource.getTimeBetweenEvictionRunsMillis()); assertEquals(validationQuery, dataSource.getValidationQuery()); assertEquals(maxActive, dataSource.getDefaultMaxActive()); assertEquals(maxIdle, dataSource.getDefaultMaxIdle()); assertEquals(maxWait, dataSource.getDefaultMaxWait()); }
From source file:org.spring.data.gemfire.app.dao.vendor.SQLFireHibernateUserDao.java
protected Session preProcess(final Session session) { Assert.notNull(session, "The Hibernate Session must not be null!"); Assert.state(session.isOpen(), "The Session is closed!"); if (session instanceof SessionImpl) { System.out.printf("The Hibernate Session is a SessionImpl!%n"); try {//www . j a v a2 s . co m Assert.state(!((SessionImpl) session).connection().isClosed(), "The Hibernate Session's Connection is closed!"); //((SessionImpl) session).connection().setAutoCommit(false); // NOTE not required for SQLFire ((SessionImpl) session).connection().setTransactionIsolation(Connection.TRANSACTION_READ_COMMITTED); } catch (SQLException e) { System.err.printf("Failed to set 'autoCommit' and 'Isolation-level' on Connection!%n%1$s%n", e); } } return session; }
From source file:com.lawulu.bdc.etl.batch.config.DatabaseConfiguration.java
@Bean(destroyMethod = "close") public DataSource dbcpDataSource() { BasicDataSource dataSource = new BasicDataSource(); dataSource.setDriverClassName("com.mysql.jdbc.Driver"); dataSource.setUrl("jdbc:mysql://127.0.0.1:3306/test"); dataSource.setUsername("root"); dataSource.setPassword("root"); dataSource.setMaxActive(20);//from ww w. j av a2 s. c o m dataSource.setMaxIdle(20); dataSource.setMaxWait(10000); dataSource.setInitialSize(5); dataSource.setValidationQuery("SELECT 1"); dataSource.setDefaultTransactionIsolation(Connection.TRANSACTION_READ_COMMITTED); return dataSource; }
From source file:org.sbq.batch.configurations.DatabaseConfiguration.java
@Bean(destroyMethod = "close") public DataSource dbcpDataSource() { BasicDataSource dataSource = new BasicDataSource(); dataSource.setDriverClassName("com.mysql.jdbc.Driver"); dataSource.setUrl("jdbc:mysql://127.0.0.1:3306/batch_db"); dataSource.setUsername("root"); dataSource.setPassword(""); dataSource.setMaxActive(20);/*from ww w . j a v a 2 s. c om*/ dataSource.setMaxIdle(20); dataSource.setMaxWait(10000); dataSource.setInitialSize(5); dataSource.setValidationQuery("SELECT 1"); dataSource.setDefaultTransactionIsolation(Connection.TRANSACTION_READ_COMMITTED); return dataSource; }
From source file:org.spring.data.gemfire.app.dao.vendor.SQLFireJpaUserDao.java
@Override protected EntityManager prepare(final EntityManager entityManager) { Assert.notNull(entityManager, "The JPA EntityManager must not be null!"); Assert.state(entityManager.isOpen(), "The EntityManager is closed!"); if (entityManager.getDelegate() instanceof Session) { Session session = (Session) entityManager.getDelegate(); if (session instanceof SessionImpl) { try { ((SessionImpl) session).connection() .setTransactionIsolation(Connection.TRANSACTION_READ_COMMITTED); //((SessionImpl) session).connection().setTransactionIsolation(Connection.TRANSACTION_READ_UNCOMMITTED); //((SessionImpl) session).connection().setTransactionIsolation(Connection.TRANSACTION_REPEATABLE_READ); //((SessionImpl) session).connection().setTransactionIsolation(Connection.TRANSACTION_SERIALIZABLE); //((SessionImpl) session).connection().setTransactionIsolation(Connection.TRANSACTION_NONE); } catch (SQLException e) { //System.err.printf("Failed to set the JDBC Connection Transaction Isolation Level to (READ_COMMITTED)!%n%1$s%n", e); throw new PersistenceException( "Failed to set the JDBC Connection Transaction Isolation-level to (READ_COMMITTED)!", e);/*from www .j av a 2s .c o m*/ } } } return entityManager; }
From source file:ws.rocket.sqlstore.test.SqlStoreTest.java
@BeforeClass public void setUp() throws SQLException, IOException { ResourceBundle bundle = ResourceBundle.getBundle("ws.rocket.sqlstore.test.test"); File dbPath = new File(bundle.getString("jdbc.dbPath")); if (!dbPath.exists()) { dbPath.mkdirs();//from www.ja v a2s . c om } System.setProperty("derby.system.home", dbPath.getCanonicalPath()); BasicDataSource ds = new BasicDataSource(); ds.setDriverClassName(bundle.getString("jdbc.driver")); ds.setUrl(bundle.getString("jdbc.url")); ds.setDefaultReadOnly(true); ds.setDefaultAutoCommit(false); ds.setDefaultTransactionIsolation(Connection.TRANSACTION_READ_COMMITTED); ds.setInitialSize(Integer.parseInt(bundle.getString("jdbc.initialConnections"))); this.dataSource = ds; boolean tableExists; try (Connection c = this.dataSource.getConnection()) { DatabaseMetaData meta = c.getMetaData(); try (ResultSet rs = meta.getTables(null, "SQLSTORE", "PERSON", new String[] { "TABLE" })) { tableExists = rs.next(); } } if (tableExists) { dropTables(); } }
From source file:org.artifactory.storage.db.util.JdbcHelper.java
/** * @return A transaction aware connection *///from ww w. ja v a2s. 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; }