本文整理匯總了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();
}
}