PS:  You should be able to call commit multiple times, without re-calling start...that should allow you to do what you want. (i.e. don't call start multiple times).

On 11/30/05, Clinton Begin <[EMAIL PROTECTED]> wrote:

Jeff,

Commit should not be decrementing the throttle.  Instead, .endTransaction() should be called for every call to .startTransaction().

Even if commit is called, end should be called too.

Cheers,
Clinton


On 11/30/05, Jeff Roberts < [EMAIL PROTECTED]> wrote:
 I have encountered what I believe to be a bug in the TransactionManager class.  It appears to me that the commit() method should be doing a txThrottle.decrement().  A slight change to the end() method is required as well to prevent too many decrement() calls.

I have fixed the code and verified that it works, but wanted to make sure that what I found is in fact a bug and not misuse of the TransactionManager.

I have a long running job and am using iBatis.  This job does numerous startTransaction(), commitTransaction() iterations.  What is happening, is that each of my startTransaction() calls increments the throttle through the begin() method on TransactionManager.  When I commit, I would expect this to decrement the throttle, but it doesn't.  Eventually, my code iterates enough times that it increments the throttle and I end up in a wait that never ends.

If it is deemed a bug, I 'm happy to submit my fix through Jira.  For clarification, here is what I did to fix the problem.

Class com.ibatis.sqlmap.engine.transaction.TransactionManager

First, I modified the commit method as shown below.  I've commented the line that I added.

 public void commit(SessionScope session) throws SQLException, TransactionException {
    Transaction trans = session.getTransaction();
    TransactionState state = session.getTransactionState();
    if (state == TransactionState.STATE_USER_PROVIDED) {
      throw new TransactionException("TransactionManager could not commit.  " +
          "A user provided connection is currently being used by this session.  " +
          "You must call the commit() method of the Connection directly.  " +
          "The calling .setUserConnection (null) will clear the user provided transaction.");
    } else if (state != TransactionState.STATE_STARTED) {
      throw new TransactionException("TransactionManager could not commit.  No transaction is started.");
    }
    if (session.isCommitRequired() || forceCommit) {
      trans.commit();
      session.setCommitRequired(false);
    }
    // Added by XWIRE
    txThrottle.decrement();
    session.setTransactionState(TransactionState.STATE_COMMITTED);
  }


I also had to edit the end() method as well as show below.  Again, this change is commented.


public void end(SessionScope session) throws SQLException, TransactionException {
    Transaction trans = session.getTransaction();
    TransactionState state = session.getTransactionState();

    if (state == TransactionState.STATE_USER_PROVIDED) {
      throw new TransactionException("TransactionManager could not end this transaction.  " +
          "A user provided connection is currently being used by this session.  " +
          "You must call the rollback() method of the Connection directly.  " +
          "The calling .setUserConnection (null) will clear the user provided transaction.");
    }

    try {
      if (trans != null) {
        try {
          if (state != TransactionState.STATE_COMMITTED) {
            if (session.isCommitRequired() || forceCommit) {
              trans.rollback();
              session.setCommitRequired(false);
            }
          }
        } finally {
          trans.close();
        }
      }
    } finally {

    // XWIRE - Added second condition to make sure throttle is not decremented if the transaction is already committed.
      if (state != TransactionState.STATE_ENDED && state != TransactionState.STATE_COMMITTED ) {
        txThrottle.decrement();
      }

      session.setTransaction(null);
      session.setTransactionState (TransactionState.STATE_ENDED);
    }
  }


Thanks,
Jeff Roberts


Yahoo! DSL Something to write home about. Just $16.99/mo. or less



Reply via email to