Hello,

I'd like to call a Stateless Session Bean remote interface method and within
that method, handle database retry logic a certain number of times if a
problem should occur.

In particular, I'm wondering how I can re-set the transaction state after I
catch a SQLException but before I perform the retry.  (so I can perform the
retry on a clean slate)

I'd like to do something like this:

  class DBUpdateHelper {    /* non EJB helper class used by EJBs */
     void doDatabaseWork( Connection conn ) throws SQLException {
       insert into table 1
       insert into table 2
     }
  }

  void someEJBmethod( ) throws RemoteException {
     int numTries= 0;
     DBUpdateHelper dbuh= new DBUpdateHelper ()
     while ( numTries < 5 ) {
        numTries++;
        try {
           Connection conn= ...;
           dbuh.doDatabaseWork( conn );
           return;
        } catch( SQLException ) {
           (Q1) somehow reset transaction state here-- rollback?
           conn.close();
           Thread.sleep(1000);  // sleep 1 second
        } catch( Exception e ) {
           throw new RemoteException( e )
        }
     }
     throw new RemoteException("Could not update database after 5
tries...");
  }

In this case, (Q1) represents the point at which I need to re-set the
transaction state in some manner.
Has anyone else tried to do database retries WITHIN the EJB?   If so, how
can this be done?

The spec appears to preclude usage of ctx.getUserTransaction().rollback()
within a TX_REQUIRED ejb.

It appears it would be possible to place the retry outside the EJB, but for
performance reasons, I'd like to place the retries within the EJB.

It also appears Bean-managed transactions in the SSB are a possibility, but
due to the numerous issues with them, I'd like to avoid them if possible.

Thanks for any thoughts!

-Steve Roth, [EMAIL PROTECTED]

===========================================================================
To unsubscribe, send email to [EMAIL PROTECTED] and include in the body
of the message "signoff EJB-INTEREST".  For general help, send email to
[EMAIL PROTECTED] and include in the body of the message "help".

Reply via email to