Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
import org.jspecify.annotations.Nullable;
import org.springframework.batch.infrastructure.item.ItemReader;
import org.springframework.batch.infrastructure.item.support.AbstractItemCountingItemStreamItemReader;
import org.springframework.beans.factory.BeanNameAware;
import org.springframework.beans.factory.InitializingBean;
import org.springframework.data.domain.Sort;
import org.springframework.data.mongodb.core.MongoOperations;
Expand All @@ -45,9 +46,11 @@
* @author LEE Juchan
* @author Mahmoud Ben Hassine
* @author Jimmy Praet
* @author Andrey Litvitski
* @since 5.1
*/
public class MongoCursorItemReader<T> extends AbstractItemCountingItemStreamItemReader<T> implements InitializingBean {
public class MongoCursorItemReader<T> extends AbstractItemCountingItemStreamItemReader<T>
implements InitializingBean, BeanNameAware {

private MongoOperations template;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
import org.jspecify.annotations.Nullable;
import org.springframework.batch.infrastructure.item.ExecutionContext;
import org.springframework.batch.infrastructure.item.ItemReader;
import org.springframework.beans.factory.BeanNameAware;
import org.springframework.beans.factory.InitializingBean;
import org.springframework.data.domain.PageRequest;
import org.springframework.data.domain.Pageable;
Expand Down Expand Up @@ -79,8 +80,10 @@
* @author Mahmoud Ben Hassine
* @author Parikshit Dutta
* @author Jimmy Praet
* @author Andrey Litvitski
*/
public class MongoPagingItemReader<T> extends AbstractPaginatedDataItemReader<T> implements InitializingBean {
public class MongoPagingItemReader<T> extends AbstractPaginatedDataItemReader<T>
implements InitializingBean, BeanNameAware {

protected MongoOperations template;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
import org.springframework.batch.infrastructure.item.adapter.AbstractMethodInvokingDelegator.InvocationTargetThrowableWrapper;
import org.springframework.batch.infrastructure.item.adapter.DynamicMethodInvocationException;
import org.springframework.batch.infrastructure.item.support.AbstractItemCountingItemStreamItemReader;
import org.springframework.beans.factory.BeanNameAware;
import org.springframework.beans.factory.InitializingBean;
import org.springframework.data.domain.PageRequest;
import org.springframework.data.domain.Pageable;
Expand Down Expand Up @@ -80,9 +81,11 @@
* @author Antoine Kapps
* @author Mahmoud Ben Hassine
* @author Jimmy Praet
* @author Andrey Litvitski
* @since 2.2
*/
public class RepositoryItemReader<T> extends AbstractItemCountingItemStreamItemReader<T> implements InitializingBean {
public class RepositoryItemReader<T> extends AbstractItemCountingItemStreamItemReader<T>
implements InitializingBean, BeanNameAware {

protected Log logger = LogFactory.getLog(getClass());

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@
* @author LEE Juchan
* @author Mahmoud Ben Hassine
* @author Stefano Cordio
* @author Andrey Litvitski
* @since 5.1
* @see MongoCursorItemReader
*/
Expand Down Expand Up @@ -278,9 +279,6 @@ public MongoCursorItemReaderBuilder<T> maxTime(Duration maxTime) {

public MongoCursorItemReader<T> build() {
Assert.notNull(this.template, "template is required.");
if (this.saveState) {
Assert.hasText(this.name, "A name is required when saveState is set to true");
}
Assert.notNull(this.targetType, "targetType is required.");
Assert.state(StringUtils.hasText(this.jsonQuery) || this.query != null, "A query is required");
Assert.notNull(this.sorts, "sorts map is required.");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@
* @author Drummond Dawson
* @author Parikshit Dutta
* @author Stefano Cordio
* @author Andrey Litvitski
* @since 5.1
*/
public class MongoPagingItemReaderBuilder<T> {
Expand Down Expand Up @@ -263,9 +264,6 @@ public MongoPagingItemReaderBuilder<T> query(Query query) {

public MongoPagingItemReader<T> build() {
Assert.notNull(this.template, "template is required.");
if (this.saveState) {
Assert.hasText(this.name, "A name is required when saveState is set to true");
}
Assert.notNull(this.targetType, "targetType is required.");
Assert.state(StringUtils.hasText(this.jsonQuery) || this.query != null, "A query is required");

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@
* @author Glenn Renfro
* @author Mahmoud Ben Hassine
* @author Drummond Dawson
* @author Andrey Litvitski
* @since 4.0
* @see RepositoryItemReader
*/
Expand Down Expand Up @@ -192,9 +193,6 @@ public RepositoryItemReader<T> build() {
Assert.notNull(this.repository, "repository is required.");
Assert.isTrue(this.pageSize > 0, "Page size must be greater than 0");
Assert.hasText(this.methodName, "methodName is required.");
if (this.saveState) {
Assert.state(StringUtils.hasText(this.name), "A name is required when saveState is set to true.");
}

RepositoryItemReader<T> reader = new RepositoryItemReader<>(this.repository, this.sorts);
if (this.arguments != null) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@

import javax.sql.DataSource;

import org.springframework.beans.factory.BeanNameAware;
import org.springframework.jdbc.core.PreparedStatementSetter;

import org.jspecify.annotations.Nullable;
Expand Down Expand Up @@ -62,8 +63,9 @@
* @author Mahmoud Ben Hassine
* @author Stefano Cordio
* @author Jimmy Praet
* @author Andrey Litvitski
*/
public class JdbcCursorItemReader<T> extends AbstractCursorItemReader<T> {
public class JdbcCursorItemReader<T> extends AbstractCursorItemReader<T> implements BeanNameAware {

private @Nullable PreparedStatement preparedStatement;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
import org.springframework.batch.infrastructure.item.ItemReader;
import org.springframework.batch.infrastructure.item.ExecutionContext;
import org.springframework.batch.infrastructure.item.ItemStreamException;
import org.springframework.beans.factory.BeanNameAware;
import org.springframework.beans.factory.InitializingBean;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.jdbc.core.RowMapper;
Expand Down Expand Up @@ -75,9 +76,10 @@
* @author Mahmoud Ben Hassine
* @author Stefano Cordio
* @author Jimmy Praet
* @author Andrey Litvitski
* @since 2.0
*/
public class JdbcPagingItemReader<T> extends AbstractPagingItemReader<T> implements InitializingBean {
public class JdbcPagingItemReader<T> extends AbstractPagingItemReader<T> implements InitializingBean, BeanNameAware {

private static final String START_AFTER_VALUE = "start.after";

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
import org.springframework.batch.infrastructure.item.ItemStreamReader;
import org.springframework.batch.infrastructure.item.database.orm.JpaQueryProvider;
import org.springframework.batch.infrastructure.item.support.AbstractItemCountingItemStreamItemReader;
import org.springframework.beans.factory.BeanNameAware;
import org.springframework.beans.factory.InitializingBean;
import org.springframework.dao.DataAccessResourceFailureException;
import org.springframework.util.Assert;
Expand All @@ -46,10 +47,12 @@
* @author Jinwoo Bae
* @author Stefano Cordio
* @author Jimmy Praet
* @author Andrey Litvitski
* @param <T> type of items to read
* @since 4.3
*/
public class JpaCursorItemReader<T> extends AbstractItemCountingItemStreamItemReader<T> implements InitializingBean {
public class JpaCursorItemReader<T> extends AbstractItemCountingItemStreamItemReader<T>
implements InitializingBean, BeanNameAware {

private EntityManagerFactory entityManagerFactory;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
import org.springframework.batch.infrastructure.item.ItemReader;
import org.springframework.batch.infrastructure.item.ExecutionContext;
import org.springframework.batch.infrastructure.item.database.orm.JpaQueryProvider;
import org.springframework.beans.factory.BeanNameAware;
import org.springframework.dao.DataAccessResourceFailureException;
import org.springframework.util.Assert;
import org.springframework.util.StringUtils;
Expand Down Expand Up @@ -83,9 +84,10 @@
* @author Mahmoud Ben Hassine
* @author Jinwoo Bae
* @author Jimmy Praet
* @author Andrey Litvitski
* @since 2.0
*/
public class JpaPagingItemReader<T> extends AbstractPagingItemReader<T> {
public class JpaPagingItemReader<T> extends AbstractPagingItemReader<T> implements BeanNameAware {

private EntityManagerFactory entityManagerFactory;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@
* @author Fabio Molignoni
* @author Juyoung Kim
* @author Stefano Cordio
* @author Andrey Litvitski
* @since 4.0
*/
public class JdbcCursorItemReaderBuilder<T> {
Expand Down Expand Up @@ -349,10 +350,6 @@ public JdbcCursorItemReaderBuilder<T> connectionAutoCommit(boolean connectionAut
* @return a fully constructed {@link JdbcCursorItemReader}
*/
public JdbcCursorItemReader<T> build() {
if (this.saveState) {
Assert.hasText(this.name, "A name is required when saveState is set to true");
}

Assert.hasText(this.sql, "A query is required");
Assert.notNull(this.dataSource, "A datasource is required");
Assert.notNull(this.rowMapper, "A rowmapper is required");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@
* @author Minsoo Kim
* @author Juyoung Kim
* @author Stefano Cordio
* @author Andrey Litvitski
* @since 4.0
* @see JdbcPagingItemReader
*/
Expand Down Expand Up @@ -318,10 +319,6 @@ public JdbcPagingItemReader<T> build() throws Exception {
Assert.isTrue(pageSize > 0, "pageSize must be greater than zero");
Assert.notNull(dataSource, "dataSource is required");

if (saveState) {
Assert.hasText(name, "A name is required when saveState is set to true");
}

JdbcPagingItemReader<T> reader = new JdbcPagingItemReader<>(this.dataSource,
queryProvider == null ? determineQueryProvider(dataSource) : queryProvider);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
* @author Mahmoud Ben Hassine
* @author Jinwoo Bae
* @author Stefano Cordio
* @author Andrey Litvitski
* @since 4.3
*/
public class JpaCursorItemReaderBuilder<T> {
Expand Down Expand Up @@ -175,9 +176,6 @@ public JpaCursorItemReaderBuilder<T> entityManagerFactory(EntityManagerFactory e
*/
public JpaCursorItemReader<T> build() {
Assert.notNull(this.entityManagerFactory, "An EntityManagerFactory is required");
if (this.saveState) {
Assert.hasText(this.name, "A name is required when saveState is set to true");
}
if (this.queryProvider == null) {
Assert.hasLength(this.queryString, "Query string is required when queryProvider is null");
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
* @author Glenn Renfro
* @author Jinwoo Bae
* @author Stefano Cordio
* @author Andrey Litvitski
* @since 4.0
*/

Expand Down Expand Up @@ -211,10 +212,6 @@ public JpaPagingItemReader<T> build() {
Assert.isTrue(this.pageSize > 0, "pageSize must be greater than zero");
Assert.notNull(this.entityManagerFactory, "An EntityManagerFactory is required");

if (this.saveState) {
Assert.hasText(this.name, "A name is required when saveState is set to true");
}

if (this.queryProvider == null) {
Assert.hasLength(this.queryString, "Query string is required when queryProvider is null");
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
import org.springframework.batch.infrastructure.item.file.separator.RecordSeparatorPolicy;
import org.springframework.batch.infrastructure.item.file.separator.SimpleRecordSeparatorPolicy;
import org.springframework.batch.infrastructure.item.support.AbstractItemCountingItemStreamItemReader;
import org.springframework.beans.factory.BeanNameAware;
import org.springframework.core.io.Resource;
import org.springframework.util.Assert;
import org.springframework.util.StringUtils;
Expand All @@ -50,12 +51,13 @@
* @author Mahmoud Ben Hassine
* @author Stefano Cordio
* @author Jimmy Praet
* @author Andrey Litvitski
*/
// FIXME the design of creating a flat file reader with an optional resource (to support
// the multi-resource case) is broken.
// FIXME The multi-resource reader should create the delegate with the current resource
public class FlatFileItemReader<T> extends AbstractItemCountingItemStreamItemReader<T>
implements ResourceAwareItemReaderItemStream<T> {
implements ResourceAwareItemReaderItemStream<T>, BeanNameAware {

private static final Log logger = LogFactory.getLog(FlatFileItemReader.class);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
import org.springframework.batch.infrastructure.item.ItemStreamException;
import org.springframework.batch.infrastructure.item.ResourceAware;
import org.springframework.batch.infrastructure.item.support.AbstractItemStreamItemReader;
import org.springframework.beans.factory.BeanNameAware;
import org.springframework.core.io.Resource;
import org.springframework.util.Assert;

Expand All @@ -43,8 +44,9 @@
* @author Lucas Ward
* @author Mahmoud Ben Hassine
* @author Jimmy Praet
* @author Andrey Litvitski
*/
public class MultiResourceItemReader<T> extends AbstractItemStreamItemReader<T> {
public class MultiResourceItemReader<T> extends AbstractItemStreamItemReader<T> implements BeanNameAware {

private static final Log logger = LogFactory.getLog(MultiResourceItemReader.class);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@
* @author François Martin
* @author Stefano Cordio
* @author Daeho Kwon
* @author Andrey Litvitski
* @since 4.0
* @see FlatFileItemReader
*/
Expand Down Expand Up @@ -465,9 +466,6 @@ public FlatFileItemReaderBuilder<T> beanMapperStrict(boolean beanMapperStrict) {
* @return a {@link FlatFileItemReader}
*/
public FlatFileItemReader<T> build() {
if (this.saveState) {
Assert.state(StringUtils.hasText(this.name), "A name is required when saveState is set to true.");
}

if (this.resource == null) {
logger.debug("The resource is null. This is only a valid scenario when "
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
* @author Glenn Renfro
* @author Drummond Dawson
* @author Stefano Cordio
* @author Andrey Litvitski
* @since 4.0
* @see MultiResourceItemReader
*/
Expand Down Expand Up @@ -137,9 +138,6 @@ public MultiResourceItemReaderBuilder<T> comparator(Comparator<Resource> compara
public MultiResourceItemReader<T> build() {
Assert.notNull(this.resources, "resources array is required.");
Assert.notNull(this.delegate, "delegate is required.");
if (this.saveState) {
Assert.state(StringUtils.hasText(this.name), "A name is required when saveState is set to true.");
}

MultiResourceItemReader<T> reader = new MultiResourceItemReader<>(this.delegate);
reader.setResources(this.resources);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
import org.springframework.batch.infrastructure.item.ItemStreamReader;
import org.springframework.batch.infrastructure.item.file.ResourceAwareItemReaderItemStream;
import org.springframework.batch.infrastructure.item.support.AbstractItemCountingItemStreamItemReader;
import org.springframework.beans.factory.BeanNameAware;
import org.springframework.core.io.Resource;
import org.springframework.util.Assert;

Expand All @@ -48,10 +49,11 @@
* @param <T> the type of json objects to read
* @author Mahmoud Ben Hassine
* @author Jimmy Praet
* @author Andrey Litvitski
* @since 4.1
*/
public class JsonItemReader<T> extends AbstractItemCountingItemStreamItemReader<T>
implements ResourceAwareItemReaderItemStream<T> {
implements ResourceAwareItemReaderItemStream<T>, BeanNameAware {

private static final Log LOGGER = LogFactory.getLog(JsonItemReader.class);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@
*
* @param <T> type of the target item
* @author Mahmoud Ben Hassine
* @author Andrey Litvitski
* @since 4.1
*/
public class JsonItemReaderBuilder<T> {
Expand Down Expand Up @@ -149,9 +150,6 @@ public JsonItemReaderBuilder<T> currentItemCount(int currentItemCount) {
*/
public JsonItemReader<T> build() {
Assert.notNull(this.jsonObjectReader, "A json object reader is required.");
if (this.saveState) {
Assert.state(StringUtils.hasText(this.name), "A name is required when saveState is set to true.");
}

if (this.resource == null) {
logger.debug("The resource is null. This is only a valid scenario when "
Expand Down
Loading
Loading