Add connection parameter to AbstractCursorItemReader#cleanupOnClose
This change makes it possible to (re)use the same connection used in the openCursor method to clean up resources when the reader is closed. Resolves #1696
This commit is contained in:
committed by
Mahmoud Ben Hassine
parent
2952e9a039
commit
e7ea16c9bc
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2006-2019 the original author or authors.
|
||||
* Copyright 2006-2020 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -396,7 +396,7 @@ implements InitializingBean {
|
||||
initialized = false;
|
||||
JdbcUtils.closeResultSet(this.rs);
|
||||
rs = null;
|
||||
cleanupOnClose();
|
||||
cleanupOnClose(con);
|
||||
|
||||
if(this.con != null && !this.con.isClosed()) {
|
||||
this.con.setAutoCommit(this.initialConnectionAutoCommit);
|
||||
@@ -413,8 +413,23 @@ implements InitializingBean {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Clean up resources.
|
||||
* @throws Exception If unable to clean up resources
|
||||
* @deprecated This method is deprecated in favor of
|
||||
* {@link AbstractCursorItemReader#cleanupOnClose(java.sql.Connection)} and
|
||||
* will be removed in a future release
|
||||
*/
|
||||
@Deprecated
|
||||
protected abstract void cleanupOnClose() throws Exception;
|
||||
|
||||
/**
|
||||
* Clean up resources.
|
||||
* @param connection to the database
|
||||
* @throws Exception If unable to clean up resources
|
||||
*/
|
||||
protected abstract void cleanupOnClose(Connection connection) throws Exception;
|
||||
|
||||
/**
|
||||
* Execute the statement to open the cursor.
|
||||
*/
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2006-2019 the original author or authors.
|
||||
* Copyright 2006-2020 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -50,6 +50,7 @@ import org.springframework.util.ClassUtils;
|
||||
* @author Peter Zozom
|
||||
* @author Robert Kasanicky
|
||||
* @author Thomas Risberg
|
||||
* @author Mahmoud Ben Hassine
|
||||
*/
|
||||
public class JdbcCursorItemReader<T> extends AbstractCursorItemReader<T> {
|
||||
|
||||
@@ -143,12 +144,26 @@ public class JdbcCursorItemReader<T> extends AbstractCursorItemReader<T> {
|
||||
|
||||
/**
|
||||
* Close the cursor and database connection.
|
||||
* @deprecated This method is deprecated in favor of
|
||||
* {@link JdbcCursorItemReader#cleanupOnClose(java.sql.Connection)} and will
|
||||
* be removed in a future release
|
||||
*/
|
||||
@Override
|
||||
@Deprecated
|
||||
protected void cleanupOnClose() throws Exception {
|
||||
JdbcUtils.closeStatement(this.preparedStatement);
|
||||
}
|
||||
|
||||
/**
|
||||
* Close the cursor and database connection.
|
||||
* @param connection to the database
|
||||
*/
|
||||
@Override
|
||||
protected void cleanupOnClose(Connection connection) throws Exception {
|
||||
JdbcUtils.closeStatement(this.preparedStatement);
|
||||
JdbcUtils.closeConnection(connection);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getSql() {
|
||||
return this.sql;
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2006-2019 the original author or authors.
|
||||
* Copyright 2006-2020 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -55,6 +55,7 @@ import org.springframework.util.ClassUtils;
|
||||
* </p>
|
||||
*
|
||||
* @author Thomas Risberg
|
||||
* @author Mahmoud Ben Hassine
|
||||
*/
|
||||
public class StoredProcedureItemReader<T> extends AbstractCursorItemReader<T> {
|
||||
|
||||
@@ -239,12 +240,26 @@ public class StoredProcedureItemReader<T> extends AbstractCursorItemReader<T> {
|
||||
|
||||
/**
|
||||
* Close the cursor and database connection.
|
||||
* @deprecated This method is deprecated in favor of
|
||||
* {@link StoredProcedureItemReader#cleanupOnClose(java.sql.Connection)} and
|
||||
* will be removed in a future release
|
||||
*/
|
||||
@Override
|
||||
@Deprecated
|
||||
protected void cleanupOnClose() throws Exception {
|
||||
JdbcUtils.closeStatement(this.callableStatement);
|
||||
}
|
||||
|
||||
/**
|
||||
* Close the cursor and database connection.
|
||||
* @param connection to the database
|
||||
*/
|
||||
@Override
|
||||
protected void cleanupOnClose(Connection connection) throws Exception {
|
||||
JdbcUtils.closeStatement(this.callableStatement);
|
||||
JdbcUtils.closeConnection(connection);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getSql() {
|
||||
if (callString != null) {
|
||||
|
||||
Reference in New Issue
Block a user