Results 1 to 3 of 3

Thread: JdbcCursorInputSource and transaction

  1. #1

    Default 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 ?
    --
    Gaëtan PITTELOUD

  2. #2
    Join Date
    Jun 2005
    Posts
    4,241

    Default

    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.

  3. #3
    Join Date
    Dec 2006
    Posts
    1,061

    Default

    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.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •