TransactionService Initialization

This is a set simple of examples that illustrate the different ways of initializing the Transaction Service in a Java application. There are four different example programs that show different initialization techniques, they are:
InitOrb         // ORB default TransactionService configuration
InitUser        // User instantiated TransactionService configuration
InitClientOrb   // Pure Client ORB default TransactionService configuration
InitClientUser  // Pure Client User instantiated TransactionService configuration

1 Compiling and Executing

Use the supplied ANT script to compile and execute the example programs. To compile run
ant
To execute first two tests run
ant run.orb

ant run.user

To execute the pure client test cases you need to start the server process and then run the client tests. To start the server run
ant run.user
To execute the client tests run
ant run.client.user

2 InitOrb Implementation

To make the Novell exteNd Messaging Platform's JTS the default transaction service of the ORB you should modify the transactions.properties file, which is located either in the top-level lib or the jre/lib/ext/classes directories) as follows:
#
# JBroker Transaction Service Properties
#
                                                                           
# the class name of the transaction service
transaction.service.class=com.sssw.jts.api.TransactionService
The following example shows how to find initial reference to the TransactionService when the Novell exteNd Messaging Platform's JTS is configured as the default service, call its recover method and resolve the JTS and JTA transaction manager interfaces to start transactions.
package init;
                                                                           
import javax.transaction.TransactionManager;
                                                                           
import org.omg.CORBA.ORB;
                                                                           
import org.omg.CosTransactions.Current;
import org.omg.CosTransactions.TransactionFactory;
                                                                           
import com.sssw.jts.api.TransactionService;
                                                                           
/**
   Initialization as default TransactionService 
 */
                                                                           
public class InitOrb
{
    public static void main(String args[]) throws Exception
    {
    |   System.setProperty("transaction.service.id", "EXAMPLES/INIT");
    |                                                                      
    |   System.out.println("+ Initialize ORB");
    |   ORB orb = ORB.init(args, null);
    |                                                                      
    |   System.out.println("+ Find TransactionService");
    |   TransactionService ts = (TransactionService)
    |       orb.resolve_initial_references("TransactionService");
    |                                                                      
    |   System.out.println("+ Get TransactionManager");
    |   TransactionManager tm = ts.getTransactionManager();
    |                                                                      
    |   System.out.println("+ Get Current");
    |   Current tc = (Current)
    |       orb.resolve_initial_references("TransactionCurrent");
    |                                                                      
    |   System.out.println("+ Get TransactionFactory");
    |   TransactionFactory tf = (TransactionFactory)
    |       orb.resolve_initial_references("TransactionFactory");
    |                                                                      
    |   System.out.println("+ Test Ok");
    }
}

3 InitUser Implementation

To remove the Novell exteNd Messaging Platform's JTS as the default transaction service of the ORB you should modify the transactions.properties file, which is located either in the top-level lib or the jre/lib/ext/classes directories) as follows:
#
# JBroker Transaction Service Properties
#
                                                                           
# the class name of the transaction service
transaction.service.class=
The following example shows how to find instantiate the TransactionService object, set it as the transaction service to the ORB, call its recover method, and use the JTS and JTA transaction manager interfaces to start transactions.
package init;
                                                                           
import java.util.Properties;
                                                                           
import javax.transaction.TransactionManager;
                                                                           
import org.omg.CORBA.ORB;
                                                                           
import org.omg.CosTransactions.Current;
import org.omg.CosTransactions.Control;
import org.omg.CosTransactions.TransactionFactory;
                                                                           
import com.sssw.jbroker.api.transaction.TSIdentification;
                                                                           
import com.sssw.jts.api.TransactionService;
                                                                           
public class InitUser
{
    public static void main(String args[]) throws Exception
    {
    |   System.setProperty("transaction.service.id", "EXAMPLES/INIT");
    |   System.setProperty(TransactionService.PROPERTY_LOG_DIRECTORY, "../../logs");
    |   System.setProperty(TransactionService.PROPERTY_LOG_FILEPREALLOC, "false");
    |                                                                      
    |   //
    |   // [1] Create a TransactionService with some properties
    |   //
    |   // NOTE: SKIP THIS STEP IF USING DEFAULT TRANSACTIONSERVICE
    |   // SET IN THE transactions.properties FILE.
    |   //
    |   System.out.println("+ Create TransactionService ... ");
    |   TransactionService jts = new TransactionService();
    |                                                                      
    |   //
    |   // [2] Initialize the ORB
    |   //
    |   System.setProperty("ORBPort", "5555");
    |   ORB orb = ORB.init(args, null);
    |                                                                      
    |   //
    |   // [3] Register the TransactionService
    |   // 
    |   // NOTE: SKIP THIS STEP IF USING DEFAULT TRANSACTIONSERVICE
    |   // SET IN THE tranactions.properties FILE.
    |   //
    |   System.out.println("+ Register TransactionService ... ");
    |   TSIdentification tsIdent = (TSIdentification)
    |       orb.resolve_initial_references("TSIdentification");
    |   tsIdent.identifyTransactionService(jts);
    |                                                                      
    |   //
    |   // [4] Recover TM auto-recovery and synchronously
    |   // before creating transactions...
    |   //
    |   System.out.println("+ Recover TransactionService ... ");
    |   TransactionService ts = (TransactionService)
    |       orb.resolve_initial_references("TransactionService");
    |                                                                      
    |   ts.recover(null, false, null);
    |                                                                      
    |   if (args.length > 0) {
    |   |   System.out.println("+ ORB on Port 5555 Running ...");
    |   |   orb.run();
    |   |   System.out.println("+ ORB on Port 5555 Done ...");
    |   |   System.exit(0);
    |   }
    |                                                                      
    |   //
    |   // [5] Transaction Management
    |   //
    |   System.out.println("+ Create Transaction with Current object ... ");
    |   Current txCurrent = (Current)
    |       orb.resolve_initial_references("TransactionCurrent");
    |   txCurrent.begin();
    |   txCurrent.rollback();
    |                                                                      
    |   System.out.println("+ Create Transaction with TransactionFactory object ... ");
    |   TransactionFactory txFactory = (TransactionFactory)
    |       orb.resolve_initial_references("TransactionFactory");
    |                                                                      
    |   Control tx = txFactory.create(60);
    |   tx.get_terminator().rollback();
    |                                                                      
    |   System.out.println("+ Create Transaction with TransactionManager object ... ");
    |   TransactionManager tm = ts.getTransactionManager();
    |   tm.begin();
    |   tm.rollback();
    }
}

4 InitClientOrb Implementation

To make the Novell exteNd Messaging Platform's JTS as the default transaction service of the pure client ORB, you should modify the transactions.properties file, which is located either in the top-level lib or the jre/lib/ext/classes directories) as follows:
#
# JBroker Transaction Service Properties
#
                                                                           
# the class name of the transaction service
transaction.service.class=com.sssw.jts.client.TransactionService
transaction.service.remote.addresses=iiop:gooners:5555
The following example shows how to find initial reference to the TransactionService when the Novell exteNd Messaging Platform's JTS is configured as the default service in a pure client ORB. In the pure client environment, an active transaction manager is required to be running on a server.
package init;
                                                                           
import java.util.Properties;
                                                                           
import javax.transaction.UserTransaction;
                                                                           
import org.omg.CORBA.ORB;
                                                                           
import org.omg.CosTransactions.Current;
import org.omg.CosTransactions.Control;
import org.omg.CosTransactions.TransactionFactory;
                                                                           
import com.sssw.jbroker.api.transaction.TSIdentification;
                                                                           
import com.sssw.jts.client.TransactionService;
                                                                           
public class InitClientOrb
{
    public static void main(String args[]) throws Exception
    {
    |   //
    |   // [1] Initialize the ORB
    |   //
    |   ORB orb = ORB.init(args, null);
    |                                                                      
    |   //
    |   // [2] Find TransactionFactory, Current ...
    |   //
    |   System.out.println("+ Create Transaction with Current object ... ");
    |   Current txCurrent = (Current)
    |       orb.resolve_initial_references("TransactionCurrent");
    |   txCurrent.begin();
    |   txCurrent.rollback();
    |                                                                      
    |   System.out.println("+ Create Transaction with TransactionFactory object ... ");
    |   TransactionFactory txFactory = (TransactionFactory)
    |       orb.resolve_initial_references("TransactionFactory");
    |                                                                      
    |   Control tx = txFactory.create(60);
    |   tx.get_terminator().rollback();
    |                                                                      
    |   System.out.println("+ Create Transaction with UserTransaction object ... ");
    |   UserTransaction userTrans = (UserTransaction)
    |       orb.resolve_initial_references("UserTransaction");
    |                                                                      
    |   userTrans.begin();
    |   userTrans.rollback();
    }
}

5 InitClientUser Implementation

To remove the Novell exteNd Messaging Platform's JTS as the default transaction service of the pure client ORB, you should modify the transactions.properties file, which is located either in the top-level lib or the jre/lib/ext/classes directories) as follows:
#
# JBroker Transaction Service Properties
#
                                                                           
# the class name of the transaction service
transaction.service.class=
The following example shows how to find instantiate the TransactionService object, set it as the transaction service to the pure client ORB, and use the JTS and JTA transaction manager interfaces to start transactions.
package init;
                                                                           
import java.util.Properties;
                                                                           
import javax.transaction.UserTransaction;
                                                                           
import org.omg.CORBA.ORB;
                                                                           
import org.omg.CosTransactions.Current;
import org.omg.CosTransactions.Control;
import org.omg.CosTransactions.TransactionFactory;
                                                                           
import com.sssw.jbroker.api.transaction.TSIdentification;
                                                                           
import com.sssw.jts.client.TransactionService;
                                                                           
public class InitClientUser
{
    public static void main(String args[]) throws Exception
    {
    |   //
    |   // [1] Create a TransactionService with some properties
    |   //
    |   // NOTE: SKIP THIS STEP IF USING DEFAULT TRANSACTIONSERVICE
    |   // SET IN THE transactions.properties FILE.
    |   //
    |   System.out.println("+ Create TransactionService ... ");
    |   Properties props = new Properties();
    |   props.setProperty("transaction.service.remote.addresses", "iiop:localhost:2506");
    |   TransactionService jts = new TransactionService(props);
    |                                                                      
    |   //
    |   // [2] Initialize the ORB
    |   //
    |   ORB orb = ORB.init(args, null);
    |                                                                      
    |   //
    |   // [3] Register the TransactionService
    |   // 
    |   System.out.println("+ Register TransactionService ... ");
    |   TSIdentification tsIdent = (TSIdentification)
    |       orb.resolve_initial_references("TSIdentification");
    |   tsIdent.identifyTransactionService(jts);
    |                                                                      
    |   //
    |   // [4] Transaction Management
    |   //
    |   System.out.println("+ Create Transaction with Current object ... ");
    |   Current txCurrent = (Current)
    |       orb.resolve_initial_references("TransactionCurrent");
    |   txCurrent.begin();
    |   txCurrent.rollback();
    |                                                                      
    |   System.out.println("+ Create Transaction with TransactionFactory object ... ");
    |   TransactionFactory txFactory = (TransactionFactory)
    |       orb.resolve_initial_references("TransactionFactory");
    |                                                                      
    |   Control tx = txFactory.create(60);
    |   tx.get_terminator().rollback();
    |                                                                      
    |   System.out.println("+ Create Transaction with UserTransaction object ... ");
    |   UserTransaction userTrans = (UserTransaction)
    |       orb.resolve_initial_references("UserTransaction");
    |                                                                      
    |   userTrans.begin();
    |   userTrans.rollback();
    }
}
Copyright © 2000-2003, Novell, Inc. All rights reserved.