ATG Transaction Best Practices Dos and Donts

Creation and Updation of Repository Items must be enclosed
with a  Transaction block.

Reading Items from Repository does not require a transaction.

if we are doing multiple operations and is dependant on each other,then we must use a single transaction,this is to either

commit or roll back the entire transaction,other wise each
operation has to be enclosed in a separate transaction block.

Use the finally block to end the transaction,this will ensure
our statement will get executed even an Exception is thrown.

Dont try to call nested methods inside one transaction,this will not serve the purpose.

Dont use any complex logic,inside the transaction,like below.

Bad Practice

try {
      td.begin(this.getTransactionManager(),
      TransactionDemarcation.REQUIRED);
      MutableRepositoryItem newItem =
      mutableRepository.createItem(“shipping”);
      float price = calculateOrdertotal(order);
    }

Best Practice


     float price = calculateOrdertotal(order);
     if(price != null){
     try {
      td.begin(this.getTransactionManager(),       
      TransactionDemarcation.REQUIRED);
      MutableRepositoryItem newItem =                               
      newItem.setPropertyValue(“price”, price);
     }

Try to minimise your code inside the transaction block.

Don’t use forward use redirect if you have code which opens a transaction, encounters an error flagging the transaction for rollback, to an error URL. Some app-server executes the rendering of the forward in the context of the transaction that was rolled back. If that is the case, a rollback exception occurs.

Also see Form Handler Best Practices

0 comments:

Post a Comment

Related Posts Plugin for WordPress, Blogger...