db-ojb-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Clute, Andrew" <Andrew.Cl...@osn.state.oh.us>
Subject Someone shed some light on using LocalTxManager versus JTATxManager?
Date Wed, 11 Feb 2004 16:23:26 GMT
Here is my current implementation:
-I am using the LocalTxManager
-I have a collection EJB's that act as SessionFacade's to my Processor
layers that handle all of my business logic
-This is deployed to Jboss 3.2.3 as an EAR file with all of my EJB's and
WAR clients
-I have been using the EJB's methods as my demarcation point for
starting/stoping the transactions inside of OJB

	Here is sameple code of one of my methods:
	/**
	  * @ejb.interface-method
	  *	tview-type="both" 
	 **/

	public CatalogItem addCatalogItem(CatalogItem item) throws
OSNException
	{
		PersistenceBroker pb =
PersistenceBrokerFactory.defaultPersistenceBroker();
		try
		{
			pb.beginPersistenceTransaction();
			CatalogProcessor processor = new
CatalogProcessor(pb);
			returnValue = processor.addCatalogItem(item);
			pb.commitTransaction();
		}
		catch (OSNException ex)
		{
			pb.removeFromCache(item);
			pb.abortTransaction();
			throw ex;
		}

		return returnValue;
	}

>From my current understaning of the situation, because I am using the
LocalTxManager, I am in fact ignoring any of the transaction services
built into Jboss to manage any of the data that OJB commits to.

What I would like to do is move to Container-Managed transactions, so I
can start to take advantage of XA Two-phase commits, and have my OJB
work and any other work I do ,say, putting messages on JMS Queue's, etc,
be in the same logic transaction.

Am I correct in my thinking that if I do want to move to CM
transactions, I would need to do the following:
-Change my transaction manager to JTATxManager and the
JTATransactionManagerClass to JBossTransactionManagerFactory
-Remove my calls in the above method that do any transaction work? If I
do not explicitly begin a transaction on the PersistenceBroker, does the
PB look to see what type of TxManager I have, and if it a JTATxManager,
it will use that transaction that was created by the EJB container?

So, my code would look like the following then, assuming that I made the
TxManager changes in the OJB.properties file:

	public CatalogItem addCatalogItem(CatalogItem item) throws
OSNException
	{
		PersistenceBroker pb =
PersistenceBrokerFactory.defaultPersistenceBroker();
		try
		{
			CatalogProcessor processor = new
CatalogProcessor(pb);
			returnValue = processor.addCatalogItem(item);
					}
		catch (OSNException ex)
		{
			pb.removeFromCache(item);
			//EJB exception is what causes the container to
roll back.
			throw new EJBException(ex);
		}

		return returnValue;
	}

Is my thinking correct? Is this is what is needed to make OJB use a CM
transaction?

Thanks!

-Andrew

---------------------------------------------------------------------
To unsubscribe, e-mail: ojb-dev-unsubscribe@db.apache.org
For additional commands, e-mail: ojb-dev-help@db.apache.org


Mime
View raw message