User: sparre
Date: 01/09/26 13:50:21
Modified: src/main/org/jboss/tm/usertx/client
ClientUserTransaction.java
ClientUserTransactionObjectFactory.java
Added: src/main/org/jboss/tm/usertx/client
ServerVMClientUserTransaction.java
Log:
Fixed bug #463790
Revision Changes Path
1.3 +4 -38
jboss/src/main/org/jboss/tm/usertx/client/ClientUserTransaction.java
Index: ClientUserTransaction.java
===================================================================
RCS file:
/cvsroot/jboss/jboss/src/main/org/jboss/tm/usertx/client/ClientUserTransaction.java,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -r1.2 -r1.3
--- ClientUserTransaction.java 2001/08/03 17:15:57 1.2
+++ ClientUserTransaction.java 2001/09/26 20:50:21 1.3
@@ -46,7 +46,7 @@
* propagation contexts of the transactions started here.
*
* @author <a href="mailto:[EMAIL PROTECTED]">Ole Husgaard</a>
- * @version $Revision: 1.2 $
+ * @version $Revision: 1.3 $
*/
public class ClientUserTransaction
implements UserTransaction,
@@ -79,19 +79,9 @@
*/
private ClientUserTransaction()
{
- // See if we have a local TM
- try {
- new InitialContext().lookup("java:/TransactionManager");
-
- // This instance lives in the server.
- isInServer = true;
- } catch (NamingException ex) {
- // This instance lives in a stand-alone client.
- isInServer = false;
-
- // No local TM: Set TPC Factory on GenericProxy.
- GenericProxy.setTPCFactory(this);
- }
+ // Tell the proxy that this is the factory for
+ // transaction propagation contexts.
+ GenericProxy.setTPCFactory(this);
}
// Public --------------------------------------------------------
@@ -103,9 +93,6 @@
public void begin()
throws NotSupportedException, SystemException
{
- if (isInServer)
- throw new SystemException("Cannot use this in the server.");
-
ThreadInfo info = getThreadInfo();
try {
@@ -130,9 +117,6 @@
IllegalStateException,
SystemException
{
- if (isInServer)
- throw new SystemException("Cannot use this in the server.");
-
ThreadInfo info = getThreadInfo();
try {
@@ -165,9 +149,6 @@
IllegalStateException,
SystemException
{
- if (isInServer)
- throw new SystemException("Cannot use this in the server.");
-
ThreadInfo info = getThreadInfo();
try {
@@ -192,9 +173,6 @@
throws IllegalStateException,
SystemException
{
- if (isInServer)
- throw new SystemException("Cannot use this in the server.");
-
ThreadInfo info = getThreadInfo();
try {
@@ -215,9 +193,6 @@
public int getStatus()
throws SystemException
{
- if (isInServer)
- throw new SystemException("Cannot use this in the server.");
-
ThreadInfo info = getThreadInfo();
Object tpc = info.getTpc();
@@ -240,9 +215,6 @@
public void setTransactionTimeout(int seconds)
throws SystemException
{
- if (isInServer)
- throw new SystemException("Cannot use this in the server.");
-
getThreadInfo().setTimeout(seconds);
}
@@ -279,12 +251,6 @@
// Private -------------------------------------------------------
-
- /**
- * Flag that this instance is living in the server.
- * Instances living in the server VM cannot be used.
- */
- private boolean isInServer;
/**
* The RMI remote interface to the real tx service
1.4 +35 -5
jboss/src/main/org/jboss/tm/usertx/client/ClientUserTransactionObjectFactory.java
Index: ClientUserTransactionObjectFactory.java
===================================================================
RCS file:
/cvsroot/jboss/jboss/src/main/org/jboss/tm/usertx/client/ClientUserTransactionObjectFactory.java,v
retrieving revision 1.3
retrieving revision 1.4
diff -u -r1.3 -r1.4
--- ClientUserTransactionObjectFactory.java 2001/08/03 17:15:57 1.3
+++ ClientUserTransactionObjectFactory.java 2001/09/26 20:50:21 1.4
@@ -10,10 +10,13 @@
import java.util.Hashtable;
import javax.naming.Context;
+import javax.naming.InitialContext;
import javax.naming.Reference;
import javax.naming.Name;
+import javax.naming.NamingException;
import javax.naming.spi.ObjectFactory;
+import javax.transaction.UserTransaction;
/**
* This is an object factory for producing client
@@ -21,21 +24,48 @@
* usage for standalone clients.
*
* @author <a href="mailto:[EMAIL PROTECTED]">Ole Husgaard</a>
- * @version $Revision: 1.3 $
+ * @version $Revision: 1.4 $
*/
public class ClientUserTransactionObjectFactory
implements ObjectFactory
{
+ /**
+ * The <code>UserTransaction</code> this factory will return.
+ * This is evaluated lazily in {@link #getUserTransaction()}.
+ */
+ static private UserTransaction userTransaction = null;
+
+ /**
+ * Get the <code>UserTransaction</code> this factory will return.
+ * This may return a cached value from a previous call.
+ */
+ static private UserTransaction getUserTransaction()
+ {
+ if (userTransaction == null) {
+ // See if we have a local TM
+ try {
+ new InitialContext().lookup("java:/TransactionManager");
+
+ // We execute in the server.
+ userTransaction = ServerVMClientUserTransaction.getSingleton();
+ } catch (NamingException ex) {
+ // We execute in a stand-alone client.
+ userTransaction = ClientUserTransaction.getSingleton();
+ }
+ }
+ return userTransaction;
+ }
+
public Object getObjectInstance(Object obj, Name name,
Context nameCtx, Hashtable environment)
throws Exception
{
Reference ref = (Reference)obj;
- if (ref.getClassName().equals(ClientUserTransaction.class.getName())) {
- return ClientUserTransaction.getSingleton();
- }
- return null;
+ if (!ref.getClassName().equals(ClientUserTransaction.class.getName()))
+ return null;
+
+ return getUserTransaction();
}
}
1.1
jboss/src/main/org/jboss/tm/usertx/client/ServerVMClientUserTransaction.java
Index: ServerVMClientUserTransaction.java
===================================================================
/*
* JBoss, the OpenSource J2EE webOS
*
* Distributable under LGPL license.
* See terms of license at gnu.org.
*/
package org.jboss.tm.usertx.client;
import javax.naming.InitialContext;
import javax.naming.NamingException;
import javax.transaction.UserTransaction;
import javax.transaction.TransactionManager;
import javax.transaction.Transaction;
import javax.transaction.Status;
import javax.transaction.NotSupportedException;
import javax.transaction.SystemException;
import javax.transaction.RollbackException;
import javax.transaction.HeuristicMixedException;
import javax.transaction.HeuristicRollbackException;
/**
* The client-side UserTransaction implementation for clients
* operating in the same VM as the server.
* This will delegate all UserTransaction calls to the
* <code>TransactionManager</code> of the server.
*
* @author <a href="mailto:[EMAIL PROTECTED]">Ole Husgaard</a>
* @version $Revision: 1.1 $
*/
public class ServerVMClientUserTransaction
implements UserTransaction
{
// Static --------------------------------------------------------
/**
* Our singleton instance.
*/
private static ServerVMClientUserTransaction singleton = null;
/**
* Return a reference to the singleton instance.
*/
public static ServerVMClientUserTransaction getSingleton()
{
if (singleton == null)
singleton = new ServerVMClientUserTransaction();
return singleton;
}
// Constructors --------------------------------------------------
/**
* Create a new instance.
*/
private ServerVMClientUserTransaction()
{
// Lookup the local TM
try {
tm = (TransactionManager)new
InitialContext().lookup("java:/TransactionManager");
} catch (NamingException ex) {
throw new RuntimeException("TransactionManager not found: " + ex);
}
}
// Public --------------------------------------------------------
//
// implements interface UserTransaction
//
public void begin()
throws NotSupportedException, SystemException
{
tm.begin();
}
public void commit()
throws RollbackException,
HeuristicMixedException,
HeuristicRollbackException,
SecurityException,
IllegalStateException,
SystemException
{
tm.commit();
}
public void rollback()
throws SecurityException,
IllegalStateException,
SystemException
{
tm.rollback();
}
public void setRollbackOnly()
throws IllegalStateException,
SystemException
{
tm.setRollbackOnly();
}
public int getStatus()
throws SystemException
{
return tm.getStatus();
}
public void setTransactionTimeout(int seconds)
throws SystemException
{
tm.setTransactionTimeout(seconds);
}
// Private -------------------------------------------------------
/**
* The <code>TransactionManagerz</code> we delegate to.
*/
private TransactionManager tm;
}
_______________________________________________
Jboss-development mailing list
[EMAIL PROTECTED]
https://lists.sourceforge.net/lists/listinfo/jboss-development