本文整理汇总了Java中org.springframework.jdbc.datasource.DataSourceUtils.doReleaseConnection方法的典型用法代码示例。如果您正苦于以下问题:Java DataSourceUtils.doReleaseConnection方法的具体用法?Java DataSourceUtils.doReleaseConnection怎么用?Java DataSourceUtils.doReleaseConnection使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.springframework.jdbc.datasource.DataSourceUtils
的用法示例。
在下文中一共展示了DataSourceUtils.doReleaseConnection方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: process
import org.springframework.jdbc.datasource.DataSourceUtils; //导入方法依赖的package包/类
public List<Object> process(List<ConcurrentRequest> requests) {
List<Object> resultList = new ArrayList<Object>();
if (CollectionUtils.isEmpty(requests))
return resultList;
List<RequestDepository> requestsDepo = fetchConnectionsAndDepositForLaterUse(requests);
final CountDownLatch latch = new CountDownLatch(requestsDepo.size());
List<Future<Object>> futures = new ArrayList<Future<Object>>();
try {
for (RequestDepository rdepo : requestsDepo) {
ConcurrentRequest request = rdepo.getOriginalRequest();
final SqlMapClientCallback action = request.getAction();
final Connection connection = rdepo.getConnectionToUse();
futures.add(request.getExecutor().submit(new Callable<Object>() {
public Object call() throws Exception {
try {
return executeWith(connection, action);
} finally {
latch.countDown();
}
}
}));
}
try {
latch.await();
} catch (InterruptedException e) {
throw new ConcurrencyFailureException(
"interrupted when processing data access request in concurrency", e);
}
} finally {
for (RequestDepository depo : requestsDepo) {
Connection springCon = depo.getConnectionToUse();
DataSource dataSource = depo.getOriginalRequest().getDataSource();
try {
if (springCon != null) {
if (depo.isTransactionAware()) {
springCon.close();
} else {
DataSourceUtils.doReleaseConnection(springCon, dataSource);
}
}
} catch (Throwable ex) {
logger.info("Could not close JDBC Connection", ex);
}
}
}
fillResultListWithFutureResults(futures, resultList);
return resultList;
}
示例2: doReleaseConnection
import org.springframework.jdbc.datasource.DataSourceUtils; //导入方法依赖的package包/类
public void doReleaseConnection(Connection con) {
try {
if (dataSource != null) {
DataSourceUtils.doReleaseConnection(con, dataSource);
} else {
con.close();
}
} catch (SQLException e) {
e.printStackTrace();
}
}
示例3: releaseConnection
import org.springframework.jdbc.datasource.DataSourceUtils; //导入方法依赖的package包/类
@Override
protected void releaseConnection(Connection connection, DataSource dataSource) throws SQLException {
if (connection != null) {
LOGGER.debug(() -> "Closing connection: [" + connection + "]");
DataSourceUtils.doReleaseConnection(connection, dataSource);
}
}
示例4: closeConnection
import org.springframework.jdbc.datasource.DataSourceUtils; //导入方法依赖的package包/类
/**
* 关闭数据库连接
*/
private void closeConnection() {
try {
if (sharedCOnnectionDepth > 0) {
sharedCOnnectionDepth--;
if (sharedCOnnectionDepth == 0 && sharedConnection != null) {
DataSourceUtils.doReleaseConnection(sharedConnection, dataSource);
}
}
} catch (SQLException ex) {
throw new PetaPojoException("close connection error", ex);
}
}
示例5: doReleaseConnection
import org.springframework.jdbc.datasource.DataSourceUtils; //导入方法依赖的package包/类
public static void doReleaseConnection(Connection connection) {
DataSource dataSource = (DataSource)AppContext.getBean(DATA_SOURCE_BEAN_ID);
try {
DataSourceUtils.doReleaseConnection(connection, dataSource);
} catch (SQLException e) {
e.printStackTrace();
}
}