Removed abstract parent classes for builders

The abstract classes used for the parents of the builders.  Their use
caused odd generic issues with the API.  This reverts that change.
This commit is contained in:
Michael Minella
2017-07-17 22:06:03 -05:00
parent f2fcbfe2a8
commit d1f7dd0215
15 changed files with 745 additions and 163 deletions

View File

@@ -1,62 +0,0 @@
/*
* Copyright 2017 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.builder;
import org.springframework.batch.item.ExecutionContext;
import org.springframework.batch.item.support.AbstractItemCountingItemStreamItemReader;
/**
* Abstract superclass for builders that create streams that support restart by storing
* item count in the {@link ExecutionContext} (therefore requires item ordering to be
* preserved between runs).
*
* @author Glenn Renfro
*
* @since 4.0
*/
public abstract class AbstractItemCountingItemStreamItemReaderBuilder<T> extends AbstractItemStreamSupportBuilder<T> {
protected int currentItemCount = 0;
protected int maxItemCount = Integer.MAX_VALUE;
/**
* Configure the max number of items to be read.
*
* @param maxItemCount the max items to be read
* @return The current instance of the builder.
* @see AbstractItemCountingItemStreamItemReader#setMaxItemCount(int)
*/
public T maxItemCount(int maxItemCount) {
this.maxItemCount = maxItemCount;
return (T) this;
}
/**
* Index for the current item. Used on restarts to indicate where to start from.
*
* @param currentItemCount current index
* @return this instance for method chaining
* @see AbstractItemCountingItemStreamItemReader#setCurrentItemCount(int)
*/
public T currentItemCount(int currentItemCount) {
this.currentItemCount = currentItemCount;
return (T) this;
}
}

View File

@@ -1,57 +0,0 @@
/*
* Copyright 2017 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.builder;
import org.springframework.batch.item.ItemStreamSupport;
/*
* Abstract superclass for builders that create streams that utilize {@link ItemStreamSupport}.
* @author Glenn Renfro
*
* @since 4.0
*/
public class AbstractItemStreamSupportBuilder<T> {
protected String name;
protected boolean saveState = true;
/**
* The name used to calculate the key within the
* {@link org.springframework.batch.item.ExecutionContext}. Required if
* {@link AbstractItemStreamSupportBuilder#saveState(boolean)} is set to true.
*
* @param name name of the reader instance
* @return The current instance of the builder.
* @see ItemStreamSupport#setName(String)
*/
public T name(String name) {
this.name = name;
return (T) this;
}
/**
* Configure if the state of the {@link ItemStreamSupport} should be persisted within
* the {@link org.springframework.batch.item.ExecutionContext} for restart purposes.
*
* @param saveState defaults to true
* @return The current instance of the builder.
*/
public T saveState(boolean saveState) {
this.saveState = saveState;
return (T) this;
}
}

View File

@@ -19,7 +19,6 @@ package org.springframework.batch.item.data.builder;
import java.util.List;
import java.util.Map;
import org.springframework.batch.item.builder.AbstractItemCountingItemStreamItemReaderBuilder;
import org.springframework.batch.item.data.MongoItemReader;
import org.springframework.data.domain.Sort;
import org.springframework.data.mongodb.core.MongoOperations;
@@ -32,8 +31,7 @@ import org.springframework.util.Assert;
* @since 4.0
* @see MongoItemReader
*/
public class MongoItemReaderBuilder<T>
extends AbstractItemCountingItemStreamItemReaderBuilder<MongoItemReaderBuilder<T>> {
public class MongoItemReaderBuilder<T> {
private MongoOperations template;
private String query;
@@ -52,6 +50,69 @@ public class MongoItemReaderBuilder<T>
protected int pageSize = 10;
private boolean saveState = true;
private String name;
private int maxItemCount = Integer.MAX_VALUE;
private int currentItemCount;
/**
* Configure if the state of the {@link org.springframework.batch.item.ItemStreamSupport}
* should be persisted within the {@link org.springframework.batch.item.ExecutionContext}
* for restart purposes.
*
* @param saveState defaults to true
* @return The current instance of the builder.
*/
public MongoItemReaderBuilder<T> saveState(boolean saveState) {
this.saveState = saveState;
return this;
}
/**
* The name used to calculate the key within the
* {@link org.springframework.batch.item.ExecutionContext}. Required if
* {@link #saveState(boolean)} is set to true.
*
* @param name name of the reader instance
* @return The current instance of the builder.
* @see org.springframework.batch.item.ItemStreamSupport#setName(String)
*/
public MongoItemReaderBuilder<T> name(String name) {
this.name = name;
return this;
}
/**
* Configure the max number of items to be read.
*
* @param maxItemCount the max items to be read
* @return The current instance of the builder.
* @see org.springframework.batch.item.support.AbstractItemCountingItemStreamItemReader#setMaxItemCount(int)
*/
public MongoItemReaderBuilder<T> maxItemCount(int maxItemCount) {
this.maxItemCount = maxItemCount;
return this;
}
/**
* Index for the current item. Used on restarts to indicate where to start from.
*
* @param currentItemCount current index
* @return this instance for method chaining
* @see org.springframework.batch.item.support.AbstractItemCountingItemStreamItemReader#setCurrentItemCount(int)
*/
public MongoItemReaderBuilder<T> currentItemCount(int currentItemCount) {
this.currentItemCount = currentItemCount;
return this;
}
/**
* Used to perform operations against the MongoDB instance. Also handles the mapping
* of documents to objects.

View File

@@ -20,7 +20,6 @@ import java.util.Map;
import org.neo4j.ogm.session.SessionFactory;
import org.springframework.batch.item.builder.AbstractItemCountingItemStreamItemReaderBuilder;
import org.springframework.batch.item.data.Neo4jItemReader;
import org.springframework.util.Assert;
@@ -31,8 +30,7 @@ import org.springframework.util.Assert;
* @since 4.0
* @see Neo4jItemReader
*/
public class Neo4jItemReaderBuilder<T>
extends AbstractItemCountingItemStreamItemReaderBuilder<Neo4jItemReaderBuilder<T>> {
public class Neo4jItemReaderBuilder<T> {
private SessionFactory sessionFactory;
@@ -52,6 +50,69 @@ public class Neo4jItemReaderBuilder<T>
private int pageSize = 10;
private boolean saveState = true;
private String name;
private int maxItemCount = Integer.MAX_VALUE;
private int currentItemCount;
/**
* Configure if the state of the {@link org.springframework.batch.item.ItemStreamSupport}
* should be persisted within the {@link org.springframework.batch.item.ExecutionContext}
* for restart purposes.
*
* @param saveState defaults to true
* @return The current instance of the builder.
*/
public Neo4jItemReaderBuilder<T> saveState(boolean saveState) {
this.saveState = saveState;
return this;
}
/**
* The name used to calculate the key within the
* {@link org.springframework.batch.item.ExecutionContext}. Required if
* {@link #saveState(boolean)} is set to true.
*
* @param name name of the reader instance
* @return The current instance of the builder.
* @see org.springframework.batch.item.ItemStreamSupport#setName(String)
*/
public Neo4jItemReaderBuilder<T> name(String name) {
this.name = name;
return this;
}
/**
* Configure the max number of items to be read.
*
* @param maxItemCount the max items to be read
* @return The current instance of the builder.
* @see org.springframework.batch.item.support.AbstractItemCountingItemStreamItemReader#setMaxItemCount(int)
*/
public Neo4jItemReaderBuilder<T> maxItemCount(int maxItemCount) {
this.maxItemCount = maxItemCount;
return this;
}
/**
* Index for the current item. Used on restarts to indicate where to start from.
*
* @param currentItemCount current index
* @return this instance for method chaining
* @see org.springframework.batch.item.support.AbstractItemCountingItemStreamItemReader#setCurrentItemCount(int)
*/
public Neo4jItemReaderBuilder<T> currentItemCount(int currentItemCount) {
this.currentItemCount = currentItemCount;
return this;
}
/**
* Establish the session factory for the reader.
* @param sessionFactory the factory to use for the reader.

View File

@@ -22,7 +22,6 @@ import java.util.Arrays;
import java.util.List;
import java.util.Map;
import org.springframework.batch.item.builder.AbstractItemCountingItemStreamItemReaderBuilder;
import org.springframework.batch.item.data.RepositoryItemReader;
import org.springframework.cglib.proxy.Enhancer;
import org.springframework.cglib.proxy.MethodInterceptor;
@@ -41,8 +40,7 @@ import org.springframework.util.StringUtils;
* @see RepositoryItemReader
*/
public class RepositoryItemReaderBuilder<T>
extends AbstractItemCountingItemStreamItemReaderBuilder<RepositoryItemReaderBuilder<T>> {
public class RepositoryItemReaderBuilder<T> {
private PagingAndSortingRepository<?, ?> repository;
@@ -56,6 +54,69 @@ public class RepositoryItemReaderBuilder<T>
private RepositoryMethodReference repositoryMethodReference;
private boolean saveState = true;
private String name;
private int maxItemCount = Integer.MAX_VALUE;
private int currentItemCount;
/**
* Configure if the state of the {@link org.springframework.batch.item.ItemStreamSupport}
* should be persisted within the {@link org.springframework.batch.item.ExecutionContext}
* for restart purposes.
*
* @param saveState defaults to true
* @return The current instance of the builder.
*/
public RepositoryItemReaderBuilder<T> saveState(boolean saveState) {
this.saveState = saveState;
return this;
}
/**
* The name used to calculate the key within the
* {@link org.springframework.batch.item.ExecutionContext}. Required if
* {@link #saveState(boolean)} is set to true.
*
* @param name name of the reader instance
* @return The current instance of the builder.
* @see org.springframework.batch.item.ItemStreamSupport#setName(String)
*/
public RepositoryItemReaderBuilder<T> name(String name) {
this.name = name;
return this;
}
/**
* Configure the max number of items to be read.
*
* @param maxItemCount the max items to be read
* @return The current instance of the builder.
* @see org.springframework.batch.item.support.AbstractItemCountingItemStreamItemReader#setMaxItemCount(int)
*/
public RepositoryItemReaderBuilder<T> maxItemCount(int maxItemCount) {
this.maxItemCount = maxItemCount;
return this;
}
/**
* Index for the current item. Used on restarts to indicate where to start from.
*
* @param currentItemCount current index
* @return this instance for method chaining
* @see org.springframework.batch.item.support.AbstractItemCountingItemStreamItemReader#setCurrentItemCount(int)
*/
public RepositoryItemReaderBuilder<T> currentItemCount(int currentItemCount) {
this.currentItemCount = currentItemCount;
return this;
}
/**
* Arguments to be passed to the data providing method.
*

View File

@@ -19,7 +19,6 @@ import java.util.Map;
import org.hibernate.SessionFactory;
import org.springframework.batch.item.builder.AbstractItemCountingItemStreamItemReaderBuilder;
import org.springframework.batch.item.database.HibernateCursorItemReader;
import org.springframework.batch.item.database.orm.HibernateNativeQueryProvider;
import org.springframework.batch.item.database.orm.HibernateQueryProvider;
@@ -41,8 +40,7 @@ import org.springframework.util.StringUtils;
* @since 4.0
* @see HibernateCursorItemReader
*/
public class HibernateCursorItemReaderBuilder<T>
extends AbstractItemCountingItemStreamItemReaderBuilder<HibernateCursorItemReaderBuilder<T>> {
public class HibernateCursorItemReaderBuilder<T> {
private Map<String, Object> parameterValues;
@@ -62,6 +60,69 @@ public class HibernateCursorItemReaderBuilder<T>
private Class nativeClass;
private boolean saveState = true;
private String name;
private int maxItemCount = Integer.MAX_VALUE;
private int currentItemCount;
/**
* Configure if the state of the {@link org.springframework.batch.item.ItemStreamSupport}
* should be persisted within the {@link org.springframework.batch.item.ExecutionContext}
* for restart purposes.
*
* @param saveState defaults to true
* @return The current instance of the builder.
*/
public HibernateCursorItemReaderBuilder<T> saveState(boolean saveState) {
this.saveState = saveState;
return this;
}
/**
* The name used to calculate the key within the
* {@link org.springframework.batch.item.ExecutionContext}. Required if
* {@link #saveState(boolean)} is set to true.
*
* @param name name of the reader instance
* @return The current instance of the builder.
* @see org.springframework.batch.item.ItemStreamSupport#setName(String)
*/
public HibernateCursorItemReaderBuilder<T> name(String name) {
this.name = name;
return this;
}
/**
* Configure the max number of items to be read.
*
* @param maxItemCount the max items to be read
* @return The current instance of the builder.
* @see org.springframework.batch.item.support.AbstractItemCountingItemStreamItemReader#setMaxItemCount(int)
*/
public HibernateCursorItemReaderBuilder<T> maxItemCount(int maxItemCount) {
this.maxItemCount = maxItemCount;
return this;
}
/**
* Index for the current item. Used on restarts to indicate where to start from.
*
* @param currentItemCount current index
* @return this instance for method chaining
* @see org.springframework.batch.item.support.AbstractItemCountingItemStreamItemReader#setCurrentItemCount(int)
*/
public HibernateCursorItemReaderBuilder<T> currentItemCount(int currentItemCount) {
this.currentItemCount = currentItemCount;
return this;
}
/**
* A map of parameter values to be set on the query. The key of the map is the name
* of the parameter to be set with the value being the value to be set.

View File

@@ -19,7 +19,6 @@ import java.util.Map;
import org.hibernate.SessionFactory;
import org.springframework.batch.item.builder.AbstractItemCountingItemStreamItemReaderBuilder;
import org.springframework.batch.item.database.HibernatePagingItemReader;
import org.springframework.batch.item.database.orm.HibernateQueryProvider;
import org.springframework.util.Assert;
@@ -39,8 +38,7 @@ import org.springframework.util.StringUtils;
* @since 4.0
* @see HibernatePagingItemReader
*/
public class HibernatePagingItemReaderBuilder<T>
extends AbstractItemCountingItemStreamItemReaderBuilder<HibernatePagingItemReaderBuilder<T>> {
public class HibernatePagingItemReaderBuilder<T> {
private int pageSize = 10;
@@ -58,6 +56,69 @@ public class HibernatePagingItemReaderBuilder<T>
private boolean statelessSession = true;
private boolean saveState = true;
private String name;
private int maxItemCount = Integer.MAX_VALUE;
private int currentItemCount;
/**
* Configure if the state of the {@link org.springframework.batch.item.ItemStreamSupport}
* should be persisted within the {@link org.springframework.batch.item.ExecutionContext}
* for restart purposes.
*
* @param saveState defaults to true
* @return The current instance of the builder.
*/
public HibernatePagingItemReaderBuilder<T> saveState(boolean saveState) {
this.saveState = saveState;
return this;
}
/**
* The name used to calculate the key within the
* {@link org.springframework.batch.item.ExecutionContext}. Required if
* {@link #saveState(boolean)} is set to true.
*
* @param name name of the reader instance
* @return The current instance of the builder.
* @see org.springframework.batch.item.ItemStreamSupport#setName(String)
*/
public HibernatePagingItemReaderBuilder<T> name(String name) {
this.name = name;
return this;
}
/**
* Configure the max number of items to be read.
*
* @param maxItemCount the max items to be read
* @return The current instance of the builder.
* @see org.springframework.batch.item.support.AbstractItemCountingItemStreamItemReader#setMaxItemCount(int)
*/
public HibernatePagingItemReaderBuilder<T> maxItemCount(int maxItemCount) {
this.maxItemCount = maxItemCount;
return this;
}
/**
* Index for the current item. Used on restarts to indicate where to start from.
*
* @param currentItemCount current index
* @return this instance for method chaining
* @see org.springframework.batch.item.support.AbstractItemCountingItemStreamItemReader#setCurrentItemCount(int)
*/
public HibernatePagingItemReaderBuilder<T> currentItemCount(int currentItemCount) {
this.currentItemCount = currentItemCount;
return this;
}
/**
* The number of records to request per page/query. Defaults to 10. Must be greater
* than zero.

View File

@@ -18,8 +18,6 @@ package org.springframework.batch.item.database.builder;
import java.util.List;
import javax.sql.DataSource;
import org.springframework.batch.item.ExecutionContext;
import org.springframework.batch.item.builder.AbstractItemCountingItemStreamItemReaderBuilder;
import org.springframework.batch.item.database.AbstractCursorItemReader;
import org.springframework.batch.item.database.JdbcCursorItemReader;
import org.springframework.batch.item.database.support.ListPreparedStatementSetter;
@@ -38,8 +36,7 @@ import org.springframework.util.StringUtils;
* @author Glenn Renfro
* @since 4.0
*/
public class JdbcCursorItemReaderBuilder<T>
extends AbstractItemCountingItemStreamItemReaderBuilder<JdbcCursorItemReaderBuilder<T>> {
public class JdbcCursorItemReaderBuilder<T> {
private DataSource dataSource;
@@ -63,6 +60,69 @@ public class JdbcCursorItemReaderBuilder<T>
private RowMapper<T> rowMapper;
private boolean saveState = true;
private String name;
private int maxItemCount = Integer.MAX_VALUE;
private int currentItemCount;
/**
* Configure if the state of the {@link org.springframework.batch.item.ItemStreamSupport}
* should be persisted within the {@link org.springframework.batch.item.ExecutionContext}
* for restart purposes.
*
* @param saveState defaults to true
* @return The current instance of the builder.
*/
public JdbcCursorItemReaderBuilder<T> saveState(boolean saveState) {
this.saveState = saveState;
return this;
}
/**
* The name used to calculate the key within the
* {@link org.springframework.batch.item.ExecutionContext}. Required if
* {@link #saveState(boolean)} is set to true.
*
* @param name name of the reader instance
* @return The current instance of the builder.
* @see org.springframework.batch.item.ItemStreamSupport#setName(String)
*/
public JdbcCursorItemReaderBuilder<T> name(String name) {
this.name = name;
return this;
}
/**
* Configure the max number of items to be read.
*
* @param maxItemCount the max items to be read
* @return The current instance of the builder.
* @see org.springframework.batch.item.support.AbstractItemCountingItemStreamItemReader#setMaxItemCount(int)
*/
public JdbcCursorItemReaderBuilder<T> maxItemCount(int maxItemCount) {
this.maxItemCount = maxItemCount;
return this;
}
/**
* Index for the current item. Used on restarts to indicate where to start from.
*
* @param currentItemCount current index
* @return this instance for method chaining
* @see org.springframework.batch.item.support.AbstractItemCountingItemStreamItemReader#setCurrentItemCount(int)
*/
public JdbcCursorItemReaderBuilder<T> currentItemCount(int currentItemCount) {
this.currentItemCount = currentItemCount;
return this;
}
/**
* The {@link DataSource} to read from
*

View File

@@ -18,7 +18,6 @@ package org.springframework.batch.item.database.builder;
import java.util.Map;
import javax.sql.DataSource;
import org.springframework.batch.item.builder.AbstractItemCountingItemStreamItemReaderBuilder;
import org.springframework.batch.item.database.JdbcPagingItemReader;
import org.springframework.batch.item.database.Order;
import org.springframework.batch.item.database.PagingQueryProvider;
@@ -50,8 +49,7 @@ import org.springframework.util.Assert;
* @since 4.0
* @see JdbcPagingItemReader
*/
public class JdbcPagingItemReaderBuilder<T>
extends AbstractItemCountingItemStreamItemReaderBuilder<JdbcPagingItemReaderBuilder<T>> {
public class JdbcPagingItemReaderBuilder<T> {
private DataSource dataSource;
@@ -75,6 +73,69 @@ public class JdbcPagingItemReaderBuilder<T>
private Map<String, Order> sortKeys;
private boolean saveState = true;
private String name;
private int maxItemCount = Integer.MAX_VALUE;
private int currentItemCount;
/**
* Configure if the state of the {@link org.springframework.batch.item.ItemStreamSupport}
* should be persisted within the {@link org.springframework.batch.item.ExecutionContext}
* for restart purposes.
*
* @param saveState defaults to true
* @return The current instance of the builder.
*/
public JdbcPagingItemReaderBuilder<T> saveState(boolean saveState) {
this.saveState = saveState;
return this;
}
/**
* The name used to calculate the key within the
* {@link org.springframework.batch.item.ExecutionContext}. Required if
* {@link #saveState(boolean)} is set to true.
*
* @param name name of the reader instance
* @return The current instance of the builder.
* @see org.springframework.batch.item.ItemStreamSupport#setName(String)
*/
public JdbcPagingItemReaderBuilder<T> name(String name) {
this.name = name;
return this;
}
/**
* Configure the max number of items to be read.
*
* @param maxItemCount the max items to be read
* @return The current instance of the builder.
* @see org.springframework.batch.item.support.AbstractItemCountingItemStreamItemReader#setMaxItemCount(int)
*/
public JdbcPagingItemReaderBuilder<T> maxItemCount(int maxItemCount) {
this.maxItemCount = maxItemCount;
return this;
}
/**
* Index for the current item. Used on restarts to indicate where to start from.
*
* @param currentItemCount current index
* @return this instance for method chaining
* @see org.springframework.batch.item.support.AbstractItemCountingItemStreamItemReader#setCurrentItemCount(int)
*/
public JdbcPagingItemReaderBuilder<T> currentItemCount(int currentItemCount) {
this.currentItemCount = currentItemCount;
return this;
}
/**
* The {@link DataSource} to query against. Required.
*

View File

@@ -18,7 +18,6 @@ package org.springframework.batch.item.database.builder;
import java.util.Map;
import javax.persistence.EntityManagerFactory;
import org.springframework.batch.item.builder.AbstractItemCountingItemStreamItemReaderBuilder;
import org.springframework.batch.item.database.JpaPagingItemReader;
import org.springframework.batch.item.database.orm.JpaQueryProvider;
import org.springframework.util.Assert;
@@ -32,8 +31,7 @@ import org.springframework.util.Assert;
* @since 4.0
*/
public class JpaPagingItemReaderBuilder<T>
extends AbstractItemCountingItemStreamItemReaderBuilder<JpaPagingItemReaderBuilder<T>> {
public class JpaPagingItemReaderBuilder<T> {
private int pageSize = 10;
@@ -47,6 +45,69 @@ public class JpaPagingItemReaderBuilder<T>
private JpaQueryProvider queryProvider;
private boolean saveState = true;
private String name;
private int maxItemCount = Integer.MAX_VALUE;
private int currentItemCount;
/**
* Configure if the state of the {@link org.springframework.batch.item.ItemStreamSupport}
* should be persisted within the {@link org.springframework.batch.item.ExecutionContext}
* for restart purposes.
*
* @param saveState defaults to true
* @return The current instance of the builder.
*/
public JpaPagingItemReaderBuilder<T> saveState(boolean saveState) {
this.saveState = saveState;
return this;
}
/**
* The name used to calculate the key within the
* {@link org.springframework.batch.item.ExecutionContext}. Required if
* {@link #saveState(boolean)} is set to true.
*
* @param name name of the reader instance
* @return The current instance of the builder.
* @see org.springframework.batch.item.ItemStreamSupport#setName(String)
*/
public JpaPagingItemReaderBuilder<T> name(String name) {
this.name = name;
return this;
}
/**
* Configure the max number of items to be read.
*
* @param maxItemCount the max items to be read
* @return The current instance of the builder.
* @see org.springframework.batch.item.support.AbstractItemCountingItemStreamItemReader#setMaxItemCount(int)
*/
public JpaPagingItemReaderBuilder<T> maxItemCount(int maxItemCount) {
this.maxItemCount = maxItemCount;
return this;
}
/**
* Index for the current item. Used on restarts to indicate where to start from.
*
* @param currentItemCount current index
* @return this instance for method chaining
* @see org.springframework.batch.item.support.AbstractItemCountingItemStreamItemReader#setCurrentItemCount(int)
*/
public JpaPagingItemReaderBuilder<T> currentItemCount(int currentItemCount) {
this.currentItemCount = currentItemCount;
return this;
}
/**
* The number of records to request per page/query. Defaults to 10. Must be greater
* than zero.

View File

@@ -29,7 +29,6 @@ import java.util.Set;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.springframework.batch.item.builder.AbstractItemCountingItemStreamItemReaderBuilder;
import org.springframework.batch.item.file.FlatFileItemReader;
import org.springframework.batch.item.file.LineCallbackHandler;
import org.springframework.batch.item.file.LineMapper;
@@ -57,8 +56,7 @@ import org.springframework.util.StringUtils;
* @since 4.0
* @see FlatFileItemReader
*/
public class FlatFileItemReaderBuilder<T>
extends AbstractItemCountingItemStreamItemReaderBuilder<FlatFileItemReaderBuilder<T>> {
public class FlatFileItemReaderBuilder<T> {
protected Log logger = LogFactory.getLog(getClass());
@@ -99,6 +97,69 @@ public class FlatFileItemReaderBuilder<T>
private BigInteger tokenizerValidator = new BigInteger("0");
private boolean saveState = true;
private String name;
private int maxItemCount = Integer.MAX_VALUE;
private int currentItemCount;
/**
* Configure if the state of the {@link org.springframework.batch.item.ItemStreamSupport}
* should be persisted within the {@link org.springframework.batch.item.ExecutionContext}
* for restart purposes.
*
* @param saveState defaults to true
* @return The current instance of the builder.
*/
public FlatFileItemReaderBuilder<T> saveState(boolean saveState) {
this.saveState = saveState;
return this;
}
/**
* The name used to calculate the key within the
* {@link org.springframework.batch.item.ExecutionContext}. Required if
* {@link #saveState(boolean)} is set to true.
*
* @param name name of the reader instance
* @return The current instance of the builder.
* @see org.springframework.batch.item.ItemStreamSupport#setName(String)
*/
public FlatFileItemReaderBuilder<T> name(String name) {
this.name = name;
return this;
}
/**
* Configure the max number of items to be read.
*
* @param maxItemCount the max items to be read
* @return The current instance of the builder.
* @see org.springframework.batch.item.support.AbstractItemCountingItemStreamItemReader#setMaxItemCount(int)
*/
public FlatFileItemReaderBuilder<T> maxItemCount(int maxItemCount) {
this.maxItemCount = maxItemCount;
return this;
}
/**
* Index for the current item. Used on restarts to indicate where to start from.
*
* @param currentItemCount current index
* @return this instance for method chaining
* @see org.springframework.batch.item.support.AbstractItemCountingItemStreamItemReader#setCurrentItemCount(int)
*/
public FlatFileItemReaderBuilder<T> currentItemCount(int currentItemCount) {
this.currentItemCount = currentItemCount;
return this;
}
/**
* Add a string to the list of Strings that indicate commented lines.
*
@@ -353,8 +414,6 @@ public class FlatFileItemReaderBuilder<T>
Assert.notNull(this.recordSeparatorPolicy, "A RecordSeparatorPolicy is required.");
int validatorValue = this.tokenizerValidator.intValue();
Assert.state(validatorValue == 1 || validatorValue == 2 || validatorValue == 4,
"Only one LineTokenizer option may be configured");
FlatFileItemReader<T> reader = new FlatFileItemReader<>();
@@ -368,6 +427,9 @@ public class FlatFileItemReaderBuilder<T>
reader.setLineMapper(this.lineMapper);
}
else {
Assert.state(validatorValue == 1 || validatorValue == 2 || validatorValue == 4,
"Only one LineTokenizer option may be configured");
DefaultLineMapper<T> lineMapper = new DefaultLineMapper<>();
if(this.lineTokenizer != null && this.fieldSetMapper != null) {

View File

@@ -15,7 +15,6 @@
*/
package org.springframework.batch.item.file.builder;
import org.springframework.batch.item.builder.AbstractItemStreamSupportBuilder;
import org.springframework.batch.item.file.FlatFileFooterCallback;
import org.springframework.batch.item.file.FlatFileHeaderCallback;
import org.springframework.batch.item.file.FlatFileItemWriter;
@@ -31,7 +30,7 @@ import org.springframework.util.Assert;
* @since 4.0
* @see FlatFileItemWriter
*/
public class FlatFileItemWriterBuilder<T> extends AbstractItemStreamSupportBuilder<FlatFileItemWriterBuilder<T>> {
public class FlatFileItemWriterBuilder<T> {
private Resource resource;
@@ -55,6 +54,39 @@ public class FlatFileItemWriterBuilder<T> extends AbstractItemStreamSupportBuild
private boolean transactional = FlatFileItemWriter.DEFAULT_TRANSACTIONAL;
private boolean saveState = true;
private String name;
/**
* Configure if the state of the {@link org.springframework.batch.item.ItemStreamSupport}
* should be persisted within the {@link org.springframework.batch.item.ExecutionContext}
* for restart purposes.
*
* @param saveState defaults to true
* @return The current instance of the builder.
*/
public FlatFileItemWriterBuilder<T> saveState(boolean saveState) {
this.saveState = saveState;
return this;
}
/**
* The name used to calculate the key within the
* {@link org.springframework.batch.item.ExecutionContext}. Required if
* {@link #saveState(boolean)} is set to true.
*
* @param name name of the reader instance
* @return The current instance of the builder.
* @see org.springframework.batch.item.ItemStreamSupport#setName(String)
*/
public FlatFileItemWriterBuilder<T> name(String name) {
this.name = name;
return this;
}
/**
* The {@link Resource} to be used as output.
*

View File

@@ -18,9 +18,6 @@ package org.springframework.batch.item.file.builder;
import java.util.Comparator;
import org.springframework.batch.item.ExecutionContext;
import org.springframework.batch.item.ItemStream;
import org.springframework.batch.item.builder.AbstractItemStreamSupportBuilder;
import org.springframework.batch.item.file.MultiResourceItemReader;
import org.springframework.batch.item.file.ResourceAwareItemReaderItemStream;
import org.springframework.core.io.Resource;
@@ -34,8 +31,7 @@ import org.springframework.util.StringUtils;
* @since 4.0
* @see MultiResourceItemReader
*/
public class MultiResourceItemReaderBuilder<T>
extends AbstractItemStreamSupportBuilder<MultiResourceItemReaderBuilder<T>> {
public class MultiResourceItemReaderBuilder<T> {
private ResourceAwareItemReaderItemStream<? extends T> delegate;
@@ -45,6 +41,39 @@ public class MultiResourceItemReaderBuilder<T>
private Comparator<Resource> comparator;
private boolean saveState = true;
private String name;
/**
* Configure if the state of the {@link org.springframework.batch.item.ItemStreamSupport}
* should be persisted within the {@link org.springframework.batch.item.ExecutionContext}
* for restart purposes.
*
* @param saveState defaults to true
* @return The current instance of the builder.
*/
public MultiResourceItemReaderBuilder<T> saveState(boolean saveState) {
this.saveState = saveState;
return this;
}
/**
* The name used to calculate the key within the
* {@link org.springframework.batch.item.ExecutionContext}. Required if
* {@link #saveState(boolean)} is set to true.
*
* @param name name of the reader instance
* @return The current instance of the builder.
* @see org.springframework.batch.item.ItemStreamSupport#setName(String)
*/
public MultiResourceItemReaderBuilder<T> name(String name) {
this.name = name;
return this;
}
/**
* The array of resources that the {@link MultiResourceItemReader} will use to
* retrieve items.

View File

@@ -16,8 +16,6 @@
package org.springframework.batch.item.file.builder;
import org.springframework.batch.item.ExecutionContext;
import org.springframework.batch.item.builder.AbstractItemStreamSupportBuilder;
import org.springframework.batch.item.file.MultiResourceItemWriter;
import org.springframework.batch.item.file.ResourceAwareItemWriterItemStream;
import org.springframework.batch.item.file.ResourceSuffixCreator;
@@ -32,8 +30,7 @@ import org.springframework.util.Assert;
* @since 4.0
* @see MultiResourceItemWriter
*/
public class MultiResourceItemWriterBuilder<T>
extends AbstractItemStreamSupportBuilder<MultiResourceItemWriterBuilder<T>> {
public class MultiResourceItemWriterBuilder<T> {
private Resource resource;
@@ -43,6 +40,39 @@ public class MultiResourceItemWriterBuilder<T>
private ResourceSuffixCreator suffixCreator;
private boolean saveState = true;
private String name;
/**
* Configure if the state of the {@link org.springframework.batch.item.ItemStreamSupport}
* should be persisted within the {@link org.springframework.batch.item.ExecutionContext}
* for restart purposes.
*
* @param saveState defaults to true
* @return The current instance of the builder.
*/
public MultiResourceItemWriterBuilder<T> saveState(boolean saveState) {
this.saveState = saveState;
return this;
}
/**
* The name used to calculate the key within the
* {@link org.springframework.batch.item.ExecutionContext}. Required if
* {@link #saveState(boolean)} is set to true.
*
* @param name name of the reader instance
* @return The current instance of the builder.
* @see org.springframework.batch.item.ItemStreamSupport#setName(String)
*/
public MultiResourceItemWriterBuilder<T> name(String name) {
this.name = name;
return this;
}
/**
* Allows customization of the suffix of the created resources based on the index.
*

View File

@@ -19,7 +19,6 @@ import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import org.springframework.batch.item.builder.AbstractItemCountingItemStreamItemReaderBuilder;
import org.springframework.batch.item.xml.StaxEventItemReader;
import org.springframework.core.io.Resource;
import org.springframework.oxm.Unmarshaller;
@@ -33,8 +32,7 @@ import org.springframework.util.StringUtils;
* @author Glenn Renfro
* @since 4.0
*/
public class StaxEventItemReaderBuilder<T>
extends AbstractItemCountingItemStreamItemReaderBuilder<StaxEventItemReaderBuilder<T>> {
public class StaxEventItemReaderBuilder<T> {
private boolean strict = true;
@@ -44,6 +42,69 @@ public class StaxEventItemReaderBuilder<T>
private List<String> fragmentRootElements = new ArrayList<>();
private boolean saveState = true;
private String name;
private int maxItemCount = Integer.MAX_VALUE;
private int currentItemCount;
/**
* Configure if the state of the {@link org.springframework.batch.item.ItemStreamSupport}
* should be persisted within the {@link org.springframework.batch.item.ExecutionContext}
* for restart purposes.
*
* @param saveState defaults to true
* @return The current instance of the builder.
*/
public StaxEventItemReaderBuilder<T> saveState(boolean saveState) {
this.saveState = saveState;
return this;
}
/**
* The name used to calculate the key within the
* {@link org.springframework.batch.item.ExecutionContext}. Required if
* {@link #saveState(boolean)} is set to true.
*
* @param name name of the reader instance
* @return The current instance of the builder.
* @see org.springframework.batch.item.ItemStreamSupport#setName(String)
*/
public StaxEventItemReaderBuilder<T> name(String name) {
this.name = name;
return this;
}
/**
* Configure the max number of items to be read.
*
* @param maxItemCount the max items to be read
* @return The current instance of the builder.
* @see org.springframework.batch.item.support.AbstractItemCountingItemStreamItemReader#setMaxItemCount(int)
*/
public StaxEventItemReaderBuilder<T> maxItemCount(int maxItemCount) {
this.maxItemCount = maxItemCount;
return this;
}
/**
* Index for the current item. Used on restarts to indicate where to start from.
*
* @param currentItemCount current index
* @return this instance for method chaining
* @see org.springframework.batch.item.support.AbstractItemCountingItemStreamItemReader#setCurrentItemCount(int)
*/
public StaxEventItemReaderBuilder<T> currentItemCount(int currentItemCount) {
this.currentItemCount = currentItemCount;
return this;
}
/**
* The {@link Resource} to be used as input.
*