Add spring-batch- to module directory names (so folks can use mvn eclipse:eclipse if they want to).

BATCH-238: Remove hibernate support for the Daos.
This commit is contained in:
dsyer
2007-12-10 21:23:48 +00:00
parent 17705f27ab
commit 8ea331bfc7
884 changed files with 956 additions and 2352 deletions

View File

@@ -0,0 +1,42 @@
/*
* Copyright 2006-2007 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.springframework.batch.core.configuration;
/**
* Checked exception that indicates a name clash when registering
* {@link JobConfiguration} instances.
*
* @author Dave Syer
*
*/
public class DuplicateJobConfigurationException extends JobConfigurationException {
/**
* Create an exception with the given message.
*/
public DuplicateJobConfigurationException(String msg) {
super(msg);
}
/**
* @param msg The message to send to caller
* @param e the cause of the exception
*/
public DuplicateJobConfigurationException(String msg, Throwable e) {
super(msg, e);
}
}

View File

@@ -0,0 +1,118 @@
/*
* Copyright 2006-2007 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.springframework.batch.core.configuration;
import java.util.ArrayList;
import java.util.List;
import org.springframework.beans.factory.BeanNameAware;
/**
* Batch domain object representing a job configuration. JobConfiguration is an
* explicit abstraction representing the configuration of a job specified by a
* developer. It should be noted that restart policy is applied to the job as a
* whole and not to a step.
*
* @author Lucas Ward
* @author Dave Syer
*/
public class JobConfiguration implements BeanNameAware {
private List stepConfigurations = new ArrayList();
private String name;
private boolean restartable = false;
private int startLimit = Integer.MAX_VALUE;
/**
* Default constructor.
*/
public JobConfiguration() {
super();
}
/**
* Convenience constructor to immediately add name (which is mandatory but
* not final).
*
* @param name
*/
public JobConfiguration(String name) {
super();
this.name = name;
}
/**
* Set the name property if it is not already set. Because of the order of
* the callbacks in a Spring container the name property will be set first
* if it is present. Care is needed with bean definition inheritance - if a
* parent bean has a name, then its children need an explicit name as well,
* otherwise they will not be unique.
*
* @see org.springframework.beans.factory.BeanNameAware#setBeanName(java.lang.String)
*/
public void setBeanName(String name) {
if (this.name==null) {
this.name = name;
}
}
/**
* Set the name property. Always overrides the default value if this object
* is a Spring bean.
*
* @see #setBeanName(java.lang.String)
*/
public void setName(String name) {
this.name = name;
}
public String getName() {
return name;
}
public List getStepConfigurations() {
return stepConfigurations;
}
public void setSteps(List stepConfigurations) {
this.stepConfigurations.clear();
this.stepConfigurations.addAll(stepConfigurations);
}
public void addStep(StepConfiguration stepConfiguration) {
this.stepConfigurations.add(stepConfiguration);
}
public int getStartLimit() {
return startLimit;
}
public void setStartLimit(int startLimit) {
this.startLimit = startLimit;
}
public void setRestartable(boolean restartable) {
this.restartable = restartable;
}
public boolean isRestartable() {
return restartable;
}
}

View File

@@ -0,0 +1,42 @@
/*
* Copyright 2006-2007 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.springframework.batch.core.configuration;
/**
* Base class for checked exceptions related to {@link JobConfiguration}
* creation, registration or use.
*
* @author Dave Syer
*
*/
public class JobConfigurationException extends Exception {
/**
* Create an exception with the given message.
*/
public JobConfigurationException(String msg) {
super(msg);
}
/**
* @param msg The message to send to caller
* @param e the cause of the exception
*/
public JobConfigurationException(String msg, Throwable e) {
super(msg, e);
}
}

View File

@@ -0,0 +1,38 @@
/*
* Copyright 2006-2007 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.springframework.batch.core.configuration;
/**
* A runtime service locator interface for retrieving job configurations by
* <code>name</code>.
*
* @author Dave Syer
*
*/
public interface JobConfigurationLocator {
/**
* Locates a {@link JobConfiguration} at runtime.
*
* @param name the name of the {@link JobConfiguration} which should be
* unique
* @return a {@link JobConfiguration} identified by the given name
*
* @throws NoSuchJobConfigurationException if the required configuratio can
* not be found.
*/
JobConfiguration getJobConfiguration(String name) throws NoSuchJobConfigurationException;
}

View File

@@ -0,0 +1,44 @@
/*
* Copyright 2006-2007 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.springframework.batch.core.configuration;
/**
* A runtime service registry interface for registering job configurations by
* <code>name</code>.
*
* @author Dave Syer
*
*/
public interface JobConfigurationRegistry extends JobConfigurationLocator {
/**
* Registers a {@link JobConfiguration} at runtime.
*
* @param jobConfiguration the {@link JobConfiguration} to be registered
*
* @throws DuplicateJobConfigurationException if a configuration with the
* same name has already been registered.
*/
void register(JobConfiguration jobConfiguration) throws DuplicateJobConfigurationException;
/**
* Unregisters a previously registered {@link JobConfiguration}. If it was
* not previously registered there is no error.
*
* @param jobConfiguration the {@link JobConfiguration} to unregister.
*/
void unregister(JobConfiguration jobConfiguration);
}

View File

@@ -0,0 +1,36 @@
/*
* Copyright 2006-2007 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.springframework.batch.core.configuration;
import java.util.Collection;
/**
* A listable extension of {@link JobConfigurationRegistry}.
*
* @author Dave Syer
*
*/
public interface ListableJobConfigurationRegistry extends JobConfigurationRegistry {
/**
* Provides the currently registered configurations. The return value is
* unmodifiable and disconnected from the underlying registry storage.
*
* @return a collection of {@link JobConfiguration} instances. Empty if none
* are registered.
*/
Collection getJobConfigurations();
}

View File

@@ -0,0 +1,42 @@
/*
* Copyright 2006-2007 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.springframework.batch.core.configuration;
/**
* Checked exception to indicate that a required {@link JobConfiguration} is not
* available.
*
* @author Dave Syer
*
*/
public class NoSuchJobConfigurationException extends JobConfigurationException {
/**
* Create an exception with the given message.
*/
public NoSuchJobConfigurationException(String msg) {
super(msg);
}
/**
* @param msg The message to send to caller
* @param e the cause of the exception
*/
public NoSuchJobConfigurationException(String msg, Throwable e) {
super(msg, e);
}
}

View File

@@ -0,0 +1,60 @@
/*
* Copyright 2006-2007 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.springframework.batch.core.configuration;
import org.springframework.batch.core.tasklet.Tasklet;
/**
* Batch domain interface representing the configuration of a step. As with the
* (@link JobConfiguration), step configuration is meant to explicitly represent
* a the configuration of a step by a developer. This allows for the separation
* of what a developer configures from the myriad of concerns required for
* executing a job.
*
* @author Dave Syer
*
*/
public interface StepConfiguration {
/**
* @return the name of this step configuration.
*/
String getName();
/**
* @return the {@link Tasklet} instance to execute for each item processed.
*/
Tasklet getTasklet();
/**
* @return true if a step that is already marked as complete can be started
* again.
*/
boolean isAllowStartIfComplete();
/**
* Flag to indicate if restart data needs to be saved for this step.
* @return true if restart data should be saved
*/
boolean isSaveRestartData();
/**
* @return the number of times a job can be started with the same
* identifier.
*/
int getStartLimit();
}

View File

@@ -0,0 +1,151 @@
/*
* Copyright 2006-2007 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.springframework.batch.core.configuration;
import org.springframework.batch.core.tasklet.Tasklet;
import org.springframework.beans.factory.BeanNameAware;
/**
* Basic no-op support implementation for use as base class for
* {@link StepConfiguration}.
*
* @author Dave Syer
*
*/
public class StepConfigurationSupport implements StepConfiguration,
BeanNameAware {
private String name;
private int startLimit = Integer.MAX_VALUE;
private Tasklet tasklet;
private boolean allowStartIfComplete;
private boolean saveRestartData = false;
/**
* Default constructor for {@link StepConfigurationSupport}.
*/
public StepConfigurationSupport() {
super();
}
/**
* @param string
*/
public StepConfigurationSupport(String string) {
super();
this.name = string;
}
/*
* (non-Javadoc)
*
* @see org.springframework.batch.core.configuration.StepConfiguration#getName()
*/
public String getName() {
return this.name;
}
/**
* Set the name property if it is not already set. Because of the order of
* the callbacks in a Spring container the name property will be set first
* if it is present. Care is needed with bean definition inheritance - if a
* parent bean has a name, then its children need an explicit name as well,
* otherwise they will not be unique.
*
* @see org.springframework.beans.factory.BeanNameAware#setBeanName(java.lang.String)
*/
public void setBeanName(String name) {
if (this.name==null) {
this.name = name;
}
}
/**
* Set the name property. Always overrides the default value if this object
* is a Spring bean.
*
* @see #setBeanName(java.lang.String)
*/
public void setName(String name) {
this.name = name;
}
/*
* (non-Javadoc)
*
* @see org.springframework.batch.core.configuration.StepConfiguration#getStartLimit()
*/
public int getStartLimit() {
return this.startLimit;
}
/**
* Public setter for the startLimit.
*
* @param startLimit
* the startLimit to set
*/
public void setStartLimit(int startLimit) {
this.startLimit = startLimit;
}
/*
* (non-Javadoc)
*
* @see org.springframework.batch.core.configuration.StepConfiguration#getTasklet()
*/
public Tasklet getTasklet() {
return this.tasklet;
}
/**
* Public setter for the tasklet.
*
* @param tasklet
* the tasklet to set
*/
public void setTasklet(Tasklet tasklet) {
this.tasklet = tasklet;
}
/*
* (non-Javadoc)
*
* @see org.springframework.batch.core.configuration.StepConfiguration#shouldAllowStartIfComplete()
*/
public boolean isAllowStartIfComplete() {
return this.allowStartIfComplete;
}
/**
* Public setter for the shouldAllowStartIfComplete.
*
* @param allowStartIfComplete
* the shouldAllowStartIfComplete to set
*/
public void setAllowStartIfComplete(boolean allowStartIfComplete) {
this.allowStartIfComplete = allowStartIfComplete;
}
public void setSaveRestartData(boolean saveRestartData) {
this.saveRestartData = saveRestartData;
}
public boolean isSaveRestartData() {
return saveRestartData;
}
}

View File

@@ -0,0 +1,7 @@
<html>
<body>
<p>
Interfaces and generic implementations of configuration concerns.
</p>
</body>
</html>

View File

@@ -0,0 +1,62 @@
/*
* Copyright 2006-2007 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.springframework.batch.core.domain;
/**
* Typesafe enumeration representating the status of an artifact within
* the batch container. See Effective Java Programming by Joshua Bloch
* for more details on the pattern used.
*
* @author Lucas Ward
*
*/
public class BatchStatus {
private final String name;
private BatchStatus(String name) {
this.name = name;
}
public String toString(){
return name;
}
public static final BatchStatus COMPLETED = new BatchStatus("COMPLETED");
public static final BatchStatus STARTED = new BatchStatus("STARTED");
public static final BatchStatus STARTING = new BatchStatus("STARTING");
public static final BatchStatus FAILED = new BatchStatus("FAILED");
public static final BatchStatus STOPPED = new BatchStatus("STOPPED");
private static final BatchStatus[] VALUES = {STARTING, STARTED, COMPLETED, FAILED, STOPPED};
public static BatchStatus getStatus(String statusAsString){
for(int i = 0; i < VALUES.length; i++){
if(VALUES[i].toString().equals(statusAsString)){
return (BatchStatus)VALUES[i];
}
}
return null;
}
}

View File

@@ -0,0 +1,109 @@
/*
* Copyright 2006-2007 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.springframework.batch.core.domain;
import java.io.Serializable;
import org.springframework.util.ClassUtils;
/**
* Batch Domain Entity class. Any class that should be uniquely identifiable
* from another should subclass from Entity. More information on this pattern
* and the difference between Entities and Value Objects can be found in Domain
* Driven Design by Eric Evans.
*
* @author Lucas Ward
* @author Dave Syer
*
*/
public class Entity implements Serializable {
private Long id;
private Integer version;
public Entity() {
super();
}
public Entity(Long id) {
super();
this.id = id;
}
public Long getId() {
return id;
}
public void setId(Long id) {
this.id = id;
}
/**
* @return the version
*/
public Integer getVersion() {
return version;
}
// @Override
public String toString() {
return ClassUtils.getShortName(getClass()) + ": id=" + getId();
}
/**
* Attempt to establish identity based on id if both exist. If either id
* does not exist use Object.equals().
*
* @see java.lang.Object#equals(java.lang.Object)
*/
public boolean equals(Object other) {
if (other == this) {
return true;
}
if (other == null) {
return false;
}
if (!(other instanceof Entity)) {
return false;
}
Entity entity = (Entity) other;
if (id == null || entity.getId() == null) {
return entity == this;
}
return id.equals(entity.getId());
}
/**
* Use ID if it exists to establish hash code, otherwise fall back to
* Object.hashCode(). Based on the same information as equals, so if that
* changes, this will. N.B. this follows the contract of Object.hashCode(),
* but will cause problems for anyone adding an unsaved {@link Entity} to a
* Set because Set.contains() will almost certainly return false for the
* {@link Entity} after it is saved. Spring Batch does not store any of its
* entities in Sets as a matter of course, so internally this is consistent.
* Clients should not be exposed to unsaved entities.
*
* @see java.lang.Object#hashCode()
*/
public int hashCode() {
if (id == null) {
return super.hashCode();
}
return 39 + 87 * id.hashCode();
}
}

View File

@@ -0,0 +1,237 @@
/*
* Copyright 2006-2007 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.springframework.batch.core.domain;
import java.sql.Timestamp;
import java.util.Collection;
import java.util.HashSet;
import org.springframework.batch.repeat.ExitStatus;
import org.springframework.batch.repeat.RepeatContext;
/**
* Batch domain object representing the execution of a job.
*
* @author Lucas Ward
*
*/
public class JobExecution extends Entity {
private JobInstance job;
private transient Collection stepExecutions = new HashSet();
private transient Collection stepContexts = new HashSet();
private transient Collection chunkContexts = new HashSet();
private BatchStatus status = BatchStatus.STARTING;
private Timestamp startTime = new Timestamp(System.currentTimeMillis());
private Timestamp endTime = null;
private ExitStatus exitStatus = ExitStatus.UNKNOWN;
// Package private constructor for Hibernate
JobExecution() {
}
/**
* Because a JobExecution isn't valid unless the job is set, this
* constructor is the only valid one from a modelling point of view.
*
* @param job
* the job of which this execution is a part
*/
public JobExecution(JobInstance job, Long id) {
this.job = job;
setId(id);
}
/**
* Constructor for transient (unsaved) instances.
*
* @param job the enclosing {@link JobInstance}
*/
public JobExecution(JobInstance job) {
this(job, null);
}
public Timestamp getEndTime() {
return endTime;
}
public void setEndTime(Timestamp endTime) {
this.endTime = endTime;
}
public Timestamp getStartTime() {
return startTime;
}
public void setStartTime(Timestamp startTime) {
this.startTime = startTime;
}
public BatchStatus getStatus() {
return status;
}
public void setStatus(BatchStatus status) {
this.status = status;
}
/**
* Convenience getter for for the id of the enclosing job. Useful for DAO
* implementations.
*
* @return the id of the enclosing job
*/
public Long getJobId() {
if (job != null) {
return job.getId();
}
return null;
}
/**
* @param exitStatus
*/
public void setExitStatus(ExitStatus exitStatus) {
this.exitStatus = exitStatus;
}
/**
* @return the exitCode
*/
public ExitStatus getExitStatus() {
return exitStatus;
}
/**
* Accessor for the potentially multiple chunk contexts that are in
* progress. In a single-threaded, sequential execution there would normally
* be only one current chunk, but in more complicated scenarios there might
* be multiple active contexts.
*
* @return all the chunk contexts that have been registered and not
* unregistered. A collection of {@link RepeatContext} objects.
*/
public Collection getChunkContexts() {
synchronized (chunkContexts) {
return new HashSet(chunkContexts);
}
}
/**
* Accessor for the potentially multiple step contexts that are in progress.
* In a single-threaded, sequential execution there would normally be only
* one current step, but in more complicated scenarios there might be
* multiple active contexts.
*
* @return all the step contexts that have been registered and not
* unregistered. A collection of {@link RepeatContext} objects.
*/
public Collection getStepContexts() {
synchronized (stepContexts) {
return new HashSet(stepContexts);
}
}
/**
* Called at the start of a step, before any business logic is processed.
*
* @param context
* the current step context.
*/
public void registerStepContext(RepeatContext stepContext) {
synchronized (stepContexts) {
this.stepContexts.add(stepContext);
}
}
/**
* Called at the end of a step, after all business logic is processed, or in
* the case of a failure.
*
* @param context
* the current step context.
*/
public void unregisterStepContext(RepeatContext stepContext) {
synchronized (stepContexts) {
this.stepContexts.remove(stepContext);
}
}
/**
* Called at the start of a chunk, before any business logic is processed.
*
* @param context
* the current chunk context.
*/
public void registerChunkContext(RepeatContext chunkContext) {
synchronized (chunkContexts) {
this.chunkContexts.add(chunkContext);
}
}
/**
* Called at the end of a chunk, after all business logic is processed, or
* in the case of a failure.
*
* @param context
* the current chunk context.
*/
public void unregisterChunkContext(RepeatContext chunkContext) {
synchronized (chunkContexts) {
this.chunkContexts.remove(chunkContext);
}
}
/**
* @return the Job that is executing.
*/
public JobInstance getJob() {
return job;
}
/**
* Accessor for the step executions.
*
* @return the step executions that were registered
*/
public Collection getStepExecutions() {
return stepExecutions;
}
/**
* Register a step execution with the current job execution.
*
* @param stepExecution
*/
public void registerStepExecution(StepExecution stepExecution) {
this.stepExecutions.add(stepExecution);
}
/* (non-Javadoc)
* @see org.springframework.batch.core.domain.Entity#toString()
*/
public String toString() {
return super.toString()+", job=["+job+"]";
}
}

View File

@@ -0,0 +1,38 @@
/*
* Copyright 2006-2007 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.springframework.batch.core.domain;
/**
* Identifier strategy for {@link JobInstance}. Different batch projects can
* have different approaches and requirements regarding the identity of a job.
* The minimum requirement is to provide a unique name to identify a job. Other
* applications or projects might add other properties like a schedule date, or
* an additional label (code).
*
* @author Dave Syer
*
*/
public interface JobIdentifier {
/**
* A name property for jobs provided by the {@link JobIdentifier} strategy.
*
* @return the name of the job
*/
public String getName();
}

View File

@@ -0,0 +1,112 @@
/*
* Copyright 2006-2007 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.springframework.batch.core.domain;
import java.util.ArrayList;
import java.util.List;
/**
* Batch domain object representing a job instance. A job instance is defined as
* a logical container for steps with unique identification of the unit as a
* whole. A job can be executed many times with the same instance, usually if it
* fails and is restarted, or if it is launched on an ad-hoc basis "on demand".
*
* @author Lucas Ward
* @author Dave Syer
*/
public class JobInstance extends Entity {
private List steps = new ArrayList();
private JobIdentifier identifier;
// TODO declare transient or make the class serializable
private BatchStatus status;
private int jobExecutionCount;
/**
* Package private constructor for Hibernate use only
*/
JobInstance() {
this(null);
}
public JobInstance(JobIdentifier identifier, Long id) {
super();
setId(id);
this.identifier = identifier;
}
public JobInstance(JobIdentifier identifier) {
this(identifier, null);
}
public BatchStatus getStatus() {
return status;
}
public void setStatus(BatchStatus status) {
this.status = status;
}
public List getSteps() {
return steps;
}
public void setSteps(List steps) {
this.steps = steps;
}
public void addStep(StepInstance step) {
this.steps.add(step);
}
public int getJobExecutionCount() {
return jobExecutionCount;
}
public void setJobExecutionCount(int jobExecutionCount) {
this.jobExecutionCount = jobExecutionCount;
}
/**
* Public accessor for the identifier property.
*
* @return the identifier
*/
public JobIdentifier getIdentifier() {
return identifier;
}
/**
* @return the identifier name if there is one
*/
public String getName() {
return identifier==null ? null : identifier.getName();
}
public JobExecution createNewJobExecution() {
return new JobExecution(this);
}
public String toString() {
return super.toString()+", identifier=["+identifier+"]";
}
}

View File

@@ -0,0 +1,230 @@
/*
* Copyright 2006-2007 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.springframework.batch.core.domain;
import java.sql.Timestamp;
import java.util.Properties;
import org.springframework.batch.repeat.ExitStatus;
/**
* Batch domain object representation the execution of a step. Unlike
* JobExecution, there are four additional properties: luwCount, commitCount,
* rollbackCount and statistics. These values represent how many times a step
* has iterated through logical units of work, how many times it has been
* committed, and any other statistics the developer wishes to store,
* respectively.
*
* @author Lucas Ward
* @author Dave Syer
*
*/
public class StepExecution extends Entity {
private JobExecution jobExecution;
private StepInstance step;
private BatchStatus status = BatchStatus.STARTING;
private int taskCount = 0;
private int commitCount = 0;
private int rollbackCount = 0;
private Timestamp startTime = new Timestamp(System.currentTimeMillis());
private Timestamp endTime = null;
private Properties statistics = new Properties();
private ExitStatus exitStatus = ExitStatus.UNKNOWN;
/**
* Package private constructor for Hibernate
*/
StepExecution() {
super();
}
/**
* Constructor with mandatory properties.
*
* @param step the step to which this execution belongs
* @param jobExecution the current job execution
*/
public StepExecution(StepInstance step, JobExecution jobExecution, Long id) {
this();
this.step= step;
this.jobExecution = jobExecution;
setId(id);
}
public StepExecution(StepInstance step, JobExecution jobExecution) {
this(step, jobExecution, null);
}
public void incrementCommitCount() {
commitCount++;
}
public void incrementTaskCount() {
taskCount++;
}
public void incrementRollbackCount() {
rollbackCount++;
}
public Properties getStatistics() {
return statistics;
}
public void setStatistics(Properties statistics) {
this.statistics = statistics;
}
public Integer getCommitCount() {
return new Integer(commitCount);
}
public void setCommitCount(int commitCount) {
this.commitCount = commitCount;
}
public Timestamp getEndTime() {
return endTime;
}
public void setEndTime(Timestamp endTime) {
this.endTime = endTime;
}
public Integer getTaskCount() {
return new Integer(taskCount);
}
public void setTaskCount(int taskCount) {
this.taskCount = taskCount;
}
public void setRollbackCount(int rollbackCount) {
this.rollbackCount = rollbackCount;
}
public Integer getRollbackCount() {
return new Integer(rollbackCount);
}
public Timestamp getStartTime() {
return startTime;
}
public void setStartTime(Timestamp startTime) {
this.startTime = startTime;
}
public BatchStatus getStatus() {
return status;
}
public void setStatus(BatchStatus status) {
this.status = status;
}
public Long getStepId() {
if (step!=null) {
return step.getId();
}
return null;
}
/**
* Accessor for the job execution id.
* @return the jobExecutionId
*/
public Long getJobExecutionId() {
if (jobExecution!=null) {
return jobExecution.getId();
}
return null;
}
/* (non-Javadoc)
* @see org.springframework.batch.container.common.domain.Entity#equals(java.lang.Object)
*/
public boolean equals(Object obj) {
Object stepId = getStepId();
Object jobExecutionId = getJobExecutionId();
if (stepId==null && jobExecutionId==null || !(obj instanceof StepExecution) || getId()!=null) {
return super.equals(obj);
}
StepExecution other = (StepExecution) obj;
if (stepId==null) {
return jobExecutionId.equals(other.getJobExecutionId());
}
return stepId.equals(other.getStepId()) && (jobExecutionId==null || jobExecutionId.equals(other.getJobExecutionId()));
}
/* (non-Javadoc)
* @see org.springframework.batch.container.common.domain.Entity#hashCode()
*/
public int hashCode() {
Object stepId = getStepId();
Object jobExecutionId = getJobExecutionId();
return super.hashCode() + 31*(stepId!=null ? stepId.hashCode() : 0) + 91*(jobExecutionId!=null ? jobExecutionId.hashCode() : 0);
}
public String toString() {
return super.toString() + ", taskCount=" + taskCount + ", commitCount=" + commitCount + ", rollbackCount="
+ rollbackCount;
}
/**
* @param exitStatus
*/
public void setExitStatus(ExitStatus exitStatus) {
this.exitStatus = exitStatus;
}
/**
* @return the exitCode
*/
public ExitStatus getExitStatus() {
return exitStatus;
}
/**
* Accessor for the step governing this execution.
* @return the step
*/
public StepInstance getStep() {
return step;
}
/**
* Accessor for the execution context information of the enclosing job.
* @return the {@link jobExecutionContext} that was used to start this step
* execution.
*/
public JobExecution getJobExecution() {
return jobExecution;
}
}

View File

@@ -0,0 +1,124 @@
/*
* Copyright 2006-2007 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.springframework.batch.core.domain;
import java.util.Properties;
import org.springframework.batch.restart.GenericRestartData;
import org.springframework.batch.restart.RestartData;
/**
* <p>
* Batch domain entity representing a step which is sequentially executed by a
* job. Logically, steps are identified as a function of a job plus each step's
* name. For example, job 'TestJob' which has 2 steps: "TestStep1" and
* "TestStep2". The first step can be thought of as identified by
* "TestJob.TestStep1". In relational terms this may be represented by a foreign
* key on the Job's ID. Therefore, Each step instance is uniquely identified by
* it's ID, which is obtained from a JobRepository. Two steps with the same name
* and same job can be considered the same step.
* </p>
*
* <p>
* Because each step represents a runnable batch artifact with it's own
* lifecycle, each step contains status and an execution count. Status
* represents the status of each step's last execution (such as started,
* completed, failed, etc) and execution count is the count of executions for
* this individual step. It should be noted that a restartable job will create a
* new step instance (the same logical step, with a different ID) for every run.
* </p>
*
* @author Lucas Ward
* @author Dave Syer
*
*/
public class StepInstance extends Entity {
private JobInstance job;
// TODO declare transient or make serializable
private BatchStatus status;
private RestartData restartData = new GenericRestartData(new Properties());
private int stepExecutionCount = 0;
private String name;
/**
* Package private constructor for Hibernate only
*/
StepInstance() {
this(null);
}
public StepInstance(Long stepId) {
this(null, null, stepId);
}
public StepInstance(JobInstance job, String name) {
this(job, name, null);
}
public StepInstance(JobInstance job, String name, Long stepId) {
setId(stepId);
this.job = job;
this.name = name;
}
public int getStepExecutionCount() {
return stepExecutionCount;
}
public void setStepExecutionCount(int stepExecutionCount) {
this.stepExecutionCount = stepExecutionCount;
}
public RestartData getRestartData() {
return restartData;
}
public void setRestartData(RestartData restartData) {
this.restartData = restartData;
}
public BatchStatus getStatus() {
return status;
}
public void setStatus(BatchStatus status) {
this.status = status;
}
public JobInstance getJob() {
return job;
}
public String getName() {
return name;
}
public Long getJobId() {
return job==null ? null : job.getId();
}
// @Override
public String toString() {
return super.toString() + ", name=" + name + ", status=" + getStatus() + " in " + job;
}
}

View File

@@ -0,0 +1,7 @@
<html>
<body>
<p>
Interfaces and generic implementations of domain concerns.
</p>
</body>
</html>

View File

@@ -0,0 +1,43 @@
/*
* Copyright 2006-2007 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.springframework.batch.core.executor;
import org.springframework.batch.common.ExceptionClassifier;
import org.springframework.batch.repeat.ExitStatus;
/**
* Extension of the ExceptionClassifier that explicitly deals with
* returns an ExitStatus. This is useful for mapping from an exception
* type to an Exit Code with a detailed message.
*
* @author Lucas Ward
*
*/
public interface ExitCodeExceptionClassifier extends ExceptionClassifier {
static final String FATAL_EXCEPTION = "FATAL_EXCEPTION";
static final String STEP_INTERRUPTED = "STEP_INTERRUPTED";
/**
* Typesafe version of classify that explicitly returns an {@link ExitStatus}
* object.
*
* @param throwable
* @return ExitStatus representing the ExitCode and Message for the given
* exception.
*/
public ExitStatus classifyForExitCode(Throwable throwable);
}

View File

@@ -0,0 +1,31 @@
/*
* Copyright 2006-2007 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.springframework.batch.core.executor;
/**
* @author Dave Syer
*
*/
public class JobExecutionException extends Exception {
public JobExecutionException(String msg) {
super(msg);
}
public JobExecutionException(String msg, Throwable cause) {
super(msg, cause);
}
}

View File

@@ -0,0 +1,36 @@
/*
* Copyright 2006-2007 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.springframework.batch.core.executor;
import org.springframework.batch.core.configuration.JobConfiguration;
import org.springframework.batch.core.domain.JobExecution;
import org.springframework.batch.io.exception.BatchCriticalException;
import org.springframework.batch.repeat.ExitStatus;
/**
* Interface for running a job from its configuration.
*
* @author Lucas Ward
* @author Dave Syer
* @see JobConfiguration
* @see JobExecution
*/
public interface JobExecutor {
public ExitStatus run(JobConfiguration configuration, JobExecution execution) throws BatchCriticalException;
}

View File

@@ -0,0 +1,73 @@
/*
* Copyright 2006-2007 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.springframework.batch.core.executor;
import org.springframework.batch.core.configuration.StepConfiguration;
import org.springframework.batch.core.domain.StepExecution;
import org.springframework.batch.io.exception.BatchCriticalException;
import org.springframework.batch.repeat.ExitStatus;
/**
* Interface for processing a step. Implementations are free to process the step
* and return when finished, or to schedule the step for processing
* concurrently, or in the future. The status of the execution should be
* trackable with the step execution. The configuration should be treated as
* immutable.<br/>
*
* Because step execution parameters and policies can vary from step to step, a
* {@link StepExecutor} should be created by the caller using a
* {@link StepExecutorFactory}.
*
* @author Lucas Ward
* @author Dave Syer
*
*/
public interface StepExecutor {
/**
* Process the step according to the given configuration. Implementations
* can be expected to modify their state when this method is called, to take
* account of any policy information in the configuration. Thus it is not
* safe to re-use an instance of {@link StepExecutor} to process multiple
* concurrent executions.
*
* @param configuration
* the configuration to use when running the step. Contains a
* recipe for the business logic of an individual processing
* operation. Also used to determine policies for commit
* intervals and exception handling, for instance.
*
* @param stepExecution
* an entity representing the step to be executed
* @throws StepInterruptedException
* if the step is interrupted externally
* @throws BatchCriticalException
* if there is a problem that needs to be signalled to the
* caller
*/
ExitStatus process(StepConfiguration configuration,
StepExecution stepExecution) throws StepInterruptedException,
BatchCriticalException;
/**
* Apply the configuration by inspecting it to see if it has any relevant
* policy information. Should be called before any calls to process.
*
* @param configuration
*/
void applyConfiguration(StepConfiguration configuration);
}

View File

@@ -0,0 +1,44 @@
/*
* Copyright 2006-2007 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.springframework.batch.core.executor;
import org.springframework.batch.core.configuration.StepConfiguration;
/**
* Factory interface for creating or locating {@link StepExecutor} instances.
* Because step execution parameters and policies can vary from step to step, a
* {@link StepExecutor} should be created by the caller using a
* {@link StepExecutorFactory}. The factory is responsible for ensuring that
* the returned instance is appropriate for the configuration supplied. If the
* {@link StepExecutor} instance is stateful (which is normal) the factory
* should return a different instance for each call.
*
* @author Dave Syer
*
*/
public interface StepExecutorFactory {
/**
* Use the configuration given to create or locate a suitable
* {@link StepExecutor}.
*
* @param configuration a {@link StepConfiguration} instance.
* @return a {@link StepExecutor} that can be used to execute a step with
* the given configuration
*/
StepExecutor getExecutor(StepConfiguration configuration);
}

View File

@@ -0,0 +1,37 @@
/*
* Copyright 2006-2007 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.springframework.batch.core.executor;
import org.springframework.batch.io.exception.BatchCriticalException;
/**
* Exception to indicate the the lifecycle has been interrupted. The exception
* state indicated is not normally recoverable by batch application clients, but
* internally it is useful to force a check. The exception will be wrapped in a
* runtime exception (usually {@link BatchCriticalException} before reaching the
* client.
*
* @author Lucas Ward
* @author Dave Syer
*
*/
public class StepInterruptedException extends JobExecutionException {
public StepInterruptedException(String msg) {
super(msg);
}
}

View File

@@ -0,0 +1,7 @@
<html>
<body>
<p>
Interfaces and generic implementations of executor concerns.
</p>
</body>
</html>

View File

@@ -0,0 +1,11 @@
<html>
<body>
<p>
Core domain context for Spring Batch covering jobs, steps,
configuration and execution abstractions. Most classes here are
interfaces with implementations saved for specific applications. This
is the public API of Spring Batch. There is a reference
implementation of the core interfaces in the execution module.
</p>
</body>
</html>

View File

@@ -0,0 +1,41 @@
/*
* Copyright 2006-2007 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.springframework.batch.core.repository;
import org.springframework.batch.io.exception.BatchCriticalException;
/**
* @author Dave Syer
*
*/
public class BatchRestartException extends BatchCriticalException {
/**
* @param string the message
*/
public BatchRestartException(String string) {
super(string);
}
/**
* @param msg the cause
* @param t the message
*/
public BatchRestartException(String msg, Throwable t) {
super(msg, t);
}
}

View File

@@ -0,0 +1,118 @@
/*
* Copyright 2006-2007 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.springframework.batch.core.repository;
import org.springframework.batch.core.configuration.JobConfiguration;
import org.springframework.batch.core.domain.JobExecution;
import org.springframework.batch.core.domain.JobIdentifier;
import org.springframework.batch.core.domain.JobInstance;
import org.springframework.batch.core.domain.StepExecution;
import org.springframework.batch.core.domain.StepInstance;
/**
* <p>
* Repository for storing batch jobs and steps. Before using any methods, a Job
* must first be obtained using the findOrCreateJob method. Once a Job and it's
* related steps are obtained, they can be updated. It should be noted that any
* reconstituted steps are expected to contain restart data <strong>if the
* RestartPolicy associated with the step returns true, and RestartData exists.</strong>
* </p>
*
* Once a Job/Steps has been created, Job and Step executions can be created and
* associated with a job, by setting the JobId and StepId respectively. Once
* these Id's are set, an execution can be persisted. If the object is in a
* transient state (i.e. it has no id of it's own) then an ID will be created
* for that specific execution, and then stored ('saved'). (NOTE: The
* relationship between a Job/Step and Job/StepExecutions is 1:N) If an ID does
* exist, then the execution will be stored ('updated').
*
*
* @author Lucas Ward
*
*/
public interface JobRepository {
/**
* Find or create a job for a given {@link JobIdentifier} and configuration.
* If the job that is uniquely identified by {@link JobIdentifier} already
* exists, its persisted values (including ID) will be returned in a new
* {@link JobInstance} object. If no previous run is found, a new job will
* be created and returned.
*
* @param jobConfiguration
* describes the configuration for this job
* @param jobIdentifier
* identifies this particular run of the configuration across
* possible restarts
*
* @return a valid job
*
*/
public JobInstance findOrCreateJob(JobConfiguration jobConfiguration,
JobIdentifier jobIdentifier);
/**
* Update a Job.
*
* Preconditions: Job must contain a valid ID. This can be ensured by first
* obtaining a job from findOrCreateJob.
*
* @param job
* @see JobInstance
*/
public void update(JobInstance job);
/**
* Save or Update a {@link JobExecution}. If no ID is found a new instance
* will be saved. If an ID does exist it will be updated. The ID should only
* be assigned to a {@link JobExecution} by calling this method - it should
* be left blank on the first call, and assigned by the
* {@link JobRepository}.
*
* Preconditions: {@link JobExecution} must contain a valid
* {@link JobInstance}.
*
* @param jobInstance
*/
public void saveOrUpdate(JobExecution jobExecution);
/**
* Update a step.
*
* Preconditions: {@link StepInstance} must contain a valid ID. This can be
* ensured by first obtaining a {@link JobInstance} from findOrCreateJob,
* and accessing it's step list.
*
* @param step
* @see StepInstance
*/
public void update(StepInstance step);
/**
* Save or Update a StepExecution. If no ID is found a new instance will be
* created. (saved). If an ID does exist it will be updated. It is not
* advisable that an ID be assigned to a JobExecution before calling this
* method. Instead, it should be left blank, to be assigned by a
* JobRepository.
*
* Preconditions: StepExecution must have a valid StepId.
*
* @param jobInstance
*/
public void saveOrUpdate(StepExecution stepExecution);
}

View File

@@ -0,0 +1,34 @@
/*
* Copyright 2006-2007 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.springframework.batch.core.repository;
/**
* This exception identifies that a batch domain object is invalid, which
* is generally caused by an invalid ID. (An ID which doesn't exist in the database).
*
* @author Lucas Ward
* @author Dave Syer
*
*/
public class NoSuchBatchDomainObjectException extends RuntimeException {
private static final long serialVersionUID = 4399621765157283111L;
public NoSuchBatchDomainObjectException(String message){
super(message);
}
}

View File

@@ -0,0 +1,7 @@
<html>
<body>
<p>
Interfaces and generic implementations of repository concerns.
</p>
</body>
</html>

View File

@@ -0,0 +1,44 @@
/*
* Copyright 2006-2007 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.springframework.batch.core.runtime;
import org.springframework.batch.core.domain.JobIdentifier;
/**
* A factory for {@link JobIdentifier} instances. A job configuration can be
* executed with many possible runtime parameters, which identify the instance
* of the job. This factory allows job identifiers to be created with different
* properties according to the {@link JobIdentifier} strategy required. For
* example some projects or jobs need a schedule date as part of the
* {@link JobIdentifier} and some do not (e.g. for an ad-hoc execution a simple
* label might be enough).
*
*
* @author Dave Syer
*
*/
public interface JobIdentifierFactory {
/**
* Get a new {@link JobIdentifier} instance.
*
* @param name
* the name of the job configuration.
* @return a {@link JobIdentifier} with the same name.
*/
public JobIdentifier getJobIdentifier(String name);
}

View File

@@ -0,0 +1,76 @@
/*
* Copyright 2006-2007 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.springframework.batch.core.runtime;
import org.apache.commons.lang.builder.EqualsBuilder;
import org.apache.commons.lang.builder.HashCodeBuilder;
import org.springframework.batch.core.domain.JobIdentifier;
import org.springframework.util.ClassUtils;
/**
* @author Dave Syer
*
*/
public class SimpleJobIdentifier implements JobIdentifier {
private String name;
/**
* Default constructor.
*/
public SimpleJobIdentifier() {
super();
}
/**
* Convenience constructor with name.
* @param name
*/
public SimpleJobIdentifier(String name) {
super();
this.name = name;
}
/* (non-Javadoc)
* @see org.springframework.batch.core.runtime.JobIdentifier#getName()
*/
public String getName() {
return this.name;
}
/**
* Public setter for the name.
*
* @param name the name to set
*/
public void setName(String name) {
this.name = name;
}
public String toString() {
return ClassUtils.getShortName(getClass())+": name=" + name;
}
public boolean equals(Object obj) {
return EqualsBuilder.reflectionEquals(this, obj);
}
public int hashCode() {
return HashCodeBuilder.reflectionHashCode(this);
}
}

View File

@@ -0,0 +1,26 @@
package org.springframework.batch.core.runtime;
import org.springframework.batch.core.domain.JobIdentifier;
/**
* Factory for {@link SimpleJobIdentifier} instances.
*
* @author Dave Syer
*
*/
public class SimpleJobIdentifierFactory implements JobIdentifierFactory {
/**
* Create a {@link JobIdentifier} with the given name.
*
* @param name the name for the {@link JobIdentifier}
* @return a {@link JobIdentifier} with the given name.
*
* @see org.springframework.batch.core.runtime.JobIdentifierFactory#getJobIdentifier(java.lang.String)
*/
public JobIdentifier getJobIdentifier(String name) {
return new SimpleJobIdentifier(name);
}
}

View File

@@ -0,0 +1,7 @@
<html>
<body>
<p>
Interfaces and generic implementations of runtime concerns.
</p>
</body>
</html>

View File

@@ -0,0 +1,39 @@
/*
* Copyright 2006-2007 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.springframework.batch.core.tasklet;
/**
* Marker interface for {@link Tasklet} implementations that are able to take a
* recovery action in the case that an exception is thrown inside
* {@link Tasklet#execute()}. Containers must ensure that the recover method is
* called in a different transactional context than the failed execution, e.g.
* by creating a new transaction with propagation REQUIRES_NEW.
*
* @author Dave Syer
*
*/
public interface Recoverable {
/**
* Take some action to recover the current batch operation. E.g. send a
* message to an error queue, or append a bad record to a special file.
*
* @param cause the exception that caused the recovery step to be called.
*/
void recover(Throwable cause);
}

View File

@@ -0,0 +1,56 @@
/*
* Copyright 2006-2007 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.springframework.batch.core.tasklet;
import org.springframework.batch.core.configuration.StepConfiguration;
import org.springframework.batch.repeat.ExitStatus;
/**
* The primary interface describing the touch-point between the batch developer
* and a spring-batch execution. The execute method will be called to indicate
* to the developer that it is time to execute business logic. The value
* returned from this method will indicate whether or not processing should
* continue. It is important to note that in the vast majority of cases this
* class should not be directly implemented by batch developers for processing.
* Most batch processing is significantly more complex than simple execute and
* should logically be broken into a minimum of two processes (read and write).
* However, many architecture teams may find creating their own implementations
* of this interface useful for differentiating different batch job types, or
* for creating more flexibility within their batch jobs.
*
* @see StepConfiguration
* @author Lucas Ward
* @author Dave Syer
*
*/
public interface Tasklet {
/**
* Primary batch processing driver. All processing of batch business data
* should be handled within this method. Any processing which intends to
* control the flow of the batch lifecycle by throwing exceptions (such as
* BatchCriticalExeception) should throw them within this method. Doing so
* outside of this method will prevent the architecture from gracefully
* shutting down and providing such features as transaction rollback.
*
* @return ExitStatus indicating whether the processing should continue (i.e.
* false when data are exhausted).
* @see org.springframework.batch.repeat.ExitStatus
*/
public ExitStatus execute() throws Exception;
}

View File

@@ -0,0 +1,7 @@
<html>
<body>
<p>
Interfaces and generic implementations of tasklet concerns.
</p>
</body>
</html>

View File

@@ -0,0 +1,8 @@
<html>
<body>
<p>
The Core domain concepts expressed as interfaces and generic
implementations.
</p>
</body>
</html>