当前位置: 首页>>代码示例>>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;未经允许,请勿转载。