/** * Close the cursor and database connection. Make call to cleanupOnClose so sub classes can cleanup * any resources they have allocated. */ @Override protected void doClose() throws Exception { initialized = false; JdbcUtils.closeResultSet(this.rs); rs = null; cleanupOnClose(); if(this.con != null) { this.con.setAutoCommit(this.initialConnectionAutoCommit); } if (useSharedExtendedConnection && dataSource instanceof ExtendedConnectionDataSourceProxy) { ((ExtendedConnectionDataSourceProxy)dataSource).stopCloseSuppression(this.con); if (!TransactionSynchronizationManager.isActualTransactionActive()) { DataSourceUtils.releaseConnection(con, dataSource); } } else { JdbcUtils.closeConnection(this.con); } }
csds.stopCloseSuppression(connection); DataSourceUtils.releaseConnection(connection, csds); template.queryForList("select egg from bar");
@Test public void testOperationWithDirectCloseCall() throws SQLException { Connection con = mock(Connection.class); DataSource ds = mock(DataSource.class); when(ds.getConnection()).thenReturn(con); // con1 con.close(); when(ds.getConnection()).thenReturn(con); // con2 con.close(); final ExtendedConnectionDataSourceProxy csds = new ExtendedConnectionDataSourceProxy(ds); Connection con1 = csds.getConnection(); csds.startCloseSuppression(con1); Connection con1_1 = csds.getConnection(); assertSame("should be same connection", con1_1, con1); con1_1.close(); // no mock call for this - should be suppressed Connection con1_2 = csds.getConnection(); assertSame("should be same connection", con1_2, con1); Connection con2 = csds.getConnection(); assertNotSame("shouldn't be same connection", con2, con1); csds.stopCloseSuppression(con1); assertTrue("should be able to close connection", csds.shouldClose(con1)); con1_1 = null; con1_2 = null; con1.close(); assertTrue("should be able to close connection", csds.shouldClose(con2)); con2.close(); }
Connection con4 = csds.getConnection(); assertNotSame("shouldn't be same connection", con4, con3); csds.stopCloseSuppression(con3); assertTrue("should be able to close connection", csds.shouldClose(con3)); con3_1 = null;
/** * Close the cursor and database connection. Make call to cleanupOnClose so sub classes can cleanup * any resources they have allocated. */ @Override protected void doClose() throws Exception { initialized = false; JdbcUtils.closeResultSet(this.rs); rs = null; cleanupOnClose(); if(this.con != null) { this.con.setAutoCommit(this.initialConnectionAutoCommit); } if (useSharedExtendedConnection && dataSource instanceof ExtendedConnectionDataSourceProxy) { ((ExtendedConnectionDataSourceProxy)dataSource).stopCloseSuppression(this.con); if (!TransactionSynchronizationManager.isActualTransactionActive()) { DataSourceUtils.releaseConnection(con, dataSource); } } else { JdbcUtils.closeConnection(this.con); } }