2012-12-05 1 views
0

Spring Ibatis DAO 구현 클래스에서 트랜잭션을 작성하는 방법.Spring ibatis의 DAO 클래스에서 트랜잭션을 작성하는 방법

일괄 처리 update.But에 다음 코드를 사용하고 있습니다. 200 레코드를 업데이트하는 데 10 초 이상 걸립니다. Google에서 검색 한 결과이 일괄 업데이트에서 트랜잭션을 구현하면 작업 속도가 빨라진다는 것을 알았습니다.

내 일괄 업데이트 코드 (클래스 SensorValueLastBeanDAOImpl에서)이 같다

public int processBatchUpdate(
     final List<SensorValueLastBean> sensorValueLast) { 

    Integer updateCount = 0; 
    try { 


     updateCount = (Integer) getSqlMapClientTemplate().execute(
       new SqlMapClientCallback<Object>() { 
        public Object doInSqlMapClient(SqlMapExecutor executor) 
          throws SQLException {           
         executor.startBatch(); 
         Iterator<SensorValueLastBean> iter = sensorValueLast 
           .iterator(); 
         while (iter.hasNext()) { 
          executor.update(
            "sensor_values_last.ibatorgenerated_updateByPrimaryKeySelective", 
            iter.next()); 
         } 
                        executor.executeBatch(); 
         return new Integer(executor.executeBatch()); 

        } 
       }); 
    } catch (Exception e) { 
     e.printStackTrace(); 
    } 

} 

난 getSqlMapClient().의 startTransaction()이 함수는 같은 에러가 표시되고 사용할 때 아래

com.ibatis.sqlmap.engine.impl.SqlMapSession에서 com.ibatis.sqlmap.engine.impl.SqlMapExecutorDelegate.startTransaction (SqlMapExecutorDelegate.java:684)
에서 java.lang.NullPointerException이 어떤 트랜잭션 관리자가 없기 때문에 Impl.startTransaction (SqlMapSessionImpl.java:164) com.ibatis.sqlmap.engine.impl.SqlMapClientImpl.startTransaction에서
(SqlMapClientImpl.java:140는)

답변

0

두 번째 오류가 발생했습니다 ibatis. 다음과 같이 구성 할 수 있습니다.

<!DOCTYPE sqlMapConfig 
PUBLIC "-//ibatis.apache.org//DTD SQL Map Config 2.0//EN" 
"http://ibatis.apache.org/dtd/sql-map-config-2.dtd"> 

<sqlMapConfig> 
    <settings useStatementNamespaces="true"/> 
    <transactionManager type="JDBC"> 
     <dataSource type="SIMPLE"> 
     <property name="JDBC.Driver" value="com.mysql.jdbc.Driver"/> 
     <property name="JDBC.ConnectionURL" 
     value="jdbc:mysql://localhost:3306/mydb"/> 
     <property name="JDBC.Username" value="root"/> 
     <property name="JDBC.Password" value="root"/> 
    </dataSource> 
</transactionManager> 
<sqlMap resource="Contact.xml"/>