Page 2 of 2 FirstFirst 12
Results 11 to 15 of 15

Thread: some class that I needed.

  1. #11
    Join Date
    Oct 2008
    Posts
    18

    Default

    sorry, only now i see that in my first post i did mention item reader,
    my mistake. ment to ask about iBatis item writer..

  2. #12
    Join Date
    Jun 2005
    Posts
    4,241

    Default

    We haven't got any database ItemWriters right now because they are often quite application specific, and the ItemWriter interface is hard to get wrong - you just update the database (business specific) and don't really have to worry about anything else (transactions, restartability etc.). If you have a proposal for some features of an iBatis writer that make it generic and add some value over just implementing the interface we could look at including those.

  3. #13
    Join Date
    Oct 2008
    Posts
    18

    Default

    could add value just the same as BatchSqlUpdateItemWriter does.

    Code:
    public class BatchIbatisUpdateItemWriter<T> implements ItemWriter<T>, InitializingBean {
    
           ...
    
    	public void write(final List<? extends T> items) throws Exception {
    
    		if (!items.isEmpty()) {
    
    			int[] values = (int[]) sqlMapClientTemplate.execute(new SqlMapClientCallback() {
    				public Object doInSqlMapClient(SqlMapExecutor executor) throws SQLException {					
    					executor.startBatch();
    					for (T item : items) {
    						executor.insert(queryId, item);
    					}					
    					List<BatchResult> detailed;
    					try {
    						detailed = executor.executeBatchDetailed();
    					} catch (BatchException e) {
    						throw new SQLException(e.getMessage() + " statement id:"+e.getFailingStatementId() + ", sql:"+e.getFailingSqlStatement() + ", batch exception:"+e.getBatchUpdateException());
    					}
    					return detailed.get(0).getUpdateCounts();					
    				}
    			});
    			
    			if (assertUpdates) {
    				for (int i = 0; i < values.length; i++) {
    					int value = values[i];
    					if (value == 0) {
    						throw new EmptyResultDataAccessException("Item " + i + " of " + values.length
    								+ " did not update any rows: [" + items.get(i) + "]", 1);
    					}
    				}
    			}
    
    		}
    
    	}
    
           ...
    
    }

  4. #14
    Join Date
    Jun 2005
    Posts
    4,241

    Default

    I see. If you sling that in a JIRA we can probably get it into 2.0 (especially if there is a test case).

  5. #15
    Join Date
    Oct 2008
    Posts
    18

Posting Permissions

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