If you set connection.setAutoCommit(false) to open a transaction, and then, if
you notice that your set of queries fail, then you should also call the
connection.rollback() operation to discard them.
On-the-fly example (hope it works ;^):


So in this case if you have an interceptor like:

 public int preInsert(HttpServletRequest request, Hashtable fieldValues,
          DbFormsConfig config, Connection con)
            throws ValidationException {


return orderShip(fieldValues);


}


public int orderShip (String productId, String orderId) { boolean ok = true; try { con.setAutoCommit(false); updateOrderItem(productId, orderId); con.commit(); } catch (SqlException ex) { ok= false; con.rollback(); } finally { if (con != null) con.close();


} if (ok) return GRANT_OPERATION; else return DENY_OPERATION; }


In this case then you wouldn't need con.setAutoCommit(true); --would you?



In this case then if the transactions before the main transaction fails, and DENY_OPERATION is returned,
  public void orderShip (String productId, String orderId)
  {
     try
     {
       con.setAutoCommit(false);
       updateOrderItem(productId, orderId);
       con.commit();
     }
     catch (SqlException ex)
     {
       con.rollback();
     }
     finally
     {
       if (con != null)
         con.close();
     }
  }

Any database event checks if there is any interceptor object binded to the
current main table. If yes, the db event uses table.processInterceptors to
execute the interceptor's PRE_INSERT hook method.
If the interceptor ***returns a DENY_OPERATION code***, the table object fires
a SqlException catched by the Controller object.
The controller then calls cleanUpConnectionAfterException(con) method that:


- checks if the current connection belongs to an open transaction
  (con != null) && (!con.getAutoCommit())
  - if yes, calls
    con.rollback();
    con.setAutoCommit(true);
    to discard transaction db operations and set the autoCommitMode to ON
    to prevent to add more operations into the transaction queue.

Finally the controller executes closeConnections(connections) to
close the connection.

Your code example could be useful to build a transactional-interceptor test
case for dbforms...


Regards,
Luca

______________________________________________
Sunil Mishra, Manager, ADP Wilco (India) Private Limited
* +91-40-2340 8600 x-8202 ---- * +91-98490-61241




-------------------------------------------------------
This SF.net email is sponsored by: The SF.net Donation Program.
Do you like what SourceForge.net is doing for the Open
Source Community?  Make a contribution, and help us add new
features and functionality. Click here: http://sourceforge.net/donate/
_______________________________________________
DbForms Mailing List

http://www.wap-force.net/dbforms



-- Shawn

Happily using M2, Opera's revolutionary e-mail client: http://www.opera.com/m2/


------------------------------------------------------- This SF.net email is sponsored by: The SF.net Donation Program. Do you like what SourceForge.net is doing for the Open Source Community? Make a contribution, and help us add new features and functionality. Click here: http://sourceforge.net/donate/ _______________________________________________ DbForms Mailing List

http://www.wap-force.net/dbforms

Reply via email to