Announcement Announcement Module
Collapse
No announcement yet.
question about transaction Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • question about transaction

    Hello.. I'm a regular user of SpringFramework and have already done some small projects for my company using Spring + iBatis..

    I am using declarative transaction demarcation like this in the web app context:

    Code:
    	<bean id="ekaDataSource" class="org.apache.commons.dbcp.datasources.SharedPoolDataSource">
    		<property name="connectionPoolDataSource">
    			<bean class="org.apache.commons.dbcp.cpdsadapter.DriverAdapterCPDS">
    			<property name="driver"><value>${jdbc.driver}</value></property>
    			<property name="url"><value>${jdbc.url}</value></property>
    			<property name="user"><value>${jdbc.user}</value></property>
    			<property name="password"><value>${jdbc.password}</value></property>
    			</bean>
    		</property>
    		<property name="maxActive"><value>0</value></property>
    		<property name="maxWait"><value>50</value></property>
    		<property name="maxIdle"><value>10</value></property>
    		<property name="defaultAutoCommit"><value>false</value></property>
    	</bean>
    
    	<bean id="ekatestTransactionManager" class="org.springframework.jdbc.datasource.DataSourceTransactionManager">
    	<property name="dataSource">
    			<ref bean="ekaDataSource"/>
    	</property>
    	</bean>
    
    	<bean id="parentManager" class="org.springframework.transaction.interceptor.TransactionProxyFactoryBean" abstract="true">
    	<property name="transactionManager"><ref bean="ekatestTransactionManager"/></property>
    	<property name="transactionAttributes">
    	    <props>
    		<prop key="*.insert*">PROPAGATION_REQUIRED,-DataAccessException</prop>
    		<prop key="*.update*">PROPAGATION_REQUIRED,-DataAccessException</prop>
    		<prop key="*.delete*">PROPAGATION_REQUIRED,-DataAccessException</prop>
    		<prop key="*.*Counter*">PROPAGATION_NESTED,-DataAccessException</prop> 
    		<prop key="*">PROPAGATION_REQUIRED,readOnly</prop>
    	    </props>
    	</property>
    	</bean>
    
    	<bean id="parentDao" abstract="true">
    		<property name="dataSource"><ref bean="ekaDataSource"/></property>
    		<property name="sqlMapClient">
    		    <bean class="org.springframework.orm.ibatis.SqlMapClientFactoryBean">
    		        <property name="configLocation">
    		            <value>WEB-INF/sql-map-config.xml</value>
    		        </property>
    		    </bean>
    		</property>  
    	</bean>
    
    	<bean id="uwManager" parent="parentManager">
    		<property name="target">
    			    <bean class="service.UwManager">
    				<property name="uwDao">
    					    <bean class="dao.UwDao" parent="parentDao" /> 
    					</property>
    			    </bean>	
    		</property>
    	</bean>
    and my dao:

    Code:
    public class UwDao extends SqlMapClientDaoSupport {
    	public String selectGetCounter(int aplikasi, String cabang) {
    		Map params = new HashMap();
    		params.put("aplikasi", new Integer(aplikasi));
    		params.put("cabang", cabang);
    		return (String) querySingle("selectGetCounter", params);
    	}
    }
    and my facade:

    Code:
    public class UwManager {
    	private UwDao uwDao;
    
    	public void setUwDao(UwDao uwDao) {
    		this.uwDao = uwDao;
    	}
    
    	public void someTransaction(){
    		String a = this.uwDao.selectGetCounter(1,"test");
    		//.. update something
    		//.. insert something
    		someNestedTransaction();
    		//.. delete something
    	}
    
    	public void someNestedTransaction(){
    		//.. update something
    		//.. insert something		
    	}
    1. The function selectGetCounter in the DAO is used to retrieve a manual sequence from a table, so to prevent duplication of sequence, I needed to commit that statement, but not the others (in one transaction).. is there a way to do this?
    2. I have a function someNestedTransaction() that is used within another transaction.. is it okay with this? (I need to rollback the entire transaction if the nested transaction encountered an exception..)
    3. In some projects, I have to combine an application that is already developed using basic jsp+servlet+jdbc and with spring+ibatis, can I combine transactions between basic jdbc and spring+ibatis? (because right now we dont have enough time to convert the entire old application to spring+ibatis..) for example maybe like this:

    Code:
    	try{
    	    DBCPBean cBean = (DBCPBean) context.getAttribute("connectionBean");
    	    con = cBean.getConnection();
    	    con.setAutoCommit(false);
    	    st = con.createStatement();
    	    rs = st.execute("some insert statement..");
    	    rs = st.execute("some update statement..");
    	    rs = st.execute("some delete statement..");
    
    	    uwManager.someTransaction(); //I want to use some functions in the uwManager facade to be a nested transactions in the old application
    
    	    rs = st.execute("some update statement..");
    	    rs = st.execute("some delete statement..");
    	
    	    con.commit();
    	} catch (Exception ex) {
    		con.rollback();
    		//.. close con, st, rs
    	}
    4. Can i programmatically rollback or commit in a transaction using declarative transaction demarcation? for example i want like this:

    Code:
    	public void someTransaction(){
    		String a = this.uwDao.selectGetCounter(1,"test");
    		//.. update something
    		//.. insert something
    		isError = someNestedTransaction();
    		//.. delete something
    		if(isError) rollback();
    		//.. update something
    		//.. insert something
    	}
    I already read in books like SpringLive and Proff Java Development with the SpringFramework but I cant seem to find some solutions to the question no. 3.. is there any way to do this?

    thank you for your help

  • #2
    hello.. I'm sorry if this question is stupid or something like that.. but I hope there's someone that can help me with this because i have a trouble understanding the concept about this.. thank you

    Comment

    Working...
    X