You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@tomee.apache.org by adxun <ad...@live.cn> on 2013/01/24 03:01:19 UTC

about openejb standalone transaction control

UserTransaction ut
=(UserTransaction)ctx.lookup("java:com/env/UserTransaction") not found
naming

why?





--
View this message in context: http://openejb.979440.n4.nabble.com/about-openejb-standalone-transaction-control-tp4660358.html
Sent from the OpenEJB Dev mailing list archive at Nabble.com.

Re: about openejb standalone transaction control

Posted by adxun <ad...@live.cn>.
I  need to defined 2 XADataSource ,but I dont know to define in openejb.xml 

if openejb not suported?





--
View this message in context: http://openejb.979440.n4.nabble.com/about-openejb-standalone-transaction-control-tp4660358p4660369.html
Sent from the OpenEJB Dev mailing list archive at Nabble.com.

Re: about openejb standalone transaction control

Posted by adxun <ad...@live.cn>.
http://commons.apache.org/dbcp/apidocs/org/apache/commons/dbcp/managed/BasicManagedDataSource.htmlshould
be available even if not configured/explicitely managed. 


404 not found!





--
View this message in context: http://openejb.979440.n4.nabble.com/about-openejb-standalone-transaction-control-tp4660358p4660373.html
Sent from the OpenEJB Dev mailing list archive at Nabble.com.

Re: about openejb standalone transaction control

Posted by adxun <ad...@live.cn>.
now I want 2 database h2 and db2 in a transaction! how to to set XADataSource
in openejb.xml ?



--
View this message in context: http://openejb.979440.n4.nabble.com/about-openejb-standalone-transaction-control-tp4660358p4660402.html
Sent from the OpenEJB Dev mailing list archive at Nabble.com.

Re: about openejb standalone transaction control

Posted by adxun <ad...@live.cn>.
<?xml version="1.0" encoding="UTF-8"?>
<openejb>


<Container id="My Singleton Container" type="SINGLETON">
  # Specifies the maximum time an invocation could wait for the
  # singleton bean instance to become available before giving up.
  #
  # After the timeout is reached a
javax.ejb.ConcurrentAccessTimeoutException
  # will be thrown.
  #
  # Usable time units: nanoseconds, microsecons, milliseconds,
  # seconds, minutes, hours, days.  Or any combination such as
  # "1 hour and 27 minutes and 10 seconds"

  AccessTimeout = 30 seconds

</Container>


<Container id="My Stateful Container" type="STATEFUL">
  # Specifies the maximum time an invocation could wait for the
  # stateful bean instance to become available before giving up.
  #
  # After the timeout is reached a
javax.ejb.ConcurrentAccessTimeoutException
  # will be thrown.
  #
  # Usable time units: nanoseconds, microsecons, milliseconds,
  # seconds, minutes, hours, days.  Or any combination such as
  # "1 hour and 27 minutes and 10 seconds"

  AccessTimeout = 30 seconds

  #  The passivator is responsible for writing beans to disk
  #  at passivation time. Different passivators can be used
  #  by setting this property to the fully qualified class name
  #  of the PassivationStrategy implementation. The passivator
  #  is not responsible for invoking any callbacks or other
  #  processing, its only responsibly is to write the bean state
  #  to disk.
  #
  #  Known implementations:
  #     org.apache.openejb.core.stateful.RAFPassivater
  #     org.apache.openejb.core.stateful.SimplePassivater

  Passivator   org.apache.openejb.core.stateful.SimplePassivater

  #  Specifies the time to wait between invocations. This
  #  value is measured in minutes. A value of 5 would
  #  result in a time-out of 5 minutes between invocations.
  #  A value of zero would mean no timeout.

  TimeOut  20

  # Specifies the frequency (in seconds) at which the bean cache is checked
for
  # idle beans.

  Frequency 60

  #  Specifies the size of the bean pools for this
  #  stateful SessionBean container.

  Capacity  1000

  #  Property name that specifies the number of instances
  #  to passivate at one time when doing bulk passivation.
  #  Must be less than the PoolSize.

  BulkPassivate  100

</Container>


<Container id="My Stateless Container" type="STATELESS">

  # Specifies the time an invokation should wait for an instance
  # of the pool to become available.
  #
  # After the timeout is reached, if an instance in the pool cannot
  # be obtained, the method invocation will fail.
  #
  # Usable time units: nanoseconds, microsecons, milliseconds,
  # seconds, minutes, hours, days.  Or any combination such as
  # "1 hour and 27 minutes and 10 seconds"

  AccessTimeout = 30 seconds

  # Specifies the size of the bean pools for this stateless
  # SessionBean container.  If StrictPooling is not used, instances
  # will still be created beyond this number if there is demand, but
  # they will not be returned to the pool and instead will be
  # immediately destroyed.

  MaxSize = 10

  # Specifies the minimum number of bean instances that should be in
  # the pool for each bean.  Pools are prefilled to the minimum on
  # startup.  Note this will create start order dependencies between
  # other beans that also eagerly start, such as other @Stateless
  # beans with a minimum or @Singleton beans using @Startup.  The
  # @DependsOn annotation can be used to appropriately influence
  # start order.
  #
  # The minimum pool size is rigidly maintained.  Instances in the
  # minimum side of the pool are not eligible for IdleTimeout or
  # GarbageCollection, but are subject to MaxAge and flushing.
  #
  # If the pool is flushed it is immediately refilled to the minimum
  # size with MaxAgeOffset applied.  If an instance from the minimum
  # side of the pool reaches its MaxAge, it is also immediately
  # replaced.  Replacement is done in a background queue using the
  # number of threads specified by CallbackThreads.

  MinSize = 0

  # StrictPooling tells the container what to do when the pool
  # reaches it's maximum size and there are incoming requests that
  # need instances.
  #
  # With strict pooling, requests will have to wait for instances to
  # become available. The pool size will never grow beyond the the
  # set MaxSize value.  The maximum amount of time a request should
  # wait is specified via the AccessTimeout setting.
  #
  # Without strict pooling, the container will create temporary
  # instances to meet demand. The instances will last for just one
  # method invocation and then are removed.
  #
  # Setting StrictPooling to false and MaxSize to 0 will result in
  # no pooling. Instead instances will be created on demand and live
  # for exactly one method call before being removed.

  StrictPooling = true

  # Specifies the maximum time that an instance should live before
  # it should be retired and removed from use.  This will happen
  # gracefully.  Useful for situations where bean instances are
  # designed to hold potentially expensive resources such as memory
  # or file handles and need to be periodically cleared out.
  #
  # Usable time units: nanoseconds, microsecons, milliseconds,
  # seconds, minutes, hours, days.  Or any combination such as
  # "1 hour and 27 minutes and 10 seconds"

  MaxAge = 0 hours

  # Specifies the maximum time that an instance should be allowed to
  # sit idly in the pool without use before it should be retired and
  # removed.
  #
  # Usable time units: nanoseconds, microsecons, milliseconds,
  # seconds, minutes, hours, days.  Or any combination such as
  # "1 hour and 27 minutes and 10 seconds"

  IdleTimeout = 0 minutes

</Container>






		<Resource id="DB2" type="DataSource">
		  JdbcDriver =com.ibm.db2.jcc.DB2Driver
		  XADataSource=com.ibm.db2.jcc.DB2XADataSource
		  JdbcUrl =jdbc:db2://22.104.102.127:61118/wiki
		  UserName =wiki
		  Password =123456
		  JtaManaged =true
		</Resource>
		
		<Resource id="H2" type="DataSource">
		  JdbcDriver=org.h2.Driver
		  XADataSource=org.h2.jdbcx.JdbcDataSource
		  JdbcUrl
=jdbc:h2:tcp://22.104.178.97:8080/mem:memdb;DB_CLOSE_DELAY=-1;MODE=DB2
		  UserName =abc
		  Password =123
		  JtaManaged =true
		</Resource>		


  <Resource id="MyJmsResourceAdapter" type="ActiveMQResourceAdapter">
			# Broker configuration URI as defined by ActiveMQ 
			# see http://activemq.apache.org/broker-configuration-uri.html 
			#BrokerXmlConfig = broker:(tcp://localhost:61616)				
			# Broker address 
			ServerUrl = tcp://localhost:61616      
  </Resource>

	<Resource id="ConnectionFactory" type="javax.jms.ConnectionFactory">
      ResourceAdapter = MyJmsResourceAdapter
  </Resource>

  <Container id="MyJmsMdbContainer" type="MESSAGE">
    	ResourceAdapter = MyJmsResourceAdapter
  </Container>

<Resource id="answerQueue" type="javax.jms.Queue"/>





<Deployments dir="apps/" />



</openejb>
mdb

import java.util.Properties;
import javax.naming.Context;
import javax.naming.InitialContext;
import javax.annotation.Resource;
import javax.ejb.MessageDriven;
import javax.ejb.MessageDrivenBean;
import javax.ejb.MessageDrivenContext;
import javax.ejb.TransactionManagement;
import javax.ejb.TransactionManagementType;
import javax.ejb.EJB;
import javax.ejb.EJBException;
import javax.ejb.CreateException;
import javax.ejb.ActivationConfigProperty;
import javax.jms.Connection;
import javax.jms.ConnectionFactory;
import javax.jms.DeliveryMode;
import javax.jms.JMSException;
import javax.jms.Message;
import javax.jms.MessageListener;
import javax.jms.MessageProducer;
import javax.jms.MessageConsumer;
import javax.jms.Queue;
import javax.jms.QueueSession;
import javax.jms.Destination;
import javax.jms.Session;
import javax.jms.TextMessage;
import javax.jms.ObjectMessage;
import javax.sql.DataSource;
import javax.rmi.PortableRemoteObject;
import javax.transaction.UserTransaction;


import java.sql.*;
import javax.sql.XAConnection;
import javax.sql.XADataSource;
import com.ibm.db2.jcc.DB2Driver;
import com.ibm.db2.jcc.DB2XADataSource;
import com.ibm.db2.jcc.DB2Xid;
import org.h2.jdbcx.JdbcDataSource;
import org.h2.jdbcx.JdbcXAConnection;
import org.h2.jdbcx.JdbcConnectionPool;


@TransactionManagement(TransactionManagementType.BEAN)
@MessageDriven(activationConfig = {
	   @ActivationConfigProperty(propertyName = "destinationType",
propertyValue = "javax.jms.Queue"),
	   @ActivationConfigProperty(propertyName = "destination", propertyValue =
"userQueue")  
	    }) 	    
public class ChatBean implements MessageDrivenBean,MessageListener {
@Resource(name="ConnectionFactory")
private  	ConnectionFactory connectionFactory;
@Resource(name="answerQueue")
private  	Queue answerQueue;

		MessageDrivenContext messageDC;
		UserTransaction ut;
		DataSource h2,db2;

		public void setMessageDrivenContext(MessageDrivenContext mtc) throws
EJBException
		{
			messageDC=mtc;
			System.out.println("MessageDrivenContext setted!");
      try{
	      Properties prop = new Properties();  
	      prop.setProperty(Context.INITIAL_CONTEXT_FACTORY,
"org.apache.openejb.client.RemoteInitialContextFactory");    
	      prop.setProperty(Context.PROVIDER_URL, "ejbd://127.0.0.1:4201"); 		        
	      InitialContext ctx = new InitialContext(prop);		        

	      db2 =(DataSource) ctx.lookup("DB2");
	      h2 =(DataSource) ctx.lookup("H2");
	    }catch(Exception e){
	    	e.printStackTrace();
	    	}					
		}	
		public void ejbRemove() throws EJBException
		{
								System.out.println("MDB Delete!");		
		}
		
    public void onMessage(Message message){
    try {
                      
            ///////////////////////////////////////////////////////
            final TextMessage textMessage = (TextMessage) message;
            final String question = textMessage.getText();           
            System.out.println("Received="+question);
            
            //May call another business process start            
            		String retString = businessMethod(question);
            //May call another business process end 
               System.out.println(retString); 
             						
						javax.jms.Connection connection =
connectionFactory.createConnection();						
		        connection.start();
		        Session session = connection.createSession(false,
Session.AUTO_ACKNOWLEDGE);
		        MessageProducer producer = session.createProducer(answerQueue);
		        producer.setDeliveryMode(DeliveryMode.NON_PERSISTENT);		         		             	        		        
		        // Create a message
		        TextMessage messageRes = session.createTextMessage(retString);		
		        // Tell the producer to send the message
		        producer.send(messageRes);	   

		        // Clean up
		        if (session != null) session.close();
		        if (connection != null) connection.close();	
		        					
						System.out.println("MDB called!!!");
        } catch (Exception e) {
	        	System.out.println("error!!!");
			        	try{
			        		ut.rollback();
			        	}catch(Exception e1){
			        		System.out.println("rollback failed!!!");
			        	}
		       e.printStackTrace();
        	}
    }

    public String businessMethod(String message) throws Exception{
		        System.out.println("businessMethod!!!");
	      		ut=(UserTransaction) messageDC.getUserTransaction();
						ut.begin();								               						                 	
	    				//DataSource h2 =(DataSource) ctx.lookup("H2");  
							//XAConnection xa=h2.getXAConnection(); 
	    				java.sql.Connection connh2=h2.getConnection();	    				
	    				StringBuffer sql1 = new StringBuffer(256);
							sql1.append(" update testh set name  ='111'  where id =1 ");			
							PreparedStatement PreStmt1 =
connh2.prepareStatement(sql1.toString());
							System.out.println(sql1);
							PreStmt1.executeUpdate();
						  PreStmt1.close();
						  connh2.close();
	    				
	    				//DataSource db2 =(DataSource) ctx.lookup("DB2");
	    				//XAConnection conndb2x=db2.getXAConnection();
	    				java.sql.Connection conndb2=db2.getConnection();	    				
	    				StringBuffer sql = new StringBuffer(256);
							sql.append(" update TEST27 set name  ='131'  where id =1 ");				
							PreparedStatement PreStmt = conndb2.prepareStatement(sql.toString());
							System.out.println(sql);
							PreStmt.executeUpdate();
						  PreStmt.close();
						  conndb2.close();					  
					  ut.commit();
					  System.out.println("businessMethod finish!");
    				return "OK_Earth";
    }
}
/////////////////////////////////////////////////////////////////////////////////
mdbclient
//javac -cp
c:\openejb451\lib\javaee-api-6.0-4.jar;c:\openejb451\lib\activemq-core-5.7.0.jar;c:\openejb451\lib\openejb-client-4.5.1.jar;c:\openejb451\lib\db2jcc.jar;c:\
MdbTestClient.java
//java -cp
c:\openejb451\lib\javaee-api-6.0-4.jar;c:\openejb451\lib\activemq-core-5.7.0.jar;c:\openejb451\lib\openejb-client-4.5.1.jar;c:\openejb451\lib\slf4j-api-1.7.2.jar;c:\openejb451\lib\slf4j-jdk14-1.7.2.jar;c:\openejb451\lib\db2jcc.jar;c:\
MdbTestClient
import java.util.Properties;
import javax.naming.Context;
import javax.naming.InitialContext;
import javax.annotation.Resource;
import javax.ejb.MessageDriven;
import javax.ejb.MessageDrivenBean;
import javax.ejb.MessageDrivenContext;
import javax.ejb.EJB;
import javax.ejb.EJBException;
import javax.ejb.CreateException;
import javax.ejb.ActivationConfigProperty;
import javax.jms.Connection;
import javax.jms.QueueConnection;
import javax.jms.ConnectionFactory;
import javax.jms.QueueConnectionFactory;
import javax.jms.DeliveryMode;
import javax.jms.JMSException;
import javax.jms.Message;
import javax.jms.MessageListener;
import javax.jms.MessageProducer;
import javax.jms.MessageConsumer;
import javax.jms.Queue;
import javax.jms.QueueSession;
import javax.jms.Destination;
import javax.jms.Session;
import javax.jms.TextMessage;
import javax.jms.ObjectMessage;
import javax.rmi.PortableRemoteObject;
import org.apache.activemq.ActiveMQConnectionFactory;
import javax.sql.DataSource;

public class MdbTestClient {    

    public static void main(String[]args) throws Exception {   
	
        // 
       
System.setProperty("ConnectionFactory","connectionfactory:org.apache.activemq.ActiveMQConnectionFactory:tcp://localhost:61616");  
        
        Properties properties = new Properties();  
        properties.setProperty(Context.INITIAL_CONTEXT_FACTORY,
"org.apache.openejb.client.RemoteInitialContextFactory");    
        properties.setProperty(Context.PROVIDER_URL,
"ejbd://127.0.0.1:4201"); 
        
        //properties.setProperty(Context.SECURITY_PRINCIPAL, "Kevin");    
        //properties.setProperty(Context.SECURITY_CREDENTIALS, "password");   
        InitialContext ctx = new InitialContext(properties); 
        //  
				ConnectionFactory connectionFactory; 
        Connection connection = null;
        Session session = null;
        Queue queue=null,Aqueue=null;    
			
System.out.println("ConnectionFactory="+System.getProperty("ConnectionFactory")); 	
                   
        queue = (Queue) ctx.lookup("userQueue"); 
        Aqueue = (Queue) ctx.lookup("answerQueue"); 
        
       
connectionFactory=(ConnectionFactory)ctx.lookup("java:ConnectionFactory");
        //connectionFactory =
(ConnectionFactory)PortableRemoteObject.narrow(ctx.lookup("java:ConnectionFactory"),ConnectionFactory.class);                  	             
        connection = connectionFactory.createConnection();    
        connection.start();
        // Create a Session
        session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
        // Create a MessageProducer from the Session to the Topic or Queue
        MessageProducer producer = session.createProducer(queue);    
        producer.setDeliveryMode(DeliveryMode.NON_PERSISTENT);         
        // Create a message
        TextMessage message = session.createTextMessage("Hello World!");
        // Tell the producer to send the message
        producer.send(message);
        // Create a MessageConsumer from the Session to the Topic or Queue
        MessageConsumer consumer = session.createConsumer(Aqueue);           
				// Receive response message
				final TextMessage retMessage=(TextMessage)consumer.receive(10000);  
        final String mess=retMessage.getText();        
        System.out.println(mess);      
        // Clean up
        if (session != null) session.close();
        if (connection != null) connection.close();
        
    }    
}  





--
View this message in context: http://openejb.979440.n4.nabble.com/about-openejb-standalone-transaction-control-tp4660358p4660401.html
Sent from the OpenEJB Dev mailing list archive at Nabble.com.

Re: about openejb standalone transaction control

Posted by adxun <ad...@live.cn>.
now I can get this 2 database common connection,but can not get  their
XAConnection....



--
View this message in context: http://openejb.979440.n4.nabble.com/about-openejb-standalone-transaction-control-tp4660358p4660405.html
Sent from the OpenEJB Dev mailing list archive at Nabble.com.

Re: about openejb standalone transaction control

Posted by adxun <ad...@live.cn>.
OK,wait moment...



--
View this message in context: http://openejb.979440.n4.nabble.com/about-openejb-standalone-transaction-control-tp4660358p4660400.html
Sent from the OpenEJB Dev mailing list archive at Nabble.com.

Re: about openejb standalone transaction control

Posted by adxun <ad...@live.cn>.
I see ,but only tansaction problem

<?xml version="1.0" encoding="UTF-8"?>
<openejb>

		<Resource id="DB2" type="DataSource">
		  JdbcDriver =com.ibm.db2.jcc.DB2Driver
		  XADataSource=com.ibm.db2.jcc.DB2XADataSource
		  JdbcUrl =jdbc:db2://22.104.102.127:61118/wiki
		  UserName =wiki
		  Password =123456
		  JtaManaged =true
		</Resource>
		
		<Resource id="H2" type="DataSource">
		  JdbcDriver=org.h2.Driver
		  XADataSource=org.h2.jdbcx.JdbcDataSource
		  JdbcUrl
=jdbc:h2:tcp://22.104.178.97:8080/mem:memdb;DB_CLOSE_DELAY=-1;MODE=DB2
		  UserName =abc
		  Password =123
		  JtaManaged =true
		</Resource>		


  <Resource id="MyJmsResourceAdapter" type="ActiveMQResourceAdapter">
			# Broker configuration URI as defined by ActiveMQ 
			# see http://activemq.apache.org/broker-configuration-uri.html 
			#BrokerXmlConfig = broker:(tcp://localhost:61616)				
			# Broker address 
			ServerUrl = tcp://localhost:61616      
  </Resource>








<Deployments dir="apps/" />



</openejb>




--
View this message in context: http://openejb.979440.n4.nabble.com/about-openejb-standalone-transaction-control-tp4660358p4660404.html
Sent from the OpenEJB Dev mailing list archive at Nabble.com.

Re: about openejb standalone transaction control

Posted by Romain Manni-Bucau <rm...@gmail.com>.
hi, can you package a project (mvn is the best solution) + share your conf
reproducing it please?

copying/pasting code in mail rarely helps in practise



*Romain Manni-Bucau*
*Twitter: @rmannibucau <https://twitter.com/rmannibucau>*
*Blog: **http://rmannibucau.wordpress.com/*<http://rmannibucau.wordpress.com/>
*LinkedIn: **http://fr.linkedin.com/in/rmannibucau*
*Github: https://github.com/rmannibucau*



2013/1/25 adxun <ad...@live.cn>

> and
>
> only connect h2 database and execute a sql ,mdb client may received info
> from mdb
>
> if connect db2 database and execute same a sql  mdb client cannot received
> info from mdb?
>
> (sql operation all in mdb and sql execute successed! sql is a update
> statement)
>
> why?
>
>
>
> --
> View this message in context:
> http://openejb.979440.n4.nabble.com/about-openejb-standalone-transaction-control-tp4660358p4660394.html
> Sent from the OpenEJB Dev mailing list archive at Nabble.com.
>

Re: about openejb standalone transaction control

Posted by adxun <ad...@live.cn>.
and

only connect h2 database and execute a sql ,mdb client may received info
from mdb 

if connect db2 database and execute same a sql  mdb client cannot received
info from mdb?

(sql operation all in mdb and sql execute successed! sql is a update
statement)

why?



--
View this message in context: http://openejb.979440.n4.nabble.com/about-openejb-standalone-transaction-control-tp4660358p4660394.html
Sent from the OpenEJB Dev mailing list archive at Nabble.com.

Re: about openejb standalone transaction control

Posted by adxun <ad...@live.cn>.
and if 2 dadabase is operated,my mdb client not receive MDB return info,1
database is operated my mdb client may receive MDB return info why? mdb only
send a "hello world" 

now 2 databases transaction no valid...



--
View this message in context: http://openejb.979440.n4.nabble.com/about-openejb-standalone-transaction-control-tp4660358p4660393.html
Sent from the OpenEJB Dev mailing list archive at Nabble.com.

Re: about openejb standalone transaction control

Posted by adxun <ad...@live.cn>.
<Resource id="DB2" type="DataSource">  
 jdbcDriver=com.ibm.db2.jcc.DB2Driver 
 XADataSource = com.ibm.db2.jcc.DB2XADataSource 
 jdbcurl=.... 
user=.... 
..... 
</Resource>  

<Resource id="H2" type="DataSource">  
 jdbcDriver=org.h2.Driver 
 XADataSource = org.h2.jdbcx.JdbcDataSource
 jdbcurl=.... 
user=.... 
..... 
</Resource>  

openejb start.... 

warning:XADataSource not supported by "DB2" 

program  work fine below,but tansaction not valid! finally h2 update
sucessed,db2 error,should be both rollback!


usert.begin();


DataSource dx=(DataSource)ctx.lookup ("H2") 
//XAConnection xa=dx.getXAConnection(); 
Connection con= dx.getConnection(); 

con.execute("update.h2_tbl..set ").... 

DataSource dx=(DataSource)ctx.lookup ("DB2") 
//XAConnection xa=dx.getXAConnection(); 
Connection con= dx.getConnection(); 

con.execute("update.db2_tbl..set ").... 



user.commit();

.....................
user.rollback()





--
View this message in context: http://openejb.979440.n4.nabble.com/about-openejb-standalone-transaction-control-tp4660358p4660392.html
Sent from the OpenEJB Dev mailing list archive at Nabble.com.

Re: about openejb standalone transaction control

Posted by adxun <ad...@live.cn>.
<Resource id="DB2" type="DataSource"> 
 jdbcDriver=com.ibm.db2.jcc.DB2Driver
 XADataSource = com.ibm.db2.jcc.DB2XADataSource
 jdbcurl=....
user=....
.....
</Resource> 

openejb start....

warning:XADataSource not supported by "DB2"

program not work fine...

DB2XADataSource dx=(DB2XADataSource)ctx.lookup ("DB2")
XAConnection xa=dx.getXAConnection();
Connection con= xa.getConnection();

con.execute("update...set ")....





--
View this message in context: http://openejb.979440.n4.nabble.com/about-openejb-standalone-transaction-control-tp4660358p4660391.html
Sent from the OpenEJB Dev mailing list archive at Nabble.com.

Re: about openejb standalone transaction control

Posted by adxun <ad...@live.cn>.
import java.util.Properties;
import javax.naming.Context;
import javax.naming.InitialContext;
import javax.annotation.Resource;
import javax.ejb.MessageDriven;
import javax.ejb.MessageDrivenBean;
import javax.ejb.MessageDrivenContext;
import javax.ejb.TransactionManagement;
import javax.ejb.TransactionManagementType;
import javax.ejb.EJB;
import javax.ejb.EJBException;
import javax.ejb.CreateException;
import javax.ejb.ActivationConfigProperty;
import javax.jms.Connection;
import javax.jms.ConnectionFactory;
import javax.jms.DeliveryMode;
import javax.jms.JMSException;
import javax.jms.Message;
import javax.jms.MessageListener;
import javax.jms.MessageProducer;
import javax.jms.MessageConsumer;
import javax.jms.Queue;
import javax.jms.QueueSession;
import javax.jms.Destination;
import javax.jms.Session;
import javax.jms.TextMessage;
import javax.jms.ObjectMessage;
import javax.sql.DataSource;
import javax.rmi.PortableRemoteObject;
import javax.transaction.UserTransaction;


import java.sql.*;
import javax.sql.XAConnection;
import javax.sql.XADataSource;
import com.ibm.db2.jcc.DB2Driver;
import com.ibm.db2.jcc.DB2XADataSource;
import com.ibm.db2.jcc.DB2Xid;
import org.h2.jdbcx.JdbcDataSource;
import org.h2.jdbcx.JdbcXAConnection;
import org.h2.jdbcx.JdbcConnectionPool;


@TransactionManagement(TransactionManagementType.BEAN)
@MessageDriven(activationConfig = {
	   @ActivationConfigProperty(propertyName = "destinationType",
propertyValue = "javax.jms.Queue"),
	   @ActivationConfigProperty(propertyName = "destination", propertyValue =
"userQueue")  
	    }) 	    
public class ChatBean implements MessageDrivenBean,MessageListener {
@Resource(name="ConnectionFactory")
private  	ConnectionFactory connectionFactory;
@Resource(name="answerQueue")
private  	Queue answerQueue;

		MessageDrivenContext messageDC;
		UserTransaction ut;
		DataSource h2,db2;

		public void setMessageDrivenContext(MessageDrivenContext mtc) throws
EJBException
		{
			messageDC=mtc;
			System.out.println("MessageDrivenContext setted!");
      try{
	      Properties prop = new Properties();  
	      prop.setProperty(Context.INITIAL_CONTEXT_FACTORY,
"org.apache.openejb.client.RemoteInitialContextFactory");    
	      prop.setProperty(Context.PROVIDER_URL, "ejbd://127.0.0.1:4201"); 		        
	      InitialContext ctx = new InitialContext(prop);		        

	      db2 =(DataSource) ctx.lookup("DB2");???????????????????
	      h2 =(DataSource) ctx.lookup("H2");??????????????????????
	    }catch(Exception e){
	    	e.printStackTrace();
	    	}					
		}	
		public void ejbRemove() throws EJBException
		{
								System.out.println("MDB Delete!");		
		}
		
    public void onMessage(Message message){
    try {
                      
            ///////////////////////////////////////////////////////
            final TextMessage textMessage = (TextMessage) message;
            final String question = textMessage.getText();           
            System.out.println("Received="+question);
            
            //May call another business process start            
            		String retString = businessMethod(question);
            //May call another business process end 
               System.out.println(retString); 
             						
						javax.jms.Connection connection =
connectionFactory.createConnection();						
		        connection.start();
		        Session session = connection.createSession(false,
Session.AUTO_ACKNOWLEDGE);
		        MessageProducer producer = session.createProducer(answerQueue);
		        producer.setDeliveryMode(DeliveryMode.NON_PERSISTENT);		         		             	        		        
		        // Create a message
		        TextMessage messageRes = session.createTextMessage(retString);		
		        // Tell the producer to send the message
		        producer.send(messageRes);	   

		        // Clean up
		        if (session != null) session.close();
		        if (connection != null) connection.close();	
		        					
						System.out.println("MDB called!!!");
        } catch (Exception e) {
	        	System.out.println("error!!!");
			        	try{
			        		ut.rollback();
			        	}catch(Exception e1){
			        		System.out.println("rollback failed!!!");
			        	}
		       e.printStackTrace();
        	}
    }

    public String businessMethod(String message) throws Exception{
		        System.out.println("businessMethod!!!");
	      		ut=(UserTransaction) messageDC.getUserTransaction();
						ut.begin();								               						                 	
	    				//DataSource h2 =(DataSource) ctx.lookup("H2");  
							//XAConnection xa=h2.getXAConnection(); ???????????
	    				java.sql.Connection connh2=h2.getConnection();	?????????    				
	    				StringBuffer sql1 = new StringBuffer(256);
							sql1.append(" update testh set name  ='111'  where id =1 ");			
							PreparedStatement PreStmt1 =
connh2.prepareStatement(sql1.toString());
							System.out.println(sql1);
							PreStmt1.executeUpdate();
						  PreStmt1.close();
						  connh2.close();
	    				
	    				//DataSource db2 =(DataSource) ctx.lookup("DB2");
	    				//XAConnection conndb2x=db2.getXAConnection();???????
	    				java.sql.Connection conndb2=db2.getConnection();?????????	    				
	    				StringBuffer sql = new StringBuffer(256);
							sql.append(" update TEST27 set name  ='131'  where id =1 ");				
							PreparedStatement PreStmt = conndb2.prepareStatement(sql.toString());
							System.out.println(sql);
							PreStmt.executeUpdate();
						  PreStmt.close();
						  conndb2.close();					  
					  ut.commit();
					  System.out.println("businessMethod finish!");
    				return "OK_Earth";
    }
}




--
View this message in context: http://openejb.979440.n4.nabble.com/about-openejb-standalone-transaction-control-tp4660358p4660412.html
Sent from the OpenEJB Dev mailing list archive at Nabble.com.

Re: about openejb standalone transaction control

Posted by adxun <ad...@live.cn>.
<Resource id="DB2" class-name="com.ibm.db2.jcc.DB2Driver">  
url=.... 
user=.... 
password=..... 
</Resource>  

<Resource id="H2" type="org.h2.jdbcx.JdbcDataSource ">  
url=.... 
user=.... 
password=..... 
</Resource>  

openejb console only display 
url property not supported by "DB2"? why



--
View this message in context: http://openejb.979440.n4.nabble.com/about-openejb-standalone-transaction-control-tp4660358p4660416.html
Sent from the OpenEJB Dev mailing list archive at Nabble.com.

Re: about openejb standalone transaction control

Posted by adxun <ad...@live.cn>.
> <Resource id="H2" class-name="org.h2.jdbcx.JdbcDataSource ">  
> url=.... 
> user=.... 
> password=..... 
> </Resource>  

not worked fine 
 by openejb.xml config file
JdbcDataSource dx=(JdbcDataSource )ctx.lookup("H2"); 
XAConnection xa=dx.getXAConnection(); error! nullpoiter


but

in program ,write 
JdbcDataSource dx =new JdbcDataSource ();
dx.setUrl("xxx");
dx.setUser("xxx");
dx.setPassword("xxx");
XAConnection xa=dx.getXAConnection();success!







--
View this message in context: http://openejb.979440.n4.nabble.com/about-openejb-standalone-transaction-control-tp4660358p4660423.html
Sent from the OpenEJB Dev mailing list archive at Nabble.com.

Re: about openejb standalone transaction control

Posted by adxun <ad...@live.cn>.
ok,I try but why not support  type="javax.sql.XADataSource">





--
View this message in context: http://openejb.979440.n4.nabble.com/about-openejb-standalone-transaction-control-tp4660358p4660419.html
Sent from the OpenEJB Dev mailing list archive at Nabble.com.

Re: about openejb standalone transaction control

Posted by Romain Manni-Bucau <rm...@gmail.com>.
take time to share a maven project reproducing the issue, you'll really
gain time

it should be reproductible in a few command(s) (typically mvn test or mvn
package tomee:run)

Note: XADataSource are supported, the issue is somewhere else and no need
of  type="javax.sql.XADataSource"

*Romain Manni-Bucau*
*Twitter: @rmannibucau <https://twitter.com/rmannibucau>*
*Blog: **http://rmannibucau.wordpress.com/*<http://rmannibucau.wordpress.com/>
*LinkedIn: **http://fr.linkedin.com/in/rmannibucau*
*Github: https://github.com/rmannibucau*



2013/1/25 adxun <ad...@live.cn>

> > <Resource id="H2" class-name="org.h2.jdbcx.JdbcDataSource ">
> > url=....
> > user=....
> > password=.....
> > </Resource>
>
> not worked fine
>
> JdbcDataSource dx=(JdbcDataSource )ctx.lookup("H2");
> XAConnection xa=dx.getXAConnection();Error!  but this I execute success in
> a
> main client program
>
>
>
> --
> View this message in context:
> http://openejb.979440.n4.nabble.com/about-openejb-standalone-transaction-control-tp4660358p4660420.html
> Sent from the OpenEJB Dev mailing list archive at Nabble.com.
>

Re: about openejb standalone transaction control

Posted by adxun <ad...@live.cn>.
> <Resource id="H2" class-name="org.h2.jdbcx.JdbcDataSource "> 
> url=.... 
> user=.... 
> password=..... 
> </Resource> 

not worked fine

JdbcDataSource dx=(JdbcDataSource )ctx.lookup("H2");
XAConnection xa=dx.getXAConnection();Error!  but this I execute success in a
main client program



--
View this message in context: http://openejb.979440.n4.nabble.com/about-openejb-standalone-transaction-control-tp4660358p4660420.html
Sent from the OpenEJB Dev mailing list archive at Nabble.com.

Re: about openejb standalone transaction control

Posted by Romain Manni-Bucau <rm...@gmail.com>.
here that's basically the doc of derby, which attribute your datasource
supports.

*Romain Manni-Bucau*
*Twitter: @rmannibucau <https://twitter.com/rmannibucau>*
*Blog: **http://rmannibucau.wordpress.com/*<http://rmannibucau.wordpress.com/>
*LinkedIn: **http://fr.linkedin.com/in/rmannibucau*
*Github: https://github.com/rmannibucau*



2013/1/25 adxun <ad...@live.cn>

> <Resource id="DB2" class-name="com.ibm.db2.jcc.DB2Driver">
> url=....
> user=....
> password=.....
> </Resource>
>
> <Resource id="H2" class-name="org.h2.jdbcx.JdbcDataSource ">
> url=....
> user=....
> password=.....
> </Resource>
>
> openejb console only display
> url property not supported by "DB2"? why ?
>
> any link doc about this?
>
>
>
> --
> View this message in context:
> http://openejb.979440.n4.nabble.com/about-openejb-standalone-transaction-control-tp4660358p4660417.html
> Sent from the OpenEJB Dev mailing list archive at Nabble.com.
>

Re: about openejb standalone transaction control

Posted by adxun <ad...@live.cn>.
<Resource id="DB2" class-name="com.ibm.db2.jcc.DB2Driver">  
url=.... 
user=.... 
password=..... 
</Resource>  

<Resource id="H2" class-name="org.h2.jdbcx.JdbcDataSource ">  
url=.... 
user=.... 
password=..... 
</Resource>  

openejb console only display 
url property not supported by "DB2"? why ?

any link doc about this?



--
View this message in context: http://openejb.979440.n4.nabble.com/about-openejb-standalone-transaction-control-tp4660358p4660417.html
Sent from the OpenEJB Dev mailing list archive at Nabble.com.

Re: about openejb standalone transaction control

Posted by Romain Manni-Bucau <rm...@gmail.com>.
ok so try (tested with h2):

<Resource id="H2" class-name="org.h2.jdbcx.JdbcDataSource">
  user = sa
  password =
  url = jdbc:h2:mem:h2
</Resource>

*Romain Manni-Bucau*
*Twitter: @rmannibucau <https://twitter.com/rmannibucau>*
*Blog: **http://rmannibucau.wordpress.com/*<http://rmannibucau.wordpress.com/>
*LinkedIn: **http://fr.linkedin.com/in/rmannibucau*
*Github: https://github.com/rmannibucau*



2013/1/25 adxun <ad...@live.cn>

>     public String businessMethod(String message) throws Exception{
>
>                         ut=(UserTransaction)
> messageDC.getUserTransaction();
>                                                 ut.begin();
>                                                     Properties prop = new
> Properties();
>               prop.setProperty(Context.INITIAL_CONTEXT_FACTORY,
> "org.apache.openejb.client.RemoteInitialContextFactory");
>               prop.setProperty(Context.PROVIDER_URL, "ejbd://
> 127.0.0.1:4201");
>               InitialContext ctx = new InitialContext(prop);
>                                         //DataSource h2 =(DataSource)
> ctx.lookup("H2");  ??????
>                                                         //XAConnection
> xah=h2.getXAConnection(); ??????
>                                         //java.sql.Connection
> connh2=xah.getConnection();???????
>                                         StringBuffer sql1 = new
> StringBuffer(256);
>                                                         sql1.append("
> update testh set name  ='111'  where id =1 ");
>                                                         PreparedStatement
> PreStmt1 =
> connh2.prepareStatement(sql1.toString());
>
> System.out.println(sql1);
>
> PreStmt1.executeUpdate();
>                                                   PreStmt1.close();
>                                                   connh2.close();
>
>                                         //DataSource db2 =(DataSource)
> ctx.lookup("DB2");??????
>                                         //XAConnection
> xad=db2.getXAConnection();????????????
>                                         //java.sql.Connection
> conndb2=db2.getConnection();????????
>                                         StringBuffer sql = new
> StringBuffer(256);
>                                                         sql.append("
> update TEST27 set name  ='131'  where id =1 ");
>                                                         PreparedStatement
> PreStmt = conndb2.prepareStatement(sql.toString());
>
> System.out.println(sql);
>
> PreStmt.executeUpdate();
>                                                   PreStmt.close();
>                                                   conndb2.close();
>                                           ut.commit();
>
> System.out.println("businessMethod finish!");
>                                 return "OK_Earth";
>     }
>
>
>
> --
> View this message in context:
> http://openejb.979440.n4.nabble.com/about-openejb-standalone-transaction-control-tp4660358p4660413.html
> Sent from the OpenEJB Dev mailing list archive at Nabble.com.
>

Re: about openejb standalone transaction control

Posted by adxun <ad...@live.cn>.
    public String businessMethod(String message) throws Exception{
		       
	      		ut=(UserTransaction) messageDC.getUserTransaction();
						ut.begin();								      Properties prop = new Properties();  
	      prop.setProperty(Context.INITIAL_CONTEXT_FACTORY,
"org.apache.openejb.client.RemoteInitialContextFactory");    
	      prop.setProperty(Context.PROVIDER_URL, "ejbd://127.0.0.1:4201"); 		        
	      InitialContext ctx = new InitialContext(prop);		               						                 	
	    				//DataSource h2 =(DataSource) ctx.lookup("H2");  ??????
							//XAConnection xah=h2.getXAConnection(); ??????
	    				//java.sql.Connection connh2=xah.getConnection();???????  				
	    				StringBuffer sql1 = new StringBuffer(256);
							sql1.append(" update testh set name  ='111'  where id =1 ");			
							PreparedStatement PreStmt1 =
connh2.prepareStatement(sql1.toString());
							System.out.println(sql1);
							PreStmt1.executeUpdate();
						  PreStmt1.close();
						  connh2.close();
	    				
	    				//DataSource db2 =(DataSource) ctx.lookup("DB2");??????
	    				//XAConnection xad=db2.getXAConnection();????????????
	    				//java.sql.Connection conndb2=db2.getConnection();????????	    				
	    				StringBuffer sql = new StringBuffer(256);
							sql.append(" update TEST27 set name  ='131'  where id =1 ");				
							PreparedStatement PreStmt = conndb2.prepareStatement(sql.toString());
							System.out.println(sql);
							PreStmt.executeUpdate();
						  PreStmt.close();
						  conndb2.close();					  
					  ut.commit();
					  System.out.println("businessMethod finish!");
    				return "OK_Earth";
    }



--
View this message in context: http://openejb.979440.n4.nabble.com/about-openejb-standalone-transaction-control-tp4660358p4660413.html
Sent from the OpenEJB Dev mailing list archive at Nabble.com.

Re: about openejb standalone transaction control

Posted by adxun <ad...@live.cn>.
openejb console display infomation


warnning: XADataSource property not supported by "DB2" 
warnning: xaDataSource property not supported by "H2" 



--
View this message in context: http://openejb.979440.n4.nabble.com/about-openejb-standalone-transaction-control-tp4660358p4660411.html
Sent from the OpenEJB Dev mailing list archive at Nabble.com.

Re: about openejb standalone transaction control

Posted by Romain Manni-Bucau <rm...@gmail.com>.
just tested and it seems fine ():

EJBContainer.createEJBContainer(new Properties() {{
                setProperty("xa", "new://Resource?type=DataSource");
                setProperty("xa.xaDataSource", "myclass"); // xa datasource
qualified name
                ...
            }})

it is the same as:

<Resource id="xa" type="DataSource">
    xaDataSource = myclass
    ...
</Resource>


*Romain Manni-Bucau*
*Twitter: @rmannibucau <https://twitter.com/rmannibucau>*
*Blog: **http://rmannibucau.wordpress.com/*<http://rmannibucau.wordpress.com/>
*LinkedIn: **http://fr.linkedin.com/in/rmannibucau*
*Github: https://github.com/rmannibucau*



2013/1/25 adxun <ad...@live.cn>

> openejb start...
>
> warnning: XADataSource property not supported by "DB2"
> warnning: XADataSource property not supported by "H2"
>
>
>
> --
> View this message in context:
> http://openejb.979440.n4.nabble.com/about-openejb-standalone-transaction-control-tp4660358p4660407.html
> Sent from the OpenEJB Dev mailing list archive at Nabble.com.
>

Re: about openejb standalone transaction control

Posted by adxun <ad...@live.cn>.
openejb start...

warnning: XADataSource property not supported by "DB2"
warnning: XADataSource property not supported by "H2"



--
View this message in context: http://openejb.979440.n4.nabble.com/about-openejb-standalone-transaction-control-tp4660358p4660407.html
Sent from the OpenEJB Dev mailing list archive at Nabble.com.

Re: about openejb standalone transaction control

Posted by Romain Manni-Bucau <rm...@gmail.com>.
basically all the underlying attributes are accessible so we can't list
them (since now you can switch the implementation too) so the attribute
should be available (if no log are printed it is the attribute is taken
into account)

*Romain Manni-Bucau*
*Twitter: @rmannibucau <https://twitter.com/rmannibucau>*
*Blog: **http://rmannibucau.wordpress.com/*<http://rmannibucau.wordpress.com/>
*LinkedIn: **http://fr.linkedin.com/in/rmannibucau*
*Github: https://github.com/rmannibucau*



2013/1/24 adxun <ad...@live.cn>

> in http://tomee.apache.org/datasource-config.html  have not XADataSource
> property
>
>
> http://openejb.apache.org/common-datasource-configurations.html?
>
> openejb.xml?
>
> <Resource id="OracleXA Database" type="DataSource">
>     #  OracleXA example
>     #
>     #  This connector will not work until you download the driver at:
>     #  http://otn.oracle.com/software/tech/java/sqlj_jdbc/content.html
>     JdbcDriver  oracle.jdbc.xa.client.OracleXADataSource
>     JdbcUrl jdbc:oracle:thin:@localhost:1521:orcl
>     UserName    scott
>     Password    tiger
> </Resource>
>
>
>
> --
> View this message in context:
> http://openejb.979440.n4.nabble.com/about-openejb-standalone-transaction-control-tp4660358p4660381.html
> Sent from the OpenEJB Dev mailing list archive at Nabble.com.
>

Re: about openejb standalone transaction control

Posted by adxun <ad...@live.cn>.
in http://tomee.apache.org/datasource-config.html  have not XADataSource
property


http://openejb.apache.org/common-datasource-configurations.html?

openejb.xml?

<Resource id="OracleXA Database" type="DataSource">
    #  OracleXA example
    #
    #  This connector will not work until you download the driver at:
    #  http://otn.oracle.com/software/tech/java/sqlj_jdbc/content.html
    JdbcDriver  oracle.jdbc.xa.client.OracleXADataSource
    JdbcUrl jdbc:oracle:thin:@localhost:1521:orcl
    UserName    scott
    Password    tiger
</Resource>



--
View this message in context: http://openejb.979440.n4.nabble.com/about-openejb-standalone-transaction-control-tp4660358p4660381.html
Sent from the OpenEJB Dev mailing list archive at Nabble.com.

Re: about openejb standalone transaction control

Posted by adxun <ad...@live.cn>.
I got it ...



--
View this message in context: http://openejb.979440.n4.nabble.com/about-openejb-standalone-transaction-control-tp4660358p4660380.html
Sent from the OpenEJB Dev mailing list archive at Nabble.com.

Re: about openejb standalone transaction control

Posted by Romain Manni-Bucau <rm...@gmail.com>.
please look how to configure a datasource in OpenEJB or TomEE :
tomee.apache.org/datasource-config.html

if the defined datasource if an XA XA tx will be used:

<Resource id="foo" type="DataSource">
 ...
 XADataSource = ...
  ...
</Resource>

lookup("openejb:Resource/foo") or lookup("java:openejb/Resource/foo")

*Romain Manni-Bucau*
*Twitter: @rmannibucau <https://twitter.com/rmannibucau>*
*Blog: **http://rmannibucau.wordpress.com/*<http://rmannibucau.wordpress.com/>
*LinkedIn: **http://fr.linkedin.com/in/rmannibucau*
*Github: https://github.com/rmannibucau*



2013/1/24 adxun <ad...@live.cn>

> if in openejb.xml
>
> <Resource id="DB2"
> type="org.apache.commons.dbcp.managed.BasicManagedDataSource">
>
> url
> user
> pwd
> ...
> </Resource>
>
> BasicManagedDataSource dsx=(BasicManagedDataSource) ctx.lookup("DB2");
> dsx.setXADataSource("com.db2.ibm.jcc.DB2XADataSource")
> XADataSource xads=dsx.getXaDataSourceInstance()
> XAConnection xa=xads.getXAConnection();
> Connection con=xa.getConnection();
>
> ?
>
>
>
> --
> View this message in context:
> http://openejb.979440.n4.nabble.com/about-openejb-standalone-transaction-control-tp4660358p4660377.html
> Sent from the OpenEJB Dev mailing list archive at Nabble.com.
>

Re: about openejb standalone transaction control

Posted by adxun <ad...@live.cn>.
if in openejb.xml

<Resource id="DB2"
type="org.apache.commons.dbcp.managed.BasicManagedDataSource">

url
user
pwd
...
</Resource>

BasicManagedDataSource dsx=(BasicManagedDataSource) ctx.lookup("DB2");
dsx.setXADataSource("com.db2.ibm.jcc.DB2XADataSource") 
XADataSource xads=dsx.getXaDataSourceInstance() 
XAConnection xa=xads.getXAConnection();
Connection con=xa.getConnection();

?



--
View this message in context: http://openejb.979440.n4.nabble.com/about-openejb-standalone-transaction-control-tp4660358p4660377.html
Sent from the OpenEJB Dev mailing list archive at Nabble.com.

Re: about openejb standalone transaction control

Posted by Romain Manni-Bucau <rm...@gmail.com>.
http://commons.apache.org/dbcp/apidocs/org/apache/commons/dbcp/managed/BasicManagedDataSource.html

openejb or tomee are the same here

*Romain Manni-Bucau*
*Twitter: @rmannibucau <https://twitter.com/rmannibucau>*
*Blog: **http://rmannibucau.wordpress.com/*<http://rmannibucau.wordpress.com/>
*LinkedIn: **http://fr.linkedin.com/in/rmannibucau*
*Github: https://github.com/rmannibucau*



2013/1/24 adxun <ad...@live.cn>

> and I only use openejb standalone as server!
>
> XADataSource xds=(XADataSource)ctx.lookup("DB2")
>
> Exception is
>  org.apache.client.ClientDataSource can not cast javax.sql.XADataSource
>
>
>
> --
> View this message in context:
> http://openejb.979440.n4.nabble.com/about-openejb-standalone-transaction-control-tp4660358p4660374.html
> Sent from the OpenEJB Dev mailing list archive at Nabble.com.
>

Re: about openejb standalone transaction control

Posted by adxun <ad...@live.cn>.
and I only use openejb standalone as server!

XADataSource xds=(XADataSource)ctx.lookup("DB2") 

Exception is
 org.apache.client.ClientDataSource can not cast javax.sql.XADataSource



--
View this message in context: http://openejb.979440.n4.nabble.com/about-openejb-standalone-transaction-control-tp4660358p4660374.html
Sent from the OpenEJB Dev mailing list archive at Nabble.com.

Re: about openejb standalone transaction control

Posted by Romain Manni-Bucau <rm...@gmail.com>.
maybe have a look to
http://openejb.979440.n4.nabble.com/Is-Tomee-not-support-XADataSource-td4642705.html

*Romain Manni-Bucau*
*Twitter: @rmannibucau <https://twitter.com/rmannibucau>*
*Blog: **http://rmannibucau.wordpress.com/*<http://rmannibucau.wordpress.com/>
*LinkedIn: **http://fr.linkedin.com/in/rmannibucau*
*Github: https://github.com/rmannibucau*



2013/1/24 adxun <ad...@live.cn>

> but how to set XADataSource in openejb.xml to support 2 Databases
> transaction?
>
> DataSource ds=(DataSource)ctx.lookup("DB2");(but I want a XA type)
> openejb.xml
> <Resource id="DB2" type="javax.sql.DataSource">(not suported XADataSource?)
> url
> user
> pwd
> driver
> ....
> </Resource>
> <Resource id="H2" type="javax.sql.DataSource">(not suported XADataSource?)
> url
> user
> pwd
> driver
> ....
> </Resource>
>
> how to set XADataSource in openejb.xml
>
>
>
>
>
> --
> View this message in context:
> http://openejb.979440.n4.nabble.com/about-openejb-standalone-transaction-control-tp4660358p4660370.html
> Sent from the OpenEJB Dev mailing list archive at Nabble.com.
>

Re: about openejb standalone transaction control

Posted by adxun <ad...@live.cn>.
but how to set XADataSource in openejb.xml to support 2 Databases
transaction? 

DataSource ds=(DataSource)ctx.lookup("DB2");(but I want a XA type) 
openejb.xml 
<Resource id="DB2" type="javax.sql.DataSource">(not suported XADataSource?) 
url 
user 
pwd 
driver 
.... 
</Resource>
<Resource id="H2" type="javax.sql.DataSource">(not suported XADataSource?) 
url 
user 
pwd 
driver 
.... 
</Resource>

how to set XADataSource in openejb.xml





--
View this message in context: http://openejb.979440.n4.nabble.com/about-openejb-standalone-transaction-control-tp4660358p4660370.html
Sent from the OpenEJB Dev mailing list archive at Nabble.com.

Re: about openejb standalone transaction control

Posted by Romain Manni-Bucau <rm...@gmail.com>.
just define a xadatasource as datasource

*Romain Manni-Bucau*
*Twitter: @rmannibucau <https://twitter.com/rmannibucau>*
*Blog: **http://rmannibucau.wordpress.com/*<http://rmannibucau.wordpress.com/>
*LinkedIn: **http://fr.linkedin.com/in/rmannibucau*
*Github: https://github.com/rmannibucau*



2013/1/24 adxun <ad...@live.cn>

> now I can get UserTrancation below
>
> MessageDrivenContext mdc;
>
> UserTrancation ut = mdc.getUserTransaction();
>
> but how to set XADataSource in openejb.xml to support 2 Databases
> transaction?
>
> DataSource ds=(DataSource)ctx.lookup("DB2");(but I want a XA type)
> openejb.xml
> <Resource id="DB2" type="javax.sql.DataSource">(not suported XADataSource?)
> url
> user
> pwd
> driver
> ....
> </Resource>
>
>
>
>
>
> --
> View this message in context:
> http://openejb.979440.n4.nabble.com/about-openejb-standalone-transaction-control-tp4660358p4660367.html
> Sent from the OpenEJB Dev mailing list archive at Nabble.com.
>

Re: about openejb standalone transaction control

Posted by adxun <ad...@live.cn>.
now I can get UserTrancation below

MessageDrivenContext mdc;

UserTrancation ut = mdc.getUserTransaction();

but how to set XADataSource in openejb.xml to support 2 Databases
transaction?

DataSource ds=(DataSource)ctx.lookup("DB2");(but I want a XA type)
openejb.xml 
<Resource id="DB2" type="javax.sql.DataSource">(not suported XADataSource?)
url
user
pwd
driver
....
</Resource>





--
View this message in context: http://openejb.979440.n4.nabble.com/about-openejb-standalone-transaction-control-tp4660358p4660367.html
Sent from the OpenEJB Dev mailing list archive at Nabble.com.

Re: about openejb standalone transaction control

Posted by adxun <ad...@live.cn>.
一。I have two database a(h2) and b(db2),both a and b need to be updated  in a
transaction!

how to set XADataSource to support transaction in openejb.xml ?


二。I want to lookup UserTransaction in a class by a MDB called? 

MDB Class{

onMessage()
{
methodA()
}

}

Business Class{
method A (){
。。。。
ctx.lookup("java:comp/env/UserTransaction");(naming not found)
}


}



--
View this message in context: http://openejb.979440.n4.nabble.com/about-openejb-standalone-transaction-control-tp4660358p4660366.html
Sent from the OpenEJB Dev mailing list archive at Nabble.com.

Re: about openejb standalone transaction control

Posted by adxun <ad...@live.cn>.
I am lookup it in a MDB ...


ps: how to support XADataSource in openejb.xml? transaction required!





--
View this message in context: http://openejb.979440.n4.nabble.com/about-openejb-standalone-transaction-control-tp4660358p4660364.html
Sent from the OpenEJB Dev mailing list archive at Nabble.com.

Re: about openejb standalone transaction control

Posted by Romain Manni-Bucau <rm...@gmail.com>.
Hi,

Where are you looking it from? It is not available in non jee beans.
Le 24 janv. 2013 05:14, "adxun" <ad...@live.cn> a écrit :

> > UserTransaction ut
> > =(UserTransaction)ctx.lookup("java:comp/env/UserTransaction") not found
> > naming
> >
> > why?
>
> ("java:comp/env/UserTransaction")
>
> the problem is same
>
> not found naming...
>
>
>
> --
> View this message in context:
> http://openejb.979440.n4.nabble.com/about-openejb-standalone-transaction-control-tp4660358p4660360.html
> Sent from the OpenEJB Dev mailing list archive at Nabble.com.
>

Re: about openejb standalone transaction control

Posted by adxun <ad...@live.cn>.
> UserTransaction ut 
> =(UserTransaction)ctx.lookup("java:comp/env/UserTransaction") not found 
> naming 
> 
> why? 

("java:comp/env/UserTransaction") 

the problem is same 

not found naming...



--
View this message in context: http://openejb.979440.n4.nabble.com/about-openejb-standalone-transaction-control-tp4660358p4660360.html
Sent from the OpenEJB Dev mailing list archive at Nabble.com.

Re: about openejb standalone transaction control

Posted by Vishwanath Krishnamurthi <to...@gmail.com>.
You're missing a 'p' ( java:comp and not java:com)

-Vishwa

On Thu, Jan 24, 2013 at 7:31 AM, adxun <ad...@live.cn> wrote:

>
> UserTransaction ut
> =(UserTransaction)ctx.lookup("java:com/env/UserTransaction") not found
> naming
>
> why?
>
>
>
>
>
> --
> View this message in context:
> http://openejb.979440.n4.nabble.com/about-openejb-standalone-transaction-control-tp4660358.html
> Sent from the OpenEJB Dev mailing list archive at Nabble.com.
>