Skip to content

Commit

Permalink
change parameterValues check -> CollectionUtils.isEmpty
Browse files Browse the repository at this point in the history
  • Loading branch information
ces518 authored and lcmarvin committed Apr 16, 2022
1 parent 49b2807 commit bc96a48
Showing 1 changed file with 7 additions and 6 deletions.
@@ -1,5 +1,5 @@
/*
* Copyright 2006-2021 the original author or authors.
* Copyright 2006-2022 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.
Expand Down Expand Up @@ -28,6 +28,7 @@
import org.springframework.batch.item.database.orm.HibernateQueryProvider;
import org.springframework.beans.factory.InitializingBean;
import org.springframework.util.Assert;
import org.springframework.util.CollectionUtils;
import org.springframework.util.StringUtils;

/**
Expand All @@ -36,7 +37,7 @@
*
* @author Dave Syer
* @author Mahmoud Ben Hassine
*
* @author June Young. Park
*/
public class HibernateItemReaderHelper<T> implements InitializingBean {

Expand Down Expand Up @@ -84,7 +85,7 @@ public void setQueryProvider(HibernateQueryProvider<? extends T> queryProvider)
*/
public void setUseStatelessSession(boolean useStatelessSession) {
Assert.state(statefulSession == null && statelessSession == null,
"The useStatelessSession flag can only be set before a session is initialized.");
"The useStatelessSession flag can only be set before a session is initialized.");
this.useStatelessSession = useStatelessSession;
}

Expand All @@ -103,7 +104,7 @@ public void afterPropertiesSet() throws Exception {
if (queryProvider == null) {
Assert.notNull(sessionFactory, "session factory must be set");
Assert.state(StringUtils.hasText(queryString) ^ StringUtils.hasText(queryName),
"queryString or queryName must be set");
"queryString or queryName must be set");
}
}

Expand All @@ -117,7 +118,7 @@ public void afterPropertiesSet() throws Exception {
*/
public ScrollableResults getForwardOnlyCursor(int fetchSize, Map<String, Object> parameterValues) {
Query<? extends T> query = createQuery();
if (parameterValues != null) {
if (!CollectionUtils.isEmpty(parameterValues)) {
query.setProperties(parameterValues);
}
return query.setFetchSize(fetchSize).scroll(ScrollMode.FORWARD_ONLY);
Expand Down Expand Up @@ -215,7 +216,7 @@ public Collection<? extends T> readPage(int page, int pageSize, int fetchSize, M
clear();

Query<? extends T> query = createQuery();
if (parameterValues != null) {
if (!CollectionUtils.isEmpty(parameterValues)) {
query.setProperties(parameterValues);
}
return query.setFetchSize(fetchSize).setFirstResult(page * pageSize).setMaxResults(pageSize).list();
Expand Down

0 comments on commit bc96a48

Please sign in to comment.