-
1. Re: Transaction via JNDI
kconner Jan 22, 2007 1:05 PM (in response to rookie1977)Do you mean the current transaction? If so lookup the TransactionManager and use the getTransaction() method.
-
2. Re: Transaction via JNDI
rookie1977 Jan 22, 2007 1:19 PM (in response to rookie1977)That is what I am looking for, but I am looking for "independance" from JBossTS, so that I can transparently fetch Transaction from JNDI instead of
javax.transaction.TransactionManager transactionManager = com.arjuna.ats.jta.TransactionManager.transactionManager();
javax.transaction.Transaction transaction = transactionManager.getTransaction(); -
3. Re: Transaction via JNDI
kconner Jan 22, 2007 1:21 PM (in response to rookie1977)You have independence, you retrieve the transaction manager from JNDI :-)
-
4. Re: Transaction via JNDI
kconner Jan 22, 2007 1:22 PM (in response to rookie1977)Sorry, should have added the JNDI name (java:/TransactionManager).
-
5. Re: Transaction via JNDI
rookie1977 Jan 22, 2007 1:24 PM (in response to rookie1977)Thank you very much for quick response.
Greetings :) -
-
7. Re: Transaction via JNDI
rookie1977 Jan 23, 2007 4:57 AM (in response to rookie1977)I still have a problem. When I retrieve the object bound to the "java:/TransactionManager" name I get javax.naming.Reference.
Reference ref = (Reference) new InitialContext().lookup("java:/TransactionManager");
However the ref.size() returns 0 so I can not get the object that is underlying this logical name. -
8. Re: Transaction via JNDI
rookie1977 Jan 23, 2007 4:58 AM (in response to rookie1977)Note that I have setup-ed the JNDI context, using -D parameters (java.naming.factory.initial, java.naming.factory.url.pkgs).
-
9. Re: Transaction via JNDI
rookie1977 Jan 23, 2007 6:41 AM (in response to rookie1977)Here is my little contribution for this problem. Thanks to the http://mail-archives.apache.org/mod_mbox/tomcat-dev/200501.mbox/%3CEBCEA7135D99624F973B12302C3717FF06C65D6E@scenm1.sysadmin.suny.edu%3E
public static TransactionManager getObjectInstance(Reference reference) throws Exception { String factoryClassName = reference.getFactoryClassName(); String className = reference.getClassName(); log.warn("Factory Class Name=" + factoryClassName); log.warn("Class Name=" + className); final Class factoryClass; ClassLoader tcl = Thread.currentThread().getContextClassLoader(); if (tcl != null) { log.warn("Using the context class loader"); try { factoryClass = tcl.loadClass(factoryClassName); } catch (ClassNotFoundException exception) { log.warn("1", exception); NamingException namingException = new NamingException( "Could not load resource factory class '" + factoryClassName + "' using the context class loader,ClassNotFoundException:" + exception.getMessage()); namingException.setRootCause(exception); throw namingException; } } else { try { factoryClass = Class.forName(factoryClassName); } catch (ClassNotFoundException exception) { log.warn("Could not load resource factory class", exception); NamingException namingException = new NamingException( "Could not load resource factory class '" + factoryClassName + "' using the JVM class loader,ClassNotFoundException:" + exception.getMessage()); namingException.setRootCause(exception); throw namingException; } } final ObjectFactory factory; try { factory = (ObjectFactory) factoryClass.newInstance(); } catch (Throwable throwable) { log.warn("Could notinstantiate factory class", throwable); NamingException namingException = new NamingException( "Could notinstantiate factory class '" + factoryClass.toString() + "': " + throwable.getMessage()); namingException.setRootCause(throwable); throw namingException; } Object newObject = factory.getObjectInstance(reference, null, null,null); if(newObject!=null) { log.warn("Returning object of type = " + newObject.getClass().getName()); } TransactionManager transactionManager = (TransactionManager) newObject; return transactionManager; }
-
10. Re: Transaction via JNDI
kconner Jan 23, 2007 7:21 AM (in response to rookie1977)Yes, the transaction manager is bound as a reference.
I'm surprised you had to handle it in the above fashion though, this is normally handled by the app server lookup.
Can you describe your setup? -
11. Re: Transaction via JNDI
rookie1977 Jan 23, 2007 8:48 AM (in response to rookie1977)I am running stand alone, non-managed environment (no EJB container) for some prototype system. Just a bunch of main methods (recovery, server, client)...