All,

I need an atomic transaction for inserting data to several tables. iBATIS supports that. I looked at the jpetstore code. I found that atomic transaction could be made at both service and DAO level. Here are some jpetstore codes.


in OrderService.java
  public void insertOrder(Order order) {
    try {
      // Get the next id within a separate transaction
      order.setOrderId(getNextId("ordernum"));

      daoManager.startTransaction();

      itemDao.updateAllQuantitiesFromOrder(order);
      orderDao.insertOrder(order);

      daoManager.commitTransaction();
    } finally {
      daoManager.endTransaction();
    }
  }

in AccountSqlMapDao.java
  public void insertAccount(Account account) {
    update("insertAccount", account);     //  btw, why is update? should it be insert? it seems to me that actual action is controlled by action id not by key word (update)
    update("insertProfile", account);
    update("insertSignon", account);
  }

in AccountService.java
 public void insertAccount(Account account) {
    accountDao.insertAccount(account);
  }


insertOrder is apparently an atomic transaction, which is enforced at service level. My question is whether insertAccount is an atomic transaction, i.e. what if
"update("insertSignon", account);" fails? Should we enforce it at DAO level (put three updates between startTransaction and endTransaction)? or we can do same thing as inserOrder, i.e. put "accountDao.insertAccount(account);" between daoManager.startTransaction and daoManager.endTransaction.

If we use Abator to generate the DAO code, it makes sense that atomic transaction is enforced at service level. But from software architecture point of view, atomic transaction should be pushed down to DAO level. any suggestions?

thanks,
Tony

Reply via email to