View Javadoc

1   /*
2    * Copyright 2006-2013 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  @SuppressWarnings("unchecked")
41  public class JobInstance extends Entity {
42  
43  	private final JobParameters jobParameters;
44  
45  	private final String jobName;
46  
47  	public JobInstance(Long id, JobParameters jobParameters, String jobName) {
48  		super(id);
49  		Assert.hasLength(jobName);
50  		// Assert.hasLength(job.getName());
51  		this.jobParameters = jobParameters == null ? new JobParameters() : jobParameters;
52  		this.jobName = jobName;
53  	}
54  
55  	/**
56  	 * @return {@link JobParameters}
57  	 */
58  	public JobParameters getJobParameters() {
59  		return jobParameters;
60  	}
61  
62  	/**
63  	 * @return the job name. (Equivalent to getJob().getName())
64  	 */
65  	public String getJobName() {
66  		return jobName;
67  	}
68  
69  	@Override
70  	public String toString() {
71  		return super.toString() + ", JobParameters=[" + jobParameters + "]" + ", Job=[" + jobName + "]";
72  	}
73  
74  }