You are viewing a plain text version of this content. The canonical link for it is here.
Posted to ojb-dev@db.apache.org by "Clute, Andrew" <An...@osn.state.oh.us> on 2004/02/11 17:23:26 UTC

Someone shed some light on using LocalTxManager versus JTATxManager?

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


Re: Someone shed some light on using LocalTxManager versus JTATxManager?

Posted by Armin Waibel <ar...@apache.org>.
Hi Andrew,

Clute, Andrew wrote:

> 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.

you are right

> 
> 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

yep

> -Remove my calls in the above method that do any transaction work?

yep, or don't use cm-tx and replace pb-transaction demarcation by 
JTA-UserTransaction calls.

> 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?

It's not allowed to start a PB-transaction in managed environment. OJB 
try to participate in current JTA-tx using Synchronization interface.

> 
> 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?

yes, all seems ok.

In managed environment you have to use DataSource from your appServer, 
only these connections will be associated with the JTA tx.

If you use PB-api I recommend you to get latest from CVS (HEAD is 
stable). I made some changes to let PB-api participate in JTA-tx and 
update the deployment doc (to generate local docs call
bin\build.bat htmldoc). Have a look in 
...broker.core.PersistenceBrokerFactorySyncImpl, this class manages the 
JTA integration when using PB-api.

regards,
Armin

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

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