Skip to content

Commit 2d874ff

Browse files
committed
Merge pull request #204 from mminella/BATCH-2007
2 parents c7176a7 + dbc8292 commit 2d874ff

File tree

63 files changed

+2057
-290
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

63 files changed

+2057
-290
lines changed

spring-batch-core-tests/src/test/java/org/springframework/batch/core/test/step/StepExecutionSerializationUtilsTests.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ public class StepExecutionSerializationUtilsTests {
4141
@Test
4242
public void testCycle() throws Exception {
4343
StepExecution stepExecution = new StepExecution("step", new JobExecution(new JobInstance(123L,
44-
"job"), 321L, new JobParameters()), 11L);
44+
"job"), 321L, new JobParameters(), null), 11L);
4545
stepExecution.getExecutionContext().put("foo.bar.spam", 123);
4646
StepExecution result = getCopy(stepExecution);
4747
assertEquals(stepExecution, result);
@@ -58,9 +58,10 @@ public void testMultipleCycles() throws Throwable {
5858
CompletionService<StepExecution> completionService = new ExecutorCompletionService<StepExecution>(executor);
5959

6060
for (int i = 0; i < repeats; i++) {
61-
final JobExecution jobExecution = new JobExecution(new JobInstance(123L, "job"), 321L, new JobParameters());
61+
final JobExecution jobExecution = new JobExecution(new JobInstance(123L, "job"), 321L, new JobParameters(), null);
6262
for (int j = 0; j < threads; j++) {
6363
completionService.submit(new Callable<StepExecution>() {
64+
@Override
6465
public StepExecution call() throws Exception {
6566
final StepExecution stepExecution = jobExecution.createStepExecution("step");
6667
stepExecution.getExecutionContext().put("foo.bar.spam", 123);

spring-batch-core/src/main/java/org/springframework/batch/core/JobExecution.java

Lines changed: 19 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -62,16 +62,27 @@ public class JobExecution extends Entity {
6262

6363
private transient volatile List<Throwable> failureExceptions = new CopyOnWriteArrayList<Throwable>();
6464

65+
private final String jobConfigurationName;
66+
6567
/**
6668
* Because a JobExecution isn't valid unless the job is set, this
6769
* constructor is the only valid one from a modeling point of view.
6870
*
6971
* @param job the job of which this execution is a part
7072
*/
71-
public JobExecution(JobInstance job, Long id, JobParameters jobParameters) {
73+
public JobExecution(JobInstance job, Long id, JobParameters jobParameters, String jobConfigurationName) {
7274
super(id);
7375
this.jobInstance = job;
7476
this.jobParameters = jobParameters == null ? new JobParameters() : jobParameters;
77+
this.jobConfigurationName = jobConfigurationName;
78+
}
79+
80+
public JobExecution(JobInstance job, JobParameters jobParameters, String jobConfigurationName) {
81+
this(job, null, jobParameters, jobConfigurationName);
82+
}
83+
84+
public JobExecution(Long id, JobParameters jobParameters, String jobConfigurationName) {
85+
this(null, id, jobParameters, jobConfigurationName);
7586
}
7687

7788
/**
@@ -80,15 +91,15 @@ public JobExecution(JobInstance job, Long id, JobParameters jobParameters) {
8091
* @param job the enclosing {@link JobInstance}
8192
*/
8293
public JobExecution(JobInstance job, JobParameters jobParameters) {
83-
this(job, null, jobParameters);
94+
this(job, null, jobParameters, null);
8495
}
8596

8697
public JobExecution(Long id, JobParameters jobParameters) {
87-
this(null, id, jobParameters);
98+
this(null, id, jobParameters, null);
8899
}
89100

90101
public JobExecution(Long id) {
91-
this(null, id, null);
102+
this(null, id, null, null);
92103
}
93104

94105
public JobParameters getJobParameters() {
@@ -256,6 +267,10 @@ public void setCreateTime(Date createTime) {
256267
this.createTime = createTime;
257268
}
258269

270+
public String getJobConfigurationName() {
271+
return this.jobConfigurationName;
272+
}
273+
259274
/**
260275
* Package private method for re-constituting the step executions from
261276
* existing instances.

spring-batch-core/src/main/java/org/springframework/batch/core/explore/JobExplorer.java

Lines changed: 23 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2006-2007 the original author or authors.
2+
* Copyright 2006-2013 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -21,23 +21,25 @@
2121
import org.springframework.batch.core.JobExecution;
2222
import org.springframework.batch.core.JobInstance;
2323
import org.springframework.batch.core.StepExecution;
24+
import org.springframework.batch.core.launch.NoSuchJobException;
2425
import org.springframework.batch.item.ExecutionContext;
2526

2627
/**
2728
* Entry point for browsing executions of running or historical jobs and steps.
2829
* Since the data may be re-hydrated from persistent storage, it may not contain
2930
* volatile fields that would have been present when the execution was active.
30-
*
31+
*
3132
* @author Dave Syer
32-
*
33+
* @author Michael Minella
34+
*
3335
* @since 2.0
3436
*/
3537
public interface JobExplorer {
3638

3739
/**
3840
* Fetch {@link JobInstance} values in descending order of creation (and
3941
* therefore usually of first execution).
40-
*
42+
*
4143
* @param jobName the name of the job to query
4244
* @param start the start index of the instances to return
4345
* @param count the maximum number of instances to return
@@ -51,7 +53,7 @@ public interface JobExplorer {
5153
* the parent {@link JobInstance} and associated {@link ExecutionContext}
5254
* and {@link StepExecution} instances (also including their execution
5355
* contexts).
54-
*
56+
*
5557
* @param executionId the job execution id
5658
* @return the {@link JobExecution} with this id, or null if not found
5759
*/
@@ -62,11 +64,11 @@ public interface JobExplorer {
6264
* {@link JobExecution} id. The execution context for the step should be
6365
* available in the result, and the parent job execution should have its
6466
* primitive properties, but may not contain the job instance information.
65-
*
67+
*
6668
* @param jobExecutionId the parent job execution id
6769
* @param stepExecutionId the step execution id
6870
* @return the {@link StepExecution} with this id, or null if not found
69-
*
71+
*
7072
* @see #getJobExecution(Long)
7173
*/
7274
StepExecution getStepExecution(Long jobExecutionId, Long stepExecutionId);
@@ -82,7 +84,7 @@ public interface JobExplorer {
8284
* executions may not be fully hydrated (e.g. their execution context may be
8385
* missing), depending on the implementation. Use
8486
* {@link #getStepExecution(Long, Long)} to hydrate them in that case.
85-
*
87+
*
8688
* @param jobInstance the {@link JobInstance} to query
8789
* @return the set of all executions for the specified {@link JobInstance}
8890
*/
@@ -93,7 +95,7 @@ public interface JobExplorer {
9395
* not be fully hydrated (e.g. their execution context may be missing),
9496
* depending on the implementation. Use
9597
* {@link #getStepExecution(Long, Long)} to hydrate them in that case.
96-
*
98+
*
9799
* @param jobName the name of the job
98100
* @return the set of running executions for jobs with the specified name
99101
*/
@@ -102,9 +104,20 @@ public interface JobExplorer {
102104
/**
103105
* Query the repository for all unique {@link JobInstance} names (sorted
104106
* alphabetically).
105-
*
107+
*
106108
* @return the set of job names that have been executed
107109
*/
108110
List<String> getJobNames();
109111

112+
/**
113+
* Query the repository for the number of unique {@link JobInstance}s
114+
* associated with the supplied job name.
115+
*
116+
* @param jobName the name of the job to query for
117+
* @return the number of {@link JobInstance}s that exist within the
118+
* associated job repository
119+
* @throws NoSuchJobException
120+
*/
121+
int getJobInstanceCount(String jobName) throws NoSuchJobException;
122+
110123
}

spring-batch-core/src/main/java/org/springframework/batch/core/explore/support/SimpleJobExplorer.java

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
import org.springframework.batch.core.JobInstance;
2424
import org.springframework.batch.core.StepExecution;
2525
import org.springframework.batch.core.explore.JobExplorer;
26+
import org.springframework.batch.core.launch.NoSuchJobException;
2627
import org.springframework.batch.core.repository.dao.ExecutionContextDao;
2728
import org.springframework.batch.core.repository.dao.JobExecutionDao;
2829
import org.springframework.batch.core.repository.dao.JobInstanceDao;
@@ -33,6 +34,7 @@
3334
*
3435
* @author Dave Syer
3536
* @author Lucas Ward
37+
* @author Michael Minella
3638
*
3739
* @see JobExplorer
3840
* @see JobInstanceDao
@@ -180,6 +182,14 @@ public List<String> getJobNames() {
180182
return jobInstanceDao.getJobNames();
181183
}
182184

185+
/* (non-Javadoc)
186+
* @see org.springframework.batch.core.explore.JobExplorer#getJobInstanceCount(java.lang.String)
187+
*/
188+
@Override
189+
public int getJobInstanceCount(String jobName) throws NoSuchJobException {
190+
return jobInstanceDao.getJobInstanceCount(jobName);
191+
}
192+
183193
/*
184194
* Find all dependencies for a JobExecution, including JobInstance (which
185195
* requires JobParameters) plus StepExecutions
@@ -198,5 +208,4 @@ private void getStepExecutionDependencies(StepExecution stepExecution) {
198208
stepExecution.setExecutionContext(ecDao.getExecutionContext(stepExecution));
199209
}
200210
}
201-
202211
}

spring-batch-core/src/main/java/org/springframework/batch/core/jsr/JobContext.java

Lines changed: 33 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121

2222
import org.springframework.batch.core.ExitStatus;
2323
import org.springframework.batch.core.JobExecution;
24+
import org.springframework.batch.core.converter.JobParametersConverter;
2425
import org.springframework.util.Assert;
2526

2627
/**
@@ -35,56 +36,86 @@ public class JobContext implements javax.batch.runtime.context.JobContext {
3536

3637
private JobExecution jobExecution;
3738
private Object transientUserData;
39+
private JobParametersConverter jobParametersConverter;
3840

3941
/**
4042
* @param jobExecution for the related job
4143
*/
42-
public JobContext(JobExecution jobExecution) {
44+
public JobContext(JobExecution jobExecution, JobParametersConverter jobParametersConverter) {
4345
Assert.notNull(jobExecution, "A JobExecution is required");
46+
Assert.notNull(jobParametersConverter, "A ParametersConverter is required");
4447

4548
this.jobExecution = jobExecution;
49+
this.jobParametersConverter = jobParametersConverter;
4650
}
4751

52+
/* (non-Javadoc)
53+
* @see javax.batch.runtime.context.JobContext#getJobName()
54+
*/
4855
@Override
4956
public String getJobName() {
5057
return jobExecution.getJobInstance().getJobName();
5158
}
5259

60+
/* (non-Javadoc)
61+
* @see javax.batch.runtime.context.JobContext#getTransientUserData()
62+
*/
5363
@Override
5464
public Object getTransientUserData() {
5565
return transientUserData;
5666
}
5767

68+
/* (non-Javadoc)
69+
* @see javax.batch.runtime.context.JobContext#setTransientUserData(java.lang.Object)
70+
*/
5871
@Override
5972
public void setTransientUserData(Object data) {
6073
transientUserData = data;
6174
}
6275

76+
/* (non-Javadoc)
77+
* @see javax.batch.runtime.context.JobContext#getInstanceId()
78+
*/
6379
@Override
6480
public long getInstanceId() {
6581
return jobExecution.getJobInstance().getId();
6682
}
6783

84+
/* (non-Javadoc)
85+
* @see javax.batch.runtime.context.JobContext#getExecutionId()
86+
*/
6887
@Override
6988
public long getExecutionId() {
7089
return jobExecution.getId();
7190
}
7291

92+
/* (non-Javadoc)
93+
* @see javax.batch.runtime.context.JobContext#getProperties()
94+
*/
7395
@Override
7496
public Properties getProperties() {
75-
return jobExecution.getJobParameters().toProperties();
97+
return jobParametersConverter.getProperties(this.jobExecution.getJobParameters());
7698
}
7799

100+
/* (non-Javadoc)
101+
* @see javax.batch.runtime.context.JobContext#getBatchStatus()
102+
*/
78103
@Override
79104
public BatchStatus getBatchStatus() {
80105
return jobExecution.getStatus().getBatchStatus();
81106
}
82107

108+
/* (non-Javadoc)
109+
* @see javax.batch.runtime.context.JobContext#getExitStatus()
110+
*/
83111
@Override
84112
public String getExitStatus() {
85113
return jobExecution.getExitStatus().getExitCode();
86114
}
87115

116+
/* (non-Javadoc)
117+
* @see javax.batch.runtime.context.JobContext#setExitStatus(java.lang.String)
118+
*/
88119
@Override
89120
public void setExitStatus(String status) {
90121
jobExecution.setExitStatus(new ExitStatus(status));

0 commit comments

Comments
 (0)