View Javadoc

1   /*
2    * Copyright 2006-2007 the original author or authors.
3    *
4    * Licensed under the Apache License, Version 2.0 (the "License");
5    * you may not use this file except in compliance with the License.
6    * You may obtain a copy of the License at
7    *
8    *      http://www.apache.org/licenses/LICENSE-2.0
9    *
10   * Unless required by applicable law or agreed to in writing, software
11   * distributed under the License is distributed on an "AS IS" BASIS,
12   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13   * See the License for the specific language governing permissions and
14   * limitations under the License.
15   */
16  
17  package org.springframework.batch.core;
18  
19  import org.springframework.util.Assert;
20  
21  /**
22   * Batch domain object representing a uniquely identifiable job run - it's
23   * identity is given by the pair {@link Job} and {@link JobParameters}.
24   * JobInstance can be restarted multiple times in case of execution failure and
25   * it's lifecycle ends with first successful execution.
26   * 
27   * Trying to execute an existing JobIntance that has already completed
28   * successfully will result in error. Error will be raised also for an attempt
29   * to restart a failed JobInstance if the Job is not restartable.
30   * 
31   * @see Job
32   * @see JobParameters
33   * @see JobExecution
34   * 
35   * @author Lucas Ward
36   * @author Dave Syer
37   * @author Robert Kasanicky
38   * 
39   */
40  public class JobInstance extends Entity {
41  
42  	private final JobParameters jobParameters;
43  
44  	private final String jobName;
45  
46  	public JobInstance(Long id, JobParameters jobParameters, String jobName) {
47  		super(id);
48  		Assert.hasLength(jobName);
49  		// Assert.hasLength(job.getName());
50  		this.jobParameters = jobParameters == null ? new JobParameters() : jobParameters;
51  		this.jobName = jobName;
52  	}
53  
54  	/**
55  	 * @return {@link JobParameters}
56  	 */
57  	public JobParameters getJobParameters() {
58  		return jobParameters;
59  	}
60  
61  	/**
62  	 * @return the job name. (Equivalent to getJob().getName())
63  	 */
64  	public String getJobName() {
65  		return jobName;
66  	}
67  
68  	public String toString() {
69  		return super.toString() + ", JobParameters=[" + jobParameters + "]" + ", Job=[" + jobName + "]";
70  	}
71  
72  }