Java Code Examples for org.springframework.jdbc.datasource.DataSourceUtils.doReleaseConnection()

The following are Jave code examples for showing how to use doReleaseConnection() of the org.springframework.jdbc.datasource.DataSourceUtils class. You can vote up the examples you like. Your votes will be used in our system to get more good examples.
+ Save this method
Example 1
Project: jkami   File: RunConfing.java   View Source Code Vote up 5 votes
public void doReleaseConnection(Connection con) {
    try {
        if (dataSource != null) {
            DataSourceUtils.doReleaseConnection(con, dataSource);
        } else {
            con.close();
        }
    } catch (SQLException e) {
        e.printStackTrace();
    }
}
 
Example 2
Project: holon-datastore-jdbc   File: DefaultSpringJdbcDatastore.java   View Source Code Vote up 5 votes
@Override
protected void releaseConnection(Connection connection, DataSource dataSource) throws SQLException {
	if (connection != null) {
		LOGGER.debug(() -> "Closing connection: [" + connection + "]");
		DataSourceUtils.doReleaseConnection(connection, dataSource);
	}
}
 
Example 3
Project: petapojo   File: Database.java   View Source Code Vote up 5 votes
/**
 * 关闭数据库连接
 */
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);
    }
}
 
Example 4
Project: bamboobsc   File: DataUtils.java   View Source Code Vote up 5 votes
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();
	}
}
 
Example 5
Project: cobarclient   File: DefaultConcurrentRequestProcessor.java   View Source Code Vote up 4 votes
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;
}