Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Distributed Transactions-- TXDataSource & XA JDBC Driver

3 views
Skip to first unread message

Suren

unread,
Mar 5, 2003, 5:35:48 PM3/5/03
to

Hi Folks,
I'm trying to do a distributed transaction on to two different
database instances within a single transaction boundary. I have
set up two connection pools for the two instances to have these
in their config.xml:
<JDBCConnectionPool DriverName="oracle.jdbc.xa.client.OracleXADataSource" KeepXAConnTillTxComplete="true"
MaxCapacity="5" Name="connPool1" Password="xxx" Properties="user=db1;
enabled=false;password=xxx;dll=ocijdbc8;protocol=thin" SupportsLocalTransaction="true"
Targets="server1" URL="jdbc:oracle:thin:@dbinstance:1521:db" XAPassword="xxx"/>

Two TXDatasource set up in config xml similar to:
<JDBCTxDataSource JNDIName="jdbc/xads1" Name="xads1" PoolName="connPool1" Targets="server1"/>

Implementation method is:
public void setMethod() throws RemoteException, Exception {
Connection conn1 = null;
Connection conn2 = null;
PreparedStatement pstmt1 = null;
PreparedStatement pstmt2 = null;
XADataSource dataSource1 = null;
XADataSource dataSource2 = null;
XAConnection xaConn1 = null;
XAConnection xaConn2 = null;
XAResource xaResource1 = null;
XAResource xaResource2 = null;
try {
Properties props = new Properties() ;
props.put(Context.INITIAL_CONTEXT_FACTORY, "weblogic.jndi.WLInitialContextFactory")
;
props.put(Context.PROVIDER_URL, "t3://localhost:8001") ;
Context initialContext = new InitialContext(props);
String dataSourceName1 = "xads1";
System.out.println("DataSource 1 is " + dataSourceName1);
String dataSourceName2 = "xads2";
System.out.println("DataSource 2 is " + dataSourceName2);
String name1 = "jdbc/" + dataSourceName1;
dataSource1 = (XADataSource)initialContext.lookup (name1);
System.out.println("DataSource 1 is " + dataSource1);
String name2 = "jdbc/" + dataSourceName2;
dataSource2 = (XADataSource)initialContext.lookup (name2);
System.out.println("DataSource 2 is " + dataSource2);
xaConn1 = dataSource1.getXAConnection();
xaConn2 = dataSource2.getXAConnection();
xaResource1 = xaConn1.getXAResource( );
xaResource2 = xaConn2.getXAResource( );
conn1 = xaConn1.getConnection();
System.out.println("Connection 1 is " + conn1);
conn2 = xaConn2.getConnection();
System.out.println("Connection 2 is " + conn2);
Xid xid1 = createXid( 1 );
Xid xid2 = createXid( 2 );
// Start transaction.
xaResource1.start( xid1, XAResource.TMNOFLAGS );
xaResource2.start( xid2, XAResource.TMNOFLAGS );
pstmt1 = conn1.prepareStatement("insert into TAB_LOC1 values('227','AL','Alaska','')");
pstmt1.executeQuery();

pstmt2 = conn2.prepareStatement("insert into TAB_LOC2 values('228','HW','Hawaii','')");
pstmt2.executeQuery();

// Suspend the transactions.
xaResource1.end( xid1, XAResource.TMSUCCESS );
xaResource2.end( xid2, XAResource.TMSUCCESS );

// Prepare the Resource Managers
int prepare1 = xaResource1.prepare( xid1 );
int prepare2 = xaResource2.prepare( xid2);

boolean doCommit = true;
if ( !( ( prepare1 == XAResource.XA_OK ) ||
( prepare1 == XAResource.XA_RDONLY ) ) ) {
doCommit = false;
}

if ( !( ( prepare2 == XAResource.XA_OK ) ||
( prepare2 == XAResource.XA_RDONLY ) ) ) {
doCommit = false;
}

if ( prepare1 == XAResource.XA_OK ) {
if ( doCommit ) {
xaResource1.commit( xid1, false );
}
else {
xaResource1.rollback( xid1 );
}
}

if ( prepare2 == XAResource.XA_OK ) {
if ( doCommit ) {
xaResource2.commit( xid2, false );
}
else {
xaResource2.rollback( xid2 );
}
}
} catch(Exception e) {
System.out.println("exception handler here ", e);
} finally {
try { pstmt1.close();conn1.close(); }
catch(Exception e) {}
try { pstmt2.close();conn2.close(); }
catch(Exception e) {}
}
}

I get this exception in this line of code:
dataSource1 = (XADataSource)initialContext.lookup (name1);

[impl.SettingsBean_osmo8z_Impl] exception handler here
java.lang.ClassCastException: weblogic.jdbc.common.internal.RmiDataSource
at com.xxx.set.ejb.impl.SetMyEjbBean.setMethod(SetMyEjbBean.java:290)
at com.xxx.set.ejb.SetMyEjbBean_osmo8z_EOImpl.setMethod(SetMyEjbBean_osmo8z_EOImpl.java:154)
at com.xxx.set.ejb.SetMyEjbBean_osmo8z_EOImpl_WLSkel.invoke(Unknown Source)
at weblogic.rmi.internal.BasicServerRef.invoke(BasicServerRef.java:362)
at weblogic.rmi.cluster.ReplicaAwareServerRef.invoke(ReplicaAwareServerRef.java:114)
at weblogic.rmi.internal.BasicServerRef$1.run(BasicServerRef.java:313)
at weblogic.security.service.SecurityServiceManager.runAs(SecurityServiceManager.java:821)
at weblogic.rmi.internal.BasicServerRef.handleRequest(BasicServerRef.java:308)
at weblogic.rmi.internal.BasicExecuteRequest.execute(BasicExecuteRequest.java:30)
at weblogic.kernel.ExecuteThread.execute(ExecuteThread.java:213)
at weblogic.kernel.ExecuteThread.run(ExecuteThread.java:189)

I will appreciate all the help.

Thanks,
Suren.

Slava Imeshev

unread,
Mar 5, 2003, 10:26:39 PM3/5/03
to
Hi Suren,

All you have to do is to look up TxDataSources, obtain the normal
JDBC connections and use them. weblogic will take care about the
XA for you if you make calls from inside a bean with transaction
attribute set, or if you provide UserTransaction.

BTW, MaxCapacity="5" is way too low for any application. Set it at least
to the number of available execution threads (15 by default).

Regards,

Slava Imeshev

"Suren" <skara...@ph.com> wrote in message
news:3e66...@newsgroups.bea.com...

Suren

unread,
Mar 6, 2003, 1:04:34 PM3/6/03
to

Hi Slava & other Folks,
Thank you for that information. I started of with this and back to it again because
of this exception...and code is below. I also set the MaxCapacity = 15. Transaction
attribute is set for this method on the Bean to be "Required". The Connection
Pool & TxDatasource information is set up as mentioned earlier.

Changed code snippet:


public void setMethod() throws RemoteException, Exception {
Connection conn1 = null;
Connection conn2 = null;
PreparedStatement pstmt1 = null;
PreparedStatement pstmt2 = null;

try {
Properties props = new Properties() ;
props.put(Context.INITIAL_CONTEXT_FACTORY,
"weblogic.jndi.WLInitialContextFactory") ;
props.put(Context.PROVIDER_URL, "t3://localhost:8001") ;
Context initialContext = new InitialContext(props);
String dataSourceName1 = "xads1";

String name1 = "jdbc/" + dataSourceName1;

Object source1 = initialContext.lookup (name1);
DataSource dataSource1 = (DataSource)source1;
String dataSourceName2 = "xads2";


String name2 = "jdbc/" + dataSourceName2;

Object source2 = initialContext.lookup (name2);
DataSource dataSource2 = (DataSource)source2;
conn1 = dataSource1.getConnection();
conn2 = dataSource2.getConnection();


pstmt1 = conn1.prepareStatement("insert into TAB_LOC1

values('228','HW','Hawaii','')");
pstmt1.executeQuery();
pstmt2 = conn2.prepareStatement("insert into TAB_LOC2
values('228','HW','Hawaii','')");
pstmt2.executeQuery();

} catch(Exception e) {


} finally {
try { pstmt1.close();conn1.close(); }
catch(Exception e) {}
try { pstmt2.close();conn2.close(); }
catch(Exception e) {}
}
}

2003/03/06 12:49:50.638 SYSTEM CCFW9999 SEVERE [SetEjbBean_osmo8z_Impl]
exception here
java.sql.SQLException: XA error: XAER_RMERR : A resource manager
error has occured in the transaction branch start() failed on
resource 'xaConnPool1': XAER_RMERR : A resource manager error
has occured in the transaction branch
oracle.jdbc.xa.OracleXAException
at oracle.jdbc.xa.OracleXAResource.checkError(OracleXAResource.java:1157)
at oracle.jdbc.xa.client.OracleXAResource.start(OracleXAResource.java:295)
at weblogic.jdbc.jta.VendorXAResource.start(VendorXAResource.java:41)
at weblogic.jdbc.jta.DataSource.start(DataSource.java:577)
at weblogic.transaction.internal.ServerResourceInfo.start
(ServerResourceInfo.java:1178)
at weblogic.transaction.internal.ServerResourceInfo.xaStart(ServerResourceInfo.java:1121)
at
weblogic.transaction.internal.ServerResourceInfo.enlist
(ServerResourceInfo.java:287) at
weblogic.transaction.internal.ServerTransactionImpl.enlistResource(ServerTransactionImpl.java:407)
at weblogic.jdbc.jta.DataSource.enlist DataSource.java:1157)
at weblogic.jdbc.jta.DataSource.refreshXAConnAndEnlist
(DataSource.java:1109)
at weblogic.jdbc.jta.Connection.getXAConn(Connection.java:147)
at weblogic.jdbc.jta.Connection.prepareStatement(Connection.java:259)
at weblogic.jdbc.rmi.internal.ConnectionImpl.prepareStatement
(ConnectionImpl.java:139)
at weblogic.jdbc.rmi.SerialConnection.prepareStatement(SerialConnection.java:92)
at com.set.ejb.impl.SetEjbBean.setMethod(SetEjbBean.java:280)
at com.set.ejb.impl.SetEjbBean_osmo8z_EOImpl.setMethod(SetEjbBean_osmo8z_EOImpl.java:154)
at com.set.ejb.impl.SetEjbBean_osmo8z_EOImpl_WLSkel.invoke(Unknown Source)


at weblogic.rmi.internal.BasicServerRef.invoke(BasicServerRef.java:362)
at weblogic.rmi.cluster.ReplicaAwareServerRef.invoke(ReplicaAwareServerRef.java:114)
at weblogic.rmi.internal.BasicServerRef$1.run(BasicServerRef.java:313)

at weblogic.security.service.SecurityServiceManager.runAs(SecurityServiceManager.java:821)


at weblogic.rmi.internal.BasicServerRef.handleRequest(BasicServerRef.java:308)
at weblogic.rmi.internal.BasicExecuteRequest.execute(BasicExecuteRequest.java:30)
at weblogic.kernel.ExecuteThread.execute(ExecuteThread.java:213)
at weblogic.kernel.ExecuteThread.run(ExecuteThread.java:189)

at weblogic.jdbc.jta.DataSource.enlist(DataSource.java:1162)
at weblogic.jdbc.jta.DataSource.refreshXAConnAndEnlist(DataSource.java:1109)
at weblogic.jdbc.jta.Connection.getXAConn(Connection.java:147)
at weblogic.jdbc.jta.Connection.prepareStatement(Connection.java:259)
at weblogic.jdbc.rmi.internal.ConnectionImpl.prepareStatement(ConnectionImpl.java:139)
at weblogic.jdbc.rmi.SerialConnection.prepareStatement(SerialConnection.java:92)
at com.set.ejb.impl.SetEjbBean.setMethod(SetEjbBean.java:280)
at com.set.ejb.impl.SettingsBean_osmo8z_EOImpl.setMethod(SetEjbBean_osmo8z_EOImpl.java:154)
at com.set.ejb.impl.SetEjbBean_osmo8z_EOImpl_WLSkel.invoke(Unknown Source)


at weblogic.rmi.internal.BasicServerRef.invoke(BasicServerRef.java:362)
at weblogic.rmi.cluster.ReplicaAwareServerRef.invoke(ReplicaAwareServerRef.java:114)
at weblogic.rmi.internal.BasicServerRef$1.run(BasicServerRef.java:313)

at weblogic.security.service.SecurityServiceManager.runAs(SecurityServiceManager.java:821)


at weblogic.rmi.internal.BasicServerRef.handleRequest(BasicServerRef.java:308)
at weblogic.rmi.internal.BasicExecuteRequest.execute(BasicExecuteRequest.java:30)
at weblogic.kernel.ExecuteThread.execute(ExecuteThread.java:213)
at weblogic.kernel.ExecuteThread.run(ExecuteThread.java:189)

I will appreciate all the help in this regard,

Thank you,
Suren.

0 new messages