當前位置: 首頁>>代碼示例>>Java>>正文


Java DataSourceUtils.doReleaseConnection方法代碼示例

本文整理匯總了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;
}
 
開發者ID:alibaba,項目名稱:cobarclient,代碼行數:57,代碼來源:DefaultConcurrentRequestProcessor.java

示例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();
    }
}
 
開發者ID:lftao,項目名稱:jkami,代碼行數:12,代碼來源:RunConfing.java

示例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);
	}
}
 
開發者ID:holon-platform,項目名稱:holon-datastore-jdbc,代碼行數:8,代碼來源:DefaultSpringJdbcDatastore.java

示例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);
    }
}
 
開發者ID:gejinlove,項目名稱:petapojo,代碼行數:16,代碼來源:Database.java

示例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();
	}
}
 
開發者ID:billchen198318,項目名稱:bamboobsc,代碼行數:9,代碼來源:DataUtils.java


注:本文中的org.springframework.jdbc.datasource.DataSourceUtils.doReleaseConnection方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。