Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
  /*
   * Copyright 2006-2008 the original author or authors.
   *
   * Licensed under the Apache License, Version 2.0 (the "License");
   * you may not use this file except in compliance with the License.
   * You may obtain a copy of the License at
   *
   *      http://www.apache.org/licenses/LICENSE-2.0
   *
  * Unless required by applicable law or agreed to in writing, software
  * distributed under the License is distributed on an "AS IS" BASIS,
  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  * See the License for the specific language governing permissions and
  * limitations under the License.
  */
 
 package org.springframework.batch.item.database;
 
 
 import java.util.Map;
 
 import  com.ibatis.sqlmap.client.SqlMapClient;

org.springframework.batch.item.ItemReader for reading database records using iBATIS in a paging fashion.

It executes the query specified as the setQueryId(String) to retrieve requested data. The query is executed using paged requests of a size specified in setPageSize(int). Additional pages are requested when needed as read() method is called, returning an object corresponding to current position. Some standard query parameters are provided by the reader and the SQL in the named query must use some or all of these parameters (depending on the SQL variant) to construct a result set of the required size. The parameters are:

  • _page: the page number to be read (starting at 0)
  • _pagesize: the size of the pages, i.e. the number of rows to return
  • _skiprows: the product of _page and _pagesize
Failure to write the correct platform-specific SQL often results in an infinite loop in the reader because it keeps asking for the next page and gets the same result set over and over.

The performance of the paging depends on the iBATIS implementation. Setting a fairly large page size and using a commit interval that matches the page size should provide better performance.

The implementation is thread-safe in between calls to open(ExecutionContext), but remember to use saveState=false if used in a multi-threaded client (no restart available).

Author(s):
Thomas Risberg
Dave Syer
Since:
2.0
 
 public class IbatisPagingItemReader<T> extends AbstractPagingItemReader<T> {
 
 	private SqlMapClient sqlMapClient;
 
 	private String queryId;
 
 
 
 	public IbatisPagingItemReader() {
 	}
 
 	public void setSqlMapClient(SqlMapClient sqlMapClient) {
 		this. = sqlMapClient;
 	}
 
 	public void setQueryId(String queryId) {
 		this. = queryId;
 	}

The parameter values to be used for the query execution.

Parameters:
parameterValues the values keyed by the parameter named used in the query string.
	public void setParameterValues(Map<StringObjectparameterValues) {
		this. = parameterValues;
	}

Check mandatory properties.

See also:
org.springframework.beans.factory.InitializingBean.afterPropertiesSet()
	public void afterPropertiesSet() throws Exception {
	}
	@SuppressWarnings("unchecked")
	protected void doReadPage() {
		Map<StringObjectparameters = new HashMap<StringObject>();
		if ( != null) {
		}
		parameters.put("_page"getPage());
		parameters.put("_pagesize"getPageSize());
		parameters.put("_skiprows"getPage() * getPageSize());
		if ( == null) {
		}
		else {
		}
	}
	protected void doJumpToPage(int itemIndex) {
	}
New to GrepCode? Check out our FAQ X