ibatis-user-java mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Wang, Jin \(Sensis\)" <Jin.W...@sensis.com.au>
Subject setUserConnection() does not reset the connection used in SQLMAP
Date Tue, 26 Apr 2005 09:28:15 GMT

Hi, Clinton and all the gurus

We try to use the global transaction manager to manage the transaction
for JMS and Oracle database transaction.
But we have problems in managing the Oracle transaction if we use IBATIS
BTW. we are not using any heavy application server (such as weblogic,
websphere, ...) and we just use
tyrex as our transaction manager and joram as our JMS server. The
transaction manager and JMS part works fine.

We create the OracleXADataSource as the following :
	oxds = new OracleXADataSource();

	//  Get the XAConnection.
	oxConn = oxds.getXAConnection();
	XAResouce xres = oxConn.getXAResource();

	final Context root = new MemoryContext(null);

	//  Create comp/userTransaction and comp/env/jdbc/jndiName
	Context ctx = root.createSubcontext( "comp" );
	ctx.bind( "userTransaction", userTrans );
	ctx.bind( "transactionManager", transMgr );
	ctx = ctx.createSubcontext( "env" );
	ctx = ctx.createSubcontext( "jdbc" );
	ctx.bind( "SfuTxDataSource", oxds);
	//  Associate the memory context with a new
	//  runtime context and associate the runtime context
	//  with the current thread.
	final RuntimeContext runCtx = RuntimeContext.newRuntimeContext(
root, null );
	RuntimeContext.setRuntimeContext( runCtx );

We did try the following two options :
	1. just use the SQLMAP's configuration sqlmapConfig.xml to tell
SQLMAP to look
	the data source created above via JNDI.
	Here is the configure file :

  <properties resource="sfuInboundDatabase.properties"/>

  <transactionManager type="EXTERNAL" >
    <property name="DefaultAutoCommit" value="false"/>
    <property name="SetAutoCommitAllowed" value="false"/>
    <property name="commitRequired" value="true"/>
    <dataSource type="JNDI">
    	<property name="DataSource"
  <sqlMap resource="sfuInBoundReferenceDbSQL.xml"/>
  <sqlMap resource="sfuInBoundDbSQL.xml"/>

	In this case, It always commits all the updates done to the
database. When we debug into the
	Sqlmap code, we found out in the init() function (called in the
getConnection() function)in
	it calls dataSource.getConnection(). Because this dataSource is
an instance of OracleXADataSource
	and the getConnection() function in OracleXADataSource returns a
default connection. This
	default connection has the autoCommit flag set to "true". which
means all the updates in the SQLMAP
	on this connection would be automatically commited. Ideally, it
should call OracleXADataSource's
	getXAConnection().getConnection() as the connection and allow
the outsider ( the code which use sqlmap)
	to access the XAConnection, then we can use the XAResource to
manage the transaction ourselves.

	2. call the setUserConnection() function to manually set the
connection. In this case, It still
	uses the connection configured from the sqlmapConfig.xml by
calling dataSource.getConnection() in
	the init() in class ExternalTransaction, and did not take the
connection we set via the setUserConnection().
	Here is what in the code (we use the same sqlmapConfig.xml file)
		XAConnection cx = oxds.getXAConnection();
		java.sql.Connection dbCon = cx.getConnection();
	When we trace the setUserConnection() method, we found out that,
at the end of day, it creates a new
	instance of transaction with class like
"UserProvidedTransaction". Somehow, this new transaction is
	not used but it is still uses the original ExternalTransaction
	If SQLMAP use the connection we set, we can manage the
transaction ourselves because this connection we
	get is from the XAConnection and with the XAConnection we can
get the XAResource, then we can use the
	TransactionManager to manage all the transactions.

We did try different ways, but it still does not work. For example,
remove the <dataSource> element from the sqlmapConfig.xml,
it cause the XML parse error. Use the SIMPLE data source type, it still
did not take the connection we manually
set via call setUserConnection().

We already exhausted, If you can show us some light to solve this
problem It would be very appreciated.

Jin Wang
Directory Technology
Phone: +61-3-9835 0016 email: jwang@sensis.com.au

The information contained in this message is proprietary of DIT,
protected from disclosure, and may be privileged. The information is
intended to be conveyed only to the designated recipient/s of the
message. If the reader of this message is not the intended recipient,
you are hereby notified that any dissemination, use, distribution or
copying of this communication is strictly prohibited and may be
unlawful. If you have received this communication in error, please
notify us immediately by replying to the message and deleting it from
your computer. Thank you.

A leading Australian advertising, information and directories business.
This email and any attachments are intended only for the use of the recipient and may be confidential
and/or legally privileged.
Sensis Pty Ltd disclaims liability for any errors, omissions, viruses, loss and/or damage
arising from using, opening or transmitting this email.
If you are not the intended recipient you must not use, interfere with, disclose, copy or
retain this email and you should notify the sender immediately by return email or by contacting
Sensis Pty Ltd by telephone on [+61 3 8653 5000]
View raw message