Announcement Announcement Module
Collapse
No announcement yet.
JdbcCursorInputSource and transaction Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • JdbcCursorInputSource and transaction

    As I walk through source code for JdbcCursorInputSource, I notice that the executeQuery() method get a SqlConnection by just calling DataSource.getConnection(). Shouldn't it be something like DataSourceUtils.getconnection(DataSource ds), as we might want to get the connection from the current transaction ?

  • #2
    Actually you almost certainly do not want the connection from the current transaction. The cursor has to stay open over the whole step execution (the duration of many transactions), so we have to explicitly manage the connection indepdendently of DataSourceUtils.

    Comment


    • #3
      The other reason that the DataSourceUtils isn't used is because it will close a connection after a transaction completes:

      Code:
      		public void afterCompletion(int status) {
      			// If we haven't closed the Connection in beforeCompletion,
      			// close it now. The holder might have been used for other
      			// cleanup in the meantime, for example by a Hibernate Session.
      			if (this.holderActive) {
      				// The thread-bound ConnectionHolder might not be available anymore,
      				// since afterCompletion might get called from a different thread.
      				if (TransactionSynchronizationManager.hasResource(this.dataSource)) {
      					TransactionSynchronizationManager.unbindResource(this.dataSource);
      				}
      				this.holderActive = false;
      				if (this.connectionHolder.hasConnection()) {
      					releaseConnection(this.connectionHolder.getConnection(), this.dataSource);
      					// Reset the ConnectionHolder: It might remain bound to the thread.
      					this.connectionHolder.setConnection(null);
      				}
      				this.connectionHolder.reset();
      			}
      		}
      See the TransactionSyncrhonization method for more information on afterCompletion.

      Comment

      Working...
      X