本文整理汇总了Java中org.apache.commons.dbcp.BasicDataSource.setDefaultTransactionIsolation方法的典型用法代码示例。如果您正苦于以下问题:Java BasicDataSource.setDefaultTransactionIsolation方法的具体用法?Java BasicDataSource.setDefaultTransactionIsolation怎么用?Java BasicDataSource.setDefaultTransactionIsolation使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.apache.commons.dbcp.BasicDataSource
的用法示例。
在下文中一共展示了BasicDataSource.setDefaultTransactionIsolation方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: _get
import org.apache.commons.dbcp.BasicDataSource; //导入方法依赖的package包/类
private static BasicDataSource _get(String D, String username, String passwd, String url, int N) {
BasicDataSource external = new BasicDataSource();
external.setDriverClassName(D.trim());
if (!X.isEmpty(username)) {
external.setUsername(username.trim());
}
if (!X.isEmpty(passwd)) {
external.setPassword(passwd.trim());
}
external.setUrl(url.trim());
external.setMaxActive(N);
external.setDefaultAutoCommit(true);
external.setMaxIdle(N);
external.setMaxWait(MAX_WAIT_TIME);
external.setDefaultAutoCommit(true);
external.setDefaultReadOnly(false);
external.setDefaultTransactionIsolation(Connection.TRANSACTION_READ_COMMITTED);
external.setValidationQuery(null);// VALIDATION_SQL);
external.setPoolPreparedStatements(true);
return external;
}
示例2: setupDataSource
import org.apache.commons.dbcp.BasicDataSource; //导入方法依赖的package包/类
@SuppressWarnings("unchecked")
private static void setupDataSource(Isolation isolation) {
ds = new BasicDataSource();
Endpoint locatorEndPoint = (Endpoint) (NetworkServerHelper.getNetworkLocatorEndpoints()).get(0);
String hostname = getHostNameFromEndpoint(locatorEndPoint);
int port = getPortFromEndpoint(locatorEndPoint);
connProp.putAll(getExtraConnProp());
try {
ds.setDriverClassName(driver);
ds.setUrl(protocol + hostname+ ":" + port);
ds.setMaxActive(100);
if (isolation == Isolation.NONE) {
} else if (isolation == Isolation.READ_COMMITTED) {
ds.setDefaultTransactionIsolation(Connection.TRANSACTION_READ_COMMITTED);
ds.setDefaultAutoCommit(false);
} else {
ds.setDefaultTransactionIsolation(Connection.TRANSACTION_REPEATABLE_READ);
ds.setDefaultAutoCommit(false);
}
StringBuilder sb = new StringBuilder();
for (Iterator<?> iter = connProp.entrySet().iterator(); iter.hasNext(); ) {
Map.Entry<String, String> entry = (Map.Entry<String, String>) iter.next();
ds.addConnectionProperty(entry.getKey(), entry.getValue()); //add additional conn prop
sb.append(entry.getKey() + " is set to " + entry.getValue() +"\n");
}
dsSet = true;
Log.getLogWriter().info("basic source url is set as " + ds.getUrl());
Log.getLogWriter().info("basic data source setting the following connection prop: " + sb.toString());
} catch (Exception e) {
throw new TestException("could not set data source" + TestHelper.getStackTrace(e));
}
}