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

  • transaction of batch update

    I'm writing a bulk update function for my application, but have encountered some transaction problems.

    First, I have defined a BatchDAO for the data access, snippet

    Code:
    public BatchDAOJdbc extends JdbcDAOSupport 
            implements BatchDAO {
    
        public int batchUpdate(String str) {
            return getJdbcTemplate().update(str);
        }
    
    }
    And then, I defined a service to make use of the BatchDAO, snippet ...
    Code:
    public BatchUpdateManagerImpl extends BaseManagerImpl 
            implements BatchUpdateManager {
    
        BatchDAO dao;
        public void setBatchDAO(BatchDAO dao) {
            this.dao = dao;
        }
    
        public int batchUpdateCommitOnError(String str) {
            return dao.batchUpdate(str);
        }
    
        public int batchUpdateRollbackOnError(String str) {
            return dao.batchUpdate(str);
        }
    
        public int batchUpdateSimulate(String str) {
            return dao.batchUpdate(str);
        }
    
    }
    and the applicationContext.xml ...
    Code:
    	
    <beans>
    	
        <bean id="propertyConfigurer" class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">
            <property name="locations">
                <list>
                    <value>classpath&#58;database.properties</value>
                </list>
            </property>
        </bean>
    	
    	<bean id="dataSource" class="org.apache.commons.dbcp.BasicDataSource" destroy-method="close">
    		<property name="driverClassName">
    			<value>$&#123;jdbc.driverClassName&#125;</value>
    		</property>
    		<property name="url">
    			<value>$&#123;jdbc.url&#125;</value>
    		</property>
    		<property name="username">
    			<value>$&#123;jdbc.username&#125;</value>
    		</property>
    		<property name="password">
    			<value>$&#123;jdbc.password&#125;</value>
    		</property>
    	</bean>
    
        <bean id="jdbcTransactionManager" class="org.springframework.jdbc.datasource.DataSourceTransactionManager">
            <property name="dataSource"><ref bean="dataSource"/></property>
        </bean>
    
        <bean id="jdbcTxProxyTemplate" abstract="true"        class="org.springframework.transaction.interceptor.TransactionProxyFactoryBean">
            <property name="transactionManager"><ref bean="jdbcTransactionManager"/></property>
            <property name="transactionAttributes">
                <props>
                    <prop key="save*">PROPAGATION_REQUIRED</prop>
                    <prop key="remove*">PROPAGATION_REQUIRED</prop>
                    <prop key="*">PROPAGATION_REQUIRED,readOnly</prop>
                </props>
            </property> 
        </bean>
    	
    	<bean id="batchUpdateManager" parent="jdbcTxProxyTemplate">
            <property name="target">
                <bean class="my.service.BatchUpdateManagerImpl">
                    <property name="batchDAO"><ref bean="batchDAO"/></property>
                </bean>
            </property>
    		<!-- Override default transaction attributes -->
            <property name="transactionAttributes">
                <props>
                    <prop key="batchUpdateSimulate*">PROPAGATION_NEVER</prop>
                    <prop key="batchUpdateCommitOnError*">PROPAGATION_REQUIRED</prop>
                    <prop key="batchUpdateRollbackOnError*">PROPAGATION_REQUIRED,-Exception</prop>
                </props>
            </property>
        </bean>
    
        <bean id="batchDAO" class="my.BatchDAOJdbc">
          <property name="dataSource">
            <ref bean="dataSource"/>
          </property>
        </bean>
    </beans>
    batchUpdateSimulate is intended to simulate running SQL once but will not commit any change
    batchUpdateCommitOnError runs the SQL and commit the previous change if there is any ongoing error
    batchUpdateRollbackOnError run the SQL and rollback if there is any ongoing error

    First Question ..
    I would like to know can I use to PROPOGATION_NEVER to acomplish the simulate function , if not , how could I do this ??

    Second Question ..
    I can't achieve the commit on error function.Suppose there are 10 SQL to run, and middle part of SQL is invalid. I expect that the first running SQL can be commit, but it was not. Is there any problem in my applicationContext.xml ??

    I'm apperciate to get some advices here , many thanks !
Working...
X