001/* 002 * Copyright 2006-2018 the original author or authors. 003 * 004 * Licensed under the Apache License, Version 2.0 (the "License"); 005 * you may not use this file except in compliance with the License. 006 * You may obtain a copy of the License at 007 * 008 * https://www.apache.org/licenses/LICENSE-2.0 009 * 010 * Unless required by applicable law or agreed to in writing, software 011 * distributed under the License is distributed on an "AS IS" BASIS, 012 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 013 * See the License for the specific language governing permissions and 014 * limitations under the License. 015 */ 016 017package org.springframework.batch.core; 018 019import org.springframework.util.Assert; 020 021/** 022 * Batch domain object representing a uniquely identifiable job run. 023 * JobInstance can be restarted multiple times in case of execution failure and 024 * it's lifecycle ends with first successful execution. 025 * 026 * Trying to execute an existing JobInstance that has already completed 027 * successfully will result in error. Error will be raised also for an attempt 028 * to restart a failed JobInstance if the Job is not restartable. 029 * 030 * @see Job 031 * @see JobParameters 032 * @see JobExecution 033 * @see javax.batch.runtime.JobInstance 034 * 035 * @author Lucas Ward 036 * @author Dave Syer 037 * @author Robert Kasanicky 038 * @author Michael Minella 039 * @author Mahmoud Ben Hassine 040 * 041 */ 042@SuppressWarnings("serial") 043public class JobInstance extends Entity implements javax.batch.runtime.JobInstance{ 044 045 private final String jobName; 046 047 public JobInstance(Long id, String jobName) { 048 super(id); 049 Assert.hasLength(jobName, "A jobName is required"); 050 this.jobName = jobName; 051 } 052 053 /** 054 * @return the job name. (Equivalent to getJob().getName()) 055 */ 056 @Override 057 public String getJobName() { 058 return jobName; 059 } 060 061 @Override 062 public String toString() { 063 return super.toString() + ", Job=[" + jobName + "]"; 064 } 065 066 @Override 067 public long getInstanceId() { 068 return super.getId(); 069 } 070}