Skip to main content

ATG - how to use the Transaction Manager

Basic concepts of Java transaction

In its simplest definition, a transaction is a set of actions that is treated as an atomic unit; either all actions take place (the transaction commits), or none of them take place (the transaction rolls back).

Managing transactions is one of the primary tasks of an application server. The application server keeps track of transactions, remembering which transaction is associated with which request, and what transactional resources (such as JDBC or JMS connection) are involved. Each active transaction is represented by a transaction object, which implements the interface javax.transaction.Transaction.

A transaction is usually associated with a thread and only one transaction can be associated with a thread at any one time. A central service, called the Transaction Manager, is responsible for keeping track of all these transactions. The Transaction Manager is implemented through the Java Transaction API (JTA).

Transaction and Dynamo applications

In Dynamo applications, the TransactionManager object is represented by a Nucleus component, /atg/dynamo/transaction/TransactionManager. Nucleus components can get a pointer directly to the /atg/dynamo/transaction/TransactionManager component. Dynamo also exposes this component to standard J2EE components, such as servlets and EJBs, through the JNDI name dynamo:/atg/dynamo/transaction/TransactionManager.

In order for a transaction to keep track of all the resources, those resources must be enlisted with the transaction. Application server does this when we get the resource connection through a conection factory. These factory objects are available in Dynamo as Nucleus services. For example, the standard Dynamo DataSource object is found at /atg/dynamo/service/jdbc/JTDataSource. Nucleus components should acquire resources through these proper connection factory services, rather than accessing drivers directly from their managers. Dynamo’s default configuration uses a JDBC driver configured to simulate two-phase commits to work with JDBC drivers that do not support the two-phase commit protocol.

Best practice in dynamo transaction handling

The application should not attempt to acquire the resource once and pass it around from component to component in the interest of avoiding the code for acquiring or closing the connection. The application server make sure that same Connection object must be returned each time a connection is requested throughout a single transaction. Application components are required to close JDBC connections when they finish doing their individual portion of work. Rather than actually closing the connection to the database, the application server intercepts these close requests and interprets them as signals from the application that it is done with the connection for the time being. The application server then responds to that signal by returning the connection to a pool, or by maintaining the connection’s transactional association.

Transaction demarcation : doing small and complete tasks

For doing some small set of tasks by a thread which is already in a transaction, the thread can suspend the current transaction. After suspending, the transaction still exists and keeps track of the resources it has used so far, but any further work done by the thread does not use that transaction. After the transaction is suspended, the thread can create a transaction. After ending this new transaction, the previously suspended transaction can be resumed. An application server can suspend and resume transactions through calls to the TransactionManager object , but individual applications should not perform these operations directly. Instead, applications should use J2EE transaction demarcation facilities.

Transaction demarcation always wraps a sequence of actions. The demarcation initializes some transactional behavior before the demarcated area begins, then ends that transactional behavior when the demarcated area ends. The application server uses these demarcations to determine the appropriate calls to the TransactionManager object.

following are the differetn transaction demarcation modes ---> Required, RequiresNew , NotSupported , Supports , Mandatory , Never.

The class atg.dtm.UserTransactionDemarcation can be used by J2EE components and Nucleus components to perform basic transaction demarcation. This class accesses the UserTransaction object to perform its operations. The class atg.dtm.TransactionDemarcation can be used by Nucleus components to demarcate areas of code at a fine granularity. J2EE components cannot use this class, because it accesses the TransactionManager object directly.

Demarcation Code Sample


try{
try{
atg.dtm.TransactionDemarcation transactionDemarcation = new TransactionDemarcation();
.....
if (isTransactionMarkedAsRollBack()){
    getTransactionManager().getTransaction().rollback();
}
transactionDemarcation.begin(getTransactionManager(),transactionDemarcation.REQUIRES_NEW);
.....
}finally {
transactionDemarcation.end();
}
}catch (TransactionDemarcationException transactionDemarcationException) {
    <handle the transactionDemarcationException>
}

Demarcation in Pages

The DSP tag libraries dsp:beginTransaction, dsp:commitTransaction, dsp:demarcateTransaction, dsp:rollbackTransaction, dsp:setTransactionRollbackOnly, dsp:transactionStatus are available for transaction management. Also the droplets /atg/dynamo/transaction/droplet/Transaction and /atg/dynamo/transaction/droplet/EndTransaction  can be used to start and transaction in pages.

Debugging rollbacks


To debug the transaction rollbacks, in the TranasactionManager component, set debugTracesForRollbacks to true. So that application throws the rollback details, else you will never know which component actually set transaction to rollback.

Comments

  1. Hi Mr.Thomas,
    I am new to ATG and running into an issue...I posted this question in Oracle atg forum also...would you be able to give any suggestions?

    I am using atg 9.1 and weblogic 10.3.2. Installed both s/w and started weblogic server. I am using cim.bat to configure and I am stuck at a point where it asks for the app server I am using and I selected 'Weblogic' and when it asked for the path..I gave the correct path where weblogic is installed...but it says Weblogic lib path not found...even though I can see the server/lib directory....any suggestions please to resolve this problem?

    ReplyDelete
  2. Nice topic,see some good tips about using transactions in the below link
    http://atgtipsandtweaks.blogspot.com/2012/05/atg-transaction-best-practices.html

    ReplyDelete
  3. @ Anonymous : Sorry, I haven't used "cim.bat" , what is this file ? Is this specific to weblogic ?

    ReplyDelete

Post a Comment

Popular posts from this blog

ATG - more about Forms and Form Handlers

An ATG form is defined by the dsp:form tag, which typically encloses DSP tags that specify form elements, such as dsp:input that provide direct access to Nucleus component properties. Find below a sample dsp:form tag.    <dsp:form action="/testPages/showPersonProperties.jsp" method="post" target="_top">      <p>Name: <dsp:input bean="/samples/Person.name" type="text"/>      <p>Age: <dsp:input bean="/samples/Person.age" type="text" value="30"/>      <p><dsp:input type="submit" bean="/samples/Person.submit"/> value="Click to submit"/>    </dsp:form>   When the user submits the form, the /samples/Person.name property is set to the value entered in the input field.Unlike standard HTML, which requires the name attribute for most input tags; the name attribute is optional for DSP form element tags. If an input tag omits the n...

Eclipse plug-in to create Class and Sequence diagrams

ModelGoon is an Eclipse plug-in avaiable for UML diagram generation from Java code. It can be used to generate Package Dependencies Diagram, Class Diagram, Interaction Diagram and Sequence Diagram. You coud get it from http://marketplace.eclipse.org/content/modelgoon-uml4java Read more about it and see some vedios about how to create the class and sequence diagram @ http://www.modelgoon.org/?tag=eclipse-plugin Find some snapshots below which gives an idea about the diagram generation.

ATG Search Indexing - behind the scene steps explained

Read more about the search indexing @  http://tips4ufromsony.blogspot.com/2011/11/atg-search-architectural-flow-search.html ATG search indexing involves index file creation, deploying and copying the index file to the search engine's box. The steps can be divided into Initial stage, Preparing Content, Indexing and Deploying. Please find below the detailed analysis of each step. 1. Initial stage:        a. Check whether the folder deployshare configured correctly @ LaunchingService.deployShare  ( \atg\search\routing\LaunchingService.deployShare ). Lets assume that it is configured to \Search2007.1\SearchEngine\i686-win32-vc71\buildedIndexFiles.        b. Lets assume that the index file folder ( \Search2007.1\SearchEngine\i686-win32-vc71\indexFiles)  has the following segments (folders) currently :                     66900...

Good features of Eclipse 3.6 (Eclipse Helios) JDT

Read the Eclipse Galileo features @  http://tips4ufromsony.blogspot.com/2011/10/good-features-of-eclipse35-eclipse.html New options in Open Resource dialog : The Open Resource dialog supports three new features: • Path patterns: If the pattern contains a /, the part before the last / is used to match a path in the workspace: • Relative paths: For example, "./T" matches all files starting with T in the folder of the active editor or selection: • Closer items on top: If the pattern matches many files with the same name, the files that are closer to the currently edited or selected resource are shown on top of the matching items list. MarketPlace :  Searching and adding new plugins for Eclipse have always been a challenge. The Eclipse Marketplace makes this much easier – it allows you to not only search a central location of all Eclipse plugins, but also allows you to find the most recent and the most popular plugins. Fix multiple proble...

ATG Product Catalog schema ER diagram

Check out the O rder schema ER-Diagram @   http://tips4ufromsony.blogspot.in/2012/02/atg-order-schema-er-diagram.html Check out the User Profile  schema ER-Diagram @ http://tips4ufromsony.blogspot.in/2012/03/atg-user-profile-schema-er-diagram.html If you would like to know the relationship between different Product Catalog tables, please find below screen shots of  Product Catalog schema ER Diagrams.