Results 1 to 5 of 5

Thread: Does spring have a plan to support iBATIS batch execution?

  1. #1
    Join Date
    Aug 2004
    Posts
    2

    Default Does spring have a plan to support iBATIS batch execution?

    Has anyone done iBATIS 2.0 batch execution on spring before?
    Looks like there is no code about it in org.springframework.orm.ibatis.SqlMapClientTemplat e in 1.1 RC2 distribution.

    To do it, I am using my own classes extended spring iBatis related classes.
    But if there is plan, please let me know. I don't want to use my own version for my project.

    --- Here is a snippet of my codes. ---
    Code:
    public Object batchExecute(List parameterObject, SqlMapClientBatchExecuteCallback action) throws DataAccessException
    {
      SqlMapSession session = getSqlMapClient().openSession();
      try {
        Connection con = DataSourceUtils.getConnection(getDataSource());
        try {
          session.setUserConnection(con);
    
          session.startBatch();
          Iterator detailListIte = parameterObject.iterator();
          while (detailListIte.hasNext()) {
            Object entry = detailListIte.next();
            action.doBatchInSqlMapClient(session, entry);
          }
          return new Integer(session.executeBatch());
    
        } catch (SQLException ex) {
          throw getExceptionTranslator().translate("SqlMapClientTemplate.batchExecute", "(mapped statement)", ex);
        } finally {
          DataSourceUtils.closeConnectionIfNecessary(con, getDataSource());
        }
      } finally {
        session.close();
      }
    }
    
    public Object batchInsert(final String statementName, final List parameterObject)
      throws DataAccessException
    {
      return batchExecute(parameterObject, new SqlMapClientBatchExecuteCallback()
      {
        public Object doBatchInSqlMapClient(SqlMapExecutor executor, Object entry) throws SQLException
        {
          return executor.insert(statementName, entry);
        }
      });
    }
    public Object batchUpdate....
    Regards,
    Tak

  2. #2
    Join Date
    Aug 2004
    Location
    Toronto, Canada
    Posts
    736

    Default

    Tak,

    Why can't you just do:

    Code:
    		getSqlMapClientTemplate().execute(new SqlMapClientCallback() {
    			public Object doInSqlMapClient(SqlMapExecutor executor)
    					throws SQLException {
    				executor.startBatch();
    				// do some iBatis operations here
    				executor.executeBatch();
    				return null;
    			}
    		});
    I'm not clear on how usage of your batchExecute method would be much shorter or more convenient...
    Colin Sampaleanu
    SpringSource - http://www.springsource.com

  3. #3

    Default

    These are two examples of the actual code in our app using iBatis batch.




    Code:
    public void insertUserRolesById(final List lst, final String user_id) {
    
    		getSqlMapClientTemplate().execute(new SqlMapClientCallback() {
    			public Object doInSqlMapClient(SqlMapExecutor executor) throws SQLException {
    				Iterator itr = lst.iterator();
    				
    				executor.startBatch();
    				executor.delete("Users.deleteUserRolesById", user_id);
    				while (itr.hasNext()) {
    					HashMap m = (HashMap) itr.next();
    					executor.insert("Users.insertUserRolesById", m);
    				}
    
    				int rowsaffected = executor.executeBatch();
    				
    				logger.info("rows afftected by insertUserRolesById: " + rowsaffected);
    
    				return new Integer(rowsaffected);
    			}
    		});
    
    	}

    Code:
    public void updateElement(final MWDomain fbo) {
    
    		getSqlMapClientTemplate().execute(new SqlMapClientCallback() {
    			public Object doInSqlMapClient(SqlMapExecutor executor) throws SQLException {
    
    				executor.startBatch();
    
    				executor.update("AuthMaint.updateConEditionStatus", fbo.getUpdateContentEdition());
    				executor.update("AuthMaint.updateCatExtendName", fbo.getUpdateCatExtendName());
    
    				Iterator itr = fbo.getContentEdition().iterator();
    				while (itr.hasNext())
    					executor.insert("AuthMaint.insertContentEdition", ((HashMap) itr.next()));
    
    				itr = fbo.getRepItem().iterator();
    				while (itr.hasNext())
    					executor.insert("AuthMaint.insertRepItem", ((HashMap) itr.next()));
    
    				itr = fbo.getDocMap().iterator();
    				while (itr.hasNext())
    					executor.insert("AuthMaint.insertDocMap", ((HashMap) itr.next()));
    
    				int rowsaffected = executor.executeBatch();
    				logger.info("rows afftected by updateFamily: " + rowsaffected);
    
    				return null;
    			}
    		});
    
    	}

  4. #4
    Join Date
    Aug 2004
    Posts
    2

    Default

    Thanks Colin,
    You saved my life.

    Tak

  5. #5
    Join Date
    Oct 2008
    Posts
    286

    Default

    the below update batch was successfully executed and the DB data was changed but the rowsaffected value still zero..

    any inputs from the community... highly appreciated..

    thanks

    Code:
    		getSqlMapClientTemplate().execute(new SqlMapClientCallback() {
    			public Object doInSqlMapClient(SqlMapExecutor executor) throws SQLException {
    				Iterator<TSimHyotaku> itr = records.iterator();
    				
    				executor.startBatch();
    				while (itr.hasNext()) {
    					TSimHyotaku record = itr.next();
    					executor.update("SDE_T_SIM_HYOTAKU.ibatorgenerated_updateByPrimaryKey", record);
    				}
    
    				int rowsaffected = executor.executeBatch();
    				
    				logger.info("rows afftected: " + rowsaffected);
    
    				return new Integer(rowsaffected);
    			}
    		});
    Eros

    Environment:
    JSP 2.0
    Dojo 1.4.1
    Ext JS 3.1 (testing)
    Spring MVC 2.5.6.SEC01 (planning to Spring 3 using STS)
    STS
    SWF 2.0.9.RELEASE
    Tiles 2.0.5
    iBatis: ibatis-sqlmap-2.3.4.726

Similar Threads

  1. Replies: 1
    Last Post: Jul 3rd, 2005, 04:08 PM
  2. New Spring Support Forums are Live
    By Colin Sampaleanu in forum Announcements
    Replies: 17
    Last Post: May 22nd, 2005, 12:57 AM
  3. Announcement: Spring IDE WebFlow Support Preview Release 1
    By Christian Dupuis in forum Announcements
    Replies: 0
    Last Post: May 20th, 2005, 08:15 PM
  4. Spring code remarks
    By Alarmnummer in forum Architecture
    Replies: 18
    Last Post: Apr 7th, 2005, 07:17 AM
  5. Replies: 14
    Last Post: Feb 21st, 2005, 05:41 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •