diff --git a/spring-batch-core/src/main/java/org/springframework/batch/core/domain/JobExecution.java b/spring-batch-core/src/main/java/org/springframework/batch/core/domain/JobExecution.java index 7c9c1d42e..7da996f83 100644 --- a/spring-batch-core/src/main/java/org/springframework/batch/core/domain/JobExecution.java +++ b/spring-batch-core/src/main/java/org/springframework/batch/core/domain/JobExecution.java @@ -16,8 +16,8 @@ package org.springframework.batch.core.domain; -import java.sql.Timestamp; import java.util.Collection; +import java.util.Date; import java.util.HashSet; import org.springframework.batch.repeat.ExitStatus; @@ -41,9 +41,9 @@ public class JobExecution extends Entity { private BatchStatus status = BatchStatus.STARTING; - private Timestamp startTime = new Timestamp(System.currentTimeMillis()); + private Date startTime = new Date(System.currentTimeMillis()); - private Timestamp endTime = null; + private Date endTime = null; private ExitStatus exitStatus = ExitStatus.UNKNOWN; @@ -72,19 +72,19 @@ public class JobExecution extends Entity { this(job, null); } - public Timestamp getEndTime() { + public Date getEndTime() { return endTime; } - public void setEndTime(Timestamp endTime) { + public void setEndTime(Date endTime) { this.endTime = endTime; } - public Timestamp getStartTime() { + public Date getStartTime() { return startTime; } - public void setStartTime(Timestamp startTime) { + public void setStartTime(Date startTime) { this.startTime = startTime; } diff --git a/spring-batch-core/src/main/java/org/springframework/batch/core/domain/StepExecution.java b/spring-batch-core/src/main/java/org/springframework/batch/core/domain/StepExecution.java index 2a7f9351a..2bd993e87 100644 --- a/spring-batch-core/src/main/java/org/springframework/batch/core/domain/StepExecution.java +++ b/spring-batch-core/src/main/java/org/springframework/batch/core/domain/StepExecution.java @@ -16,7 +16,7 @@ package org.springframework.batch.core.domain; -import java.sql.Timestamp; +import java.util.Date; import java.util.Properties; import org.springframework.batch.repeat.ExitStatus; @@ -47,9 +47,9 @@ public class StepExecution extends Entity { private int rollbackCount = 0; - private Timestamp startTime = new Timestamp(System.currentTimeMillis()); + private Date startTime = new Date(System.currentTimeMillis()); - private Timestamp endTime = null; + private Date endTime = null; private Properties statistics = new Properties(); @@ -103,11 +103,11 @@ public class StepExecution extends Entity { this.commitCount = commitCount; } - public Timestamp getEndTime() { + public Date getEndTime() { return endTime; } - public void setEndTime(Timestamp endTime) { + public void setEndTime(Date endTime) { this.endTime = endTime; } @@ -127,11 +127,11 @@ public class StepExecution extends Entity { return new Integer(rollbackCount); } - public Timestamp getStartTime() { + public Date getStartTime() { return startTime; } - public void setStartTime(Timestamp startTime) { + public void setStartTime(Date startTime) { this.startTime = startTime; } diff --git a/spring-batch-core/src/test/java/org/springframework/batch/core/domain/JobExecutionTests.java b/spring-batch-core/src/test/java/org/springframework/batch/core/domain/JobExecutionTests.java index c1ce0111a..25f6fedfa 100644 --- a/spring-batch-core/src/test/java/org/springframework/batch/core/domain/JobExecutionTests.java +++ b/spring-batch-core/src/test/java/org/springframework/batch/core/domain/JobExecutionTests.java @@ -15,7 +15,7 @@ */ package org.springframework.batch.core.domain; -import java.sql.Timestamp; +import java.util.Date; import junit.framework.TestCase; @@ -44,7 +44,7 @@ public class JobExecutionTests extends TestCase { */ public void testGetEndTime() { assertNull(execution.getEndTime()); - execution.setEndTime(new Timestamp(100L)); + execution.setEndTime(new Date(100L)); assertEquals(100L, execution.getEndTime().getTime()); } @@ -53,7 +53,7 @@ public class JobExecutionTests extends TestCase { */ public void testIsRunning() { assertTrue(execution.isRunning()); - execution.setEndTime(new Timestamp(100L)); + execution.setEndTime(new Date(100L)); assertFalse(execution.isRunning()); } @@ -62,7 +62,7 @@ public class JobExecutionTests extends TestCase { */ public void testGetStartTime() { assertNotNull(execution.getStartTime()); - execution.setStartTime(new Timestamp(0L)); + execution.setStartTime(new Date(0L)); assertEquals(0L, execution.getStartTime().getTime()); } diff --git a/spring-batch-core/src/test/java/org/springframework/batch/core/domain/StepExecutionTests.java b/spring-batch-core/src/test/java/org/springframework/batch/core/domain/StepExecutionTests.java index 67d222c44..c616b91bd 100644 --- a/spring-batch-core/src/test/java/org/springframework/batch/core/domain/StepExecutionTests.java +++ b/spring-batch-core/src/test/java/org/springframework/batch/core/domain/StepExecutionTests.java @@ -15,13 +15,13 @@ */ package org.springframework.batch.core.domain; -import java.sql.Timestamp; +import java.util.Date; import java.util.Properties; -import org.springframework.batch.repeat.ExitStatus; - import junit.framework.TestCase; +import org.springframework.batch.repeat.ExitStatus; + /** * @author Dave Syer * @@ -45,7 +45,7 @@ public class StepExecutionTests extends TestCase { */ public void testGetEndTime() { assertNull(execution.getEndTime()); - execution.setEndTime(new Timestamp(0L)); + execution.setEndTime(new Date(0L)); assertEquals(0L, execution.getEndTime().getTime()); } @@ -55,7 +55,7 @@ public class StepExecutionTests extends TestCase { */ public void testGetStartTime() { assertNotNull(execution.getStartTime()); - execution.setStartTime(new Timestamp(10L)); + execution.setStartTime(new Date(10L)); assertEquals(10L, execution.getStartTime().getTime()); } diff --git a/spring-batch-execution/src/main/java/org/springframework/batch/execution/job/DefaultJobExecutor.java b/spring-batch-execution/src/main/java/org/springframework/batch/execution/job/DefaultJobExecutor.java index 6d88c677a..a5dca5603 100644 --- a/spring-batch-execution/src/main/java/org/springframework/batch/execution/job/DefaultJobExecutor.java +++ b/spring-batch-execution/src/main/java/org/springframework/batch/execution/job/DefaultJobExecutor.java @@ -16,7 +16,7 @@ package org.springframework.batch.execution.job; -import java.sql.Timestamp; +import java.util.Date; import java.util.Iterator; import java.util.List; @@ -118,7 +118,7 @@ public class DefaultJobExecutor implements JobExecutor { status = exceptionClassifier.classifyForExitCode(t); rethrow(t); } finally { - execution.setEndTime(new Timestamp(System.currentTimeMillis())); + execution.setEndTime(new Date(System.currentTimeMillis())); execution.setExitStatus(status); jobRepository.saveOrUpdate(execution); } diff --git a/spring-batch-execution/src/main/java/org/springframework/batch/execution/step/simple/SimpleStepExecutor.java b/spring-batch-execution/src/main/java/org/springframework/batch/execution/step/simple/SimpleStepExecutor.java index 4b62de4c9..61c4cdb0d 100644 --- a/spring-batch-execution/src/main/java/org/springframework/batch/execution/step/simple/SimpleStepExecutor.java +++ b/spring-batch-execution/src/main/java/org/springframework/batch/execution/step/simple/SimpleStepExecutor.java @@ -16,7 +16,7 @@ package org.springframework.batch.execution.step.simple; -import java.sql.Timestamp; +import java.util.Date; import java.util.Iterator; import java.util.Properties; @@ -161,7 +161,7 @@ public class SimpleStepExecutor implements StepExecutor { stepScopeContext.setAttribute(StepScope.ID_KEY, stepExecution.getJobExecution().getJob().getIdentifier()); try { - stepExecution.setStartTime(new Timestamp(System.currentTimeMillis())); + stepExecution.setStartTime(new Date(System.currentTimeMillis())); updateStatus(stepExecution, BatchStatus.STARTED); final boolean saveRestartData = configuration.isSaveRestartData(); @@ -265,7 +265,7 @@ public class SimpleStepExecutor implements StepExecutor { } finally { stepExecution.setExitStatus(status); - stepExecution.setEndTime(new Timestamp(System.currentTimeMillis())); + stepExecution.setEndTime(new Date(System.currentTimeMillis())); try { jobRepository.saveOrUpdate(stepExecution); } diff --git a/spring-batch-execution/src/test/java/org/springframework/batch/execution/repository/SimpleJobRepositoryTests.java b/spring-batch-execution/src/test/java/org/springframework/batch/execution/repository/SimpleJobRepositoryTests.java index 3633f6624..48bd036f0 100644 --- a/spring-batch-execution/src/test/java/org/springframework/batch/execution/repository/SimpleJobRepositoryTests.java +++ b/spring-batch-execution/src/test/java/org/springframework/batch/execution/repository/SimpleJobRepositoryTests.java @@ -16,8 +16,8 @@ package org.springframework.batch.execution.repository; -import java.sql.Timestamp; import java.util.ArrayList; +import java.util.Date; import java.util.Iterator; import java.util.List; @@ -174,7 +174,7 @@ public class SimpleJobRepositoryTests extends TestCase { executions.add(execution); // For this test it is important that the execution is finished // and the executions in the list contain one with an end date - execution.setEndTime(new Timestamp(System.currentTimeMillis())); + execution.setEndTime(new Date(System.currentTimeMillis())); jobDaoControl.setReturnValue(executions); jobDao.update(databaseJob); jobDao.save(new JobExecution(databaseJob)); diff --git a/spring-batch-execution/src/test/java/org/springframework/batch/execution/repository/dao/AbstractJobDaoTests.java b/spring-batch-execution/src/test/java/org/springframework/batch/execution/repository/dao/AbstractJobDaoTests.java index 7775c5b3d..50e640b8b 100644 --- a/spring-batch-execution/src/test/java/org/springframework/batch/execution/repository/dao/AbstractJobDaoTests.java +++ b/spring-batch-execution/src/test/java/org/springframework/batch/execution/repository/dao/AbstractJobDaoTests.java @@ -16,8 +16,8 @@ package org.springframework.batch.execution.repository.dao; -import java.sql.Timestamp; import java.text.SimpleDateFormat; +import java.util.Date; import java.util.List; import java.util.Map; @@ -47,7 +47,7 @@ public abstract class AbstractJobDaoTests extends protected JobExecution jobExecution; - protected Timestamp jobExecutionStartTime = new Timestamp(System + protected Date jobExecutionStartTime = new Date(System .currentTimeMillis()); protected String[] getConfigLocations() { @@ -74,7 +74,7 @@ public abstract class AbstractJobDaoTests extends job = jobDao.createJob(jobRuntimeInformation); // Create an execution - jobExecutionStartTime = new Timestamp(System.currentTimeMillis()); + jobExecutionStartTime = new Date(System.currentTimeMillis()); jobExecution = new JobExecution(job); jobExecution.setStartTime(jobExecutionStartTime); jobExecution.setStatus(BatchStatus.STARTED); @@ -188,7 +188,7 @@ public abstract class AbstractJobDaoTests extends jobExecution.setStatus(BatchStatus.COMPLETED); jobExecution.setExitStatus(ExitStatus.FINISHED); - jobExecution.setEndTime(new Timestamp(System.currentTimeMillis())); + jobExecution.setEndTime(new Date(System.currentTimeMillis())); jobDao.update(jobExecution); List executions = jobDao.findJobExecutions(job); diff --git a/spring-batch-execution/src/test/java/org/springframework/batch/execution/repository/dao/AbstractStepDaoTests.java b/spring-batch-execution/src/test/java/org/springframework/batch/execution/repository/dao/AbstractStepDaoTests.java index d9065ffbb..43e0367d2 100644 --- a/spring-batch-execution/src/test/java/org/springframework/batch/execution/repository/dao/AbstractStepDaoTests.java +++ b/spring-batch-execution/src/test/java/org/springframework/batch/execution/repository/dao/AbstractStepDaoTests.java @@ -16,7 +16,7 @@ package org.springframework.batch.execution.repository.dao; -import java.sql.Timestamp; +import java.util.Date; import java.util.List; import java.util.Properties; @@ -88,7 +88,7 @@ public abstract class AbstractStepDaoTests extends AbstractTransactionalDataSour stepExecution = new StepExecution(step1, jobExecution); stepExecution.setStatus(BatchStatus.STARTED); - stepExecution.setStartTime(new Timestamp(System.currentTimeMillis())); + stepExecution.setStartTime(new Date(System.currentTimeMillis())); stepDao.save(stepExecution); } @@ -162,7 +162,7 @@ public abstract class AbstractStepDaoTests extends AbstractTransactionalDataSour StepExecution execution = new StepExecution(step2, jobExecution); execution.setStatus(BatchStatus.STARTED); - execution.setStartTime(new Timestamp(System.currentTimeMillis())); + execution.setStartTime(new Date(System.currentTimeMillis())); Properties statistics = new Properties(); statistics.setProperty("statistic.key1", "0"); statistics.setProperty("statistic.key2", "5"); @@ -180,7 +180,7 @@ public abstract class AbstractStepDaoTests extends AbstractTransactionalDataSour public void testUpdateStepExecution(){ stepExecution.setStatus(BatchStatus.COMPLETED); - stepExecution.setEndTime(new Timestamp(System.currentTimeMillis())); + stepExecution.setEndTime(new Date(System.currentTimeMillis())); stepExecution.setCommitCount(5); stepExecution.setTaskCount(5); stepExecution.setStatistics(new Properties()); diff --git a/spring-batch-execution/src/test/java/org/springframework/batch/execution/runtime/ScheduledJobIdentifierTests.java b/spring-batch-execution/src/test/java/org/springframework/batch/execution/runtime/ScheduledJobIdentifierTests.java index 9171b8126..bb1c0be63 100644 --- a/spring-batch-execution/src/test/java/org/springframework/batch/execution/runtime/ScheduledJobIdentifierTests.java +++ b/spring-batch-execution/src/test/java/org/springframework/batch/execution/runtime/ScheduledJobIdentifierTests.java @@ -15,8 +15,7 @@ */ package org.springframework.batch.execution.runtime; -import java.sql.Date; -import java.sql.Timestamp; +import java.util.Date; import junit.framework.TestCase; @@ -80,7 +79,7 @@ public class ScheduledJobIdentifierTests extends TestCase { public void testEqualsInstanceWithTimestamp() throws Exception { ScheduledJobIdentifier other = new ScheduledJobIdentifier(instance.getName()); other.setJobKey(instance.getJobKey()); - other.setScheduleDate(new Timestamp(instance.getScheduleDate().getTime())); + other.setScheduleDate(new Date(instance.getScheduleDate().getTime())); assertEquals(instance, other); assertEquals(other, instance); assertEquals(instance.hashCode(), other.hashCode()); diff --git a/spring-batch-samples/pom.xml b/spring-batch-samples/pom.xml index 5c087ed3e..eaa63c6b8 100644 --- a/spring-batch-samples/pom.xml +++ b/spring-batch-samples/pom.xml @@ -106,12 +106,6 @@ easymock - - cglib - cglib-nodep - test - - com.thoughtworks.xstream xstream diff --git a/spring-batch-samples/src/test/java/org/springframework/batch/sample/dao/JdbcJobRepositoryTests.java b/spring-batch-samples/src/test/java/org/springframework/batch/sample/dao/JdbcJobRepositoryTests.java index 2c1db1439..c2818689d 100644 --- a/spring-batch-samples/src/test/java/org/springframework/batch/sample/dao/JdbcJobRepositoryTests.java +++ b/spring-batch-samples/src/test/java/org/springframework/batch/sample/dao/JdbcJobRepositoryTests.java @@ -19,8 +19,7 @@ import org.springframework.test.AbstractTransactionalDataSourceSpringContextTest import org.springframework.transaction.support.TransactionCallback; import org.springframework.transaction.support.TransactionTemplate; -public class JdbcJobRepositoryTests extends - AbstractTransactionalDataSourceSpringContextTests { +public class JdbcJobRepositoryTests extends AbstractTransactionalDataSourceSpringContextTests { private ScheduledJobIdentifier jobIdentifier; @@ -29,6 +28,7 @@ public class JdbcJobRepositoryTests extends private JobConfiguration jobConfiguration; private Set jobExecutionIds = new HashSet(); + private Set jobIds = new HashSet(); private List list = new ArrayList(); @@ -38,19 +38,18 @@ public class JdbcJobRepositoryTests extends } protected String[] getConfigLocations() { - return new String[] { "simple-container-definition.xml" }; // , "alt-data-source-context.xml" }; + return new String[] { "simple-container-definition.xml" }; } protected void onSetUpInTransaction() throws Exception { jobIdentifier = new ScheduledJobIdentifier("Job1"); jobIdentifier.setName("Job1"); jobIdentifier.setJobKey("TestStream"); - jobIdentifier.setScheduleDate(new SimpleDateFormat("yyyyMMdd") - .parse("20070505")); + jobIdentifier.setScheduleDate(new SimpleDateFormat("yyyyMMdd").parse("20070505")); jobConfiguration = new JobConfiguration("test-job"); jobConfiguration.setRestartable(true); } - + protected void onSetUpBeforeTransaction() throws Exception { startNewTransaction(); getJdbcTemplate().update("DELETE FROM BATCH_JOB_EXECUTION"); @@ -63,30 +62,26 @@ public class JdbcJobRepositoryTests extends startNewTransaction(); for (Iterator iterator = jobExecutionIds.iterator(); iterator.hasNext();) { Long id = (Long) iterator.next(); - getJdbcTemplate().update( - "DELETE FROM BATCH_JOB_EXECUTION where ID=?", - new Object[] { id }); + getJdbcTemplate().update("DELETE FROM BATCH_JOB_EXECUTION where ID=?", new Object[] { id }); } for (Iterator iterator = jobIds.iterator(); iterator.hasNext();) { Long id = (Long) iterator.next(); - getJdbcTemplate().update("DELETE FROM BATCH_JOB where ID=?", - new Object[] { id }); + getJdbcTemplate().update("DELETE FROM BATCH_JOB where ID=?", new Object[] { id }); } setComplete(); endTransaction(); - int count = getJdbcTemplate().queryForInt( - "SELECT COUNT(*) FROM BATCH_JOB"); - assertEquals(0, count); + for (Iterator iterator = jobIds.iterator(); iterator.hasNext();) { + Long id = (Long) iterator.next(); + int count = getJdbcTemplate().queryForInt("SELECT COUNT(*) FROM BATCH_JOB where ID=?", new Object[] { id }); + assertEquals(0, count); + } } public void testFindOrCreateJob() throws Exception { jobConfiguration.setName("foo"); - int before = getJdbcTemplate().queryForInt( - "SELECT COUNT(*) FROM BATCH_JOB"); - JobExecution execution = repository.findOrCreateJob(jobConfiguration, - jobIdentifier); - int after = getJdbcTemplate().queryForInt( - "SELECT COUNT(*) FROM BATCH_JOB"); + int before = getJdbcTemplate().queryForInt("SELECT COUNT(*) FROM BATCH_JOB"); + JobExecution execution = repository.findOrCreateJob(jobConfiguration, jobIdentifier); + int after = getJdbcTemplate().queryForInt("SELECT COUNT(*) FROM BATCH_JOB"); assertEquals(before + 1, after); assertNotNull(execution.getId()); } @@ -95,8 +90,7 @@ public class JdbcJobRepositoryTests extends jobConfiguration.setName("bar"); - int before = getJdbcTemplate().queryForInt( - "SELECT COUNT(*) FROM BATCH_JOB"); + int before = getJdbcTemplate().queryForInt("SELECT COUNT(*) FROM BATCH_JOB"); assertEquals(0, before); endTransaction(); @@ -107,7 +101,8 @@ public class JdbcJobRepositoryTests extends try { execution = doConcurrentStart(); fail("Expected JobExecutionAlreadyRunningException"); - } catch (JobExecutionAlreadyRunningException e) { + } + catch (JobExecutionAlreadyRunningException e) { // expected } long t1 = System.currentTimeMillis(); @@ -118,24 +113,19 @@ public class JdbcJobRepositoryTests extends assertNotNull(execution); - int after = getJdbcTemplate().queryForInt( - "SELECT COUNT(*) FROM BATCH_JOB"); + int after = getJdbcTemplate().queryForInt("SELECT COUNT(*) FROM BATCH_JOB"); assertNotNull(execution.getId()); assertEquals(before + 1, after); - logger - .info("Duration: " - + (t1 - t0) - + " - the second transaction did not block if this number is less than about 1000."); + logger.info("Duration: " + (t1 - t0) + + " - the second transaction did not block if this number is less than about 1000."); } - public void testFindOrCreateJobConcurrentlyWhenJobAlreadyExists() - throws Exception { + public void testFindOrCreateJobConcurrentlyWhenJobAlreadyExists() throws Exception { jobConfiguration.setName("spam"); - JobExecution execution = repository.findOrCreateJob(jobConfiguration, - jobIdentifier); + JobExecution execution = repository.findOrCreateJob(jobConfiguration, jobIdentifier); cacheJobIds(execution); execution.setEndTime(new Timestamp(System.currentTimeMillis())); repository.saveOrUpdate(execution); @@ -147,8 +137,7 @@ public class JdbcJobRepositoryTests extends startNewTransaction(); - int before = getJdbcTemplate().queryForInt( - "SELECT COUNT(*) FROM BATCH_JOB"); + int before = getJdbcTemplate().queryForInt("SELECT COUNT(*) FROM BATCH_JOB"); assertEquals(1, before); endTransaction(); @@ -158,20 +147,18 @@ public class JdbcJobRepositoryTests extends try { execution = doConcurrentStart(); fail("Expected JobExecutionAlreadyRunningException"); - } catch (JobExecutionAlreadyRunningException e) { + } + catch (JobExecutionAlreadyRunningException e) { // expected } long t1 = System.currentTimeMillis(); - int after = getJdbcTemplate().queryForInt( - "SELECT COUNT(*) FROM BATCH_JOB"); + int after = getJdbcTemplate().queryForInt("SELECT COUNT(*) FROM BATCH_JOB"); assertNotNull(execution.getId()); assertEquals(before, after); - logger - .info("Duration: " - + (t1 - t0) - + " - the second transaction did not block if this number is less than about 1000."); + logger.info("Duration: " + (t1 - t0) + + " - the second transaction did not block if this number is less than about 1000."); } private void cacheJobIds(JobExecution execution) { @@ -181,30 +168,26 @@ public class JdbcJobRepositoryTests extends jobIds.add(execution.getJobId()); } - private JobExecution doConcurrentStart() throws InterruptedException, - JobExecutionAlreadyRunningException { + private JobExecution doConcurrentStart() throws InterruptedException, JobExecutionAlreadyRunningException { new Thread(new Runnable() { public void run() { try { - new TransactionTemplate(transactionManager) - .execute(new TransactionCallback() { - public Object doInTransaction( - org.springframework.transaction.TransactionStatus status) { - try { - JobExecution execution = repository - .findOrCreateJob( - jobConfiguration, - jobIdentifier); - cacheJobIds(execution); - list.add(execution); - Thread.sleep(1000); - } catch (Exception e) { - list.add(e); - } - return null; - } - }); - } catch (RuntimeException e) { + new TransactionTemplate(transactionManager).execute(new TransactionCallback() { + public Object doInTransaction(org.springframework.transaction.TransactionStatus status) { + try { + JobExecution execution = repository.findOrCreateJob(jobConfiguration, jobIdentifier); + cacheJobIds(execution); + list.add(execution); + Thread.sleep(1000); + } + catch (Exception e) { + list.add(e); + } + return null; + } + }); + } + catch (RuntimeException e) { list.add(e); } @@ -212,8 +195,7 @@ public class JdbcJobRepositoryTests extends }).start(); Thread.sleep(400); - JobExecution execution = repository.findOrCreateJob(jobConfiguration, - jobIdentifier); + JobExecution execution = repository.findOrCreateJob(jobConfiguration, jobIdentifier); cacheJobIds(execution); int count = 0; @@ -221,10 +203,8 @@ public class JdbcJobRepositoryTests extends Thread.sleep(200); } - assertEquals("Timed out waiting for JobExecution to be created", 1, - list.size()); - assertTrue("JobExecution not created in thread", - list.get(0) instanceof JobExecution); + assertEquals("Timed out waiting for JobExecution to be created", 1, list.size()); + assertTrue("JobExecution not created in thread", list.get(0) instanceof JobExecution); return (JobExecution) list.get(0); }