BATCH-970: made the transaction participation configurable
This commit is contained in:
@@ -134,6 +134,8 @@ public class JdbcCursorItemReader<T> extends AbstractItemCountingItemStreamItemR
|
||||
|
||||
private boolean driverSupportsAbsolute = false;
|
||||
|
||||
private boolean participateInExistingTransaction = false;
|
||||
|
||||
public JdbcCursorItemReader() {
|
||||
setName(ClassUtils.getShortName(JdbcCursorItemReader.class));
|
||||
}
|
||||
@@ -171,7 +173,12 @@ public class JdbcCursorItemReader<T> extends AbstractItemCountingItemStreamItemR
|
||||
Assert.state(dataSource != null, "DataSource must not be null.");
|
||||
|
||||
try {
|
||||
this.con = DataSourceUtils.getConnection(dataSource);
|
||||
if (participateInExistingTransaction) {
|
||||
this.con = DataSourceUtils.getConnection(dataSource);
|
||||
}
|
||||
else {
|
||||
this.con = dataSource.getConnection();
|
||||
}
|
||||
preparedStatement = this.con.prepareStatement(sql, ResultSet.TYPE_FORWARD_ONLY, ResultSet.CONCUR_READ_ONLY,
|
||||
ResultSet.HOLD_CURSORS_OVER_COMMIT);
|
||||
applyStatementSettings(preparedStatement);
|
||||
@@ -377,6 +384,19 @@ public class JdbcCursorItemReader<T> extends AbstractItemCountingItemStreamItemR
|
||||
this.driverSupportsAbsolute = driverSupportsAbsolute;
|
||||
}
|
||||
|
||||
/**
|
||||
* Indicate whether the cursor should be opened as part of an existing transaction or if it
|
||||
* should be opened in its own transaction. The default is for the cursor to be opened in its
|
||||
* own transaction. If you set this flag to true then you should wrap the DataSource in a
|
||||
* {@link org.springframework.jdbc.datasource.SingleConnectionDataSource} to prevent the
|
||||
* connection from being closed after each commit.
|
||||
*
|
||||
* @param participateInExistingTransaction <code>false</code> by default
|
||||
*/
|
||||
public void setParticipateInExistingTransaction(boolean participateInExistingTransaction) {
|
||||
this.participateInExistingTransaction = participateInExistingTransaction;
|
||||
}
|
||||
|
||||
/**
|
||||
* Check the result set is in synch with the currentRow attribute. This is
|
||||
* important to ensure that the user hasn't modified the current row.
|
||||
|
||||
Reference in New Issue
Block a user