本文整理汇总了Java中org.springframework.batch.core.JobInstance类的典型用法代码示例。如果您正苦于以下问题:Java JobInstance类的具体用法?Java JobInstance怎么用?Java JobInstance使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
JobInstance类属于org.springframework.batch.core包,在下文中一共展示了JobInstance类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: testGetJobs
import org.springframework.batch.core.JobInstance; //导入依赖的package包/类
@Disabled
@Test
public void testGetJobs() throws Exception {
Set<String> jobNames = new HashSet<>();
jobNames.add("job1");
jobNames.add("job2");
jobNames.add("job3");
Long job1Id = 1L;
Long job2Id = 2L;
List<Long> jobExecutions = new ArrayList<>();
jobExecutions.add(job1Id);
JobInstance jobInstance = new JobInstance(job1Id, "job1");
expect(jobOperator.getJobNames()).andReturn(jobNames).anyTimes();
expect(jobOperator.getJobInstances(eq("job1"), eq(0), eq(1))).andReturn(jobExecutions);
expect(jobExplorer.getJobInstance(eq(job1Id))).andReturn(jobInstance);
// expect(jobOperator.getJobInstances(eq("job2"), eq(0), eq(1))).andReturn(null);
replayAll();
assertThat(service.getJobs(), nullValue());
}
示例2: createSampleJob
import org.springframework.batch.core.JobInstance; //导入依赖的package包/类
private static void createSampleJob(String jobName, int jobExecutionCount) {
JobInstance instance = jobRepository.createJobInstance(jobName, new JobParameters());
jobInstances.add(instance);
TaskExecution taskExecution = dao.createTaskExecution(jobName, new Date(), new ArrayList<String>(), null);
Map<String, JobParameter> jobParameterMap = new HashMap<>();
jobParameterMap.put("foo", new JobParameter("FOO", true));
jobParameterMap.put("bar", new JobParameter("BAR", false));
JobParameters jobParameters = new JobParameters(jobParameterMap);
JobExecution jobExecution = null;
for (int i = 0; i < jobExecutionCount; i++) {
jobExecution = jobRepository.createJobExecution(instance, jobParameters, null);
taskBatchDao.saveRelationship(taskExecution, jobExecution);
StepExecution stepExecution = new StepExecution("foobar", jobExecution);
jobRepository.add(stepExecution);
}
}
示例3: assertCorrectMixins
import org.springframework.batch.core.JobInstance; //导入依赖的package包/类
private void assertCorrectMixins(RestTemplate restTemplate) {
boolean containsMappingJackson2HttpMessageConverter = false;
for (HttpMessageConverter<?> converter : restTemplate.getMessageConverters()) {
if (converter instanceof MappingJackson2HttpMessageConverter) {
containsMappingJackson2HttpMessageConverter = true;
final MappingJackson2HttpMessageConverter jacksonConverter = (MappingJackson2HttpMessageConverter) converter;
final ObjectMapper objectMapper = jacksonConverter.getObjectMapper();
assertNotNull(objectMapper.findMixInClassFor(JobExecution.class));
assertNotNull(objectMapper.findMixInClassFor(JobParameters.class));
assertNotNull(objectMapper.findMixInClassFor(JobParameter.class));
assertNotNull(objectMapper.findMixInClassFor(JobInstance.class));
assertNotNull(objectMapper.findMixInClassFor(ExitStatus.class));
assertNotNull(objectMapper.findMixInClassFor(StepExecution.class));
assertNotNull(objectMapper.findMixInClassFor(ExecutionContext.class));
assertNotNull(objectMapper.findMixInClassFor(StepExecutionHistory.class));
}
}
if (!containsMappingJackson2HttpMessageConverter) {
fail("Expected that the restTemplate's list of Message Converters contained a "
+ "MappingJackson2HttpMessageConverter");
}
}
示例4: mapRow
import org.springframework.batch.core.JobInstance; //导入依赖的package包/类
/**
* @param resultSet Set the result set
* @param rowNumber Set the row number
* @throws SQLException if there is a problem
* @return a job execution instance
*/
public final JobExecution mapRow(final ResultSet resultSet,
final int rowNumber) throws SQLException {
JobInstance jobInstance = new JobInstance(resultSet.getBigDecimal(
"JOB_INSTANCE_ID").longValue(),
new JobParameters(), resultSet.getString("JOB_NAME"));
JobExecution jobExecution = new JobExecution(jobInstance,
resultSet.getBigDecimal("JOB_EXECUTION_ID").longValue());
jobExecution.setStartTime(resultSet.getTimestamp("START_TIME"));
jobExecution.setCreateTime(resultSet.getTimestamp("CREATE_TIME"));
jobExecution.setEndTime(resultSet.getTimestamp("END_TIME"));
jobExecution.setStatus(BatchStatus.valueOf(resultSet
.getString("STATUS")));
ExitStatus exitStatus = new ExitStatus(
resultSet.getString("EXIT_CODE"),
resultSet.getString("EXIT_MESSAGE"));
jobExecution.setExitStatus(exitStatus);
return jobExecution;
}
示例5: list
import org.springframework.batch.core.JobInstance; //导入依赖的package包/类
@Override
public List<JobInstance> list(Integer page, Integer size) {
HttpEntity<JobInstance> requestEntity = new HttpEntity<JobInstance>(httpHeaders);
Map<String,Object> uriVariables = new HashMap<String,Object>();
uriVariables.put("resource", resourceDir);
if(size == null) {
uriVariables.put("limit", "");
} else {
uriVariables.put("limit", size);
}
if(page == null) {
uriVariables.put("start", "");
} else {
uriVariables.put("start", page);
}
ParameterizedTypeReference<List<JobInstance>> typeRef = new ParameterizedTypeReference<List<JobInstance>>() {};
HttpEntity<List<JobInstance>> responseEntity = restTemplate.exchange(baseUri + "/{resource}?limit={limit}&start={start}", HttpMethod.GET,
requestEntity, typeRef,uriVariables);
return responseEntity.getBody();
}
示例6: create
import org.springframework.batch.core.JobInstance; //导入依赖的package包/类
/**
* @param jobInstance
* the job instance to save
* @return A response entity containing a newly created job instance
*/
@RequestMapping(value = "/jobInstance",
method = RequestMethod.POST)
public final ResponseEntity<JobInstance> create(@RequestBody final JobInstance jobInstance) {
HttpHeaders httpHeaders = new HttpHeaders();
try {
httpHeaders.setLocation(new URI(baseUrl + "/jobInstance/"
+ jobInstance.getId()));
} catch (URISyntaxException e) {
logger.error(e.getMessage());
}
service.save(jobInstance);
ResponseEntity<JobInstance> response = new ResponseEntity<JobInstance>(
jobInstance, httpHeaders, HttpStatus.CREATED);
return response;
}
示例7: createJobInstance
import org.springframework.batch.core.JobInstance; //导入依赖的package包/类
/**
* @param jobId
* Set the job id
* @param jobName
* Set the job name
* @param authorityName
* Set the authority name
* @param version
* Set the version
*/
public void createJobInstance(String jobId,
String jobName, String authorityName,
String version) {
enableAuthentication();
Long id = null;
if (jobId != null && jobId.length() > 0) {
id = Long.parseLong(jobId);
}
Integer v = null;
if (version != null && version.length() > 0) {
v = Integer.parseInt(version);
}
Map<String, JobParameter> jobParameterMap = new HashMap<String, JobParameter>();
if (authorityName != null && authorityName.length() > 0) {
jobParameterMap.put("authority.name", new JobParameter(
authorityName));
}
JobParameters jobParameters = new JobParameters(jobParameterMap);
JobInstance jobInstance = new JobInstance(id, jobParameters, jobName);
jobInstance.setVersion(v);
data.push(jobInstance);
jobInstanceService.save(jobInstance);
disableAuthentication();
}
示例8: setupModule
import org.springframework.batch.core.JobInstance; //导入依赖的package包/类
@Override
public final void setupModule(final SetupContext setupContext) {
SimpleKeyDeserializers keyDeserializers = new SimpleKeyDeserializers();
keyDeserializers.addDeserializer(Location.class,
new GeographicalRegionKeyDeserializer());
setupContext.addKeyDeserializers(keyDeserializers);
SimpleSerializers simpleSerializers = new SimpleSerializers();
simpleSerializers.addSerializer(new JobInstanceSerializer());
simpleSerializers.addSerializer(new JobExecutionSerializer());
setupContext.addSerializers(simpleSerializers);
SimpleDeserializers simpleDeserializers = new SimpleDeserializers();
simpleDeserializers.addDeserializer(JobInstance.class,
new JobInstanceDeserializer());
simpleDeserializers.addDeserializer(JobExecution.class,
new JobExecutionDeserializer(jobInstanceService));
simpleDeserializers.addDeserializer(JobExecutionException.class,
new JobExecutionExceptionDeserializer());
setupContext.addDeserializers(simpleDeserializers);
}
示例9: testWriteJobInstance
import org.springframework.batch.core.JobInstance; //导入依赖的package包/类
/**
*
* @throws Exception
* if there is a problem serializing the object
*/
@Test
public void testWriteJobInstance() throws Exception {
Map<String, JobParameter> jobParameterMap
= new HashMap<String, JobParameter>();
jobParameterMap.put("authority.name", new JobParameter("test"));
JobInstance jobInstance = new JobInstance(1L, new JobParameters(
jobParameterMap), "testJob");
jobInstance.setVersion(1);
try {
objectMapper.writeValueAsString(jobInstance);
} catch (Exception e) {
fail("No exception expected here");
}
}
示例10: unmarshal
import org.springframework.batch.core.JobInstance; //导入依赖的package包/类
@Override
public StepExecution unmarshal(AdaptedStepExecution v) throws Exception {
JobExecution je = new JobExecution(v.getJobExecutionId());
JobInstance ji = new JobInstance(v.getJobInstanceId(), v.getJobName());
je.setJobInstance(ji);
StepExecution step = new StepExecution(v.getStepName(), je);
step.setId(v.getId());
step.setStartTime(v.getStartTime());
step.setEndTime(v.getEndTime());
step.setReadSkipCount(v.getReadSkipCount());
step.setWriteSkipCount(v.getWriteSkipCount());
step.setProcessSkipCount(v.getProcessSkipCount());
step.setReadCount(v.getReadCount());
step.setWriteCount(v.getWriteCount());
step.setFilterCount(v.getFilterCount());
step.setRollbackCount(v.getRollbackCount());
step.setExitStatus(new ExitStatus(v.getExitCode()));
step.setLastUpdated(v.getLastUpdated());
step.setVersion(v.getVersion());
step.setStatus(v.getStatus());
step.setExecutionContext(v.getExecutionContext());
return step;
}
示例11: marshallStepExecutionTest
import org.springframework.batch.core.JobInstance; //导入依赖的package包/类
@Test
public void marshallStepExecutionTest() throws Exception {
JobInstance jobInstance = new JobInstance(1234L, "test");
JobExecution jobExecution = new JobExecution(123L);
jobExecution.setJobInstance(jobInstance);
StepExecution step = new StepExecution("testStep", jobExecution);
step.setLastUpdated(new Date(System.currentTimeMillis()));
StepExecutionAdapter adapter = new StepExecutionAdapter();
AdaptedStepExecution adStep = adapter.marshal(step);
jaxb2Marshaller.marshal(adStep, result);
Fragment frag = new Fragment(new DOMBuilder().build(doc));
frag.setNamespaces(getNamespaceProvider().getNamespaces());
frag.prettyPrint();
frag.assertElementExists("/msb:stepExecution");
frag.assertElementExists("/msb:stepExecution/msb:lastUpdated");
frag.assertElementValue("/msb:stepExecution/msb:stepName", "testStep");
}
开发者ID:marklogic-community,项目名称:marklogic-spring-batch,代码行数:18,代码来源:MarshallSpringBatchPojoToXmlTest.java
示例12: testGetLastInstances
import org.springframework.batch.core.JobInstance; //导入依赖的package包/类
/**
* Create and retrieve a job instance.
*/
@Transactional
@Test
public void testGetLastInstances() throws Exception {
testCreateAndRetrieve();
// unrelated job instance that should be ignored by the query
jobInstanceDao.createJobInstance("anotherJob", new JobParameters());
// we need two instances of the same job to check ordering
jobInstanceDao.createJobInstance(fooJob, new JobParameters());
List<JobInstance> jobInstances = jobInstanceDao.getJobInstances(fooJob, 0, 2);
assertEquals(2, jobInstances.size());
assertEquals(fooJob, jobInstances.get(0).getJobName());
assertEquals(fooJob, jobInstances.get(1).getJobName());
assertEquals(Integer.valueOf(0), jobInstances.get(0).getVersion());
assertEquals(Integer.valueOf(0), jobInstances.get(1).getVersion());
//assertTrue("Last instance should be first on the list", jobInstances.get(0).getCreateDateTime() > jobInstances.get(1)
// .getId());
}
开发者ID:marklogic-community,项目名称:marklogic-spring-batch,代码行数:27,代码来源:MarkLogicJobInstanceDaoTests.java
示例13: testGetLastInstancesPastEnd
import org.springframework.batch.core.JobInstance; //导入依赖的package包/类
/**
* Create and retrieve a job instance.
*/
@Transactional
@Test
public void testGetLastInstancesPastEnd() throws Exception {
testCreateAndRetrieve();
// unrelated job instance that should be ignored by the query
jobInstanceDao.createJobInstance("anotherJob", new JobParameters());
// we need two instances of the same job to check ordering
jobInstanceDao.createJobInstance(fooJob, new JobParameters());
List<JobInstance> jobInstances = jobInstanceDao.getJobInstances(fooJob, 4, 2);
assertEquals(0, jobInstances.size());
}
开发者ID:marklogic-community,项目名称:marklogic-spring-batch,代码行数:20,代码来源:MarkLogicJobInstanceDaoTests.java
示例14: onSetUp
import org.springframework.batch.core.JobInstance; //导入依赖的package包/类
@Before
public void onSetUp() throws Exception {
jobParameters = new JobParameters();
jobInstance = new JobInstance(12345L, "execJob");
execution = new JobExecution(jobInstance, new JobParameters());
execution.setStartTime(new Date(System.currentTimeMillis()));
execution.setLastUpdated(new Date(System.currentTimeMillis()));
execution.setEndTime(new Date(System.currentTimeMillis()));
jobExecutionDao = new MarkLogicJobExecutionDao(getClient(), getBatchProperties());
}
开发者ID:marklogic-community,项目名称:marklogic-spring-batch,代码行数:11,代码来源:MarkLogicJobExecutionDaoTests.java
示例15: executeInternal
import org.springframework.batch.core.JobInstance; //导入依赖的package包/类
@SuppressWarnings("unchecked")
protected void executeInternal(JobExecutionContext context) {
Map<String, Object> jobDataMap = context.getMergedJobDataMap();
String jobName = (String) jobDataMap.get(JOB_NAME);
LOGGER.info("Quartz trigger firing with Spring Batch jobName=" + jobName);
try {
Job job = jobLocator.getJob(jobName);
JobParameters previousJobParameters = null;
List<JobInstance> jobInstances = jobExplorer.getJobInstances(jobName, 0, 1);
if ((jobInstances != null) && (jobInstances.size() > 0)) {
previousJobParameters = jobInstances.get(0).getJobParameters();
}
JobParameters jobParameters = getJobParametersFromJobMap(jobDataMap, previousJobParameters);
if (job.getJobParametersIncrementer() != null) {
jobParameters = job.getJobParametersIncrementer().getNext(jobParameters);
}
jobLauncher.run(jobLocator.getJob(jobName), jobParameters);
} catch (JobExecutionException e) {
LOGGER.error("Could not execute job.", e);
}
}