diff --git a/spring-batch-infrastructure/src/main/java/org/springframework/batch/item/builder/AbstractItemCountingItemStreamItemReaderBuilder.java b/spring-batch-infrastructure/src/main/java/org/springframework/batch/item/builder/AbstractItemCountingItemStreamItemReaderBuilder.java deleted file mode 100644 index 744e6efd8..000000000 --- a/spring-batch-infrastructure/src/main/java/org/springframework/batch/item/builder/AbstractItemCountingItemStreamItemReaderBuilder.java +++ /dev/null @@ -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 extends AbstractItemStreamSupportBuilder { - - 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; - } - -} diff --git a/spring-batch-infrastructure/src/main/java/org/springframework/batch/item/builder/AbstractItemStreamSupportBuilder.java b/spring-batch-infrastructure/src/main/java/org/springframework/batch/item/builder/AbstractItemStreamSupportBuilder.java deleted file mode 100644 index a957aead6..000000000 --- a/spring-batch-infrastructure/src/main/java/org/springframework/batch/item/builder/AbstractItemStreamSupportBuilder.java +++ /dev/null @@ -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 { - 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; - } -} diff --git a/spring-batch-infrastructure/src/main/java/org/springframework/batch/item/data/builder/MongoItemReaderBuilder.java b/spring-batch-infrastructure/src/main/java/org/springframework/batch/item/data/builder/MongoItemReaderBuilder.java index 68ff79fed..0f6e67c10 100644 --- a/spring-batch-infrastructure/src/main/java/org/springframework/batch/item/data/builder/MongoItemReaderBuilder.java +++ b/spring-batch-infrastructure/src/main/java/org/springframework/batch/item/data/builder/MongoItemReaderBuilder.java @@ -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 - extends AbstractItemCountingItemStreamItemReaderBuilder> { +public class MongoItemReaderBuilder { private MongoOperations template; private String query; @@ -52,6 +50,69 @@ public class MongoItemReaderBuilder 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 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 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 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 currentItemCount(int currentItemCount) { + this.currentItemCount = currentItemCount; + + return this; + } + /** * Used to perform operations against the MongoDB instance. Also handles the mapping * of documents to objects. diff --git a/spring-batch-infrastructure/src/main/java/org/springframework/batch/item/data/builder/Neo4jItemReaderBuilder.java b/spring-batch-infrastructure/src/main/java/org/springframework/batch/item/data/builder/Neo4jItemReaderBuilder.java index ea5822d85..47430c7ad 100644 --- a/spring-batch-infrastructure/src/main/java/org/springframework/batch/item/data/builder/Neo4jItemReaderBuilder.java +++ b/spring-batch-infrastructure/src/main/java/org/springframework/batch/item/data/builder/Neo4jItemReaderBuilder.java @@ -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 - extends AbstractItemCountingItemStreamItemReaderBuilder> { +public class Neo4jItemReaderBuilder { private SessionFactory sessionFactory; @@ -52,6 +50,69 @@ public class Neo4jItemReaderBuilder 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 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 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 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 currentItemCount(int currentItemCount) { + this.currentItemCount = currentItemCount; + + return this; + } + /** * Establish the session factory for the reader. * @param sessionFactory the factory to use for the reader. diff --git a/spring-batch-infrastructure/src/main/java/org/springframework/batch/item/data/builder/RepositoryItemReaderBuilder.java b/spring-batch-infrastructure/src/main/java/org/springframework/batch/item/data/builder/RepositoryItemReaderBuilder.java index 9d426baa6..0aa754c63 100644 --- a/spring-batch-infrastructure/src/main/java/org/springframework/batch/item/data/builder/RepositoryItemReaderBuilder.java +++ b/spring-batch-infrastructure/src/main/java/org/springframework/batch/item/data/builder/RepositoryItemReaderBuilder.java @@ -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 - extends AbstractItemCountingItemStreamItemReaderBuilder> { +public class RepositoryItemReaderBuilder { private PagingAndSortingRepository repository; @@ -56,6 +54,69 @@ public class RepositoryItemReaderBuilder 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 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 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 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 currentItemCount(int currentItemCount) { + this.currentItemCount = currentItemCount; + + return this; + } + /** * Arguments to be passed to the data providing method. * diff --git a/spring-batch-infrastructure/src/main/java/org/springframework/batch/item/database/builder/HibernateCursorItemReaderBuilder.java b/spring-batch-infrastructure/src/main/java/org/springframework/batch/item/database/builder/HibernateCursorItemReaderBuilder.java index e3f56d3fc..88e1b4684 100644 --- a/spring-batch-infrastructure/src/main/java/org/springframework/batch/item/database/builder/HibernateCursorItemReaderBuilder.java +++ b/spring-batch-infrastructure/src/main/java/org/springframework/batch/item/database/builder/HibernateCursorItemReaderBuilder.java @@ -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 - extends AbstractItemCountingItemStreamItemReaderBuilder> { +public class HibernateCursorItemReaderBuilder { private Map parameterValues; @@ -62,6 +60,69 @@ public class HibernateCursorItemReaderBuilder 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 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 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 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 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. diff --git a/spring-batch-infrastructure/src/main/java/org/springframework/batch/item/database/builder/HibernatePagingItemReaderBuilder.java b/spring-batch-infrastructure/src/main/java/org/springframework/batch/item/database/builder/HibernatePagingItemReaderBuilder.java index 745c187e7..9dffb9975 100644 --- a/spring-batch-infrastructure/src/main/java/org/springframework/batch/item/database/builder/HibernatePagingItemReaderBuilder.java +++ b/spring-batch-infrastructure/src/main/java/org/springframework/batch/item/database/builder/HibernatePagingItemReaderBuilder.java @@ -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 - extends AbstractItemCountingItemStreamItemReaderBuilder> { +public class HibernatePagingItemReaderBuilder { private int pageSize = 10; @@ -58,6 +56,69 @@ public class HibernatePagingItemReaderBuilder 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 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 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 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 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. diff --git a/spring-batch-infrastructure/src/main/java/org/springframework/batch/item/database/builder/JdbcCursorItemReaderBuilder.java b/spring-batch-infrastructure/src/main/java/org/springframework/batch/item/database/builder/JdbcCursorItemReaderBuilder.java index 4baed5b6b..8ce8d3d2d 100644 --- a/spring-batch-infrastructure/src/main/java/org/springframework/batch/item/database/builder/JdbcCursorItemReaderBuilder.java +++ b/spring-batch-infrastructure/src/main/java/org/springframework/batch/item/database/builder/JdbcCursorItemReaderBuilder.java @@ -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 - extends AbstractItemCountingItemStreamItemReaderBuilder> { +public class JdbcCursorItemReaderBuilder { private DataSource dataSource; @@ -63,6 +60,69 @@ public class JdbcCursorItemReaderBuilder private RowMapper 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 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 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 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 currentItemCount(int currentItemCount) { + this.currentItemCount = currentItemCount; + + return this; + } + /** * The {@link DataSource} to read from * diff --git a/spring-batch-infrastructure/src/main/java/org/springframework/batch/item/database/builder/JdbcPagingItemReaderBuilder.java b/spring-batch-infrastructure/src/main/java/org/springframework/batch/item/database/builder/JdbcPagingItemReaderBuilder.java index f669e654e..7c6b4a255 100644 --- a/spring-batch-infrastructure/src/main/java/org/springframework/batch/item/database/builder/JdbcPagingItemReaderBuilder.java +++ b/spring-batch-infrastructure/src/main/java/org/springframework/batch/item/database/builder/JdbcPagingItemReaderBuilder.java @@ -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 - extends AbstractItemCountingItemStreamItemReaderBuilder> { +public class JdbcPagingItemReaderBuilder { private DataSource dataSource; @@ -75,6 +73,69 @@ public class JdbcPagingItemReaderBuilder private Map 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 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 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 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 currentItemCount(int currentItemCount) { + this.currentItemCount = currentItemCount; + + return this; + } + /** * The {@link DataSource} to query against. Required. * diff --git a/spring-batch-infrastructure/src/main/java/org/springframework/batch/item/database/builder/JpaPagingItemReaderBuilder.java b/spring-batch-infrastructure/src/main/java/org/springframework/batch/item/database/builder/JpaPagingItemReaderBuilder.java index e3dba4904..695656a97 100644 --- a/spring-batch-infrastructure/src/main/java/org/springframework/batch/item/database/builder/JpaPagingItemReaderBuilder.java +++ b/spring-batch-infrastructure/src/main/java/org/springframework/batch/item/database/builder/JpaPagingItemReaderBuilder.java @@ -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 - extends AbstractItemCountingItemStreamItemReaderBuilder> { +public class JpaPagingItemReaderBuilder { private int pageSize = 10; @@ -47,6 +45,69 @@ public class JpaPagingItemReaderBuilder 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 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 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 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 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. diff --git a/spring-batch-infrastructure/src/main/java/org/springframework/batch/item/file/builder/FlatFileItemReaderBuilder.java b/spring-batch-infrastructure/src/main/java/org/springframework/batch/item/file/builder/FlatFileItemReaderBuilder.java index 46dfd1a80..e7763ee21 100644 --- a/spring-batch-infrastructure/src/main/java/org/springframework/batch/item/file/builder/FlatFileItemReaderBuilder.java +++ b/spring-batch-infrastructure/src/main/java/org/springframework/batch/item/file/builder/FlatFileItemReaderBuilder.java @@ -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 - extends AbstractItemCountingItemStreamItemReaderBuilder> { +public class FlatFileItemReaderBuilder { protected Log logger = LogFactory.getLog(getClass()); @@ -99,6 +97,69 @@ public class FlatFileItemReaderBuilder 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 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 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 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 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 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 reader = new FlatFileItemReader<>(); @@ -368,6 +427,9 @@ public class FlatFileItemReaderBuilder reader.setLineMapper(this.lineMapper); } else { + Assert.state(validatorValue == 1 || validatorValue == 2 || validatorValue == 4, + "Only one LineTokenizer option may be configured"); + DefaultLineMapper lineMapper = new DefaultLineMapper<>(); if(this.lineTokenizer != null && this.fieldSetMapper != null) { diff --git a/spring-batch-infrastructure/src/main/java/org/springframework/batch/item/file/builder/FlatFileItemWriterBuilder.java b/spring-batch-infrastructure/src/main/java/org/springframework/batch/item/file/builder/FlatFileItemWriterBuilder.java index 538677f19..574fa7b9d 100644 --- a/spring-batch-infrastructure/src/main/java/org/springframework/batch/item/file/builder/FlatFileItemWriterBuilder.java +++ b/spring-batch-infrastructure/src/main/java/org/springframework/batch/item/file/builder/FlatFileItemWriterBuilder.java @@ -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 extends AbstractItemStreamSupportBuilder> { +public class FlatFileItemWriterBuilder { private Resource resource; @@ -55,6 +54,39 @@ public class FlatFileItemWriterBuilder 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 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 name(String name) { + this.name = name; + + return this; + } + /** * The {@link Resource} to be used as output. * diff --git a/spring-batch-infrastructure/src/main/java/org/springframework/batch/item/file/builder/MultiResourceItemReaderBuilder.java b/spring-batch-infrastructure/src/main/java/org/springframework/batch/item/file/builder/MultiResourceItemReaderBuilder.java index 4cc9725f7..6eabba652 100644 --- a/spring-batch-infrastructure/src/main/java/org/springframework/batch/item/file/builder/MultiResourceItemReaderBuilder.java +++ b/spring-batch-infrastructure/src/main/java/org/springframework/batch/item/file/builder/MultiResourceItemReaderBuilder.java @@ -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 - extends AbstractItemStreamSupportBuilder> { +public class MultiResourceItemReaderBuilder { private ResourceAwareItemReaderItemStream delegate; @@ -45,6 +41,39 @@ public class MultiResourceItemReaderBuilder private Comparator 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 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 name(String name) { + this.name = name; + + return this; + } + /** * The array of resources that the {@link MultiResourceItemReader} will use to * retrieve items. diff --git a/spring-batch-infrastructure/src/main/java/org/springframework/batch/item/file/builder/MultiResourceItemWriterBuilder.java b/spring-batch-infrastructure/src/main/java/org/springframework/batch/item/file/builder/MultiResourceItemWriterBuilder.java index 3beb634b7..0e33eb13f 100644 --- a/spring-batch-infrastructure/src/main/java/org/springframework/batch/item/file/builder/MultiResourceItemWriterBuilder.java +++ b/spring-batch-infrastructure/src/main/java/org/springframework/batch/item/file/builder/MultiResourceItemWriterBuilder.java @@ -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 - extends AbstractItemStreamSupportBuilder> { +public class MultiResourceItemWriterBuilder { private Resource resource; @@ -43,6 +40,39 @@ public class MultiResourceItemWriterBuilder 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 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 name(String name) { + this.name = name; + + return this; + } + /** * Allows customization of the suffix of the created resources based on the index. * diff --git a/spring-batch-infrastructure/src/main/java/org/springframework/batch/item/xml/builder/StaxEventItemReaderBuilder.java b/spring-batch-infrastructure/src/main/java/org/springframework/batch/item/xml/builder/StaxEventItemReaderBuilder.java index d6ddb251b..f97798c6a 100644 --- a/spring-batch-infrastructure/src/main/java/org/springframework/batch/item/xml/builder/StaxEventItemReaderBuilder.java +++ b/spring-batch-infrastructure/src/main/java/org/springframework/batch/item/xml/builder/StaxEventItemReaderBuilder.java @@ -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 - extends AbstractItemCountingItemStreamItemReaderBuilder> { +public class StaxEventItemReaderBuilder { private boolean strict = true; @@ -44,6 +42,69 @@ public class StaxEventItemReaderBuilder private List 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 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 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 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 currentItemCount(int currentItemCount) { + this.currentItemCount = currentItemCount; + + return this; + } + /** * The {@link Resource} to be used as input. *