You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user-java@ibatis.apache.org by "Elangovan, Kumaravel" <ku...@fmr.com> on 2007/07/30 09:24:24 UTC

programmatic transaction management in ibatis

Hi,

We would like to implement programmatic transaction management in one
action class of our application (spring with ibatis SQL maps) as it
involves in updation of two tables.

current SqlMapConfig.properties is

	<transactionManager commitRequired="true" type="JDBC">         
		<dataSource type="JNDI">
			<property name="DataSource"
value="${datasourcename}"/>         
		</dataSource>     
	</transactionManager>

and dao.xml is

<daoConfig>
	<!-- Example SQL Maps DAO Configuration -->
	<context>
		<transactionManager type="SQLMAP">
			<property name="SqlMapConfigResource"
value="ibatis/FsaPlusAdmin/SqlMapConfig.xml" />
		</transactionManager>
		<dao interface="name of the interface"
implementation="name of the implementation" />
</context>
</daoConfig>

We want transaction to be remanin default except in that action
class(Here transaction has to be rolled back if updation of 1st table
fails).

As I am new to ibatis, could anyone please explain how to configure
external transaction and to use that in the action class.

Regards,
kumar

RE: programmatic transaction management in ibatis

Posted by "Elangovan, Kumaravel" <ku...@fmr.com>.
Hi All,
 
Thanks for your help. We have implemented it using ibatis dao manager.
daoManager.startTransaction();
daoManager.commitTransaction();
daoManager.endTransaction(); 
 Its working fine.
 
Regards,
Kumar


  _____  

	From: Andrey Rogov [mailto:andrey.rogov@gmail.com] 
	Sent: Tuesday, July 31, 2007 2:22 PM
	To: user-java@ibatis.apache.org
	Subject: Re: programmatic transaction management in ibatis
	
	
	Kumar, may be this should help.
	programmatic transaction management method -
	 
	import
org.springframework.transaction.PlatformTransactionManager ;
	
	import org.springframework.transaction.TransactionDefinition ;
	import org.springframework.transaction.TransactionStatus ;
	import
org.springframework.transaction.DefaultTransactionDefinition ;
	 
	 
	private PlatformTransactionDefinition transactionManager ;
	 
	private TransactionDefinition getDefinition( int isolationLevel)
{
	      DefaultTransactionDefinition def = new
DefaultTransactionDefinition(
TransactionDefinition.PROPAGATION_REQUIRED) ; 
	      def.setIsolationLevel(isolationLevel) ;
	      return def ;
	}
	 
	public void insert( Parameterobject object ) {
	      TransactionStatus status =
transactionManager.getTransaction(
getDefinition(TransactionDefinition.ISOLATION_READ_COMMITED)) ;
	       try {
	                insert( object  ) ;
	                transactionManager.commit(status) ;
	       }
	        catch ( Throwable t ){
	                transactionManager.rollback(status) ;
	       }
	  }
	 
	 
	 


	 
	2007/7/30, Elangovan, Kumaravel <ku...@fmr.com>: 


		Hi, 

		We would like to implement programmatic transaction
management in one action class of our application (spring with ibatis
SQL maps) as it involves in updation of two tables.

		current SqlMapConfig.properties is 

		        <transactionManager commitRequired="true"
type="JDBC">         
		                <dataSource type="JNDI"> 
		                        <property name="DataSource"
value="${datasourcename}"/>         
		                </dataSource>     
		        </transactionManager> 

		and dao.xml is 

		<daoConfig> 
		        <!-- Example SQL Maps DAO Configuration --> 
		        <context> 
		                <transactionManager type="SQLMAP"> 
		                        <property
name="SqlMapConfigResource" value="ibatis/FsaPlusAdmin/SqlMapConfig.xml"
/> 
		                </transactionManager> 
		                <dao interface="name of the interface"
implementation="name of the implementation" /> 
		</context> 
		</daoConfig> 

		We want transaction to be remanin default except in that
action class(Here transaction has to be rolled back if updation of 1st
table fails).

		As I am new to ibatis, could anyone please explain how
to configure external transaction and to use that in the action class.

		Regards, 
		kumar 



Re: programmatic transaction management in ibatis

Posted by Andrey Rogov <an...@gmail.com>.
Kumar, may be this should help.
programmatic transaction management method -

import org.springframework.transaction.PlatformTransactionManager ;
 import org.springframework.transaction.TransactionDefinition ;
 import org.springframework.transaction.TransactionStatus ;
 import org.springframework.transaction.DefaultTransactionDefinition ;


private PlatformTransactionDefinition transactionManager ;

private TransactionDefinition getDefinition( int isolationLevel) {
      DefaultTransactionDefinition def = new  DefaultTransactionDefinition(
TransactionDefinition.PROPAGATION_REQUIRED) ;
      def.setIsolationLevel(isolationLevel) ;
      return def ;
}

public void insert( Parameterobject object ) {
      TransactionStatus status = transactionManager.getTransaction(
getDefinition(TransactionDefinition.ISOLATION_READ_COMMITED)) ;
       try {
                insert( object  ) ;
                transactionManager.commit(status) ;
       }
        catch ( Throwable t ){
                transactionManager.rollback(status) ;
       }
  }






2007/7/30, Elangovan, Kumaravel <ku...@fmr.com>:
>
>
> Hi,
>
> We would like to implement programmatic transaction management in one
> action class of our application (spring with ibatis SQL maps) as it involves
> in updation of two tables.
>
> current* SqlMapConfig.properties* is
>
>         <transactionManager commitRequired="true" type="JDBC">
>                 <dataSource type="JNDI">
>                         <property name="DataSource"
> value="${datasourcename}"/>
>                 </dataSource>
>         </transactionManager>
>
> and* dao.xml* is
>
> <daoConfig>
>         <!-- Example SQL Maps DAO Configuration -->
>         <context>
>                 <transactionManager type="SQLMAP">
>                         <property name="SqlMapConfigResource"
> value="ibatis/FsaPlusAdmin/SqlMapConfig.xml" />
>                 </transactionManager>
>                 <dao interface="name of the interface"
> implementation="name of the implementation" />
> </context>
> </daoConfig>
>
> We want transaction to be remanin default except in that action class(Here
> transaction has to be rolled back if updation of 1st table fails).
>
> As I am new to ibatis, could anyone please explain how to configure
> external transaction and to use that in the action class.
>
> Regards,
> kumar
>

Re: programmatic transaction management in ibatis

Posted by Andrey Rogov <an...@gmail.com>.
Hi,
To better understand how to work with declarative transactions spring +
ibatis look at two samples. 1. - Ibm developers works shows how to apply
AOP method.
http://www.ibm.com/developerworks/search/searchResults.jsp?searchType=1&searchSite=dW&searchScope=dW&query=SPRING
apache geronimo & spring framework *Part 4: Throwing Spring AOP and Spring
Web Flow into the mix*

2. - and without AOP - jPetStore sample spring + ibatis on the spring site /


regards, Andrey



2007/7/30, Elangovan, Kumaravel <ku...@fmr.com>:
>
>
> Hi,
>
> We would like to implement programmatic transaction management in one
> action class of our application (spring with ibatis SQL maps) as it involves
> in updation of two tables.
>
> current* SqlMapConfig.properties* is
>
>         <transactionManager commitRequired="true" type="JDBC">
>                 <dataSource type="JNDI">
>                         <property name="DataSource"
> value="${datasourcename}"/>
>                 </dataSource>
>         </transactionManager>
>
> and* dao.xml* is
>
> <daoConfig>
>         <!-- Example SQL Maps DAO Configuration -->
>         <context>
>                 <transactionManager type="SQLMAP">
>                         <property name="SqlMapConfigResource"
> value="ibatis/FsaPlusAdmin/SqlMapConfig.xml" />
>                 </transactionManager>
>                 <dao interface="name of the interface"
> implementation="name of the implementation" />
> </context>
> </daoConfig>
>
> We want transaction to be remanin default except in that action class(Here
> transaction has to be rolled back if updation of 1st table fails).
>
> As I am new to ibatis, could anyone please explain how to configure
> external transaction and to use that in the action class.
>
> Regards,
> kumar
>

Re: programmatic transaction management in ibatis

Posted by Chris Lamey <cl...@localmatters.com>.
Hello,

I'm confused, can't you just code in the transaction support in the
class you want and not in the others?  Or have you done that already and
it's not working?

BTW, I would strongly suggest you don't go the programmatic transaction
route and instead use Spring's declarative transactions.

Cheers,
Chris

On Mon, 2007-07-30 at 12:54 +0530, Elangovan, Kumaravel wrote:
> 
> Hi,
> 
> We would like to implement programmatic transaction management in one
> action class of our application (spring with ibatis SQL maps) as it
> involves in updation of two tables.
> 
> current SqlMapConfig.properties is
> 
>         <transactionManager commitRequired="true"
> type="JDBC">          
>                 <dataSource type="JNDI"> 
>                         <property name="DataSource"
> value="${datasourcename}"/>          
>                 </dataSource>      
>         </transactionManager>
> 
> and dao.xml is
> 
> <daoConfig> 
>         <!-- Example SQL Maps DAO Configuration --> 
>         <context> 
>                 <transactionManager type="SQLMAP"> 
>                         <property name="SqlMapConfigResource"
> value="ibatis/FsaPlusAdmin/SqlMapConfig.xml" /> 
>                 </transactionManager> 
>                 <dao interface="name of the interface"
> implementation="name of the implementation" /> 
> </context> 
> </daoConfig>
> 
> We want transaction to be remanin default except in that action
> class(Here transaction has to be rolled back if updation of 1st table
> fails).
> 
> As I am new to ibatis, could anyone please explain how to configure
> external transaction and to use that in the action class.
> 
> Regards, 
> kumar
>