Updated for various code warnings
This commit addresses a number of deprications and other code warnings. There are still many more to address, but this is a start.
This commit is contained in:
@@ -48,7 +48,7 @@ allprojects {
|
||||
|
||||
environmentProperty = project.hasProperty('environment') ? getProperty('environment') : 'hsql'
|
||||
|
||||
springVersionDefault = '5.0.0.M5'
|
||||
springVersionDefault = '5.0.0.BUILD-SNAPSHOT'
|
||||
springVersion = project.hasProperty('springVersion') ? getProperty('springVersion') : springVersionDefault
|
||||
springRetryVersion = '1.2.0.RELEASE'
|
||||
springAmqpVersion = '1.5.6.RELEASE'
|
||||
@@ -58,7 +58,7 @@ allprojects {
|
||||
springDataMongodbVersion = '2.0.0.BUILD-SNAPSHOT'
|
||||
springDataNeo4jVersion = '5.0.0.BUILD-SNAPSHOT'
|
||||
springIntegrationVersion = '5.0.0.M1'
|
||||
springLdapVersion = '2.0.4.RELEASE'
|
||||
springLdapVersion = '2.3.1.RELEASE'
|
||||
|
||||
activemqVersion = '5.13.2'
|
||||
aspectjVersion = '1.8.9'
|
||||
|
||||
@@ -15,11 +15,18 @@
|
||||
*/
|
||||
package org.springframework.batch.core.test.ldif;
|
||||
|
||||
import java.io.BufferedReader;
|
||||
import java.io.File;
|
||||
import java.io.FileInputStream;
|
||||
import java.io.InputStreamReader;
|
||||
import java.net.MalformedURLException;
|
||||
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import org.springframework.batch.core.ExitStatus;
|
||||
import org.springframework.batch.core.Job;
|
||||
import org.springframework.batch.core.JobExecution;
|
||||
@@ -34,12 +41,6 @@ import org.springframework.test.context.ContextConfiguration;
|
||||
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
|
||||
import org.springframework.util.Assert;
|
||||
|
||||
import java.io.BufferedReader;
|
||||
import java.io.File;
|
||||
import java.io.FileInputStream;
|
||||
import java.io.InputStreamReader;
|
||||
import java.net.MalformedURLException;
|
||||
|
||||
@RunWith(SpringJUnit4ClassRunner.class)
|
||||
@ContextConfiguration(locations = { "/simple-job-launcher-context.xml", "/applicationContext-test2.xml"})
|
||||
public class MappingLdifReaderTests {
|
||||
@@ -78,7 +79,7 @@ public class MappingLdifReaderTests {
|
||||
|
||||
//Check output.
|
||||
Assert.isTrue(actual.exists(), "Actual does not exist.");
|
||||
Assert.isTrue(compareFiles(expected.getFile(), actual.getFile()));
|
||||
Assert.isTrue(compareFiles(expected.getFile(), actual.getFile()), "Files were not equal");
|
||||
}
|
||||
|
||||
@Test
|
||||
|
||||
@@ -79,7 +79,7 @@ public class DataSourceInitializer implements InitializingBean, DisposableBean {
|
||||
|
||||
@Override
|
||||
public void afterPropertiesSet() throws Exception {
|
||||
Assert.notNull(dataSource);
|
||||
Assert.notNull(dataSource, "A DataSource is required");
|
||||
logger.info("Initializing with scripts: "+Arrays.asList(initScripts));
|
||||
if (!initialized && initialize) {
|
||||
try {
|
||||
|
||||
@@ -45,7 +45,7 @@ public class JobInstance extends Entity implements javax.batch.runtime.JobInstan
|
||||
|
||||
public JobInstance(Long id, String jobName) {
|
||||
super(id);
|
||||
Assert.hasLength(jobName);
|
||||
Assert.hasLength(jobName, "A jobName is required");
|
||||
this.jobName = jobName;
|
||||
}
|
||||
|
||||
|
||||
@@ -97,7 +97,7 @@ public class StepExecution extends Entity {
|
||||
*/
|
||||
public StepExecution(String stepName, JobExecution jobExecution) {
|
||||
super();
|
||||
Assert.hasLength(stepName);
|
||||
Assert.hasLength(stepName, "A stepName is required");
|
||||
this.stepName = stepName;
|
||||
this.jobExecution = jobExecution;
|
||||
}
|
||||
@@ -112,7 +112,7 @@ public class StepExecution extends Entity {
|
||||
@SuppressWarnings("unused")
|
||||
private StepExecution(String stepName) {
|
||||
super();
|
||||
Assert.hasLength(stepName);
|
||||
Assert.hasLength(stepName, "A stepName is required");
|
||||
this.stepName = stepName;
|
||||
this.jobExecution = null;
|
||||
}
|
||||
|
||||
@@ -25,6 +25,8 @@ package org.springframework.batch.core.configuration;
|
||||
*/
|
||||
public class BatchConfigurationException extends RuntimeException {
|
||||
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
/**
|
||||
* @param t an exception to be wrapped
|
||||
*/
|
||||
|
||||
@@ -19,7 +19,6 @@ import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
|
||||
import org.springframework.beans.BeansException;
|
||||
import org.springframework.beans.factory.BeanFactoryAware;
|
||||
import org.springframework.beans.factory.FactoryBean;
|
||||
import org.springframework.beans.factory.config.BeanFactoryPostProcessor;
|
||||
@@ -57,7 +56,7 @@ public class ClasspathXmlApplicationContextsFactoryBean implements FactoryBean<A
|
||||
* resources can be given as a pattern (e.g.
|
||||
* <code>classpath*:/config/*-context.xml</code>).
|
||||
*
|
||||
* @param resources
|
||||
* @param resources array of resources to use
|
||||
*/
|
||||
public void setResources(Resource[] resources) {
|
||||
this.resources = Arrays.asList(resources);
|
||||
@@ -105,7 +104,6 @@ public class ClasspathXmlApplicationContextsFactoryBean implements FactoryBean<A
|
||||
* in {@link #setResources(Resource[])}.
|
||||
*
|
||||
* @return an array of {@link ApplicationContextFactory}
|
||||
* @throws Exception
|
||||
* @see org.springframework.beans.factory.FactoryBean#getObject()
|
||||
*/
|
||||
@Override
|
||||
@@ -115,7 +113,7 @@ public class ClasspathXmlApplicationContextsFactoryBean implements FactoryBean<A
|
||||
return new ApplicationContextFactory[0];
|
||||
}
|
||||
|
||||
List<ApplicationContextFactory> applicationContextFactories = new ArrayList<ApplicationContextFactory>();
|
||||
List<ApplicationContextFactory> applicationContextFactories = new ArrayList<>();
|
||||
for (Resource resource : resources) {
|
||||
GenericApplicationContextFactory factory = new GenericApplicationContextFactory(resource);
|
||||
factory.setCopyConfiguration(copyConfiguration);
|
||||
@@ -158,7 +156,6 @@ public class ClasspathXmlApplicationContextsFactoryBean implements FactoryBean<A
|
||||
* factories.
|
||||
*
|
||||
* @param applicationContext the {@link ApplicationContext} to set
|
||||
* @throws BeansException
|
||||
* @see ApplicationContextAware#setApplicationContext(org.springframework.context.ApplicationContext)
|
||||
*/
|
||||
@Override
|
||||
|
||||
@@ -43,7 +43,7 @@ public class MapJobRegistry implements JobRegistry {
|
||||
|
||||
@Override
|
||||
public void register(JobFactory jobFactory) throws DuplicateJobException {
|
||||
Assert.notNull(jobFactory);
|
||||
Assert.notNull(jobFactory, "jobFactory is null");
|
||||
String name = jobFactory.getJobName();
|
||||
Assert.notNull(name, "Job configuration must have a name.");
|
||||
JobFactory previousValue = map.putIfAbsent(name, jobFactory);
|
||||
|
||||
@@ -24,6 +24,10 @@ import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
|
||||
import org.w3c.dom.Element;
|
||||
import org.w3c.dom.Node;
|
||||
import org.w3c.dom.NodeList;
|
||||
|
||||
import org.springframework.batch.core.job.flow.FlowExecutionStatus;
|
||||
import org.springframework.beans.factory.config.BeanDefinition;
|
||||
import org.springframework.beans.factory.parsing.CompositeComponentDefinition;
|
||||
@@ -33,9 +37,6 @@ import org.springframework.beans.factory.xml.AbstractSingleBeanDefinitionParser;
|
||||
import org.springframework.beans.factory.xml.ParserContext;
|
||||
import org.springframework.util.StringUtils;
|
||||
import org.springframework.util.xml.DomUtils;
|
||||
import org.w3c.dom.Element;
|
||||
import org.w3c.dom.Node;
|
||||
import org.w3c.dom.NodeList;
|
||||
|
||||
/**
|
||||
* @author Dave Syer
|
||||
@@ -89,7 +90,7 @@ public abstract class AbstractFlowParser extends AbstractSingleBeanDefinitionPar
|
||||
* is available (null is fine, but the quality of error reports is better if
|
||||
* it is available).
|
||||
*
|
||||
* @param jobFactoryRef
|
||||
* @param jobFactoryRef name of the ref
|
||||
*/
|
||||
protected void setJobFactoryRef(String jobFactoryRef) {
|
||||
this.jobFactoryRef = jobFactoryRef;
|
||||
@@ -179,7 +180,7 @@ public abstract class AbstractFlowParser extends AbstractSingleBeanDefinitionPar
|
||||
/**
|
||||
* Find all of the elements that are pointed to by this element.
|
||||
*
|
||||
* @param element
|
||||
* @param element The parent element
|
||||
* @return a collection of reachable element names
|
||||
*/
|
||||
private Set<String> findReachableElements(Element element) {
|
||||
@@ -208,8 +209,8 @@ public abstract class AbstractFlowParser extends AbstractSingleBeanDefinitionPar
|
||||
/**
|
||||
* Find all of the elements reachable from the startElement.
|
||||
*
|
||||
* @param startElement
|
||||
* @param reachableElementMap
|
||||
* @param startElement name of the element to start from
|
||||
* @param reachableElementMap Map of elements that can be reached from the startElement
|
||||
* @param accumulator a collection of reachable element names
|
||||
*/
|
||||
protected void findAllReachableElements(String startElement, Map<String, Set<String>> reachableElementMap,
|
||||
|
||||
@@ -15,6 +15,10 @@
|
||||
*/
|
||||
package org.springframework.batch.core.configuration.xml;
|
||||
|
||||
import org.w3c.dom.Element;
|
||||
import org.w3c.dom.Node;
|
||||
import org.w3c.dom.NodeList;
|
||||
|
||||
import org.springframework.batch.core.listener.StepListenerMetaData;
|
||||
import org.springframework.beans.MutablePropertyValues;
|
||||
import org.springframework.beans.factory.config.BeanDefinition;
|
||||
@@ -28,9 +32,6 @@ import org.springframework.beans.factory.xml.BeanDefinitionParserDelegate;
|
||||
import org.springframework.beans.factory.xml.ParserContext;
|
||||
import org.springframework.util.StringUtils;
|
||||
import org.springframework.util.xml.DomUtils;
|
||||
import org.w3c.dom.Element;
|
||||
import org.w3c.dom.Node;
|
||||
import org.w3c.dom.NodeList;
|
||||
|
||||
/**
|
||||
* Internal parser for the <step/> elements inside a job. A step element
|
||||
@@ -89,7 +90,7 @@ public abstract class AbstractStepParser {
|
||||
|
||||
/**
|
||||
* @param stepElement The <step/> element
|
||||
* @param parserContext
|
||||
* @param parserContext context
|
||||
* @param jobFactoryRef the reference to the {@link JobParserJobFactoryBean}
|
||||
* from the enclosing tag. Use 'null' if unknown.
|
||||
*/
|
||||
|
||||
@@ -17,6 +17,8 @@ package org.springframework.batch.core.configuration.xml;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import org.w3c.dom.Element;
|
||||
|
||||
import org.springframework.batch.core.listener.StepListenerMetaData;
|
||||
import org.springframework.batch.repeat.policy.SimpleCompletionPolicy;
|
||||
import org.springframework.beans.BeanMetadataElement;
|
||||
@@ -35,7 +37,6 @@ import org.springframework.beans.factory.xml.ParserContext;
|
||||
import org.springframework.util.CollectionUtils;
|
||||
import org.springframework.util.StringUtils;
|
||||
import org.springframework.util.xml.DomUtils;
|
||||
import org.w3c.dom.Element;
|
||||
|
||||
/**
|
||||
* Internal parser for the <chunk/> element inside a step.
|
||||
@@ -67,8 +68,8 @@ public class ChunkElementParser {
|
||||
StepListenerMetaData.itemListenerMetaData());
|
||||
|
||||
/**
|
||||
* @param element
|
||||
* @param parserContext
|
||||
* @param element the element to parse
|
||||
* @param parserContext the context to use
|
||||
*/
|
||||
protected void parse(Element element, AbstractBeanDefinition bd, ParserContext parserContext, boolean underspecified) {
|
||||
|
||||
|
||||
@@ -85,7 +85,7 @@ InitializingBean {
|
||||
* Convenience constructor to immediately add name (which is mandatory but
|
||||
* not final).
|
||||
*
|
||||
* @param name
|
||||
* @param name name of the job
|
||||
*/
|
||||
public AbstractJob(String name) {
|
||||
super();
|
||||
@@ -154,7 +154,7 @@ InitializingBean {
|
||||
* Retrieve the step with the given name. If there is no Step with the given
|
||||
* name, then return null.
|
||||
*
|
||||
* @param stepName
|
||||
* @param stepName name of the step
|
||||
* @return the Step
|
||||
*/
|
||||
@Override
|
||||
@@ -242,7 +242,7 @@ InitializingBean {
|
||||
* state of the batch meta domain (jobs, steps, executions) during the life
|
||||
* of a job.
|
||||
*
|
||||
* @param jobRepository
|
||||
* @param jobRepository repository to use during the job execution
|
||||
*/
|
||||
public void setJobRepository(JobRepository jobRepository) {
|
||||
this.jobRepository = jobRepository;
|
||||
|
||||
@@ -67,11 +67,7 @@ public class StepState extends AbstractState implements StepLocator, StepHolder
|
||||
return new FlowExecutionStatus(executor.executeStep(step));
|
||||
}
|
||||
|
||||
/**
|
||||
* @deprecated in favor of using {@link StepLocator#getStep(String)}.
|
||||
*/
|
||||
@Override
|
||||
@Deprecated
|
||||
public Step getStep() {
|
||||
return step;
|
||||
}
|
||||
|
||||
@@ -37,7 +37,7 @@ public class JobListenerAdapter implements JobExecutionListener {
|
||||
* @param delegate to be delegated to
|
||||
*/
|
||||
public JobListenerAdapter(JobListener delegate) {
|
||||
Assert.notNull(delegate);
|
||||
Assert.notNull(delegate, "Delegate is required");
|
||||
this.delegate = delegate;
|
||||
}
|
||||
|
||||
|
||||
@@ -39,7 +39,7 @@ public class BatchletStep extends TaskletStep {
|
||||
*/
|
||||
public BatchletStep(String name, BatchPropertyContext propertyContext) {
|
||||
super(name);
|
||||
Assert.notNull(propertyContext);
|
||||
Assert.notNull(propertyContext, "A propertyContext is required");
|
||||
this.propertyContext = propertyContext;
|
||||
}
|
||||
|
||||
|
||||
@@ -15,8 +15,22 @@
|
||||
*/
|
||||
package org.springframework.batch.core.launch.support;
|
||||
|
||||
import java.io.BufferedReader;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStreamReader;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.Collections;
|
||||
import java.util.HashMap;
|
||||
import java.util.HashSet;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Properties;
|
||||
import java.util.Set;
|
||||
|
||||
import org.apache.commons.logging.Log;
|
||||
import org.apache.commons.logging.LogFactory;
|
||||
|
||||
import org.springframework.batch.core.BatchStatus;
|
||||
import org.springframework.batch.core.ExitStatus;
|
||||
import org.springframework.batch.core.Job;
|
||||
@@ -44,19 +58,6 @@ import org.springframework.context.support.ClassPathXmlApplicationContext;
|
||||
import org.springframework.util.Assert;
|
||||
import org.springframework.util.StringUtils;
|
||||
|
||||
import java.io.BufferedReader;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStreamReader;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.Collections;
|
||||
import java.util.HashMap;
|
||||
import java.util.HashSet;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Properties;
|
||||
import java.util.Set;
|
||||
|
||||
/**
|
||||
* <p>
|
||||
* Basic launcher for starting jobs from the command line. In general, it is
|
||||
|
||||
@@ -15,9 +15,6 @@
|
||||
*/
|
||||
package org.springframework.batch.core.listener;
|
||||
|
||||
import static org.springframework.batch.support.MethodInvokerUtils.getMethodInvokerByAnnotation;
|
||||
import static org.springframework.batch.support.MethodInvokerUtils.getMethodInvokerForInterface;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.HashSet;
|
||||
import java.util.Map;
|
||||
@@ -26,6 +23,7 @@ import java.util.Set;
|
||||
|
||||
import org.apache.commons.logging.Log;
|
||||
import org.apache.commons.logging.LogFactory;
|
||||
|
||||
import org.springframework.aop.TargetSource;
|
||||
import org.springframework.aop.framework.Advised;
|
||||
import org.springframework.aop.framework.ProxyFactory;
|
||||
@@ -37,6 +35,9 @@ import org.springframework.beans.factory.InitializingBean;
|
||||
import org.springframework.core.Ordered;
|
||||
import org.springframework.util.Assert;
|
||||
|
||||
import static org.springframework.batch.support.MethodInvokerUtils.getMethodInvokerByAnnotation;
|
||||
import static org.springframework.batch.support.MethodInvokerUtils.getMethodInvokerForInterface;
|
||||
|
||||
/**
|
||||
* {@link FactoryBean} implementation that builds a listener based on the
|
||||
* various lifecycle methods or annotations that are provided. There are three
|
||||
@@ -157,7 +158,10 @@ public abstract class AbstractListenerFactoryBean<T> implements FactoryBean<Obje
|
||||
else {
|
||||
proxyFactory.setTarget(delegate);
|
||||
}
|
||||
proxyFactory.setInterfaces(listenerInterfaces.toArray(new Class[0]));
|
||||
@SuppressWarnings("rawtypes")
|
||||
Class[] a = new Class[0];
|
||||
|
||||
proxyFactory.setInterfaces(listenerInterfaces.toArray(a));
|
||||
proxyFactory.addAdvisor(new DefaultPointcutAdvisor(new MethodInvokerMethodInterceptor(invokerMap, ordered)));
|
||||
return proxyFactory.getProxy();
|
||||
|
||||
|
||||
@@ -81,7 +81,7 @@ public abstract class AbstractJdbcBatchMetadataDao implements InitializingBean {
|
||||
|
||||
@Override
|
||||
public void afterPropertiesSet() throws Exception {
|
||||
Assert.notNull(jdbcTemplate);
|
||||
Assert.notNull(jdbcTemplate, "JdbcOperations is required");
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -52,11 +52,11 @@ public class DefaultExecutionContextSerializer implements ExecutionContextSerial
|
||||
@Override
|
||||
@SuppressWarnings("unchecked")
|
||||
public void serialize(Map<String, Object> context, OutputStream out) throws IOException {
|
||||
Assert.notNull(context);
|
||||
Assert.notNull(out);
|
||||
Assert.notNull(context, "context is required");
|
||||
Assert.notNull(out, "OutputStream is required");
|
||||
|
||||
for(Object value : context.values()) {
|
||||
Assert.notNull(value);
|
||||
Assert.notNull(value, "A null value was found");
|
||||
if (!(value instanceof Serializable)) {
|
||||
throw new IllegalArgumentException(
|
||||
"Value: [ " + value + "must be serializable."
|
||||
|
||||
@@ -15,19 +15,20 @@
|
||||
*/
|
||||
package org.springframework.batch.core.repository.dao;
|
||||
|
||||
import com.fasterxml.jackson.core.type.TypeReference;
|
||||
import com.fasterxml.jackson.databind.DeserializationFeature;
|
||||
import com.fasterxml.jackson.databind.MapperFeature;
|
||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
import org.springframework.batch.core.repository.ExecutionContextSerializer;
|
||||
import org.springframework.util.Assert;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.io.OutputStream;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
import com.fasterxml.jackson.core.type.TypeReference;
|
||||
import com.fasterxml.jackson.databind.DeserializationFeature;
|
||||
import com.fasterxml.jackson.databind.MapperFeature;
|
||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
|
||||
import org.springframework.batch.core.repository.ExecutionContextSerializer;
|
||||
import org.springframework.util.Assert;
|
||||
|
||||
/**
|
||||
* Implementation that uses Jackson2 to provide (de)serialization.
|
||||
*
|
||||
@@ -60,8 +61,8 @@ public class Jackson2ExecutionContextStringSerializer implements ExecutionContex
|
||||
|
||||
public void serialize(Map<String, Object> context, OutputStream out) throws IOException {
|
||||
|
||||
Assert.notNull(context);
|
||||
Assert.notNull(out);
|
||||
Assert.notNull(context, "A context is required");
|
||||
Assert.notNull(out, "An OutputStream is required");
|
||||
|
||||
objectMapper.writeValue(out, context);
|
||||
}
|
||||
|
||||
@@ -172,7 +172,7 @@ public class JdbcJobExecutionDao extends AbstractJdbcBatchMetadataDao implements
|
||||
*/
|
||||
private void validateJobExecution(JobExecution jobExecution) {
|
||||
|
||||
Assert.notNull(jobExecution);
|
||||
Assert.notNull(jobExecution, "jobExecution cannot be null");
|
||||
Assert.notNull(jobExecution.getJobId(), "JobExecution Job-Id cannot be null.");
|
||||
Assert.notNull(jobExecution.getStatus(), "JobExecution status cannot be null.");
|
||||
Assert.notNull(jobExecution.getCreateTime(), "JobExecution create time cannot be null");
|
||||
|
||||
@@ -153,7 +153,7 @@ JobInstanceDao, InitializingBean {
|
||||
if (instances.isEmpty()) {
|
||||
return null;
|
||||
} else {
|
||||
Assert.state(instances.size() == 1);
|
||||
Assert.state(instances.size() == 1, "instance counte must be 1 but was " + instances.size());
|
||||
return instances.get(0);
|
||||
}
|
||||
}
|
||||
@@ -282,7 +282,7 @@ JobInstanceDao, InitializingBean {
|
||||
@Override
|
||||
public void afterPropertiesSet() throws Exception {
|
||||
super.afterPropertiesSet();
|
||||
Assert.notNull(jobIncrementer);
|
||||
Assert.notNull(jobIncrementer, "JobIncrementer is required");
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -211,7 +211,7 @@ public class JdbcStepExecutionDao extends AbstractJdbcBatchMetadataDao implement
|
||||
* @throws IllegalArgumentException
|
||||
*/
|
||||
private void validateStepExecution(StepExecution stepExecution) {
|
||||
Assert.notNull(stepExecution);
|
||||
Assert.notNull(stepExecution, "stepExecution is required");
|
||||
Assert.notNull(stepExecution.getStepName(), "StepExecution step name cannot be null.");
|
||||
Assert.notNull(stepExecution.getStartTime(), "StepExecution start time cannot be null.");
|
||||
Assert.notNull(stepExecution.getStatus(), "StepExecution status cannot be null.");
|
||||
|
||||
@@ -53,7 +53,7 @@ public class MapJobExecutionDao implements JobExecutionDao {
|
||||
|
||||
@Override
|
||||
public void saveJobExecution(JobExecution jobExecution) {
|
||||
Assert.isTrue(jobExecution.getId() == null);
|
||||
Assert.isTrue(jobExecution.getId() == null, "jobExecution id is not null");
|
||||
Long newId = currentId.getAndIncrement();
|
||||
jobExecution.setId(newId);
|
||||
jobExecution.incrementVersion();
|
||||
|
||||
@@ -68,8 +68,8 @@ public class MapStepExecutionDao implements StepExecutionDao {
|
||||
@Override
|
||||
public void saveStepExecution(StepExecution stepExecution) {
|
||||
|
||||
Assert.isTrue(stepExecution.getId() == null);
|
||||
Assert.isTrue(stepExecution.getVersion() == null);
|
||||
Assert.isTrue(stepExecution.getId() == null, "stepExecution id was not null");
|
||||
Assert.isTrue(stepExecution.getVersion() == null, "stepExecution version was not null");
|
||||
Assert.notNull(stepExecution.getJobExecutionId(), "JobExecution must be saved already.");
|
||||
|
||||
Map<Long, StepExecution> executions = executionsByJobExecutionId.get(stepExecution.getJobExecutionId());
|
||||
@@ -89,7 +89,7 @@ public class MapStepExecutionDao implements StepExecutionDao {
|
||||
@Override
|
||||
public void updateStepExecution(StepExecution stepExecution) {
|
||||
|
||||
Assert.notNull(stepExecution.getJobExecutionId());
|
||||
Assert.notNull(stepExecution.getJobExecutionId(), "jobExecution id is null");
|
||||
|
||||
Map<Long, StepExecution> executions = executionsByJobExecutionId.get(stepExecution.getJobExecutionId());
|
||||
Assert.notNull(executions, "step executions for given job execution are expected to be already saved");
|
||||
|
||||
@@ -45,6 +45,7 @@ import org.springframework.util.Assert;
|
||||
* versions, this serializer is depricated in favor of
|
||||
* {@link Jackson2ExecutionContextStringSerializer}
|
||||
*/
|
||||
@Deprecated
|
||||
public class XStreamExecutionContextStringSerializer implements ExecutionContextSerializer, InitializingBean {
|
||||
|
||||
private ReflectionProvider reflectionProvider = null;
|
||||
@@ -87,8 +88,8 @@ public class XStreamExecutionContextStringSerializer implements ExecutionContext
|
||||
*/
|
||||
@Override
|
||||
public void serialize(Map<String, Object> context, OutputStream out) throws IOException {
|
||||
Assert.notNull(context);
|
||||
Assert.notNull(out);
|
||||
Assert.notNull(context, "context is required");
|
||||
Assert.notNull(out, "An OutputStream is required");
|
||||
|
||||
out.write(xstream.toXML(context).getBytes());
|
||||
}
|
||||
|
||||
@@ -136,7 +136,7 @@ public abstract class AbstractStep implements Step, InitializingBean, BeanNameAw
|
||||
/**
|
||||
* Convenient constructor for setting only the name property.
|
||||
*
|
||||
* @param name
|
||||
* @param name Name of the step
|
||||
*/
|
||||
public AbstractStep(String name) {
|
||||
this.name = name;
|
||||
@@ -147,7 +147,7 @@ public abstract class AbstractStep implements Step, InitializingBean, BeanNameAw
|
||||
* {@link StepExecution} before returning.
|
||||
*
|
||||
* @param stepExecution the current step context
|
||||
* @throws Exception
|
||||
* @throws Exception checked exception thrown by implementation
|
||||
*/
|
||||
protected abstract void doExecute(StepExecution stepExecution) throws Exception;
|
||||
|
||||
@@ -156,7 +156,7 @@ public abstract class AbstractStep implements Step, InitializingBean, BeanNameAw
|
||||
* acquire resources. Does nothing by default.
|
||||
*
|
||||
* @param ctx the {@link ExecutionContext} to use
|
||||
* @throws Exception
|
||||
* @throws Exception checked exception thrown by implementation
|
||||
*/
|
||||
protected void open(ExecutionContext ctx) throws Exception {
|
||||
}
|
||||
@@ -166,7 +166,7 @@ public abstract class AbstractStep implements Step, InitializingBean, BeanNameAw
|
||||
* of the finally block), to close or release resources. Does nothing by default.
|
||||
*
|
||||
* @param ctx the {@link ExecutionContext} to use
|
||||
* @throws Exception
|
||||
* @throws Exception checked exception thrown by implementation
|
||||
*/
|
||||
protected void close(ExecutionContext ctx) throws Exception {
|
||||
}
|
||||
@@ -293,7 +293,7 @@ public abstract class AbstractStep implements Step, InitializingBean, BeanNameAw
|
||||
/**
|
||||
* Registers the {@link StepExecution} for property resolution via {@link StepScope}
|
||||
*
|
||||
* @param stepExecution
|
||||
* @param stepExecution StepExecution to use when hydrating the StepScoped beans
|
||||
*/
|
||||
protected void doExecutionRegistration(StepExecution stepExecution) {
|
||||
StepSynchronizationManager.register(stepExecution);
|
||||
|
||||
@@ -198,7 +198,7 @@ public class FaultTolerantStepBuilder<I, O> extends SimpleStepBuilder<I, O> {
|
||||
*/
|
||||
@Override
|
||||
@SuppressWarnings("unchecked")
|
||||
public SimpleStepBuilder listener(Object listener) {
|
||||
public SimpleStepBuilder<I, O> listener(Object listener) {
|
||||
super.listener(listener);
|
||||
|
||||
Set<Method> skipListenerMethods = new HashSet<Method>();
|
||||
@@ -224,7 +224,7 @@ public class FaultTolerantStepBuilder<I, O> extends SimpleStepBuilder<I, O> {
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
SimpleStepBuilder result = this;
|
||||
SimpleStepBuilder<I, O> result = this;
|
||||
return result;
|
||||
}
|
||||
|
||||
@@ -548,12 +548,9 @@ public class FaultTolerantStepBuilder<I, O> extends SimpleStepBuilder<I, O> {
|
||||
types.add(ExhaustedRetryException.class);
|
||||
final Classifier<Throwable, Boolean> panic = new BinaryExceptionClassifier(types, true);
|
||||
|
||||
classifier = new Classifier<Throwable, Boolean>() {
|
||||
@Override
|
||||
public Boolean classify(Throwable classifiable) {
|
||||
// Rollback if either the user's list or our own applies
|
||||
return panic.classify(classifiable) || binary.classify(classifiable);
|
||||
}
|
||||
classifier = (Classifier<Throwable, Boolean>) classifiable -> {
|
||||
// Rollback if either the user's list or our own applies
|
||||
return panic.classify(classifiable) || binary.classify(classifiable);
|
||||
};
|
||||
|
||||
}
|
||||
@@ -700,8 +697,9 @@ public class FaultTolerantStepBuilder<I, O> extends SimpleStepBuilder<I, O> {
|
||||
return skipPolicyWrapper;
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
private void addNonSkippableExceptionIfMissing(Class<? extends Throwable>... cls) {
|
||||
List<Class<? extends Throwable>> exceptions = new ArrayList<Class<? extends Throwable>>();
|
||||
List<Class<? extends Throwable>> exceptions = new ArrayList<>();
|
||||
for (Class<? extends Throwable> exceptionClass : nonSkippableExceptionClasses) {
|
||||
exceptions.add(exceptionClass);
|
||||
}
|
||||
@@ -713,8 +711,9 @@ public class FaultTolerantStepBuilder<I, O> extends SimpleStepBuilder<I, O> {
|
||||
nonSkippableExceptionClasses = exceptions;
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
private void addNonRetryableExceptionIfMissing(Class<? extends Throwable>... cls) {
|
||||
List<Class<? extends Throwable>> exceptions = new ArrayList<Class<? extends Throwable>>();
|
||||
List<Class<? extends Throwable>> exceptions = new ArrayList<>();
|
||||
for (Class<? extends Throwable> exceptionClass : nonRetryableExceptionClasses) {
|
||||
exceptions.add(exceptionClass);
|
||||
}
|
||||
|
||||
@@ -249,10 +249,10 @@ public class SimpleStepBuilder<I, O> extends AbstractTaskletStepBuilder<SimpleSt
|
||||
*/
|
||||
@SuppressWarnings("unchecked")
|
||||
@Override
|
||||
public SimpleStepBuilder listener(Object listener) {
|
||||
public SimpleStepBuilder<I, O> listener(Object listener) {
|
||||
super.listener(listener);
|
||||
|
||||
Set<Method> itemListenerMethods = new HashSet<Method>();
|
||||
Set<Method> itemListenerMethods = new HashSet<>();
|
||||
itemListenerMethods.addAll(ReflectionUtils.findMethod(listener.getClass(), BeforeRead.class));
|
||||
itemListenerMethods.addAll(ReflectionUtils.findMethod(listener.getClass(), AfterRead.class));
|
||||
itemListenerMethods.addAll(ReflectionUtils.findMethod(listener.getClass(), BeforeProcess.class));
|
||||
@@ -270,7 +270,7 @@ public class SimpleStepBuilder<I, O> extends AbstractTaskletStepBuilder<SimpleSt
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
SimpleStepBuilder result = this;
|
||||
SimpleStepBuilder<I, O> result = this;
|
||||
return result;
|
||||
}
|
||||
|
||||
|
||||
@@ -66,7 +66,7 @@ public class Chunk<W> implements Iterable<W> {
|
||||
|
||||
/**
|
||||
* Add the item to the chunk.
|
||||
* @param item
|
||||
* @param item the item to add
|
||||
*/
|
||||
public void add(W item) {
|
||||
items.add(item);
|
||||
|
||||
@@ -54,7 +54,7 @@ public class ChunkOrientedTasklet<I> implements Tasklet {
|
||||
* readers. Main (or only) use case for setting this flag to false is a
|
||||
* transactional JMS item reader.
|
||||
*
|
||||
* @param buffering
|
||||
* @param buffering indicator
|
||||
*/
|
||||
public void setBuffering(boolean buffering) {
|
||||
this.buffering = buffering;
|
||||
|
||||
@@ -49,7 +49,7 @@ public class CallableTaskletAdapter implements Tasklet, InitializingBean {
|
||||
*/
|
||||
@Override
|
||||
public void afterPropertiesSet() throws Exception {
|
||||
Assert.notNull(callable);
|
||||
Assert.notNull(callable, "A Callable is required");
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -50,7 +50,7 @@ public class ConfigurableSystemProcessExitCodeMapper implements SystemProcessExi
|
||||
* {@link org.springframework.batch.core.ExitStatus} values.
|
||||
*/
|
||||
public void setMappings(Map<Object, ExitStatus> mappings) {
|
||||
Assert.notNull(mappings.get(ELSE_KEY));
|
||||
Assert.notNull(mappings.get(ELSE_KEY), "Missing value for " + ELSE_KEY);
|
||||
this.mappings = mappings;
|
||||
}
|
||||
|
||||
|
||||
@@ -15,11 +15,10 @@
|
||||
*/
|
||||
package org.springframework.batch.core.configuration.xml;
|
||||
|
||||
import static org.junit.Assert.fail;
|
||||
|
||||
import java.util.ArrayList;
|
||||
|
||||
import org.junit.Before;
|
||||
|
||||
import org.springframework.batch.core.Job;
|
||||
import org.springframework.batch.core.JobExecution;
|
||||
import org.springframework.batch.core.JobParametersBuilder;
|
||||
@@ -31,6 +30,8 @@ import org.springframework.batch.core.repository.JobRestartException;
|
||||
import org.springframework.batch.core.repository.support.MapJobRepositoryFactoryBean;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
|
||||
import static org.junit.Assert.fail;
|
||||
|
||||
/**
|
||||
* @author Dan Garrette
|
||||
* @since 2.0
|
||||
@@ -63,11 +64,6 @@ public abstract class AbstractJobParserTests {
|
||||
return jobRepository.createJobExecution(job.getName(), new JobParametersBuilder().addLong("key1", 1L).toJobParameters());
|
||||
}
|
||||
|
||||
/**
|
||||
* @param jobExecution
|
||||
* @param stepName
|
||||
* @return the StepExecution corresponding to the specified step
|
||||
*/
|
||||
protected StepExecution getStepExecution(JobExecution jobExecution, String stepName) {
|
||||
for (StepExecution stepExecution : jobExecution.getStepExecutions()) {
|
||||
if (stepExecution.getStepName().equals(stepName)) {
|
||||
|
||||
@@ -15,18 +15,13 @@
|
||||
*/
|
||||
package org.springframework.batch.core.configuration.xml;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertFalse;
|
||||
import static org.junit.Assert.assertNotNull;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
import static org.junit.Assert.fail;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.Arrays;
|
||||
import java.util.Collection;
|
||||
import java.util.Map;
|
||||
|
||||
import org.junit.Test;
|
||||
|
||||
import org.springframework.batch.core.Step;
|
||||
import org.springframework.batch.core.step.item.SimpleChunkProcessor;
|
||||
import org.springframework.batch.core.step.skip.SkipPolicy;
|
||||
@@ -50,6 +45,12 @@ import org.springframework.retry.policy.SimpleRetryPolicy;
|
||||
import org.springframework.test.util.ReflectionTestUtils;
|
||||
import org.springframework.util.StringUtils;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertFalse;
|
||||
import static org.junit.Assert.assertNotNull;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
import static org.junit.Assert.fail;
|
||||
|
||||
/**
|
||||
* @author Dan Garrette
|
||||
* @author Dave Syer
|
||||
@@ -338,7 +339,7 @@ public class ChunkElementParserTests {
|
||||
/**
|
||||
* @param object the target object
|
||||
* @param path the path to the required field
|
||||
* @return
|
||||
* @return The field
|
||||
*/
|
||||
private Object getNestedPath(Object object, String path) {
|
||||
while (StringUtils.hasText(path)) {
|
||||
|
||||
@@ -43,9 +43,9 @@ public abstract class AbstractJsrTestCase {
|
||||
* reach one of those statuses within the given timeout, a {@link java.util.concurrent.TimeoutException} is
|
||||
* thrown.
|
||||
*
|
||||
* @param jobName
|
||||
* @param properties
|
||||
* @param timeout
|
||||
* @param jobName Name of the job to run
|
||||
* @param properties Properties to pass the job
|
||||
* @param timeout length of time to wait for a job to finish
|
||||
* @return the {@link javax.batch.runtime.JobExecution} for the final state of the job
|
||||
* @throws java.util.concurrent.TimeoutException if the timeout occurs
|
||||
*/
|
||||
@@ -78,9 +78,9 @@ public abstract class AbstractJsrTestCase {
|
||||
* reach one of those statuses within the given timeout, a {@link java.util.concurrent.TimeoutException} is
|
||||
* thrown.
|
||||
*
|
||||
* @param executionId
|
||||
* @param properties
|
||||
* @param timeout
|
||||
* @param executionId The execution id to restart
|
||||
* @param properties The Properties to pass to the new run
|
||||
* @param timeout The length of time to wait for the job to run
|
||||
* @return the {@link JobExecution} for the final state of the job
|
||||
* @throws java.util.concurrent.TimeoutException if the timeout occurs
|
||||
*/
|
||||
|
||||
@@ -15,12 +15,9 @@
|
||||
*/
|
||||
package org.springframework.batch.core.jsr.configuration.xml;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.util.List;
|
||||
import java.util.Properties;
|
||||
|
||||
import javax.batch.api.BatchProperty;
|
||||
import javax.batch.api.Batchlet;
|
||||
import javax.batch.api.Decider;
|
||||
@@ -35,12 +32,15 @@ import javax.batch.runtime.context.JobContext;
|
||||
import javax.inject.Inject;
|
||||
|
||||
import org.junit.Test;
|
||||
|
||||
import org.springframework.batch.core.StepContribution;
|
||||
import org.springframework.batch.core.jsr.AbstractJsrTestCase;
|
||||
import org.springframework.batch.core.scope.context.ChunkContext;
|
||||
import org.springframework.batch.core.step.tasklet.Tasklet;
|
||||
import org.springframework.batch.repeat.RepeatStatus;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
|
||||
/**
|
||||
* <p>
|
||||
* Configuration test for parsing various <properties /> elements defined by JSR-352.
|
||||
@@ -78,30 +78,30 @@ public class JobPropertyTests extends AbstractJsrTestCase {
|
||||
|
||||
@Override
|
||||
public void open(Serializable serializable) throws Exception {
|
||||
org.springframework.util.Assert.notNull(stepContext);
|
||||
org.springframework.util.Assert.isNull(stepContext.getProperties().get("step2PropertyName1"));
|
||||
org.springframework.util.Assert.isNull(stepContext.getProperties().get("step2PropertyName2"));
|
||||
org.springframework.util.Assert.isTrue(stepContext.getProperties().get("step1PropertyName1").equals("step1PropertyValue1"));
|
||||
org.springframework.util.Assert.isTrue(stepContext.getProperties().get("step1PropertyName2").equals("step1PropertyValue2"));
|
||||
org.springframework.util.Assert.isTrue(stepContext.getProperties().get("jobPropertyName1") == null);
|
||||
org.springframework.util.Assert.isTrue(stepContext.getProperties().get("jobPropertyName2") == null);
|
||||
org.springframework.util.Assert.isTrue("readerPropertyValue1".equals(readerPropertyName1));
|
||||
org.springframework.util.Assert.isTrue("readerPropertyValue2".equals(readerPropertyName2));
|
||||
org.springframework.util.Assert.isTrue("annotationNamedReaderPropertyValue".equals(annotationNamedProperty));
|
||||
org.springframework.util.Assert.isNull(notDefinedProperty);
|
||||
org.springframework.util.Assert.isNull(notDefinedAnnotationNamedProperty);
|
||||
org.springframework.util.Assert.isNull(batchAnnotatedOnlyField);
|
||||
org.springframework.util.Assert.notNull(injectAnnotatedOnlyField);
|
||||
org.springframework.util.Assert.isTrue("job1".equals(injectAnnotatedOnlyField.getJobName()));
|
||||
org.springframework.util.Assert.isNull(readerPropertyName3);
|
||||
org.springframework.util.Assert.notNull(stepContext, "stepContext is not null");
|
||||
org.springframework.util.Assert.isNull(stepContext.getProperties().get("step2PropertyName1"), "step2PropertyName1 is not null");
|
||||
org.springframework.util.Assert.isNull(stepContext.getProperties().get("step2PropertyName2"), "step2PropertyName2 is not null");
|
||||
org.springframework.util.Assert.isTrue(stepContext.getProperties().get("step1PropertyName1").equals("step1PropertyValue1"), "The value of step2PropertyName1 does not equal step2PropertyName1");
|
||||
org.springframework.util.Assert.isTrue(stepContext.getProperties().get("step1PropertyName2").equals("step1PropertyValue2"), "The value of step2PropertyName2 does not equal step2PropertyName2");
|
||||
org.springframework.util.Assert.isNull(stepContext.getProperties().get("jobPropertyName1"), "jobPropertyName1 is not null");
|
||||
org.springframework.util.Assert.isNull(stepContext.getProperties().get("jobPropertyName2") == null, "jobPropertyName2 is not null");
|
||||
org.springframework.util.Assert.isTrue("readerPropertyValue1".equals(readerPropertyName1), "The value of readerPropertyValue1 does not equal readerPropertyValue1");
|
||||
org.springframework.util.Assert.isTrue("readerPropertyValue2".equals(readerPropertyName2), "The value of readerPropertyValue2 does not equal readerPropertyValue2");
|
||||
org.springframework.util.Assert.isTrue("annotationNamedReaderPropertyValue".equals(annotationNamedProperty), "The value of annotationNamedReaderPropertyValue does not equal annotationNamedReaderPropertyValue");
|
||||
org.springframework.util.Assert.isNull(notDefinedProperty, "notDefinedProperty is not null");
|
||||
org.springframework.util.Assert.isNull(notDefinedAnnotationNamedProperty, "notDefinedAnnotationNamedProperty is not null");
|
||||
org.springframework.util.Assert.isNull(batchAnnotatedOnlyField, "batchAnnotatedOnlyField is not null");
|
||||
org.springframework.util.Assert.notNull(injectAnnotatedOnlyField, "injectAnnotatedOnlyField is not null");
|
||||
org.springframework.util.Assert.isTrue("job1".equals(injectAnnotatedOnlyField.getJobName()), "injectAnnotatedOnlyField does not equal job1");
|
||||
org.springframework.util.Assert.isNull(readerPropertyName3, "readerPropertyName3 is not null");
|
||||
|
||||
Properties jobProperties = injectAnnotatedOnlyField.getProperties();
|
||||
org.springframework.util.Assert.isTrue(jobProperties.size() == 5);
|
||||
org.springframework.util.Assert.isTrue(jobProperties.get("jobPropertyName1").equals("jobPropertyValue1"));
|
||||
org.springframework.util.Assert.isTrue(jobProperties.get("jobPropertyName2").equals("jobPropertyValue2"));
|
||||
org.springframework.util.Assert.isTrue(jobProperties.get("step2name").equals("step2"));
|
||||
org.springframework.util.Assert.isTrue(jobProperties.get("filestem").equals("postings"));
|
||||
org.springframework.util.Assert.isTrue(jobProperties.get("x").equals("xVal"));
|
||||
org.springframework.util.Assert.isTrue(jobProperties.size() == 5, "jobProperties has the wrong number of values. Expected 5, got " + jobProperties.size());
|
||||
org.springframework.util.Assert.isTrue(jobProperties.get("jobPropertyName1").equals("jobPropertyValue1"), "The value of jobPropertyName1 does not equal jobPropertyName1");
|
||||
org.springframework.util.Assert.isTrue(jobProperties.get("jobPropertyName2").equals("jobPropertyValue2"), "The value of jobPropertyName2 does not equal jobPropertyName2");
|
||||
org.springframework.util.Assert.isTrue(jobProperties.get("step2name").equals("step2"), "The value of step2name does note equal step2");
|
||||
org.springframework.util.Assert.isTrue(jobProperties.get("filestem").equals("postings"), "The value of filestem does not equal postings");
|
||||
org.springframework.util.Assert.isTrue(jobProperties.get("x").equals("xVal"), "The value of x does not equal xVal");
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -133,11 +133,11 @@ public class JobPropertyTests extends AbstractJsrTestCase {
|
||||
|
||||
@Override
|
||||
public Object processItem(Object o) throws Exception {
|
||||
org.springframework.util.Assert.isTrue("processorPropertyValue1".equals(processorPropertyName1));
|
||||
org.springframework.util.Assert.isTrue("processorPropertyValue2".equals(processorPropertyName2));
|
||||
org.springframework.util.Assert.isTrue("annotationNamedProcessorPropertyValue".equals(annotationNamedProperty));
|
||||
org.springframework.util.Assert.isNull(notDefinedProperty);
|
||||
org.springframework.util.Assert.isNull(notDefinedAnnotationNamedProperty);
|
||||
org.springframework.util.Assert.isTrue("processorPropertyValue1".equals(processorPropertyName1), "The value of processorPropertyValue1 does not equal processorPropertyValue1");
|
||||
org.springframework.util.Assert.isTrue("processorPropertyValue2".equals(processorPropertyName2), "The value of processorPropertyValue2 does not equal processorPropertyValue2");
|
||||
org.springframework.util.Assert.isTrue("annotationNamedProcessorPropertyValue".equals(annotationNamedProperty), "The value of annotationNamedProcessorPropertyValue does not equal annotationNamedProcessorPropertyValue");
|
||||
org.springframework.util.Assert.isNull(notDefinedProperty, "The notDefinedProperty is not null");
|
||||
org.springframework.util.Assert.isNull(notDefinedAnnotationNamedProperty, "The notDefinedNamedProperty is not null");
|
||||
|
||||
return o;
|
||||
}
|
||||
@@ -152,11 +152,11 @@ public class JobPropertyTests extends AbstractJsrTestCase {
|
||||
|
||||
@Override
|
||||
public void open(Serializable serializable) throws Exception {
|
||||
org.springframework.util.Assert.isTrue("writerPropertyValue1".equals(writerPropertyName1));
|
||||
org.springframework.util.Assert.isTrue("writerPropertyValue2".equals(writerPropertyName2));
|
||||
org.springframework.util.Assert.isTrue("annotationNamedWriterPropertyValue".equals(annotationNamedProperty));
|
||||
org.springframework.util.Assert.isNull(notDefinedProperty);
|
||||
org.springframework.util.Assert.isNull(notDefinedAnnotationNamedProperty);
|
||||
org.springframework.util.Assert.isTrue("writerPropertyValue1".equals(writerPropertyName1), "The value of writerPropertyValue1 does not equal writerPropertyValue1");
|
||||
org.springframework.util.Assert.isTrue("writerPropertyValue2".equals(writerPropertyName2), "The value of writerPropertyValue2 does not equal writerPropertyValue2");
|
||||
org.springframework.util.Assert.isTrue("annotationNamedWriterPropertyValue".equals(annotationNamedProperty), "The value of annotationNamedWriterPropertyValue does not equal annotationNamedWriterPropertyValue");
|
||||
org.springframework.util.Assert.isNull(notDefinedProperty, "notDefinedProperty is not null");
|
||||
org.springframework.util.Assert.isNull(notDefinedAnnotationNamedProperty, "notDefinedAnnotationNamedProperty is not null");
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -188,11 +188,11 @@ public class JobPropertyTests extends AbstractJsrTestCase {
|
||||
|
||||
@Override
|
||||
public void beginCheckpoint() throws Exception {
|
||||
org.springframework.util.Assert.isTrue("algorithmPropertyValue1".equals(algorithmPropertyName1));
|
||||
org.springframework.util.Assert.isTrue("algorithmPropertyValue2".equals(algorithmPropertyName2));
|
||||
org.springframework.util.Assert.isTrue("annotationNamedAlgorithmPropertyValue".equals(annotationNamedProperty));
|
||||
org.springframework.util.Assert.isNull(notDefinedProperty);
|
||||
org.springframework.util.Assert.isNull(notDefinedAnnotationNamedProperty);
|
||||
org.springframework.util.Assert.isTrue("algorithmPropertyValue1".equals(algorithmPropertyName1), "The value of algorithmPropertyValue1 does not equal algorithmPropertyValue1");
|
||||
org.springframework.util.Assert.isTrue("algorithmPropertyValue2".equals(algorithmPropertyName2), "The value of algorithmPropertyValue2 does not equal algorithmPropertyValue2");
|
||||
org.springframework.util.Assert.isTrue("annotationNamedAlgorithmPropertyValue".equals(annotationNamedProperty), "The annotationNamedAlgorithmPropertyValue does not equal annotationNamedAlgorithmPropertyValue");
|
||||
org.springframework.util.Assert.isNull(notDefinedProperty, "notDefinedProperty is not null");
|
||||
org.springframework.util.Assert.isNull(notDefinedAnnotationNamedProperty, "notDefinedAnnotationNamedProperty is not null");
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -214,11 +214,11 @@ public class JobPropertyTests extends AbstractJsrTestCase {
|
||||
|
||||
@Override
|
||||
public String decide(javax.batch.runtime.StepExecution[] executions) throws Exception {
|
||||
org.springframework.util.Assert.isTrue("deciderPropertyValue1".equals(deciderPropertyName1));
|
||||
org.springframework.util.Assert.isTrue("deciderPropertyValue2".equals(deciderPropertyName2));
|
||||
org.springframework.util.Assert.isTrue("annotationNamedDeciderPropertyValue".equals(annotationNamedProperty));
|
||||
org.springframework.util.Assert.isNull(notDefinedProperty);
|
||||
org.springframework.util.Assert.isNull(notDefinedAnnotationNamedProperty);
|
||||
org.springframework.util.Assert.isTrue("deciderPropertyValue1".equals(deciderPropertyName1), "The value of deciderPropertyValue1 does not equal deciderPropertyValue1");
|
||||
org.springframework.util.Assert.isTrue("deciderPropertyValue2".equals(deciderPropertyName2), "The value of deciderPropertyValue2 does not equal deciderPropertyValue2");
|
||||
org.springframework.util.Assert.isTrue("annotationNamedDeciderPropertyValue".equals(annotationNamedProperty), "The value of annotationNamedDeciderPropertyValue does not equal annotationNamedDeciderPropertyValue");
|
||||
org.springframework.util.Assert.isNull(notDefinedProperty, "notDefinedProperty is not null");
|
||||
org.springframework.util.Assert.isNull(notDefinedAnnotationNamedProperty, "notDefinedAnnotationNamedProperty is not null");
|
||||
|
||||
return "step2";
|
||||
}
|
||||
@@ -233,11 +233,11 @@ public class JobPropertyTests extends AbstractJsrTestCase {
|
||||
|
||||
@Override
|
||||
public void beforeStep() throws Exception {
|
||||
org.springframework.util.Assert.isTrue("stepListenerPropertyValue1".equals(stepListenerPropertyName1));
|
||||
org.springframework.util.Assert.isTrue("stepListenerPropertyValue2".equals(stepListenerPropertyName2));
|
||||
org.springframework.util.Assert.isTrue("annotationNamedStepListenerPropertyValue".equals(annotationNamedProperty));
|
||||
org.springframework.util.Assert.isNull(notDefinedProperty);
|
||||
org.springframework.util.Assert.isNull(notDefinedAnnotationNamedProperty);
|
||||
org.springframework.util.Assert.isTrue("stepListenerPropertyValue1".equals(stepListenerPropertyName1), "The value of stepListenerPropertyValue1 does not equal stepListenerPropertyValue1");
|
||||
org.springframework.util.Assert.isTrue("stepListenerPropertyValue2".equals(stepListenerPropertyName2), "The value of stepListenerPropertyValue2 does not equal stepListenerPropertyValue2");
|
||||
org.springframework.util.Assert.isTrue("annotationNamedStepListenerPropertyValue".equals(annotationNamedProperty), "The value of annotationNamedStepListenerPropertyValue does note equal annotationNamedStepListenerPropertyValue");
|
||||
org.springframework.util.Assert.isNull(notDefinedProperty, "notDefinedProperty is not null");
|
||||
org.springframework.util.Assert.isNull(notDefinedAnnotationNamedProperty, "notDefinedAnnotationNamedProperty is not null");
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -258,22 +258,22 @@ public class JobPropertyTests extends AbstractJsrTestCase {
|
||||
|
||||
@Override
|
||||
public String process() throws Exception {
|
||||
org.springframework.util.Assert.notNull(stepContext);
|
||||
org.springframework.util.Assert.isNull(stepContext.getProperties().get("step1PropertyName1"));
|
||||
org.springframework.util.Assert.isNull(stepContext.getProperties().get("step1PropertyName2"));
|
||||
org.springframework.util.Assert.isTrue(stepContext.getProperties().get("step2PropertyName1").equals("step2PropertyValue1"));
|
||||
org.springframework.util.Assert.isTrue(stepContext.getProperties().get("step2PropertyName2").equals("step2PropertyValue2"));
|
||||
org.springframework.util.Assert.isTrue(stepContext.getProperties().get("jobPropertyName1") == null);
|
||||
org.springframework.util.Assert.isTrue(stepContext.getProperties().get("jobPropertyName2") == null);
|
||||
org.springframework.util.Assert.notNull(stepContext, "StepContext is not null");
|
||||
org.springframework.util.Assert.isNull(stepContext.getProperties().get("step1PropertyName1"), "The value of step1PropertyName1 is not null");
|
||||
org.springframework.util.Assert.isNull(stepContext.getProperties().get("step1PropertyName2"), "The value of step1PropertyName2 is not null");
|
||||
org.springframework.util.Assert.isTrue(stepContext.getProperties().get("step2PropertyName1").equals("step2PropertyValue1"), "The value of step2PropertyName1 does not equal step2PropertyName1");
|
||||
org.springframework.util.Assert.isTrue(stepContext.getProperties().get("step2PropertyName2").equals("step2PropertyValue2"), "The value of step2PropertyName2 does not equal step2PropertyName2");
|
||||
org.springframework.util.Assert.isTrue(stepContext.getProperties().get("jobPropertyName1") == null, "jobPropertyName1 is not null");
|
||||
org.springframework.util.Assert.isTrue(stepContext.getProperties().get("jobPropertyName2") == null, "jobPropertyName2 is not null");
|
||||
|
||||
org.springframework.util.Assert.isTrue("batchletPropertyValue1".equals(batchletPropertyName1));
|
||||
org.springframework.util.Assert.isTrue("batchletPropertyValue2".equals(batchletPropertyName2));
|
||||
org.springframework.util.Assert.isTrue("annotationNamedBatchletPropertyValue".equals(annotationNamedProperty));
|
||||
org.springframework.util.Assert.isTrue("postings.txt".equals(infile));
|
||||
org.springframework.util.Assert.isTrue("xVal".equals(y));
|
||||
org.springframework.util.Assert.isNull(notDefinedProperty);
|
||||
org.springframework.util.Assert.isNull(notDefinedAnnotationNamedProperty);
|
||||
org.springframework.util.Assert.isNull(x);
|
||||
org.springframework.util.Assert.isTrue("batchletPropertyValue1".equals(batchletPropertyName1), "batchletPropertyValue1 does not equal batchletPropertyValue1");
|
||||
org.springframework.util.Assert.isTrue("batchletPropertyValue2".equals(batchletPropertyName2), "batchletPropertyValue2 does not equal batchletPropertyValue2");
|
||||
org.springframework.util.Assert.isTrue("annotationNamedBatchletPropertyValue".equals(annotationNamedProperty), "annotationNamedBatchletPropertyValue does not equal annotationNamedBatchletPropertyValue");
|
||||
org.springframework.util.Assert.isTrue("postings.txt".equals(infile), "infile does not equal postings.txt");
|
||||
org.springframework.util.Assert.isTrue("xVal".equals(y), "y does not equal xVal");
|
||||
org.springframework.util.Assert.isNull(notDefinedProperty, "notDefinedProperty is not null");
|
||||
org.springframework.util.Assert.isNull(notDefinedAnnotationNamedProperty, "notDefinedAnnotationNamedProperty is not null");
|
||||
org.springframework.util.Assert.isNull(x, "x is not null");
|
||||
|
||||
return null;
|
||||
}
|
||||
@@ -290,7 +290,7 @@ public class JobPropertyTests extends AbstractJsrTestCase {
|
||||
|
||||
@Override
|
||||
public RepeatStatus execute(StepContribution contribution, ChunkContext chunkContext) throws Exception {
|
||||
org.springframework.util.Assert.isTrue("p1val".equals(p1));
|
||||
org.springframework.util.Assert.isTrue("p1val".equals(p1), "Expected p1val, got " + p1);
|
||||
|
||||
return RepeatStatus.FINISHED;
|
||||
}
|
||||
|
||||
@@ -15,11 +15,16 @@
|
||||
*/
|
||||
package org.springframework.batch.core.jsr.configuration.xml;
|
||||
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.springframework.batch.core.jsr.AbstractJsrTestCase;
|
||||
import org.springframework.util.Assert;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.HashSet;
|
||||
import java.util.List;
|
||||
import java.util.Properties;
|
||||
import java.util.Set;
|
||||
import java.util.Vector;
|
||||
import java.util.regex.Matcher;
|
||||
import java.util.regex.Pattern;
|
||||
import javax.batch.api.BatchProperty;
|
||||
import javax.batch.api.Batchlet;
|
||||
import javax.batch.api.chunk.AbstractItemReader;
|
||||
@@ -31,16 +36,12 @@ import javax.batch.runtime.JobExecution;
|
||||
import javax.batch.runtime.context.JobContext;
|
||||
import javax.batch.runtime.context.StepContext;
|
||||
import javax.inject.Inject;
|
||||
import java.io.Serializable;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.HashSet;
|
||||
import java.util.List;
|
||||
import java.util.Properties;
|
||||
import java.util.Set;
|
||||
import java.util.Vector;
|
||||
import java.util.regex.Matcher;
|
||||
import java.util.regex.Pattern;
|
||||
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
|
||||
import org.springframework.batch.core.jsr.AbstractJsrTestCase;
|
||||
import org.springframework.util.Assert;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
@@ -221,14 +222,14 @@ public class PartitionParserTests extends AbstractJsrTestCase {
|
||||
public void analyzeCollectorData(Serializable data) throws Exception {
|
||||
name = artifactName;
|
||||
|
||||
Assert.isTrue(data.equals("c"));
|
||||
Assert.isTrue(data.equals("c"), "Expected c but was " + data);
|
||||
jobContext.setExitStatus(jobContext.getExitStatus() + data + "a");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void analyzeStatus(BatchStatus batchStatus, String exitStatus)
|
||||
throws Exception {
|
||||
Assert.isTrue(batchStatus.equals(BatchStatus.COMPLETED));
|
||||
Assert.isTrue(batchStatus.equals(BatchStatus.COMPLETED), String.format("expected %s but received %s", BatchStatus.COMPLETED, batchStatus));
|
||||
jobContext.setExitStatus(jobContext.getExitStatus() + "AS");
|
||||
}
|
||||
}
|
||||
|
||||
@@ -124,7 +124,7 @@ public class RetryListenerTests {
|
||||
|
||||
String currentItem = (String) item;
|
||||
|
||||
Assert.isTrue("three".equals(currentItem));
|
||||
Assert.isTrue("three".equals(currentItem), "currentItem was expected to be three but was not " + currentItem);
|
||||
Assert.isInstanceOf(IllegalArgumentException.class, ex);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -37,8 +37,9 @@ public class ThreadLocalClassloaderBeanPostProcessorTestsBatchlet implements Bat
|
||||
@Override
|
||||
public String process() throws Exception {
|
||||
Assert.isTrue("someParameter".equals(jobParam1), jobParam1 + " does not equal someParamter");
|
||||
Assert.isTrue("threadLocalClassloaderBeanPostProcessorTestsJob".equals(jobContext.getJobName()));
|
||||
Assert.isTrue("step1".equals(stepContext.getStepName()));
|
||||
Assert.isTrue("threadLocalClassloaderBeanPostProcessorTestsJob".equals(jobContext.getJobName()),
|
||||
"jobName does not equal threadLocalClassloaderBeanPostProcessorTestsJob");
|
||||
Assert.isTrue("step1".equals(stepContext.getStepName()), "stepName does not equal step1");
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
@@ -140,8 +140,8 @@ public class DecisionStepTests extends AbstractJsrTestCase {
|
||||
|
||||
@Override
|
||||
public String decide(StepExecution[] executions) throws Exception {
|
||||
Assert.isTrue(executions.length == 1);
|
||||
Assert.isTrue(executions[0].getStepName().equals("step1"));
|
||||
Assert.isTrue(executions.length == 1, "Invalid array length");
|
||||
Assert.isTrue(executions[0].getStepName().equals("step1"), "Incorrect step name");
|
||||
|
||||
if(runs == 0) {
|
||||
runs++;
|
||||
|
||||
@@ -15,15 +15,16 @@
|
||||
*/
|
||||
package org.springframework.batch.core.listener;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertFalse;
|
||||
|
||||
import org.junit.Test;
|
||||
|
||||
import org.springframework.batch.core.ExitStatus;
|
||||
import org.springframework.batch.core.JobExecution;
|
||||
import org.springframework.batch.core.StepExecution;
|
||||
import org.springframework.util.Assert;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertFalse;
|
||||
|
||||
/**
|
||||
* Tests for {@link ExecutionContextPromotionListener}.
|
||||
*/
|
||||
@@ -57,8 +58,8 @@ public class ExecutionContextPromotionListenerTests {
|
||||
StepExecution stepExecution = jobExecution.createStepExecution("step1");
|
||||
stepExecution.setExitStatus(ExitStatus.COMPLETED);
|
||||
|
||||
Assert.state(jobExecution.getExecutionContext().isEmpty());
|
||||
Assert.state(stepExecution.getExecutionContext().isEmpty());
|
||||
Assert.state(jobExecution.getExecutionContext().isEmpty(), "Job ExecutionContext is not empty");
|
||||
Assert.state(stepExecution.getExecutionContext().isEmpty(), "Step ExecutionContext is not empty");
|
||||
|
||||
stepExecution.getExecutionContext().putString(key, value);
|
||||
stepExecution.getExecutionContext().putString(key2, value2);
|
||||
@@ -87,8 +88,8 @@ public class ExecutionContextPromotionListenerTests {
|
||||
StepExecution stepExecution = jobExecution.createStepExecution("step1");
|
||||
stepExecution.setExitStatus(new ExitStatus(status));
|
||||
|
||||
Assert.state(jobExecution.getExecutionContext().isEmpty());
|
||||
Assert.state(stepExecution.getExecutionContext().isEmpty());
|
||||
Assert.state(jobExecution.getExecutionContext().isEmpty(), "Job ExecutionContext is not empty");
|
||||
Assert.state(stepExecution.getExecutionContext().isEmpty(), "Step ExecutionContext is not empty");
|
||||
|
||||
stepExecution.getExecutionContext().putString(key, value);
|
||||
stepExecution.getExecutionContext().putString(key2, value2);
|
||||
@@ -117,8 +118,8 @@ public class ExecutionContextPromotionListenerTests {
|
||||
StepExecution stepExecution = jobExecution.createStepExecution("step1");
|
||||
stepExecution.setExitStatus(new ExitStatus(status2));
|
||||
|
||||
Assert.state(jobExecution.getExecutionContext().isEmpty());
|
||||
Assert.state(stepExecution.getExecutionContext().isEmpty());
|
||||
Assert.state(jobExecution.getExecutionContext().isEmpty(), "Job ExecutionContext is not empty");
|
||||
Assert.state(stepExecution.getExecutionContext().isEmpty(), "Step ExecutionContext is not empty");
|
||||
|
||||
stepExecution.getExecutionContext().putString(key, value);
|
||||
stepExecution.getExecutionContext().putString(key2, value2);
|
||||
@@ -147,8 +148,8 @@ public class ExecutionContextPromotionListenerTests {
|
||||
StepExecution stepExecution = jobExecution.createStepExecution("step1");
|
||||
stepExecution.setExitStatus(new ExitStatus(status));
|
||||
|
||||
Assert.state(jobExecution.getExecutionContext().isEmpty());
|
||||
Assert.state(stepExecution.getExecutionContext().isEmpty());
|
||||
Assert.state(jobExecution.getExecutionContext().isEmpty(), "Job ExecutionContext is not empty");
|
||||
Assert.state(stepExecution.getExecutionContext().isEmpty(), "Step ExecutionContext is not empty");
|
||||
|
||||
stepExecution.getExecutionContext().putString(key, value);
|
||||
stepExecution.getExecutionContext().putString(key2, value2);
|
||||
@@ -176,8 +177,8 @@ public class ExecutionContextPromotionListenerTests {
|
||||
StepExecution stepExecution = jobExecution.createStepExecution("step1");
|
||||
stepExecution.setExitStatus(ExitStatus.COMPLETED);
|
||||
|
||||
Assert.state(jobExecution.getExecutionContext().isEmpty());
|
||||
Assert.state(stepExecution.getExecutionContext().isEmpty());
|
||||
Assert.state(jobExecution.getExecutionContext().isEmpty(), "Job ExecutionContext is not empty");
|
||||
Assert.state(stepExecution.getExecutionContext().isEmpty(), "Step ExecutionContext is not empty");
|
||||
|
||||
stepExecution.getExecutionContext().putString(key, value);
|
||||
|
||||
@@ -203,8 +204,8 @@ public class ExecutionContextPromotionListenerTests {
|
||||
StepExecution stepExecution = jobExecution.createStepExecution("step1");
|
||||
stepExecution.setExitStatus(ExitStatus.COMPLETED);
|
||||
|
||||
Assert.state(jobExecution.getExecutionContext().isEmpty());
|
||||
Assert.state(stepExecution.getExecutionContext().isEmpty());
|
||||
Assert.state(jobExecution.getExecutionContext().isEmpty(), "Job ExecutionContext is not empty");
|
||||
Assert.state(stepExecution.getExecutionContext().isEmpty(), "Step ExecutionContext is not empty");
|
||||
|
||||
jobExecution.getExecutionContext().putString(key, value);
|
||||
|
||||
@@ -231,8 +232,8 @@ public class ExecutionContextPromotionListenerTests {
|
||||
StepExecution stepExecution = jobExecution.createStepExecution("step1");
|
||||
stepExecution.setExitStatus(ExitStatus.COMPLETED);
|
||||
|
||||
Assert.state(jobExecution.getExecutionContext().isEmpty());
|
||||
Assert.state(stepExecution.getExecutionContext().isEmpty());
|
||||
Assert.state(jobExecution.getExecutionContext().isEmpty(), "Job ExecutionContext is not empty");
|
||||
Assert.state(stepExecution.getExecutionContext().isEmpty(), "Step ExecutionContext is not empty");
|
||||
|
||||
stepExecution.getExecutionContext().putString(key, value);
|
||||
|
||||
|
||||
@@ -15,23 +15,17 @@
|
||||
*/
|
||||
package org.springframework.batch.core.listener;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertFalse;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
import static org.springframework.batch.core.listener.StepListenerMetaData.AFTER_STEP;
|
||||
import static org.springframework.batch.core.listener.StepListenerMetaData.AFTER_WRITE;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import javax.sql.DataSource;
|
||||
|
||||
import org.aopalliance.intercept.MethodInterceptor;
|
||||
import org.aopalliance.intercept.MethodInvocation;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
|
||||
import org.springframework.aop.framework.ProxyFactory;
|
||||
import org.springframework.batch.core.ChunkListener;
|
||||
import org.springframework.batch.core.ExitStatus;
|
||||
@@ -63,6 +57,12 @@ import org.springframework.beans.factory.InitializingBean;
|
||||
import org.springframework.core.Ordered;
|
||||
import org.springframework.util.Assert;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertFalse;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
import static org.springframework.batch.core.listener.StepListenerMetaData.AFTER_STEP;
|
||||
import static org.springframework.batch.core.listener.StepListenerMetaData.AFTER_WRITE;
|
||||
|
||||
/**
|
||||
* @author Lucas Ward
|
||||
*
|
||||
@@ -380,7 +380,7 @@ public class StepListenerFactoryBeanTests {
|
||||
@Override
|
||||
@AfterStep
|
||||
public ExitStatus afterStep(StepExecution stepExecution) {
|
||||
Assert.notNull(stepExecution);
|
||||
Assert.notNull(stepExecution, "A stepExecution is required");
|
||||
callcount++;
|
||||
return null;
|
||||
}
|
||||
@@ -399,7 +399,7 @@ public class StepListenerFactoryBeanTests {
|
||||
|
||||
@Override
|
||||
public ExitStatus afterStep(StepExecution stepExecution) {
|
||||
Assert.notNull(stepExecution);
|
||||
Assert.notNull(stepExecution, "A stepExecution is required");
|
||||
callcount++;
|
||||
return null;
|
||||
}
|
||||
@@ -489,7 +489,7 @@ public class StepListenerFactoryBeanTests {
|
||||
|
||||
@AfterRead
|
||||
public void afterReadMethod(Object item) {
|
||||
Assert.notNull(item);
|
||||
Assert.notNull(item, "An item is required");
|
||||
afterReadCalled = true;
|
||||
}
|
||||
|
||||
|
||||
@@ -15,11 +15,6 @@
|
||||
*/
|
||||
package org.springframework.batch.core.repository.dao;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertNotNull;
|
||||
import static org.junit.Assert.assertNull;
|
||||
import static org.junit.Assert.fail;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.Date;
|
||||
@@ -28,6 +23,7 @@ import java.util.Set;
|
||||
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
|
||||
import org.springframework.batch.core.BatchStatus;
|
||||
import org.springframework.batch.core.ExitStatus;
|
||||
import org.springframework.batch.core.JobExecution;
|
||||
@@ -36,7 +32,12 @@ import org.springframework.batch.core.JobParameters;
|
||||
import org.springframework.batch.core.StepExecution;
|
||||
import org.springframework.dao.OptimisticLockingFailureException;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
import org.springframework.util.Assert;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertNotNull;
|
||||
import static org.junit.Assert.assertNull;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
import static org.junit.Assert.fail;
|
||||
|
||||
public abstract class AbstractJobExecutionDaoTests {
|
||||
|
||||
@@ -307,13 +308,13 @@ public abstract class AbstractJobExecutionDaoTests {
|
||||
dao.saveJobExecution(exec1);
|
||||
|
||||
JobExecution exec2 = new JobExecution(jobInstance, jobParameters);
|
||||
Assert.state(exec1.getId() != null);
|
||||
assertTrue(exec1.getId() != null);
|
||||
exec2.setId(exec1.getId());
|
||||
|
||||
exec2.setStatus(BatchStatus.STARTED);
|
||||
exec2.setVersion(7);
|
||||
Assert.state(exec1.getVersion() != exec2.getVersion());
|
||||
Assert.state(exec1.getStatus() != exec2.getStatus());
|
||||
assertTrue(exec1.getVersion() != exec2.getVersion());
|
||||
assertTrue(exec1.getStatus() != exec2.getStatus());
|
||||
|
||||
dao.synchronizeStatus(exec2);
|
||||
|
||||
@@ -334,13 +335,13 @@ public abstract class AbstractJobExecutionDaoTests {
|
||||
dao.saveJobExecution(exec1);
|
||||
|
||||
JobExecution exec2 = new JobExecution(jobInstance, jobParameters);
|
||||
Assert.state(exec1.getId() != null);
|
||||
assertTrue(exec1.getId() != null);
|
||||
exec2.setId(exec1.getId());
|
||||
|
||||
exec2.setStatus(BatchStatus.UNKNOWN);
|
||||
exec2.setVersion(7);
|
||||
Assert.state(exec1.getVersion() != exec2.getVersion());
|
||||
Assert.state(exec1.getStatus().isLessThan(exec2.getStatus()));
|
||||
assertTrue(exec1.getVersion() != exec2.getVersion());
|
||||
assertTrue(exec1.getStatus().isLessThan(exec2.getStatus()));
|
||||
|
||||
dao.synchronizeStatus(exec2);
|
||||
|
||||
|
||||
@@ -15,10 +15,6 @@
|
||||
*/
|
||||
package org.springframework.batch.core.step.item;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertFalse;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
@@ -30,6 +26,10 @@ import org.junit.runner.RunWith;
|
||||
import org.junit.runners.Parameterized;
|
||||
import org.junit.runners.Parameterized.Parameters;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertFalse;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
|
||||
/**
|
||||
* @author Dave Syer
|
||||
*
|
||||
@@ -81,8 +81,7 @@ public class AlmostStatefulRetryChunkTests {
|
||||
}
|
||||
|
||||
/**
|
||||
* @param chunk
|
||||
* @throws Exception
|
||||
* @param chunk Chunk to retry
|
||||
*/
|
||||
private void statefulRetry(Chunk<String> chunk) throws Exception {
|
||||
if (retryAttempts <= retryLimit) {
|
||||
@@ -113,8 +112,7 @@ public class AlmostStatefulRetryChunkTests {
|
||||
}
|
||||
|
||||
/**
|
||||
* @param chunk
|
||||
* @throws Exception
|
||||
* @param chunk Chunk to recover
|
||||
*/
|
||||
private void recover(Chunk<String> chunk) throws Exception {
|
||||
for (Chunk<String>.ChunkIterator iterator = chunk.iterator(); iterator.hasNext();) {
|
||||
@@ -129,8 +127,7 @@ public class AlmostStatefulRetryChunkTests {
|
||||
}
|
||||
|
||||
/**
|
||||
* @param items
|
||||
* @throws Exception
|
||||
* @param items items to write
|
||||
*/
|
||||
private void doWrite(List<String> items) throws Exception {
|
||||
if (items.contains("fail")) {
|
||||
|
||||
@@ -224,7 +224,7 @@ public class SystemCommandTaskletIntegrationTests {
|
||||
@Test
|
||||
public void testWorkingDirectory() throws Exception {
|
||||
File notExistingFile = new File("not-existing-path");
|
||||
Assert.state(!notExistingFile.exists());
|
||||
Assert.state(!notExistingFile.exists(), "not-existing-path does actually exist");
|
||||
|
||||
try {
|
||||
tasklet.setWorkingDirectory(notExistingFile.getCanonicalPath());
|
||||
@@ -235,8 +235,8 @@ public class SystemCommandTaskletIntegrationTests {
|
||||
}
|
||||
|
||||
File notDirectory = File.createTempFile(this.getClass().getName(), null);
|
||||
Assert.state(notDirectory.exists());
|
||||
Assert.state(!notDirectory.isDirectory());
|
||||
Assert.state(notDirectory.exists(), "The file does not exist");
|
||||
Assert.state(!notDirectory.isDirectory(), "The file is actually a directory");
|
||||
|
||||
try {
|
||||
tasklet.setWorkingDirectory(notDirectory.getCanonicalPath());
|
||||
@@ -247,8 +247,8 @@ public class SystemCommandTaskletIntegrationTests {
|
||||
}
|
||||
|
||||
File directory = notDirectory.getParentFile();
|
||||
Assert.state(directory.exists());
|
||||
Assert.state(directory.isDirectory());
|
||||
Assert.state(directory.exists(), "The directory does not exist");
|
||||
Assert.state(directory.isDirectory(), "The directory is not a directory");
|
||||
|
||||
// no error expected now
|
||||
tasklet.setWorkingDirectory(directory.getCanonicalPath());
|
||||
|
||||
@@ -16,9 +16,14 @@
|
||||
|
||||
package test.jdbc.datasource;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.List;
|
||||
import javax.sql.DataSource;
|
||||
|
||||
import org.apache.commons.io.IOUtils;
|
||||
import org.apache.commons.logging.Log;
|
||||
import org.apache.commons.logging.LogFactory;
|
||||
|
||||
import org.springframework.beans.factory.BeanInitializationException;
|
||||
import org.springframework.beans.factory.InitializingBean;
|
||||
import org.springframework.context.support.ClassPathXmlApplicationContext;
|
||||
@@ -33,10 +38,6 @@ import org.springframework.util.Assert;
|
||||
import org.springframework.util.ClassUtils;
|
||||
import org.springframework.util.StringUtils;
|
||||
|
||||
import javax.sql.DataSource;
|
||||
import java.io.IOException;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* Wrapper for a {@link DataSource} that can run scripts on start up and shut
|
||||
* down. Us as a bean definition <br><br>
|
||||
@@ -75,7 +76,7 @@ public class DataSourceInitializer implements InitializingBean {
|
||||
|
||||
@Override
|
||||
public void afterPropertiesSet() throws Exception {
|
||||
Assert.notNull(dataSource);
|
||||
Assert.notNull(dataSource, "A DataSource is required");
|
||||
initialize();
|
||||
}
|
||||
|
||||
|
||||
@@ -16,16 +16,8 @@
|
||||
|
||||
package org.springframework.batch.container.jms;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertFalse;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
import static org.junit.Assert.fail;
|
||||
import static org.mockito.Mockito.mock;
|
||||
import static org.mockito.Mockito.when;
|
||||
|
||||
import java.lang.reflect.InvocationTargetException;
|
||||
import java.lang.reflect.Method;
|
||||
|
||||
import javax.jms.ConnectionFactory;
|
||||
import javax.jms.JMSException;
|
||||
import javax.jms.Message;
|
||||
@@ -35,11 +27,19 @@ import javax.jms.Session;
|
||||
|
||||
import org.aopalliance.aop.Advice;
|
||||
import org.junit.Test;
|
||||
|
||||
import org.springframework.batch.repeat.interceptor.RepeatOperationsInterceptor;
|
||||
import org.springframework.batch.repeat.policy.SimpleCompletionPolicy;
|
||||
import org.springframework.batch.repeat.support.RepeatTemplate;
|
||||
import org.springframework.util.ReflectionUtils;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertFalse;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
import static org.junit.Assert.fail;
|
||||
import static org.mockito.Mockito.mock;
|
||||
import static org.mockito.Mockito.when;
|
||||
|
||||
public class BatchMessageListenerContainerTests {
|
||||
|
||||
BatchMessageListenerContainer container;
|
||||
@@ -186,13 +186,12 @@ public class BatchMessageListenerContainerTests {
|
||||
}
|
||||
|
||||
private boolean doExecute(Session session, MessageConsumer consumer) throws IllegalAccessException {
|
||||
Method method = ReflectionUtils.findMethod(container.getClass(), "receiveAndExecute", new Class[] {
|
||||
Object.class, Session.class, MessageConsumer.class });
|
||||
Method method = ReflectionUtils.findMethod(container.getClass(), "receiveAndExecute", Object.class, Session.class, MessageConsumer.class);
|
||||
method.setAccessible(true);
|
||||
boolean received;
|
||||
try {
|
||||
// A null invoker is not normal, but we don't care about the invoker for a unit test
|
||||
received = ((Boolean) method.invoke(container, new Object[] { null, session, consumer })).booleanValue();
|
||||
received = (Boolean) method.invoke(container, null, session, consumer);
|
||||
}
|
||||
catch (InvocationTargetException e) {
|
||||
if (e.getCause() instanceof RuntimeException) {
|
||||
|
||||
@@ -16,13 +16,8 @@
|
||||
|
||||
package org.springframework.batch.repeat.jms;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertNull;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import javax.jms.JMSException;
|
||||
import javax.jms.Message;
|
||||
import javax.jms.Session;
|
||||
@@ -45,6 +40,10 @@ import org.springframework.test.context.ContextConfiguration;
|
||||
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
|
||||
import org.springframework.util.ClassUtils;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertNull;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
|
||||
@RunWith(SpringJUnit4ClassRunner.class)
|
||||
@ContextConfiguration(locations = "/org/springframework/batch/jms/jms-context.xml")
|
||||
@DirtiesContext
|
||||
@@ -190,9 +189,9 @@ public class AsynchronousTests {
|
||||
}
|
||||
|
||||
/**
|
||||
* @param list
|
||||
* @param timeout
|
||||
* @throws InterruptedException
|
||||
* @param list resource to monitor
|
||||
* @param timeout how long to monitor for
|
||||
* @throws InterruptedException If interrupted while waiting
|
||||
*/
|
||||
private void waitFor(List<String> list, int size, int timeout) throws InterruptedException {
|
||||
int count = 0;
|
||||
|
||||
@@ -79,7 +79,7 @@ public class DataSourceInitializer implements InitializingBean, DisposableBean {
|
||||
|
||||
@Override
|
||||
public void afterPropertiesSet() throws Exception {
|
||||
Assert.notNull(dataSource);
|
||||
Assert.notNull(dataSource, "DataSource is required");
|
||||
logger.info("Initializing with scripts: " + Arrays.asList(initScripts));
|
||||
if (!initialized && initialize) {
|
||||
try {
|
||||
|
||||
@@ -107,10 +107,7 @@ public abstract class AbstractMethodInvokingDelegator<T> implements Initializing
|
||||
try {
|
||||
invoker.prepare();
|
||||
}
|
||||
catch (ClassNotFoundException e) {
|
||||
throw new DynamicMethodInvocationException(e);
|
||||
}
|
||||
catch (NoSuchMethodException e) {
|
||||
catch (ClassNotFoundException | NoSuchMethodException e) {
|
||||
throw new DynamicMethodInvocationException(e);
|
||||
}
|
||||
|
||||
@@ -132,8 +129,8 @@ public abstract class AbstractMethodInvokingDelegator<T> implements Initializing
|
||||
|
||||
@Override
|
||||
public void afterPropertiesSet() throws Exception {
|
||||
Assert.notNull(targetObject);
|
||||
Assert.hasLength(targetMethod);
|
||||
Assert.notNull(targetObject, "targetObject must not be null");
|
||||
Assert.hasLength(targetMethod, "targetMethod must not be empty");
|
||||
Assert.state(targetClassDeclaresTargetMethod(),
|
||||
"target class must declare a method with matching name and parameter types");
|
||||
}
|
||||
@@ -148,7 +145,7 @@ public abstract class AbstractMethodInvokingDelegator<T> implements Initializing
|
||||
Method[] memberMethods = invoker.getTargetClass().getMethods();
|
||||
Method[] declaredMethods = invoker.getTargetClass().getDeclaredMethods();
|
||||
|
||||
List<Method> allMethods = new ArrayList<Method>();
|
||||
List<Method> allMethods = new ArrayList<>();
|
||||
allMethods.addAll(Arrays.asList(memberMethods));
|
||||
allMethods.addAll(Arrays.asList(declaredMethods));
|
||||
|
||||
|
||||
@@ -62,7 +62,7 @@ ItemWriter<T> {
|
||||
@Override
|
||||
public void afterPropertiesSet() throws Exception {
|
||||
super.afterPropertiesSet();
|
||||
Assert.notEmpty(fieldsUsedAsTargetMethodArguments);
|
||||
Assert.notEmpty(fieldsUsedAsTargetMethodArguments, "fieldsUsedAsTargetMethodArguments must not be empty");
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -16,7 +16,15 @@
|
||||
|
||||
package org.springframework.batch.item.data;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.regex.Matcher;
|
||||
import java.util.regex.Pattern;
|
||||
|
||||
import com.mongodb.util.JSON;
|
||||
|
||||
import org.springframework.batch.item.ExecutionContext;
|
||||
import org.springframework.batch.item.ItemReader;
|
||||
import org.springframework.beans.factory.InitializingBean;
|
||||
@@ -30,13 +38,6 @@ import org.springframework.util.Assert;
|
||||
import org.springframework.util.ClassUtils;
|
||||
import org.springframework.util.StringUtils;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.regex.Matcher;
|
||||
import java.util.regex.Pattern;
|
||||
|
||||
/**
|
||||
* <p>
|
||||
* Restartable {@link ItemReader} that reads documents from MongoDB
|
||||
@@ -117,7 +118,7 @@ public class MongoItemReader<T> extends AbstractPaginatedDataItemReader<T> imple
|
||||
* {@link List} of values to be substituted in for each of the
|
||||
* parameters in the query.
|
||||
*
|
||||
* @param parameterValues
|
||||
* @param parameterValues values
|
||||
*/
|
||||
public void setParameterValues(List<Object> parameterValues) {
|
||||
this.parameterValues = parameterValues;
|
||||
@@ -163,11 +164,11 @@ public class MongoItemReader<T> extends AbstractPaginatedDataItemReader<T> imple
|
||||
@SuppressWarnings("unchecked")
|
||||
protected Iterator<T> doPageRead() {
|
||||
|
||||
Pageable pageRequest = new PageRequest(page, pageSize, sort);
|
||||
Pageable pageRequest = PageRequest.of(page, pageSize, sort);
|
||||
|
||||
String populatedQuery = replacePlaceholders(query, parameterValues);
|
||||
|
||||
Query mongoQuery = null;
|
||||
Query mongoQuery;
|
||||
|
||||
if(StringUtils.hasText(fields)) {
|
||||
mongoQuery = new BasicQuery(populatedQuery, fields);
|
||||
@@ -222,12 +223,12 @@ public class MongoItemReader<T> extends AbstractPaginatedDataItemReader<T> imple
|
||||
}
|
||||
|
||||
private Sort convertToSort(Map<String, Sort.Direction> sorts) {
|
||||
List<Sort.Order> sortValues = new ArrayList<Sort.Order>();
|
||||
List<Sort.Order> sortValues = new ArrayList<>();
|
||||
|
||||
for (Map.Entry<String, Sort.Direction> curSort : sorts.entrySet()) {
|
||||
sortValues.add(new Sort.Order(curSort.getValue(), curSort.getKey()));
|
||||
}
|
||||
|
||||
return new Sort(sortValues);
|
||||
return Sort.by(sortValues);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -20,7 +20,6 @@ import java.util.ArrayList;
|
||||
import java.util.Iterator;
|
||||
|
||||
import org.neo4j.ogm.session.Session;
|
||||
import org.neo4j.ogm.session.SessionFactory;
|
||||
|
||||
/**
|
||||
* <p>
|
||||
@@ -29,19 +28,16 @@ import org.neo4j.ogm.session.SessionFactory;
|
||||
*
|
||||
* @author Michael Minella
|
||||
*/
|
||||
public class Neo4jItemReader<T> extends AbstractNeo4jItemReader {
|
||||
public class Neo4jItemReader<T> extends AbstractNeo4jItemReader<T> {
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
@Override
|
||||
protected Iterator<T> doPageRead() {
|
||||
SessionFactory factory = getSessionFactory();
|
||||
Session session = getSessionFactory().openSession();
|
||||
|
||||
Iterable<T> queryResults;
|
||||
|
||||
Session session = factory.openSession();
|
||||
|
||||
queryResults = session.query(getTargetType(),
|
||||
generateLimitCypherQuery(),
|
||||
getParameterValues());
|
||||
Iterable<T> queryResults = session.query(getTargetType(),
|
||||
generateLimitCypherQuery(),
|
||||
getParameterValues());
|
||||
|
||||
if(queryResults != null) {
|
||||
return queryResults.iterator();
|
||||
|
||||
@@ -127,7 +127,7 @@ public class RepositoryItemReader<T> extends AbstractItemCountingItemStreamItemR
|
||||
* Specifies what method on the repository to call. This method must take
|
||||
* {@link org.springframework.data.domain.Pageable} as the <em>last</em> argument.
|
||||
*
|
||||
* @param methodName
|
||||
* @param methodName name of the method to invoke
|
||||
*/
|
||||
public void setMethodName(String methodName) {
|
||||
this.methodName = methodName;
|
||||
@@ -187,15 +187,16 @@ public class RepositoryItemReader<T> extends AbstractItemCountingItemStreamItemR
|
||||
* Available for overriding as needed.
|
||||
*
|
||||
* @return the list of items that make up the page
|
||||
* @throws Exception
|
||||
* @throws Exception Based on what the underlying method throws or related to the
|
||||
* calling of the method
|
||||
*/
|
||||
@SuppressWarnings("unchecked")
|
||||
protected List<T> doPageRead() throws Exception {
|
||||
Pageable pageRequest = new PageRequest(page, pageSize, sort);
|
||||
Pageable pageRequest = PageRequest.of(page, pageSize, sort);
|
||||
|
||||
MethodInvoker invoker = createMethodInvoker(repository, methodName);
|
||||
|
||||
List<Object> parameters = new ArrayList<Object>();
|
||||
List<Object> parameters = new ArrayList<>();
|
||||
|
||||
if(arguments != null && arguments.size() > 0) {
|
||||
parameters.addAll(arguments);
|
||||
@@ -224,23 +225,20 @@ public class RepositoryItemReader<T> extends AbstractItemCountingItemStreamItemR
|
||||
}
|
||||
|
||||
private Sort convertToSort(Map<String, Sort.Direction> sorts) {
|
||||
List<Sort.Order> sortValues = new ArrayList<Sort.Order>();
|
||||
List<Sort.Order> sortValues = new ArrayList<>();
|
||||
|
||||
for (Map.Entry<String, Sort.Direction> curSort : sorts.entrySet()) {
|
||||
sortValues.add(new Sort.Order(curSort.getValue(), curSort.getKey()));
|
||||
}
|
||||
|
||||
return new Sort(sortValues);
|
||||
return Sort.by(sortValues);
|
||||
}
|
||||
|
||||
private Object doInvoke(MethodInvoker invoker) throws Exception{
|
||||
try {
|
||||
invoker.prepare();
|
||||
}
|
||||
catch (ClassNotFoundException e) {
|
||||
throw new DynamicMethodInvocationException(e);
|
||||
}
|
||||
catch (NoSuchMethodException e) {
|
||||
catch (ClassNotFoundException | NoSuchMethodException e) {
|
||||
throw new DynamicMethodInvocationException(e);
|
||||
}
|
||||
|
||||
|
||||
@@ -246,7 +246,7 @@ implements InitializingBean {
|
||||
/**
|
||||
* Moves the cursor in the ResultSet to the position specified by the row
|
||||
* parameter by traversing the ResultSet.
|
||||
* @param row
|
||||
* @param row The index of the row to move to
|
||||
*/
|
||||
private void moveCursorToRow(int row) {
|
||||
try {
|
||||
|
||||
@@ -143,10 +143,7 @@ public class ExtendedConnectionDataSourceProxy implements SmartDataSource, Initi
|
||||
* @return true or false
|
||||
*/
|
||||
public boolean isCloseSuppressionActive(Connection connection) {
|
||||
if (connection == null) {
|
||||
return false;
|
||||
}
|
||||
return connection.equals(closeSuppressedConnection);
|
||||
return connection != null && connection.equals(closeSuppressedConnection);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -240,6 +237,7 @@ public class ExtendedConnectionDataSourceProxy implements SmartDataSource, Initi
|
||||
* @param target the original Connection to wrap
|
||||
* @return the wrapped Connection
|
||||
*/
|
||||
@SuppressWarnings("rawtypes")
|
||||
protected Connection getCloseSuppressingConnectionProxy(Connection target) {
|
||||
return (Connection) Proxy.newProxyInstance(ConnectionProxy.class.getClassLoader(),
|
||||
new Class[] { ConnectionProxy.class }, new CloseSuppressingInvocationHandler(target, this));
|
||||
@@ -265,29 +263,27 @@ public class ExtendedConnectionDataSourceProxy implements SmartDataSource, Initi
|
||||
public Object invoke(Object proxy, Method method, Object[] args) throws Throwable {
|
||||
// Invocation on ConnectionProxy interface coming in...
|
||||
|
||||
if (method.getName().equals("equals")) {
|
||||
// Only consider equal when proxies are identical.
|
||||
return (proxy == args[0] ? Boolean.TRUE : Boolean.FALSE);
|
||||
}
|
||||
else if (method.getName().equals("hashCode")) {
|
||||
// Use hashCode of Connection proxy.
|
||||
return new Integer(System.identityHashCode(proxy));
|
||||
}
|
||||
else if (method.getName().equals("close")) {
|
||||
// Handle close method: don't pass the call on if we are
|
||||
// suppressing close calls.
|
||||
if (dataSource.completeCloseCall((Connection) proxy)) {
|
||||
return null;
|
||||
}
|
||||
else {
|
||||
target.close();
|
||||
return null;
|
||||
}
|
||||
}
|
||||
else if (method.getName().equals("getTargetConnection")) {
|
||||
// Handle getTargetConnection method: return underlying
|
||||
// Connection.
|
||||
return this.target;
|
||||
switch (method.getName()) {
|
||||
case "equals":
|
||||
// Only consider equal when proxies are identical.
|
||||
return (proxy == args[0] ? Boolean.TRUE : Boolean.FALSE);
|
||||
case "hashCode":
|
||||
// Use hashCode of Connection proxy.
|
||||
return System.identityHashCode(proxy);
|
||||
case "close":
|
||||
// Handle close method: don't pass the call on if we are
|
||||
// suppressing close calls.
|
||||
if (dataSource.completeCloseCall((Connection) proxy)) {
|
||||
return null;
|
||||
}
|
||||
else {
|
||||
target.close();
|
||||
return null;
|
||||
}
|
||||
case "getTargetConnection":
|
||||
// Handle getTargetConnection method: return underlying
|
||||
// Connection.
|
||||
return this.target;
|
||||
}
|
||||
|
||||
// Invoke method on target Connection.
|
||||
@@ -306,10 +302,7 @@ public class ExtendedConnectionDataSourceProxy implements SmartDataSource, Initi
|
||||
*/
|
||||
@Override
|
||||
public boolean isWrapperFor(Class<?> iface) throws SQLException {
|
||||
if (iface.isAssignableFrom(SmartDataSource.class) || iface.isAssignableFrom(dataSource.getClass())) {
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
return iface.isAssignableFrom(SmartDataSource.class) || iface.isAssignableFrom(dataSource.getClass());
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -334,7 +327,7 @@ public class ExtendedConnectionDataSourceProxy implements SmartDataSource, Initi
|
||||
|
||||
@Override
|
||||
public void afterPropertiesSet() throws Exception {
|
||||
Assert.notNull(dataSource);
|
||||
Assert.notNull(dataSource, "DataSource is required");
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -348,14 +341,8 @@ public class ExtendedConnectionDataSourceProxy implements SmartDataSource, Initi
|
||||
try {
|
||||
invoker.prepare();
|
||||
return (Logger) invoker.invoke();
|
||||
} catch (ClassNotFoundException cnfe) {
|
||||
throw new SQLFeatureNotSupportedException(cnfe);
|
||||
} catch (NoSuchMethodException nsme) {
|
||||
} catch (ClassNotFoundException | NoSuchMethodException | IllegalAccessException | InvocationTargetException nsme) {
|
||||
throw new SQLFeatureNotSupportedException(nsme);
|
||||
} catch (IllegalAccessException iae) {
|
||||
throw new SQLFeatureNotSupportedException(iae);
|
||||
} catch (InvocationTargetException ite) {
|
||||
throw new SQLFeatureNotSupportedException(ite);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -115,7 +115,7 @@ public class HibernateCursorItemReader<T> extends AbstractItemCountingItemStream
|
||||
*
|
||||
* @param queryProvider Hibernate query provider
|
||||
*/
|
||||
public void setQueryProvider(HibernateQueryProvider queryProvider) {
|
||||
public void setQueryProvider(HibernateQueryProvider<T> queryProvider) {
|
||||
helper.setQueryProvider(queryProvider);
|
||||
}
|
||||
|
||||
|
||||
@@ -40,6 +40,7 @@ import org.springframework.util.StringUtils;
|
||||
* @author Dave Syer
|
||||
*
|
||||
*/
|
||||
@SuppressWarnings("rawtype")
|
||||
public class HibernateItemReaderHelper<T> implements InitializingBean {
|
||||
|
||||
private SessionFactory sessionFactory;
|
||||
@@ -48,7 +49,7 @@ public class HibernateItemReaderHelper<T> implements InitializingBean {
|
||||
|
||||
private String queryName = "";
|
||||
|
||||
private HibernateQueryProvider queryProvider;
|
||||
private HibernateQueryProvider<T> queryProvider;
|
||||
|
||||
private boolean useStatelessSession = true;
|
||||
|
||||
@@ -73,7 +74,7 @@ public class HibernateItemReaderHelper<T> implements InitializingBean {
|
||||
/**
|
||||
* @param queryProvider Hibernate query provider
|
||||
*/
|
||||
public void setQueryProvider(HibernateQueryProvider queryProvider) {
|
||||
public void setQueryProvider(HibernateQueryProvider<T> queryProvider) {
|
||||
this.queryProvider = queryProvider;
|
||||
}
|
||||
|
||||
|
||||
@@ -108,7 +108,7 @@ public class HibernatePagingItemReader<T> extends AbstractPagingItemReader<T>
|
||||
*
|
||||
* @param queryProvider Hibernate query provider
|
||||
*/
|
||||
public void setQueryProvider(HibernateQueryProvider queryProvider) {
|
||||
public void setQueryProvider(HibernateQueryProvider<T> queryProvider) {
|
||||
helper.setQueryProvider(queryProvider);
|
||||
}
|
||||
|
||||
|
||||
@@ -31,6 +31,7 @@ public interface ItemPreparedStatementSetter<T> {
|
||||
/**
|
||||
* Set parameter values on the given PreparedStatement as determined from
|
||||
* the provided item.
|
||||
* @param item the item to obtain the values from
|
||||
* @param ps the PreparedStatement to invoke setter methods on
|
||||
* @throws SQLException if a SQLException is encountered (i.e. there is no
|
||||
* need to catch SQLException)
|
||||
|
||||
@@ -142,7 +142,7 @@ public class JdbcBatchItemWriter<T> implements ItemWriter<T>, InitializingBean {
|
||||
public void afterPropertiesSet() {
|
||||
Assert.notNull(namedParameterJdbcTemplate, "A DataSource or a NamedParameterJdbcTemplate is required.");
|
||||
Assert.notNull(sql, "An SQL statement is required.");
|
||||
List<String> namedParameters = new ArrayList<String>();
|
||||
List<String> namedParameters = new ArrayList<>();
|
||||
parameterCount = JdbcParameterUtils.countParameterPlaceholders(sql, namedParameters);
|
||||
if (namedParameters.size() > 0) {
|
||||
if (parameterCount != namedParameters.size()) {
|
||||
@@ -158,7 +158,7 @@ public class JdbcBatchItemWriter<T> implements ItemWriter<T>, InitializingBean {
|
||||
/* (non-Javadoc)
|
||||
* @see org.springframework.batch.item.ItemWriter#write(java.util.List)
|
||||
*/
|
||||
@SuppressWarnings("unchecked")
|
||||
@SuppressWarnings({"unchecked", "rawtypes"})
|
||||
@Override
|
||||
public void write(final List<? extends T> items) throws Exception {
|
||||
|
||||
|
||||
@@ -68,7 +68,7 @@ public class JdbcCursorItemReader<T> extends AbstractCursorItemReader<T> {
|
||||
/**
|
||||
* Set the RowMapper to be used for all calls to read().
|
||||
*
|
||||
* @param rowMapper
|
||||
* @param rowMapper the mapper used to map each item
|
||||
*/
|
||||
public void setRowMapper(RowMapper<T> rowMapper) {
|
||||
this.rowMapper = rowMapper;
|
||||
@@ -79,7 +79,7 @@ public class JdbcCursorItemReader<T> extends AbstractCursorItemReader<T> {
|
||||
* should be a complete and valid SQL statement, as it will be run directly
|
||||
* without any modification.
|
||||
*
|
||||
* @param sql
|
||||
* @param sql SQL statement
|
||||
*/
|
||||
public void setSql(String sql) {
|
||||
this.sql = sql;
|
||||
@@ -89,7 +89,7 @@ public class JdbcCursorItemReader<T> extends AbstractCursorItemReader<T> {
|
||||
* Set the PreparedStatementSetter to use if any parameter values that need
|
||||
* to be set in the supplied query.
|
||||
*
|
||||
* @param preparedStatementSetter
|
||||
* @param preparedStatementSetter PreparedStatementSetter responsible for filling out the statement
|
||||
*/
|
||||
public void setPreparedStatementSetter(PreparedStatementSetter preparedStatementSetter) {
|
||||
this.preparedStatementSetter = preparedStatementSetter;
|
||||
|
||||
@@ -163,14 +163,14 @@ public class JdbcPagingItemReader<T> extends AbstractPagingItemReader<T> impleme
|
||||
@Override
|
||||
public void afterPropertiesSet() throws Exception {
|
||||
super.afterPropertiesSet();
|
||||
Assert.notNull(dataSource);
|
||||
Assert.notNull(dataSource, "DataSource may not be null");
|
||||
JdbcTemplate jdbcTemplate = new JdbcTemplate(dataSource);
|
||||
if (fetchSize != VALUE_NOT_SET) {
|
||||
jdbcTemplate.setFetchSize(fetchSize);
|
||||
}
|
||||
jdbcTemplate.setMaxRows(getPageSize());
|
||||
namedParameterJdbcTemplate = new NamedParameterJdbcTemplate(jdbcTemplate);
|
||||
Assert.notNull(queryProvider);
|
||||
Assert.notNull(queryProvider, "QueryProvider may not be null");
|
||||
queryProvider.init(dataSource);
|
||||
this.firstPageSql = queryProvider.generateFirstPageQuery(getPageSize());
|
||||
this.remainingPagesSql = queryProvider.generateRemainingPagesQuery(getPageSize());
|
||||
@@ -180,7 +180,7 @@ public class JdbcPagingItemReader<T> extends AbstractPagingItemReader<T> impleme
|
||||
@SuppressWarnings("unchecked")
|
||||
protected void doReadPage() {
|
||||
if (results == null) {
|
||||
results = new CopyOnWriteArrayList<T>();
|
||||
results = new CopyOnWriteArrayList<>();
|
||||
}
|
||||
else {
|
||||
results.clear();
|
||||
@@ -253,7 +253,7 @@ public class JdbcPagingItemReader<T> extends AbstractPagingItemReader<T> impleme
|
||||
startAfterValues = (Map<String, Object>) executionContext.get(getExecutionContextKey(START_AFTER_VALUE));
|
||||
|
||||
if(startAfterValues == null) {
|
||||
startAfterValues = new LinkedHashMap<String, Object>();
|
||||
startAfterValues = new LinkedHashMap<>();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -285,7 +285,7 @@ public class JdbcPagingItemReader<T> extends AbstractPagingItemReader<T> impleme
|
||||
}
|
||||
|
||||
private Map<String, Object> getParameterMap(Map<String, Object> values, Map<String, Object> sortKeyValues) {
|
||||
Map<String, Object> parameterMap = new LinkedHashMap<String, Object>();
|
||||
Map<String, Object> parameterMap = new LinkedHashMap<>();
|
||||
if (values != null) {
|
||||
parameterMap.putAll(values);
|
||||
}
|
||||
@@ -301,14 +301,14 @@ public class JdbcPagingItemReader<T> extends AbstractPagingItemReader<T> impleme
|
||||
}
|
||||
|
||||
private List<Object> getParameterList(Map<String, Object> values, Map<String, Object> sortKeyValue) {
|
||||
SortedMap<String, Object> sm = new TreeMap<String, Object>();
|
||||
SortedMap<String, Object> sm = new TreeMap<>();
|
||||
if (values != null) {
|
||||
sm.putAll(values);
|
||||
}
|
||||
List<Object> parameterList = new ArrayList<Object>();
|
||||
List<Object> parameterList = new ArrayList<>();
|
||||
parameterList.addAll(sm.values());
|
||||
if (sortKeyValue != null && sortKeyValue.size() > 0) {
|
||||
List<Map.Entry<String, Object>> keys = new ArrayList<Map.Entry<String,Object>>(sortKeyValue.entrySet());
|
||||
List<Map.Entry<String, Object>> keys = new ArrayList<>(sortKeyValue.entrySet());
|
||||
|
||||
for(int i = 0; i < keys.size(); i++) {
|
||||
for(int j = 0; j < i; j++) {
|
||||
@@ -328,7 +328,7 @@ public class JdbcPagingItemReader<T> extends AbstractPagingItemReader<T> impleme
|
||||
private class PagingRowMapper implements RowMapper<T> {
|
||||
@Override
|
||||
public T mapRow(ResultSet rs, int rowNum) throws SQLException {
|
||||
startAfterValues = new LinkedHashMap<String, Object>();
|
||||
startAfterValues = new LinkedHashMap<>();
|
||||
for (Map.Entry<String, Order> sortKey : queryProvider.getSortKeys().entrySet()) {
|
||||
startAfterValues.put(sortKey.getKey(), rs.getObject(sortKey.getKey()));
|
||||
}
|
||||
|
||||
@@ -45,6 +45,8 @@ public class JdbcParameterUtils {
|
||||
* suite the batch processing requirements.
|
||||
*
|
||||
* @param sql String to search in. Returns 0 if the given String is <code>null</code>.
|
||||
* @param namedParameterHolder holder for the named parameters
|
||||
* @return the number of named parameter placeholders
|
||||
*/
|
||||
public static int countParameterPlaceholders(String sql, List<String> namedParameterHolder ) {
|
||||
if (sql == null) {
|
||||
|
||||
@@ -89,7 +89,7 @@ public class JpaPagingItemReader<T> extends AbstractPagingItemReader<T> {
|
||||
|
||||
private EntityManager entityManager;
|
||||
|
||||
private final Map<String, Object> jpaPropertyMap = new HashMap<String, Object>();
|
||||
private final Map<String, Object> jpaPropertyMap = new HashMap<>();
|
||||
|
||||
private String queryString;
|
||||
|
||||
@@ -136,7 +136,7 @@ public class JpaPagingItemReader<T> extends AbstractPagingItemReader<T> {
|
||||
* particular transaction. (e.g. Hibernate with a JTA transaction). NOTE: may cause
|
||||
* problems in guaranteeing the object consistency in the EntityManagerFactory.
|
||||
*
|
||||
* @param transacted
|
||||
* @param transacted indicator
|
||||
*/
|
||||
public void setTransacted(boolean transacted) {
|
||||
this.transacted = transacted;
|
||||
@@ -147,12 +147,8 @@ public class JpaPagingItemReader<T> extends AbstractPagingItemReader<T> {
|
||||
super.afterPropertiesSet();
|
||||
|
||||
if (queryProvider == null) {
|
||||
Assert.notNull(entityManagerFactory);
|
||||
Assert.hasLength(queryString);
|
||||
}
|
||||
// making sure that the appropriate (JPA) query provider is set
|
||||
else {
|
||||
Assert.isTrue(queryProvider != null, "JPA query provider must be set");
|
||||
Assert.notNull(entityManagerFactory, "EntityManager is required when queryProvider is null");
|
||||
Assert.hasLength(queryString, "Query string is required when queryProvider is null");
|
||||
}
|
||||
}
|
||||
|
||||
@@ -209,7 +205,7 @@ public class JpaPagingItemReader<T> extends AbstractPagingItemReader<T> {
|
||||
}
|
||||
|
||||
if (results == null) {
|
||||
results = new CopyOnWriteArrayList<T>();
|
||||
results = new CopyOnWriteArrayList<>();
|
||||
}
|
||||
else {
|
||||
results.clear();
|
||||
|
||||
@@ -16,8 +16,8 @@
|
||||
|
||||
package org.springframework.batch.item.database;
|
||||
|
||||
import javax.sql.DataSource;
|
||||
import java.util.Map;
|
||||
import javax.sql.DataSource;
|
||||
|
||||
|
||||
/**
|
||||
@@ -34,6 +34,7 @@ public interface PagingQueryProvider {
|
||||
* Initialize the query provider using the provided {@link DataSource} if necessary.
|
||||
*
|
||||
* @param dataSource DataSource to use for any initialization
|
||||
* @throws Exception for errors when initializing
|
||||
*/
|
||||
void init(DataSource dataSource) throws Exception;
|
||||
|
||||
|
||||
@@ -81,7 +81,7 @@ public class StoredProcedureItemReader<T> extends AbstractCursorItemReader<T> {
|
||||
/**
|
||||
* Set the RowMapper to be used for all calls to read().
|
||||
*
|
||||
* @param rowMapper
|
||||
* @param rowMapper the RowMapper to use to map the results
|
||||
*/
|
||||
public void setRowMapper(RowMapper<T> rowMapper) {
|
||||
this.rowMapper = rowMapper;
|
||||
@@ -92,7 +92,7 @@ public class StoredProcedureItemReader<T> extends AbstractCursorItemReader<T> {
|
||||
* should be a complete and valid SQL statement, as it will be run directly
|
||||
* without any modification.
|
||||
*
|
||||
* @param sprocedureName
|
||||
* @param sprocedureName the SQL used to call the statement
|
||||
*/
|
||||
public void setProcedureName(String sprocedureName) {
|
||||
this.procedureName = sprocedureName;
|
||||
@@ -102,7 +102,7 @@ public class StoredProcedureItemReader<T> extends AbstractCursorItemReader<T> {
|
||||
* Set the PreparedStatementSetter to use if any parameter values that need
|
||||
* to be set in the supplied query.
|
||||
*
|
||||
* @param preparedStatementSetter
|
||||
* @param preparedStatementSetter used to populate the SQL
|
||||
*/
|
||||
public void setPreparedStatementSetter(PreparedStatementSetter preparedStatementSetter) {
|
||||
this.preparedStatementSetter = preparedStatementSetter;
|
||||
@@ -120,6 +120,8 @@ public class StoredProcedureItemReader<T> extends AbstractCursorItemReader<T> {
|
||||
|
||||
/**
|
||||
* Set whether this stored procedure is a function.
|
||||
*
|
||||
* @param function indicator
|
||||
*/
|
||||
public void setFunction(boolean function) {
|
||||
this.function = function;
|
||||
|
||||
@@ -45,7 +45,7 @@ public class HibernateCursorItemReaderBuilder<T> {
|
||||
|
||||
private int fetchSize;
|
||||
|
||||
private HibernateQueryProvider queryProvider;
|
||||
private HibernateQueryProvider<T> queryProvider;
|
||||
|
||||
private String queryString;
|
||||
|
||||
@@ -124,7 +124,7 @@ public class HibernateCursorItemReaderBuilder<T> {
|
||||
* @return this instance for method chaining
|
||||
* @see HibernateCursorItemReader#setQueryProvider(HibernateQueryProvider)
|
||||
*/
|
||||
public HibernateCursorItemReaderBuilder<T> queryProvider(HibernateQueryProvider queryProvider) {
|
||||
public HibernateCursorItemReaderBuilder<T> queryProvider(HibernateQueryProvider<T> queryProvider) {
|
||||
this.queryProvider = queryProvider;
|
||||
|
||||
return this;
|
||||
|
||||
@@ -167,6 +167,7 @@ public class JdbcBatchItemWriterBuilder<T> {
|
||||
*
|
||||
* @return a {@link JdbcBatchItemWriter}
|
||||
*/
|
||||
@SuppressWarnings("unchecked")
|
||||
public JdbcBatchItemWriter<T> build() {
|
||||
Assert.state(this.dataSource != null || this.namedParameterJdbcTemplate != null,
|
||||
"Either a DataSource or a NamedParameterJdbcTemplate is required");
|
||||
|
||||
@@ -35,7 +35,7 @@ import org.hibernate.StatelessSession;
|
||||
* @since 2.1
|
||||
*
|
||||
*/
|
||||
public abstract class AbstractHibernateQueryProvider implements HibernateQueryProvider {
|
||||
public abstract class AbstractHibernateQueryProvider<T> implements HibernateQueryProvider<T> {
|
||||
|
||||
private StatelessSession statelessSession;
|
||||
private Session statefulSession;
|
||||
|
||||
@@ -43,7 +43,7 @@ public abstract class AbstractJpaQueryProvider implements JpaQueryProvider, Init
|
||||
* {@link HibernateQueryProvider} to participate in a user's managed transaction.
|
||||
* </p>
|
||||
*
|
||||
* @param entityManager
|
||||
* @param entityManager EntityManager to use
|
||||
*/
|
||||
@Override
|
||||
public void setEntityManager(EntityManager entityManager) {
|
||||
|
||||
@@ -33,7 +33,7 @@ import org.springframework.batch.item.ItemReader;
|
||||
* @since 2.1
|
||||
*
|
||||
*/
|
||||
public interface HibernateQueryProvider {
|
||||
public interface HibernateQueryProvider<T> {
|
||||
|
||||
/**
|
||||
* <p>
|
||||
@@ -43,7 +43,7 @@ public interface HibernateQueryProvider {
|
||||
*
|
||||
* @return created query
|
||||
*/
|
||||
Query createQuery();
|
||||
Query<T> createQuery();
|
||||
|
||||
/**
|
||||
* <p>
|
||||
|
||||
@@ -16,6 +16,12 @@
|
||||
|
||||
package org.springframework.batch.item.database.support;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.LinkedHashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import javax.sql.DataSource;
|
||||
|
||||
import org.springframework.batch.item.database.JdbcParameterUtils;
|
||||
import org.springframework.batch.item.database.Order;
|
||||
import org.springframework.batch.item.database.PagingQueryProvider;
|
||||
@@ -23,12 +29,6 @@ import org.springframework.dao.InvalidDataAccessApiUsageException;
|
||||
import org.springframework.util.Assert;
|
||||
import org.springframework.util.StringUtils;
|
||||
|
||||
import javax.sql.DataSource;
|
||||
import java.util.ArrayList;
|
||||
import java.util.LinkedHashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* Abstract SQL Paging Query Provider to serve as a base class for all provided
|
||||
* SQL paging query providers.
|
||||
@@ -182,7 +182,7 @@ public abstract class AbstractSqlPagingQueryProvider implements PagingQueryProvi
|
||||
*/
|
||||
@Override
|
||||
public void init(DataSource dataSource) throws Exception {
|
||||
Assert.notNull(dataSource);
|
||||
Assert.notNull(dataSource, "A DataSource is required");
|
||||
Assert.hasLength(selectClause, "selectClause must be specified");
|
||||
Assert.hasLength(fromClause, "fromClause must be specified");
|
||||
Assert.notEmpty(sortKeys, "sortKey must be specified");
|
||||
|
||||
@@ -152,7 +152,7 @@ InitializingBean {
|
||||
/**
|
||||
* Setter for resource. Represents a file that can be written.
|
||||
*
|
||||
* @param resource
|
||||
* @param resource the resource to be written to
|
||||
*/
|
||||
@Override
|
||||
public void setResource(Resource resource) {
|
||||
@@ -208,7 +208,7 @@ InitializingBean {
|
||||
* update. Setting this to false means that it will always start at the
|
||||
* beginning on a restart.
|
||||
*
|
||||
* @param saveState
|
||||
* @param saveState if true, state will be persisted
|
||||
*/
|
||||
public void setSaveState(boolean saveState) {
|
||||
this.saveState = saveState;
|
||||
@@ -448,14 +448,14 @@ InitializingBean {
|
||||
}
|
||||
|
||||
/**
|
||||
* @param append
|
||||
* @param append if true, append to previously created file
|
||||
*/
|
||||
public void setAppendAllowed(boolean append) {
|
||||
this.append = append;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param executionContext
|
||||
* @param executionContext state from which to restore writing from
|
||||
*/
|
||||
public void restoreFrom(ExecutionContext executionContext) {
|
||||
lastMarkedByteOffsetPosition = executionContext.getLong(getExecutionContextKey(RESTART_DATA_NAME));
|
||||
@@ -470,14 +470,14 @@ InitializingBean {
|
||||
}
|
||||
|
||||
/**
|
||||
* @param shouldDeleteIfExists
|
||||
* @param shouldDeleteIfExists indicator
|
||||
*/
|
||||
public void setDeleteIfExists(boolean shouldDeleteIfExists) {
|
||||
this.shouldDeleteIfExists = shouldDeleteIfExists;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param encoding
|
||||
* @param encoding file encoding
|
||||
*/
|
||||
public void setEncoding(String encoding) {
|
||||
this.encoding = encoding;
|
||||
@@ -527,7 +527,7 @@ InitializingBean {
|
||||
}
|
||||
|
||||
/**
|
||||
* @param line
|
||||
* @param line String to be written to the file
|
||||
* @throws IOException
|
||||
*/
|
||||
public void write(String line) throws IOException {
|
||||
@@ -542,7 +542,7 @@ InitializingBean {
|
||||
/**
|
||||
* Truncate the output at the last known good point.
|
||||
*
|
||||
* @throws IOException
|
||||
* @throws IOException if unable to work with file
|
||||
*/
|
||||
public void truncate() throws IOException {
|
||||
fileChannel.truncate(lastMarkedByteOffsetPosition);
|
||||
@@ -552,7 +552,7 @@ InitializingBean {
|
||||
/**
|
||||
* Creates the buffered writer for the output file channel based on
|
||||
* configuration information.
|
||||
* @throws IOException
|
||||
* @throws IOException if unable to initialize buffer
|
||||
*/
|
||||
private void initializeBufferedWriter() throws IOException {
|
||||
|
||||
@@ -574,7 +574,8 @@ InitializingBean {
|
||||
}
|
||||
}
|
||||
|
||||
Assert.state(outputBufferedWriter != null);
|
||||
Assert.state(outputBufferedWriter != null,
|
||||
"Unable to initialize buffered writer");
|
||||
// in case of restarting reset position to last committed point
|
||||
if (restarted) {
|
||||
checkFileSize();
|
||||
@@ -596,12 +597,7 @@ InitializingBean {
|
||||
try {
|
||||
final FileChannel channel = fileChannel;
|
||||
if (transactional) {
|
||||
TransactionAwareBufferedWriter writer = new TransactionAwareBufferedWriter(channel, new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
closeStream();
|
||||
}
|
||||
});
|
||||
TransactionAwareBufferedWriter writer = new TransactionAwareBufferedWriter(channel, () -> closeStream());
|
||||
|
||||
writer.setEncoding(encoding);
|
||||
writer.setForceSync(forceSync);
|
||||
|
||||
@@ -380,7 +380,7 @@ public class FlatFileItemReaderBuilder<T> {
|
||||
* Builds the {@link FlatFileItemReader}.
|
||||
*
|
||||
* @return a {@link FlatFileItemReader}
|
||||
* @throws Exception
|
||||
* @throws Exception if an error occurs during construction
|
||||
*/
|
||||
public FlatFileItemReader<T> build() throws Exception {
|
||||
if(this.saveState) {
|
||||
@@ -574,7 +574,7 @@ public class FlatFileItemReaderBuilder<T> {
|
||||
* Returns a {@link DelimitedLineTokenizer}
|
||||
*
|
||||
* @return {@link DelimitedLineTokenizer}
|
||||
* @throws Exception
|
||||
* @throws Exception if an error occurs during construction
|
||||
*/
|
||||
public DelimitedLineTokenizer build() throws Exception {
|
||||
Assert.notNull(this.fieldSetFactory, "A FieldSetFactory is required.");
|
||||
|
||||
@@ -16,6 +16,15 @@
|
||||
|
||||
package org.springframework.batch.item.file.mapping;
|
||||
|
||||
import java.beans.PropertyEditor;
|
||||
import java.util.HashMap;
|
||||
import java.util.HashSet;
|
||||
import java.util.Map;
|
||||
import java.util.Properties;
|
||||
import java.util.Set;
|
||||
import java.util.concurrent.ConcurrentHashMap;
|
||||
import java.util.concurrent.ConcurrentMap;
|
||||
|
||||
import org.springframework.batch.item.file.transform.FieldSet;
|
||||
import org.springframework.batch.support.DefaultPropertyEditorRegistrar;
|
||||
import org.springframework.beans.BeanWrapperImpl;
|
||||
@@ -32,15 +41,6 @@ import org.springframework.util.ReflectionUtils;
|
||||
import org.springframework.validation.BindException;
|
||||
import org.springframework.validation.DataBinder;
|
||||
|
||||
import java.beans.PropertyEditor;
|
||||
import java.util.HashMap;
|
||||
import java.util.HashSet;
|
||||
import java.util.Map;
|
||||
import java.util.Properties;
|
||||
import java.util.Set;
|
||||
import java.util.concurrent.ConcurrentHashMap;
|
||||
import java.util.concurrent.ConcurrentMap;
|
||||
|
||||
/**
|
||||
* {@link FieldSetMapper} implementation based on bean property paths. The
|
||||
* {@link FieldSet} to be mapped should have field name meta data corresponding
|
||||
@@ -198,7 +198,7 @@ public class BeanWrapperFieldSetMapper<T> extends DefaultPropertyEditorRegistrar
|
||||
* {@link #initBinder(DataBinder)} and
|
||||
* {@link #registerCustomEditors(PropertyEditorRegistry)}.
|
||||
*
|
||||
* @param target
|
||||
* @param target Object to bind to
|
||||
* @return a {@link DataBinder} that can be used to bind properties to the
|
||||
* target.
|
||||
*/
|
||||
@@ -243,9 +243,8 @@ public class BeanWrapperFieldSetMapper<T> extends DefaultPropertyEditorRegistrar
|
||||
}
|
||||
|
||||
/**
|
||||
* @param bean
|
||||
* @param properties
|
||||
* @return
|
||||
* @param bean Object to get properties for
|
||||
* @param properties Properties to retrieve
|
||||
*/
|
||||
private Properties getBeanProperties(Object bean, Properties properties) {
|
||||
|
||||
@@ -254,9 +253,9 @@ public class BeanWrapperFieldSetMapper<T> extends DefaultPropertyEditorRegistrar
|
||||
// Map from field names to property names
|
||||
DistanceHolder distanceKey = new DistanceHolder(cls, distanceLimit);
|
||||
if (!propertiesMatched.containsKey(distanceKey)) {
|
||||
propertiesMatched.putIfAbsent(distanceKey, new ConcurrentHashMap<String, String>());
|
||||
propertiesMatched.putIfAbsent(distanceKey, new ConcurrentHashMap<>());
|
||||
}
|
||||
Map<String, String> matches = new HashMap<String, String>(propertiesMatched.get(distanceKey));
|
||||
Map<String, String> matches = new HashMap<>(propertiesMatched.get(distanceKey));
|
||||
|
||||
@SuppressWarnings({ "unchecked", "rawtypes" })
|
||||
Set<String> keys = new HashSet(properties.keySet());
|
||||
@@ -285,7 +284,7 @@ public class BeanWrapperFieldSetMapper<T> extends DefaultPropertyEditorRegistrar
|
||||
}
|
||||
}
|
||||
|
||||
propertiesMatched.replace(distanceKey, new ConcurrentHashMap<String, String>(matches));
|
||||
propertiesMatched.replace(distanceKey, new ConcurrentHashMap<>(matches));
|
||||
return properties;
|
||||
}
|
||||
|
||||
@@ -378,7 +377,7 @@ public class BeanWrapperFieldSetMapper<T> extends DefaultPropertyEditorRegistrar
|
||||
* {@link #mapFieldSet(FieldSet)} will fail of the FieldSet contains fields
|
||||
* that cannot be mapped to the bean.
|
||||
*
|
||||
* @param strict
|
||||
* @param strict indicator
|
||||
*/
|
||||
public void setStrict(boolean strict) {
|
||||
this.strict = strict;
|
||||
|
||||
@@ -35,6 +35,7 @@ public interface FieldSetMapper<T> {
|
||||
* Method used to map data obtained from a {@link FieldSet} into an object.
|
||||
*
|
||||
* @param fieldSet the {@link FieldSet} to map
|
||||
* @return the populated object
|
||||
* @throws BindException if there is a problem with the binding
|
||||
*/
|
||||
T mapFieldSet(FieldSet fieldSet) throws BindException;
|
||||
|
||||
@@ -45,6 +45,8 @@ public class DefaultRecordSeparatorPolicy extends SimpleRecordSeparatorPolicy {
|
||||
|
||||
/**
|
||||
* Convenient constructor with quote character as parameter.
|
||||
*
|
||||
* @param quoteCharacter value used to indicate a quoted string
|
||||
*/
|
||||
public DefaultRecordSeparatorPolicy(String quoteCharacter) {
|
||||
this(quoteCharacter, CONTINUATION);
|
||||
@@ -53,6 +55,9 @@ public class DefaultRecordSeparatorPolicy extends SimpleRecordSeparatorPolicy {
|
||||
/**
|
||||
* Convenient constructor with quote character and continuation marker as
|
||||
* parameters.
|
||||
*
|
||||
* @param quoteCharacter value used to indicate a quoted string
|
||||
* @param continuation value used to indicate a line continuation
|
||||
*/
|
||||
public DefaultRecordSeparatorPolicy(String quoteCharacter, String continuation) {
|
||||
super();
|
||||
|
||||
@@ -38,7 +38,7 @@ public class SuffixRecordSeparatorPolicy extends DefaultRecordSeparatorPolicy {
|
||||
/**
|
||||
* Lines ending in this terminator String signal the end of a record.
|
||||
*
|
||||
* @param suffix
|
||||
* @param suffix suffix to indicate the end of a record
|
||||
*/
|
||||
public void setSuffix(String suffix) {
|
||||
this.suffix = suffix;
|
||||
@@ -48,7 +48,7 @@ public class SuffixRecordSeparatorPolicy extends DefaultRecordSeparatorPolicy {
|
||||
* Flag to indicate that the decision to terminate a record should ignore
|
||||
* whitespace at the end of the line.
|
||||
*
|
||||
* @param ignoreWhitespace
|
||||
* @param ignoreWhitespace indicator
|
||||
*/
|
||||
public void setIgnoreWhitespace(boolean ignoreWhitespace) {
|
||||
this.ignoreWhitespace = ignoreWhitespace;
|
||||
|
||||
@@ -77,7 +77,7 @@ public abstract class AbstractLineTokenizer implements LineTokenizer {
|
||||
* Setter for column names. Optional, but if set, then all lines must have
|
||||
* as many or fewer tokens.
|
||||
*
|
||||
* @param names
|
||||
* @param names names of each column
|
||||
*/
|
||||
public void setNames(String[] names) {
|
||||
this.names = names==null ? null : Arrays.asList(names).toArray(new String[names.length]);
|
||||
|
||||
@@ -29,10 +29,6 @@ public enum Alignment {
|
||||
private String code;
|
||||
private String label;
|
||||
|
||||
/**
|
||||
* @param code
|
||||
* @param label
|
||||
*/
|
||||
private Alignment(String code, String label) {
|
||||
Assert.notNull(code, "'code' must not be null");
|
||||
|
||||
|
||||
@@ -102,8 +102,8 @@ public class DefaultFieldSet implements FieldSet {
|
||||
* @see FieldSet#readString(String)
|
||||
*/
|
||||
public DefaultFieldSet(String[] tokens, String[] names) {
|
||||
Assert.notNull(tokens);
|
||||
Assert.notNull(names);
|
||||
Assert.notNull(tokens, "Tokens must not be null");
|
||||
Assert.notNull(names, "Names must not be null");
|
||||
if (tokens.length != names.length) {
|
||||
throw new IllegalArgumentException("Field names must be same length as values: names="
|
||||
+ Arrays.asList(names) + ", values=" + Arrays.asList(tokens));
|
||||
|
||||
@@ -80,7 +80,7 @@ public class DelimitedLineTokenizer extends AbstractLineTokenizer
|
||||
* @param delimiter the desired delimiter. This is required
|
||||
*/
|
||||
public DelimitedLineTokenizer(String delimiter) {
|
||||
Assert.notNull(delimiter);
|
||||
Assert.notNull(delimiter, "A delimiter is required");
|
||||
Assert.state(!delimiter.equals(String.valueOf(DEFAULT_QUOTE_CHARACTER)), "[" + DEFAULT_QUOTE_CHARACTER
|
||||
+ "] is not allowed as delimiter for tokenizers.");
|
||||
|
||||
@@ -91,7 +91,7 @@ public class DelimitedLineTokenizer extends AbstractLineTokenizer
|
||||
/**
|
||||
* Setter for the delimiter character.
|
||||
*
|
||||
* @param delimiter
|
||||
* @param delimiter the String used as a delimiter
|
||||
*/
|
||||
public void setDelimiter(String delimiter) {
|
||||
this.delimiter = delimiter;
|
||||
@@ -106,7 +106,7 @@ public class DelimitedLineTokenizer extends AbstractLineTokenizer
|
||||
* @param includedFields the included fields to set
|
||||
*/
|
||||
public void setIncludedFields(int[] includedFields) {
|
||||
this.includedFields = new HashSet<Integer>();
|
||||
this.includedFields = new HashSet<>();
|
||||
for (int i : includedFields) {
|
||||
this.includedFields.add(i);
|
||||
}
|
||||
@@ -139,7 +139,7 @@ public class DelimitedLineTokenizer extends AbstractLineTokenizer
|
||||
@Override
|
||||
protected List<String> doTokenize(String line) {
|
||||
|
||||
List<String> tokens = new ArrayList<String>();
|
||||
List<String> tokens = new ArrayList<>();
|
||||
|
||||
// line is never null in current implementation
|
||||
// line is checked in parent: AbstractLineTokenizer.tokenize()
|
||||
@@ -281,6 +281,6 @@ public class DelimitedLineTokenizer extends AbstractLineTokenizer
|
||||
|
||||
@Override
|
||||
public void afterPropertiesSet() throws Exception {
|
||||
Assert.state(null != delimiter && 0 != delimiter.length());
|
||||
Assert.hasLength(this.delimiter, "A delimiter is required");
|
||||
}
|
||||
}
|
||||
|
||||
@@ -50,7 +50,7 @@ public abstract class ExtractorLineAggregator<T> implements LineAggregator<T> {
|
||||
*/
|
||||
@Override
|
||||
public String aggregate(T item) {
|
||||
Assert.notNull(item);
|
||||
Assert.notNull(item, "Item is required");
|
||||
Object[] fields = this.fieldExtractor.extract(item);
|
||||
|
||||
//
|
||||
|
||||
@@ -78,7 +78,7 @@ public class FormatterLineAggregator<T> extends ExtractorLineAggregator<T> {
|
||||
@Override
|
||||
protected String doAggregate(Object[] fields) {
|
||||
|
||||
Assert.notNull(format);
|
||||
Assert.notNull(format, "A format is required");
|
||||
|
||||
String value = String.format(locale, format, fields);
|
||||
|
||||
|
||||
@@ -162,7 +162,7 @@ public class LdifReader extends AbstractItemCountingItemStreamItemReader<LdapAtt
|
||||
|
||||
public void afterPropertiesSet() throws Exception {
|
||||
Assert.notNull(resource, "A resource is required to parse.");
|
||||
Assert.notNull(ldifParser);
|
||||
Assert.notNull(ldifParser, "A parser is required");
|
||||
}
|
||||
|
||||
}
|
||||
@@ -171,7 +171,7 @@ public class MappingLdifReader<T> extends AbstractItemCountingItemStreamItemRead
|
||||
|
||||
public void afterPropertiesSet() throws Exception {
|
||||
Assert.notNull(resource, "A resource is required to parse.");
|
||||
Assert.notNull(ldifParser);
|
||||
Assert.notNull(ldifParser, "A parser is required");
|
||||
}
|
||||
|
||||
}
|
||||
@@ -51,7 +51,7 @@ public final class FileUtils {
|
||||
*/
|
||||
public static void setUpOutputFile(File file, boolean restarted, boolean append, boolean overwriteOutputFile) {
|
||||
|
||||
Assert.notNull(file);
|
||||
Assert.notNull(file, "An output file is required");
|
||||
|
||||
try {
|
||||
if (!restarted) {
|
||||
|
||||
@@ -352,7 +352,7 @@ ResourceAwareItemWriterItemStream<T>, InitializingBean {
|
||||
*/
|
||||
@Override
|
||||
public void afterPropertiesSet() throws Exception {
|
||||
Assert.notNull(marshaller);
|
||||
Assert.notNull(marshaller, "A Marshaller is required");
|
||||
if (rootTagName.contains("{")) {
|
||||
rootTagNamespace = rootTagName.replaceAll("\\{(.*)\\}.*", "$1");
|
||||
rootTagName = rootTagName.replaceAll("\\{.*\\}(.*)", "$1");
|
||||
|
||||
@@ -16,17 +16,18 @@
|
||||
|
||||
package org.springframework.batch.item.xml;
|
||||
|
||||
import org.apache.commons.logging.Log;
|
||||
import org.apache.commons.logging.LogFactory;
|
||||
import org.springframework.util.Assert;
|
||||
import org.springframework.util.ClassUtils;
|
||||
|
||||
import java.lang.reflect.Constructor;
|
||||
import java.lang.reflect.Method;
|
||||
import javax.xml.stream.XMLEventReader;
|
||||
import javax.xml.stream.XMLEventWriter;
|
||||
import javax.xml.transform.Result;
|
||||
import javax.xml.transform.Source;
|
||||
import java.lang.reflect.Constructor;
|
||||
import java.lang.reflect.Method;
|
||||
|
||||
import org.apache.commons.logging.Log;
|
||||
import org.apache.commons.logging.LogFactory;
|
||||
|
||||
import org.springframework.util.Assert;
|
||||
import org.springframework.util.ClassUtils;
|
||||
|
||||
/**
|
||||
* This class provides a little bit of indirection to avoid ugly conditional object creation. It is unfortunately
|
||||
@@ -69,10 +70,10 @@ public abstract class StaxUtils {
|
||||
Class<?> clzz = ClassUtils.forName(staxSourceClassNameOnSpringOxm30, defaultClassLoader);
|
||||
|
||||
// javax.xml.transform.Source
|
||||
staxUtilsSourceMethodOnSpring30 = ClassUtils.getStaticMethod(clzz, "createStaxSource", new Class[]{ XMLEventReader.class});
|
||||
staxUtilsSourceMethodOnSpring30 = ClassUtils.getStaticMethod(clzz, "createStaxSource", XMLEventReader.class);
|
||||
|
||||
// javax.xml.transform.Result
|
||||
staxUtilsResultMethodOnSpring30 = ClassUtils.getStaticMethod(clzz, "createStaxResult", new Class[]{XMLEventWriter.class});
|
||||
staxUtilsResultMethodOnSpring30 = ClassUtils.getStaticMethod(clzz, "createStaxResult", XMLEventWriter.class);
|
||||
} else if (hasSpringWs15StaxSupport) {
|
||||
|
||||
// javax.xml.transform.Source
|
||||
@@ -126,7 +127,7 @@ public abstract class StaxUtils {
|
||||
}
|
||||
|
||||
public static XMLEventWriter getXmlEventWriter(Result r) throws Exception {
|
||||
Method m = r.getClass().getDeclaredMethod("getXMLEventWriter", new Class[]{});
|
||||
Method m = r.getClass().getDeclaredMethod("getXMLEventWriter");
|
||||
boolean accessible = m.isAccessible();
|
||||
m.setAccessible(true);
|
||||
Object result = m.invoke(r);
|
||||
@@ -135,7 +136,7 @@ public abstract class StaxUtils {
|
||||
}
|
||||
|
||||
public static XMLEventReader getXmlEventReader(Source s) throws Exception {
|
||||
Method m = s.getClass().getDeclaredMethod("getXMLEventReader", new Class[]{});
|
||||
Method m = s.getClass().getDeclaredMethod("getXMLEventReader");
|
||||
boolean accessible = m.isAccessible();
|
||||
m.setAccessible(true);
|
||||
Object result = m.invoke(s);
|
||||
|
||||
@@ -49,7 +49,7 @@ public abstract class CheckpointSupport extends ItemStreamSupport{
|
||||
* @param checkpointKey key to store the checkpoint object with in the {@link ExecutionContext}
|
||||
*/
|
||||
public CheckpointSupport(String checkpointKey) {
|
||||
Assert.hasText(checkpointKey);
|
||||
Assert.hasText(checkpointKey, "checkpointKey is required");
|
||||
this.checkpointKey = checkpointKey;
|
||||
}
|
||||
|
||||
@@ -72,7 +72,7 @@ public abstract class CheckpointSupport extends ItemStreamSupport{
|
||||
* Used to open a batch artifact with previously saved checkpoint information.
|
||||
*
|
||||
* @param checkpoint previously saved checkpoint object
|
||||
* @throws Exception
|
||||
* @throws Exception thrown by the implementation
|
||||
*/
|
||||
protected abstract void doOpen(Serializable checkpoint) throws Exception;
|
||||
|
||||
@@ -94,7 +94,7 @@ public abstract class CheckpointSupport extends ItemStreamSupport{
|
||||
* batch artifact.
|
||||
*
|
||||
* @return the current state of the batch artifact
|
||||
* @throws Exception
|
||||
* @throws Exception thrown by the implementation
|
||||
*/
|
||||
protected abstract Serializable doCheckpoint() throws Exception;
|
||||
|
||||
@@ -113,7 +113,7 @@ public abstract class CheckpointSupport extends ItemStreamSupport{
|
||||
/**
|
||||
* Used to close the underlying batch artifact
|
||||
*
|
||||
* @throws Exception
|
||||
* @throws Exception thrown by the underlying implementation
|
||||
*/
|
||||
protected abstract void doClose() throws Exception;
|
||||
|
||||
|
||||
@@ -54,6 +54,8 @@ public interface RepeatContext extends AttributeAccessor {
|
||||
|
||||
/**
|
||||
* Public accessor for the complete flag.
|
||||
*
|
||||
* @return indicator if the repeat is complete
|
||||
*/
|
||||
boolean isCompleteOnly();
|
||||
|
||||
@@ -66,6 +68,8 @@ public interface RepeatContext extends AttributeAccessor {
|
||||
/**
|
||||
* Public accessor for the termination flag. If this flag is set then the
|
||||
* complete flag will also be.
|
||||
*
|
||||
* @return indicates if the repeat should terminate
|
||||
*/
|
||||
boolean isTerminateOnly();
|
||||
|
||||
|
||||
@@ -43,12 +43,7 @@ public class RethrowOnThresholdExceptionHandler implements ExceptionHandler {
|
||||
|
||||
protected final Log logger = LogFactory.getLog(RethrowOnThresholdExceptionHandler.class);
|
||||
|
||||
private Classifier<? super Throwable, IntegerHolder> exceptionClassifier = new Classifier<Throwable, IntegerHolder>() {
|
||||
@Override
|
||||
public RethrowOnThresholdExceptionHandler.IntegerHolder classify(Throwable classifiable) {
|
||||
return ZERO;
|
||||
}
|
||||
};
|
||||
private Classifier<? super Throwable, IntegerHolder> exceptionClassifier = (Classifier<Throwable, IntegerHolder>) classifiable -> ZERO;
|
||||
|
||||
private boolean useParent = false;
|
||||
|
||||
@@ -82,7 +77,7 @@ public class RethrowOnThresholdExceptionHandler implements ExceptionHandler {
|
||||
for (Entry<Class<? extends Throwable>, Integer> entry : thresholds.entrySet()) {
|
||||
typeMap.put(entry.getKey(), new IntegerHolder(entry.getValue()));
|
||||
}
|
||||
exceptionClassifier = new SubclassClassifier<Throwable, IntegerHolder>(typeMap, ZERO);
|
||||
exceptionClassifier = new SubclassClassifier<>(typeMap, ZERO);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -123,7 +118,7 @@ public class RethrowOnThresholdExceptionHandler implements ExceptionHandler {
|
||||
private final int value;
|
||||
|
||||
/**
|
||||
* @param value
|
||||
* @param value value within holder
|
||||
*/
|
||||
public IntegerHolder(int value) {
|
||||
this.value = value;
|
||||
|
||||
@@ -16,8 +16,14 @@
|
||||
|
||||
package org.springframework.batch.repeat.support;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.Collection;
|
||||
import java.util.List;
|
||||
|
||||
import org.apache.commons.logging.Log;
|
||||
import org.apache.commons.logging.LogFactory;
|
||||
|
||||
import org.springframework.batch.repeat.CompletionPolicy;
|
||||
import org.springframework.batch.repeat.RepeatCallback;
|
||||
import org.springframework.batch.repeat.RepeatContext;
|
||||
@@ -30,11 +36,6 @@ import org.springframework.batch.repeat.exception.ExceptionHandler;
|
||||
import org.springframework.batch.repeat.policy.DefaultResultCompletionPolicy;
|
||||
import org.springframework.util.Assert;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.Collection;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* Simple implementation and base class for batch templates implementing
|
||||
* {@link RepeatOperations}. Provides a framework including interceptors and
|
||||
@@ -76,7 +77,7 @@ public class RepeatTemplate implements RepeatOperations {
|
||||
* Set the listeners for this template, registering them for callbacks at
|
||||
* appropriate times in the iteration.
|
||||
*
|
||||
* @param listeners
|
||||
* @param listeners listeners to be used
|
||||
*/
|
||||
public void setListeners(RepeatListener[] listeners) {
|
||||
this.listeners = Arrays.asList(listeners).toArray(new RepeatListener[listeners.length]);
|
||||
@@ -85,10 +86,10 @@ public class RepeatTemplate implements RepeatOperations {
|
||||
/**
|
||||
* Register an additional listener.
|
||||
*
|
||||
* @param listener
|
||||
* @param listener a single listener to be added to the list
|
||||
*/
|
||||
public void registerListener(RepeatListener listener) {
|
||||
List<RepeatListener> list = new ArrayList<RepeatListener>(Arrays.asList(listeners));
|
||||
List<RepeatListener> list = new ArrayList<>(Arrays.asList(listeners));
|
||||
list.add(listener);
|
||||
listeners = list.toArray(new RepeatListener[list.size()]);
|
||||
}
|
||||
@@ -121,7 +122,7 @@ public class RepeatTemplate implements RepeatOperations {
|
||||
* @throws IllegalArgumentException if the argument is null
|
||||
*/
|
||||
public void setCompletionPolicy(CompletionPolicy terminationPolicy) {
|
||||
Assert.notNull(terminationPolicy);
|
||||
Assert.notNull(terminationPolicy, "CompletionPolicy is required");
|
||||
this.completionPolicy = terminationPolicy;
|
||||
}
|
||||
|
||||
@@ -172,8 +173,7 @@ public class RepeatTemplate implements RepeatOperations {
|
||||
// processing takes place.
|
||||
boolean running = !isMarkedComplete(context);
|
||||
|
||||
for (int i = 0; i < listeners.length; i++) {
|
||||
RepeatListener interceptor = listeners[i];
|
||||
for (RepeatListener interceptor : listeners) {
|
||||
interceptor.open(context);
|
||||
running = running && !isMarkedComplete(context);
|
||||
if (!running)
|
||||
@@ -188,7 +188,7 @@ public class RepeatTemplate implements RepeatOperations {
|
||||
Collection<Throwable> throwables = state.getThrowables();
|
||||
// Keep a separate list of exceptions we handled that need to be
|
||||
// rethrown
|
||||
Collection<Throwable> deferred = new ArrayList<Throwable>();
|
||||
Collection<Throwable> deferred = new ArrayList<>();
|
||||
|
||||
try {
|
||||
|
||||
@@ -361,6 +361,7 @@ public class RepeatTemplate implements RepeatOperations {
|
||||
* @param callback the callback to execute.
|
||||
* @param state maintained by the implementation.
|
||||
* @return a finished result.
|
||||
* @throws Throwable any Throwable emitted during the iteration
|
||||
*
|
||||
* @see #isComplete(RepeatContext)
|
||||
* @see #createInternalState(RepeatContext)
|
||||
|
||||
@@ -83,7 +83,7 @@ public class TaskExecutorRepeatTemplate extends RepeatTemplate {
|
||||
* @throws IllegalArgumentException if the argument is null
|
||||
*/
|
||||
public void setTaskExecutor(TaskExecutor taskExecutor) {
|
||||
Assert.notNull(taskExecutor);
|
||||
Assert.notNull(taskExecutor, "A TaskExecutor is required");
|
||||
this.taskExecutor = taskExecutor;
|
||||
}
|
||||
|
||||
@@ -99,7 +99,7 @@ public class TaskExecutorRepeatTemplate extends RepeatTemplate {
|
||||
protected RepeatStatus getNextResult(RepeatContext context, RepeatCallback callback, RepeatInternalState state)
|
||||
throws Throwable {
|
||||
|
||||
ExecutingRunnable runnable = null;
|
||||
ExecutingRunnable runnable;
|
||||
|
||||
ResultQueue<ResultHolder> queue = ((ResultQueueInternalState) state).getResultQueue();
|
||||
|
||||
|
||||
@@ -57,7 +57,7 @@ public class MethodInvokerUtils {
|
||||
Assert.isTrue(!paramsRequired, errorMsg);
|
||||
// if no method was found for the given parameters, and the
|
||||
// parameters aren't required, then try with no params
|
||||
method = ClassUtils.getMethodIfAvailable(object.getClass(), methodName, new Class[] {});
|
||||
method = ClassUtils.getMethodIfAvailable(object.getClass(), methodName);
|
||||
Assert.notNull(method, errorMsg);
|
||||
}
|
||||
return new SimpleMethodInvoker(object, method);
|
||||
@@ -66,8 +66,8 @@ public class MethodInvokerUtils {
|
||||
/**
|
||||
* Create a String representation of the array of parameter types.
|
||||
*
|
||||
* @param paramTypes
|
||||
* @return String
|
||||
* @param paramTypes types of the parameters to be used
|
||||
* @return String a String representation of those types
|
||||
*/
|
||||
public static String getParamTypesString(Class<?>... paramTypes) {
|
||||
StringBuilder paramTypesList = new StringBuilder("(");
|
||||
@@ -116,22 +116,19 @@ public class MethodInvokerUtils {
|
||||
final Class<?> targetClass = (target instanceof Advised) ? ((Advised) target).getTargetSource()
|
||||
.getTargetClass() : target.getClass();
|
||||
if (mi != null) {
|
||||
ReflectionUtils.doWithMethods(targetClass, new ReflectionUtils.MethodCallback() {
|
||||
@Override
|
||||
public void doWith(Method method) throws IllegalArgumentException, IllegalAccessException {
|
||||
Annotation annotation = AnnotationUtils.findAnnotation(method, annotationType);
|
||||
if (annotation != null) {
|
||||
Class<?>[] paramTypes = method.getParameterTypes();
|
||||
if (paramTypes.length > 0) {
|
||||
String errorMsg = "The method [" + method.getName() + "] on target class ["
|
||||
+ targetClass.getSimpleName() + "] is incompatible with the signature ["
|
||||
+ getParamTypesString(expectedParamTypes) + "] expected for the annotation ["
|
||||
+ annotationType.getSimpleName() + "].";
|
||||
ReflectionUtils.doWithMethods(targetClass, method -> {
|
||||
Annotation annotation = AnnotationUtils.findAnnotation(method, annotationType);
|
||||
if (annotation != null) {
|
||||
Class<?>[] paramTypes = method.getParameterTypes();
|
||||
if (paramTypes.length > 0) {
|
||||
String errorMsg = "The method [" + method.getName() + "] on target class ["
|
||||
+ targetClass.getSimpleName() + "] is incompatible with the signature ["
|
||||
+ getParamTypesString(expectedParamTypes) + "] expected for the annotation ["
|
||||
+ annotationType.getSimpleName() + "].";
|
||||
|
||||
Assert.isTrue(paramTypes.length == expectedParamTypes.length, errorMsg);
|
||||
for (int i = 0; i < paramTypes.length; i++) {
|
||||
Assert.isTrue(expectedParamTypes[i].isAssignableFrom(paramTypes[i]), errorMsg);
|
||||
}
|
||||
Assert.isTrue(paramTypes.length == expectedParamTypes.length, errorMsg);
|
||||
for (int i = 0; i < paramTypes.length; i++) {
|
||||
Assert.isTrue(expectedParamTypes[i].isAssignableFrom(paramTypes[i]), errorMsg);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -162,17 +159,14 @@ public class MethodInvokerUtils {
|
||||
// Proxy with no target cannot have annotations
|
||||
return null;
|
||||
}
|
||||
final AtomicReference<Method> annotatedMethod = new AtomicReference<Method>();
|
||||
ReflectionUtils.doWithMethods(targetClass, new ReflectionUtils.MethodCallback() {
|
||||
@Override
|
||||
public void doWith(Method method) throws IllegalArgumentException, IllegalAccessException {
|
||||
Annotation annotation = AnnotationUtils.findAnnotation(method, annotationType);
|
||||
if (annotation != null) {
|
||||
Assert.isNull(annotatedMethod.get(), "found more than one method on target class ["
|
||||
+ targetClass.getSimpleName() + "] with the annotation type ["
|
||||
+ annotationType.getSimpleName() + "].");
|
||||
annotatedMethod.set(method);
|
||||
}
|
||||
final AtomicReference<Method> annotatedMethod = new AtomicReference<>();
|
||||
ReflectionUtils.doWithMethods(targetClass, method -> {
|
||||
Annotation annotation = AnnotationUtils.findAnnotation(method, annotationType);
|
||||
if (annotation != null) {
|
||||
Assert.isNull(annotatedMethod.get(), "found more than one method on target class ["
|
||||
+ targetClass.getSimpleName() + "] with the annotation type ["
|
||||
+ annotationType.getSimpleName() + "].");
|
||||
annotatedMethod.set(method);
|
||||
}
|
||||
});
|
||||
Method method = annotatedMethod.get();
|
||||
@@ -192,20 +186,17 @@ public class MethodInvokerUtils {
|
||||
* @return a MethodInvoker that calls a method on the delegate
|
||||
*/
|
||||
public static <C, T> MethodInvoker getMethodInvokerForSingleArgument(Object target) {
|
||||
final AtomicReference<Method> methodHolder = new AtomicReference<Method>();
|
||||
ReflectionUtils.doWithMethods(target.getClass(), new ReflectionUtils.MethodCallback() {
|
||||
@Override
|
||||
public void doWith(Method method) throws IllegalArgumentException, IllegalAccessException {
|
||||
if (method.getParameterTypes() == null || method.getParameterTypes().length != 1) {
|
||||
return;
|
||||
}
|
||||
if (method.getReturnType().equals(Void.TYPE) || ReflectionUtils.isEqualsMethod(method)) {
|
||||
return;
|
||||
}
|
||||
Assert.state(methodHolder.get() == null,
|
||||
"More than one non-void public method detected with single argument.");
|
||||
methodHolder.set(method);
|
||||
final AtomicReference<Method> methodHolder = new AtomicReference<>();
|
||||
ReflectionUtils.doWithMethods(target.getClass(), method -> {
|
||||
if (method.getParameterTypes() == null || method.getParameterTypes().length != 1) {
|
||||
return;
|
||||
}
|
||||
if (method.getReturnType().equals(Void.TYPE) || ReflectionUtils.isEqualsMethod(method)) {
|
||||
return;
|
||||
}
|
||||
Assert.state(methodHolder.get() == null,
|
||||
"More than one non-void public method detected with single argument.");
|
||||
methodHolder.set(method);
|
||||
});
|
||||
Method method = methodHolder.get();
|
||||
return new SimpleMethodInvoker(target, method);
|
||||
|
||||
@@ -15,13 +15,13 @@
|
||||
*/
|
||||
package org.springframework.batch.support;
|
||||
|
||||
import org.springframework.core.annotation.AnnotationUtils;
|
||||
|
||||
import java.lang.annotation.Annotation;
|
||||
import java.lang.reflect.Method;
|
||||
import java.util.HashSet;
|
||||
import java.util.Set;
|
||||
|
||||
import org.springframework.core.annotation.AnnotationUtils;
|
||||
|
||||
/**
|
||||
* Provides reflection based utilities for Spring Batch that are not available
|
||||
* via Spring Core
|
||||
@@ -41,10 +41,11 @@ public class ReflectionUtils {
|
||||
* @param annotationType The type of annotation to look for
|
||||
* @return a set of {@link java.lang.reflect.Method} instances if any are found, an empty set if not.
|
||||
*/
|
||||
@SuppressWarnings("rawtypes")
|
||||
public static final Set<Method> findMethod(Class clazz, Class<? extends Annotation> annotationType) {
|
||||
|
||||
Method [] declaredMethods = org.springframework.util.ReflectionUtils.getAllDeclaredMethods(clazz);
|
||||
Set<Method> results = new HashSet<Method>();
|
||||
Set<Method> results = new HashSet<>();
|
||||
|
||||
for (Method curMethod : declaredMethods) {
|
||||
Annotation annotation = AnnotationUtils.findAnnotation(curMethod, annotationType);
|
||||
|
||||
@@ -65,7 +65,7 @@ public class SimpleMethodInvoker implements MethodInvoker {
|
||||
this.method = ClassUtils.getMethodIfAvailable(object.getClass(), methodName, paramTypes);
|
||||
if (this.method == null) {
|
||||
// try with no params
|
||||
this.method = ClassUtils.getMethodIfAvailable(object.getClass(), methodName, new Class[] {});
|
||||
this.method = ClassUtils.getMethodIfAvailable(object.getClass(), methodName);
|
||||
}
|
||||
if (this.method == null) {
|
||||
throw new IllegalArgumentException("No methods found for name: [" + methodName + "] in class: ["
|
||||
|
||||
@@ -15,18 +15,19 @@
|
||||
*/
|
||||
package org.springframework.batch.item.adapter;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertNull;
|
||||
import static org.junit.Assert.fail;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import org.junit.Before;
|
||||
import org.junit.Ignore;
|
||||
import org.junit.Test;
|
||||
|
||||
import org.springframework.batch.item.adapter.AbstractMethodInvokingDelegator.InvocationTargetThrowableWrapper;
|
||||
import org.springframework.util.Assert;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertNull;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
import static org.junit.Assert.fail;
|
||||
|
||||
/**
|
||||
* Tests for {@link AbstractMethodInvokingDelegator}
|
||||
@@ -75,7 +76,7 @@ public class AbstractDelegatorTests {
|
||||
|
||||
// using the arguments setter should work equally well
|
||||
foo.setName("foo");
|
||||
Assert.state(!foo.getName().equals(NEW_FOO_NAME));
|
||||
assertTrue(!foo.getName().equals(NEW_FOO_NAME));
|
||||
delegator.setArguments(new Object[] { NEW_FOO_NAME });
|
||||
delegator.afterPropertiesSet();
|
||||
delegator.invokeDelegateMethod();
|
||||
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user