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.artifactory.storage.db.spring.ArtifactoryDataSource.java
public ArtifactoryDataSource(StorageProperties storageProperties) { GenericObjectPool.Config poolConfig = new GenericObjectPool.Config(); poolConfig.maxActive = storageProperties.getMaxActiveConnections(); poolConfig.maxIdle = storageProperties.getMaxIdleConnections(); ObjectPool connectionPool = new GenericObjectPool(null, poolConfig); ConnectionFactory connectionFactory = new DriverManagerConnectionFactory( connectionUrl = storageProperties.getConnectionUrl(), storageProperties.getUsername(), storageProperties.getPassword()); PoolableConnectionFactory pcf = new ArtifactoryPoolableConnectionFactory(connectionFactory, connectionPool, null, null, false, false);//from w ww . j ava 2 s . c om pcf.setDefaultTransactionIsolation(Connection.TRANSACTION_READ_COMMITTED); setPool(connectionPool); genericPool = (GenericObjectPool) _pool; }
From source file:iudex.da.ContentUpdater.java
public void update(List<UniMap> references) throws SQLException { Connection conn = dataSource().getConnection(); try {//from ww w . j ava 2 s . c o m conn.setAutoCommit(false); conn.setTransactionIsolation(Connection.TRANSACTION_READ_COMMITTED); update(references, conn); conn.commit(); } finally { if (conn != null) conn.close(); } }
From source file:org.apache.slide.store.impl.rdbms.JDBCStore.java
protected static String isolationLevelToString(int isolationLevel) { String levelString;//from w ww .j a va 2 s .com switch (isolationLevel) { case Connection.TRANSACTION_NONE: levelString = TRANSACTION_NONE; break; case Connection.TRANSACTION_READ_UNCOMMITTED: levelString = TRANSACTION_READ_UNCOMMITTED; break; case Connection.TRANSACTION_READ_COMMITTED: levelString = TRANSACTION_READ_COMMITTED; break; case Connection.TRANSACTION_REPEATABLE_READ: levelString = TRANSACTION_REPEATABLE_READ; break; case Connection.TRANSACTION_SERIALIZABLE: levelString = TRANSACTION_SERIALIZABLE; break; default: levelString = "UNKNOWN"; break; } return levelString; }
From source file:com.alibaba.dubbo.governance.status.DatabaseStatusChecker.java
private String getIsolation(int i) { if (i == Connection.TRANSACTION_READ_COMMITTED) { return "READ_COMMITTED"; }/*from ww w . ja va2 s.c om*/ if (i == Connection.TRANSACTION_READ_UNCOMMITTED) { return "READ_UNCOMMITTED"; } if (i == Connection.TRANSACTION_REPEATABLE_READ) { return "REPEATABLE_READ"; } if (i == Connection.TRANSACTION_SERIALIZABLE) { return "SERIALIZABLE)"; } return "NONE"; }
From source file:org.apache.hadoop.vertica.VerticaInputSplit.java
/** (@inheritDoc) */ public void configure(Configuration conf) throws Exception { LOG.trace("Input split configured"); vtconfig = new VerticaConfiguration(conf); connection = vtconfig.getConnection(false); connection.setAutoCommit(true);// w w w . j ava 2 s .com connection.setTransactionIsolation(Connection.TRANSACTION_READ_COMMITTED); }
From source file:JDBCMeta.java
/** * Convert a TransactionIsolation int (defined in java.sql.Connection) to * the corresponding printable string.//from w w w. j a v a 2 s . co m */ public static String transactionIsolationToString(int txisolation) { switch (txisolation) { case Connection.TRANSACTION_NONE: // transactions not supported. return "TRANSACTION_NONE"; case Connection.TRANSACTION_READ_UNCOMMITTED: // All three phenomena can occur return "TRANSACTION_NONE"; case Connection.TRANSACTION_READ_COMMITTED: // Dirty reads are prevented; non-repeatable reads and // phantom reads can occur. return "TRANSACTION_READ_COMMITTED"; case Connection.TRANSACTION_REPEATABLE_READ: // Dirty reads and non-repeatable reads are prevented; // phantom reads can occur. return "TRANSACTION_REPEATABLE_READ"; case Connection.TRANSACTION_SERIALIZABLE: // All three phenomena prvented; slowest! return "TRANSACTION_SERIALIZABLE"; default: throw new IllegalArgumentException(txisolation + " not a valid TX_ISOLATION"); } }
From source file:org.apache.hadoop.hive.metastore.txn.CompactionTxnHandler.java
/** * This will look through the completed_txn_components table and look for partitions or tables * that may be ready for compaction. Also, look through txns and txn_components tables for * aborted transactions that we should add to the list. * @param maxAborted Maximum number of aborted queries to allow before marking this as a * potential compaction. * @return list of CompactionInfo structs. These will not have id, type, * or runAs set since these are only potential compactions not actual ones. */// w w w . j av a 2s .c om public Set<CompactionInfo> findPotentialCompactions(int maxAborted) throws MetaException { Connection dbConn = null; Set<CompactionInfo> response = new HashSet<CompactionInfo>(); Statement stmt = null; try { try { dbConn = getDbConn(Connection.TRANSACTION_READ_COMMITTED); stmt = dbConn.createStatement(); // Check for completed transactions String s = "select distinct ctc_database, ctc_table, " + "ctc_partition from COMPLETED_TXN_COMPONENTS"; LOG.debug("Going to execute query <" + s + ">"); ResultSet rs = stmt.executeQuery(s); while (rs.next()) { CompactionInfo info = new CompactionInfo(); info.dbname = rs.getString(1); info.tableName = rs.getString(2); info.partName = rs.getString(3); response.add(info); } // Check for aborted txns s = "select tc_database, tc_table, tc_partition " + "from TXNS, TXN_COMPONENTS " + "where txn_id = tc_txnid and txn_state = '" + TXN_ABORTED + "' " + "group by tc_database, tc_table, tc_partition " + "having count(*) > " + maxAborted; LOG.debug("Going to execute query <" + s + ">"); rs = stmt.executeQuery(s); while (rs.next()) { CompactionInfo info = new CompactionInfo(); info.dbname = rs.getString(1); info.tableName = rs.getString(2); info.partName = rs.getString(3); info.tooManyAborts = true; response.add(info); } LOG.debug("Going to rollback"); dbConn.rollback(); } catch (SQLException e) { LOG.error("Unable to connect to transaction database " + e.getMessage()); checkRetryable(dbConn, e, "findPotentialCompactions(maxAborted:" + maxAborted + ")"); } finally { closeDbConn(dbConn); closeStmt(stmt); } return response; } catch (RetryException e) { return findPotentialCompactions(maxAborted); } }
From source file:org.mybatis.guice.datasource.dbcp.PerUserPoolDataSourceModuleTest.java
@Test public void configure_PerUserDefaultTransactionIsolation() throws Throwable { Injector injector = Guice.createInjector( new PerUserPoolDataSourceModule.Builder().setPerUserDefaultTransactionIsolationProviderClass( PerUserDefaultTransactionIsolationProvider.class).create()); PerUserPoolDataSourceProvider provider = injector.getInstance(PerUserPoolDataSourceProvider.class); PerUserPoolDataSource dataSource = (PerUserPoolDataSource) provider.get(); assertEquals((Integer) Connection.TRANSACTION_READ_COMMITTED, dataSource.getPerUserDefaultTransactionIsolation("test_user")); assertEquals((Integer) Connection.TRANSACTION_SERIALIZABLE, dataSource.getPerUserDefaultTransactionIsolation("test_user2")); }
From source file:fr.xebia.management.config.ManagedBasicDataSourceBeanDefinitionParser.java
@Override protected AbstractBeanDefinition parseInternal(Element element, ParserContext parserContext) { BeanDefinitionBuilder builder = BeanDefinitionBuilder.rootBeanDefinition(ManagedBasicDataSource.class); builder.setRole(BeanDefinition.ROLE_APPLICATION); builder.getRawBeanDefinition().setSource(parserContext.extractSource(element)); fillBuilderWithAttributeIfExists(builder, element, "accessToUnderlyingConnectionAllowed", "access-to-underlying-connection-allowed", boolean.class, parserContext); fillBuilderWithAttributeIfExists(builder, element, "connectionInitSqls", "connection-init-sqls", java.util.Collection.class, parserContext); fillBuilderWithAttributeIfExists(builder, element, "connectionProperties", "connection-properties", String.class, parserContext); fillBuilderWithAttributeIfExists(builder, element, "defaultAutoCommit", "default-auto-commit", boolean.class, parserContext); fillBuilderWithAttributeIfExists(builder, element, "defaultCatalog", "default-catalog", String.class, parserContext);//from w ww .j a v a2 s .co m fillBuilderWithAttributeIfExists(builder, element, "defaultReadOnly", "default-read-only", boolean.class, parserContext); Element defaultTransactionIsolationElement = DomUtils.getChildElementByTagName(element, "default-transaction-isolation"); if (defaultTransactionIsolationElement != null) { int defaultTransactionIsolation; String value = defaultTransactionIsolationElement.getAttribute("value"); if ("NONE".equals(value)) { defaultTransactionIsolation = Connection.TRANSACTION_NONE; } else if ("READ_UNCOMMITTED".equals(value)) { defaultTransactionIsolation = Connection.TRANSACTION_READ_UNCOMMITTED; } else if ("READ_COMMITTED".equals(value)) { defaultTransactionIsolation = Connection.TRANSACTION_READ_COMMITTED; } else if ("REPEATABLE_READ".equals(value)) { defaultTransactionIsolation = Connection.TRANSACTION_REPEATABLE_READ; } else if ("SERIALIZABLE".equals(value)) { defaultTransactionIsolation = Connection.TRANSACTION_SERIALIZABLE; } else { String msg = "Invalid value for '<default-transaction-isolation' value=\"" + value + "\" />'"; parserContext.getReaderContext().fatal(msg, defaultTransactionIsolationElement); throw new IllegalStateException(msg); } builder.addPropertyValue("defaultTransactionIsolation", defaultTransactionIsolation); } fillBuilderWithAttributeIfExists(builder, element, "driverClassName", "driver-class-name", String.class, parserContext); fillBuilderWithAttributeIfExists(builder, element, "initialSize", "initial-size", int.class, parserContext); fillBuilderWithAttributeIfExists(builder, element, "logAbandoned", "log-abandoned", boolean.class, parserContext); fillBuilderWithAttributeIfExists(builder, element, "maxActive", "max-active", int.class, parserContext); fillBuilderWithAttributeIfExists(builder, element, "maxIdle", "max-idle", int.class, parserContext); fillBuilderWithAttributeIfExists(builder, element, "maxOpenPreparedStatements", "max-open-prepared-statements", int.class, parserContext); fillBuilderWithAttributeIfExists(builder, element, "maxWait", "max-wait", long.class, parserContext); fillBuilderWithAttributeIfExists(builder, element, "minEvictableIdleTimeMillis", "min-evictable-idle-time-millis", long.class, parserContext); fillBuilderWithAttributeIfExists(builder, element, "minIdle", "min-idle", int.class, parserContext); fillBuilderWithAttributeIfExists(builder, element, "numTestsPerEvictionRun", "num-tests-per-eviction-run", int.class, parserContext); fillBuilderWithAttributeIfExists(builder, element, "password", "password", String.class, parserContext); fillBuilderWithAttributeIfExists(builder, element, "poolPreparedStatements", "pool-prepared-statements", boolean.class, parserContext); fillBuilderWithAttributeIfExists(builder, element, "removeAbandoned", "remove-abandoned", boolean.class, parserContext); fillBuilderWithAttributeIfExists(builder, element, "removeAbandonedTimeout", "remove-abandoned-timeout", int.class, parserContext); fillBuilderWithAttributeIfExists(builder, element, "testOnBorrow", "test-on-borrow", boolean.class, parserContext); fillBuilderWithAttributeIfExists(builder, element, "testOnReturn", "test-on-return", boolean.class, parserContext); fillBuilderWithAttributeIfExists(builder, element, "testWhileIdle", "test-while-idle", boolean.class, parserContext); fillBuilderWithAttributeIfExists(builder, element, "timeBetweenEvictionRunsMillis", "time-between-eviction-runs-millis", long.class, parserContext); fillBuilderWithAttributeIfExists(builder, element, "url", "url", String.class, parserContext); fillBuilderWithAttributeIfExists(builder, element, "username", "username", String.class, parserContext); fillBuilderWithAttributeIfExists(builder, element, "validationQuery", "validation-query", String.class, parserContext); fillBuilderWithAttributeIfExists(builder, element, "validationQueryTimeout", "validation-query-timeout", int.class, parserContext); builder.setDestroyMethodName("close"); return builder.getBeanDefinition(); }
From source file:org.apache.slide.store.impl.rdbms.JDBCStore.java
protected static int stringToIsolationLevelToString(String levelString) { if (TRANSACTION_NONE.equals(levelString)) { return Connection.TRANSACTION_NONE; } else if (TRANSACTION_READ_UNCOMMITTED.equals(levelString)) { return Connection.TRANSACTION_READ_UNCOMMITTED; } else if (TRANSACTION_READ_COMMITTED.equals(levelString)) { return Connection.TRANSACTION_READ_COMMITTED; } else if (TRANSACTION_REPEATABLE_READ.equals(levelString)) { return Connection.TRANSACTION_REPEATABLE_READ; } else if (TRANSACTION_SERIALIZABLE.equals(levelString)) { return Connection.TRANSACTION_SERIALIZABLE; } else {/*from w w w . j av a 2 s . c om*/ return -1; } }