diff --git a/spring-batch-core/src/main/java/org/springframework/batch/core/JobExecution.java b/spring-batch-core/src/main/java/org/springframework/batch/core/JobExecution.java index 8617966f7d..bb4c99296b 100644 --- a/spring-batch-core/src/main/java/org/springframework/batch/core/JobExecution.java +++ b/spring-batch-core/src/main/java/org/springframework/batch/core/JobExecution.java @@ -18,10 +18,10 @@ import java.io.IOException; import java.io.ObjectInputStream; +import java.time.OffsetDateTime; import java.util.ArrayList; import java.util.Collection; import java.util.Collections; -import java.util.Date; import java.util.HashSet; import java.util.LinkedHashSet; import java.util.List; @@ -52,13 +52,13 @@ public class JobExecution extends Entity { private volatile BatchStatus status = BatchStatus.STARTING; - private volatile Date startTime = null; + private volatile OffsetDateTime startTime = null; - private volatile Date createTime = new Date(System.currentTimeMillis()); + private volatile OffsetDateTime createTime = OffsetDateTime.now(); - private volatile Date endTime = null; + private volatile OffsetDateTime endTime = null; - private volatile Date lastUpdated = null; + private volatile OffsetDateTime lastUpdated = null; private volatile ExitStatus exitStatus = ExitStatus.UNKNOWN; @@ -140,7 +140,7 @@ public JobParameters getJobParameters() { * @return The current end time. */ @Nullable - public Date getEndTime() { + public OffsetDateTime getEndTime() { return endTime; } @@ -154,9 +154,9 @@ public void setJobInstance(JobInstance jobInstance) { /** * Set the end time. - * @param endTime The {@link Date} to be used for the end time. + * @param endTime The {@link OffsetDateTime} to be used for the end time. */ - public void setEndTime(Date endTime) { + public void setEndTime(OffsetDateTime endTime) { this.endTime = endTime; } @@ -164,15 +164,15 @@ public void setEndTime(Date endTime) { * @return The current start time. */ @Nullable - public Date getStartTime() { + public OffsetDateTime getStartTime() { return startTime; } /** * Set the start time. - * @param startTime The {@link Date} to be used for the start time. + * @param startTime The {@link OffsetDateTime} to be used for the start time. */ - public void setStartTime(Date startTime) { + public void setStartTime(OffsetDateTime startTime) { this.startTime = startTime; } @@ -290,14 +290,14 @@ public ExecutionContext getExecutionContext() { /** * @return the time when this execution was created. */ - public Date getCreateTime() { + public OffsetDateTime getCreateTime() { return createTime; } /** * @param createTime The creation time of this execution. */ - public void setCreateTime(Date createTime) { + public void setCreateTime(OffsetDateTime createTime) { this.createTime = createTime; } @@ -317,16 +317,16 @@ void addStepExecution(StepExecution stepExecution) { * was updated. */ @Nullable - public Date getLastUpdated() { + public OffsetDateTime getLastUpdated() { return lastUpdated; } /** * Set the last time this {@code JobExecution} was updated. - * @param lastUpdated The {@link Date} instance to which to set the job execution's - * {@code lastUpdated} attribute. + * @param lastUpdated The {@link OffsetDateTime} instance to which to set the job + * execution's {@code lastUpdated} attribute. */ - public void setLastUpdated(Date lastUpdated) { + public void setLastUpdated(OffsetDateTime lastUpdated) { this.lastUpdated = lastUpdated; } diff --git a/spring-batch-core/src/main/java/org/springframework/batch/core/StepExecution.java b/spring-batch-core/src/main/java/org/springframework/batch/core/StepExecution.java index 958048b92c..6400b114e5 100644 --- a/spring-batch-core/src/main/java/org/springframework/batch/core/StepExecution.java +++ b/spring-batch-core/src/main/java/org/springframework/batch/core/StepExecution.java @@ -18,8 +18,8 @@ import java.io.IOException; import java.io.ObjectInputStream; +import java.time.OffsetDateTime; import java.util.ArrayList; -import java.util.Date; import java.util.List; import java.util.concurrent.CopyOnWriteArrayList; @@ -61,13 +61,13 @@ public class StepExecution extends Entity { private volatile long writeSkipCount = 0; - private volatile Date startTime = null; + private volatile OffsetDateTime startTime = null; - private volatile Date createTime = new Date(System.currentTimeMillis()); + private volatile OffsetDateTime createTime = OffsetDateTime.now(); - private volatile Date endTime = null; + private volatile OffsetDateTime endTime = null; - private volatile Date lastUpdated = null; + private volatile OffsetDateTime lastUpdated = null; private volatile ExecutionContext executionContext = new ExecutionContext(); @@ -156,7 +156,7 @@ public void setCommitCount(long commitCount) { * @return the time when this execution ended or {@code null} if the step is running. */ @Nullable - public Date getEndTime() { + public OffsetDateTime getEndTime() { return endTime; } @@ -164,7 +164,7 @@ public Date getEndTime() { * Sets the time when this execution ended. * @param endTime The time when this execution ended. */ - public void setEndTime(Date endTime) { + public void setEndTime(OffsetDateTime endTime) { this.endTime = endTime; } @@ -236,7 +236,7 @@ public void setRollbackCount(long rollbackCount) { * Gets the time this execution was created * @return the time when this execution was created. */ - public Date getCreateTime() { + public OffsetDateTime getCreateTime() { return createTime; } @@ -244,7 +244,7 @@ public Date getCreateTime() { * Sets the time this execution was created * @param createTime creation time of this execution. */ - public void setCreateTime(Date createTime) { + public void setCreateTime(OffsetDateTime createTime) { this.createTime = createTime; } @@ -253,7 +253,7 @@ public void setCreateTime(Date createTime) { * @return the time when this execution started. */ @Nullable - public Date getStartTime() { + public OffsetDateTime getStartTime() { return startTime; } @@ -261,7 +261,7 @@ public Date getStartTime() { * Sets the time when this execution started. * @param startTime The time when this execution started. */ - public void setStartTime(Date startTime) { + public void setStartTime(OffsetDateTime startTime) { this.startTime = startTime; } @@ -457,16 +457,16 @@ public void setProcessSkipCount(long processSkipCount) { * @return the Date representing the last time this execution was persisted. */ @Nullable - public Date getLastUpdated() { + public OffsetDateTime getLastUpdated() { return lastUpdated; } /** * Sets the time when the {@code StepExecution} was last updated before persisting. - * @param lastUpdated the {@link Date} instance used to establish the last updated - * date for the {@code StepExecution}. + * @param lastUpdated the {@link OffsetDateTime} instance used to establish the last + * updated date for the {@code StepExecution}. */ - public void setLastUpdated(Date lastUpdated) { + public void setLastUpdated(OffsetDateTime lastUpdated) { this.lastUpdated = lastUpdated; } diff --git a/spring-batch-core/src/main/java/org/springframework/batch/core/job/AbstractJob.java b/spring-batch-core/src/main/java/org/springframework/batch/core/job/AbstractJob.java index 22fee94e1b..a2d28774f5 100644 --- a/spring-batch-core/src/main/java/org/springframework/batch/core/job/AbstractJob.java +++ b/spring-batch-core/src/main/java/org/springframework/batch/core/job/AbstractJob.java @@ -16,8 +16,8 @@ package org.springframework.batch.core.job; +import java.time.OffsetDateTime; import java.util.Collection; -import java.util.Date; import java.util.List; import java.util.stream.Collectors; @@ -296,7 +296,7 @@ public final void execute(JobExecution execution) { if (execution.getStatus() != BatchStatus.STOPPING) { - execution.setStartTime(new Date()); + execution.setStartTime(OffsetDateTime.now()); updateStatus(execution, BatchStatus.STARTED); listener.beforeJob(execution); @@ -352,7 +352,7 @@ public final void execute(JobExecution execution) { } stopObservation(execution, observation); longTaskTimerSample.stop(); - execution.setEndTime(new Date()); + execution.setEndTime(OffsetDateTime.now()); try { listener.afterJob(execution); diff --git a/spring-batch-core/src/main/java/org/springframework/batch/core/launch/support/SimpleJobOperator.java b/spring-batch-core/src/main/java/org/springframework/batch/core/launch/support/SimpleJobOperator.java index 3cf5ed90e6..41618ce108 100644 --- a/spring-batch-core/src/main/java/org/springframework/batch/core/launch/support/SimpleJobOperator.java +++ b/spring-batch-core/src/main/java/org/springframework/batch/core/launch/support/SimpleJobOperator.java @@ -15,8 +15,8 @@ */ package org.springframework.batch.core.launch.support; +import java.time.OffsetDateTime; import java.util.ArrayList; -import java.util.Date; import java.util.LinkedHashMap; import java.util.LinkedHashSet; import java.util.List; @@ -447,7 +447,7 @@ public JobExecution abandon(long jobExecutionId) logger.info("Aborting job execution: " + jobExecution); } jobExecution.upgradeStatus(BatchStatus.ABANDONED); - jobExecution.setEndTime(new Date()); + jobExecution.setEndTime(OffsetDateTime.now()); jobRepository.update(jobExecution); return jobExecution; diff --git a/spring-batch-core/src/main/java/org/springframework/batch/core/observability/BatchMetrics.java b/spring-batch-core/src/main/java/org/springframework/batch/core/observability/BatchMetrics.java index 841f76e6a7..c9e50ee52a 100644 --- a/spring-batch-core/src/main/java/org/springframework/batch/core/observability/BatchMetrics.java +++ b/spring-batch-core/src/main/java/org/springframework/batch/core/observability/BatchMetrics.java @@ -16,8 +16,8 @@ package org.springframework.batch.core.observability; import java.time.Duration; +import java.time.OffsetDateTime; import java.util.Arrays; -import java.util.Date; import java.util.concurrent.TimeUnit; import io.micrometer.core.instrument.LongTaskTimer; @@ -142,7 +142,7 @@ public static LongTaskTimer createLongTaskTimer(String name, String description, * @return the duration between start time and end time */ @Nullable - public static Duration calculateDuration(@Nullable Date startTime, @Nullable Date endTime) { + public static Duration calculateDuration(@Nullable OffsetDateTime startTime, @Nullable OffsetDateTime endTime) { if (startTime == null || endTime == null) { return null; } diff --git a/spring-batch-core/src/main/java/org/springframework/batch/core/repository/dao/JdbcJobExecutionDao.java b/spring-batch-core/src/main/java/org/springframework/batch/core/repository/dao/JdbcJobExecutionDao.java index 1cec812df7..e717ae8463 100644 --- a/spring-batch-core/src/main/java/org/springframework/batch/core/repository/dao/JdbcJobExecutionDao.java +++ b/spring-batch-core/src/main/java/org/springframework/batch/core/repository/dao/JdbcJobExecutionDao.java @@ -19,6 +19,7 @@ import java.sql.ResultSet; import java.sql.SQLException; import java.sql.Types; +import java.time.OffsetDateTime; import java.util.HashMap; import java.util.HashSet; import java.util.List; @@ -170,8 +171,8 @@ public void saveJobExecution(JobExecution jobExecution) { jobExecution.getExitStatus().getExitCode(), jobExecution.getExitStatus().getExitDescription(), jobExecution.getVersion(), jobExecution.getCreateTime(), jobExecution.getLastUpdated() }; getJdbcTemplate().update(getQuery(SAVE_JOB_EXECUTION), parameters, - new int[] { Types.BIGINT, Types.BIGINT, Types.TIMESTAMP, Types.TIMESTAMP, Types.VARCHAR, Types.VARCHAR, - Types.VARCHAR, Types.INTEGER, Types.TIMESTAMP, Types.TIMESTAMP }); + new int[] { Types.BIGINT, Types.BIGINT, Types.TIMESTAMP_WITH_TIMEZONE, Types.TIMESTAMP_WITH_TIMEZONE, Types.VARCHAR, Types.VARCHAR, + Types.VARCHAR, Types.INTEGER, Types.TIMESTAMP_WITH_TIMEZONE, Types.TIMESTAMP_WITH_TIMEZONE }); insertJobParameters(jobExecution.getId(), jobExecution.getJobParameters()); } @@ -232,8 +233,8 @@ public void updateJobExecution(JobExecution jobExecution) { } int count = getJdbcTemplate().update(getQuery(UPDATE_JOB_EXECUTION), parameters, - new int[] { Types.TIMESTAMP, Types.TIMESTAMP, Types.VARCHAR, Types.VARCHAR, Types.VARCHAR, - Types.INTEGER, Types.TIMESTAMP, Types.TIMESTAMP, Types.BIGINT, Types.INTEGER }); + new int[] { Types.TIMESTAMP_WITH_TIMEZONE, Types.TIMESTAMP_WITH_TIMEZONE, Types.VARCHAR, Types.VARCHAR, Types.VARCHAR, + Types.INTEGER, Types.TIMESTAMP_WITH_TIMEZONE, Types.TIMESTAMP_WITH_TIMEZONE, Types.BIGINT, Types.INTEGER }); // Avoid concurrent modifications... if (count == 0) { @@ -433,12 +434,12 @@ public JobExecution mapRow(ResultSet rs, int rowNum) throws SQLException { jobExecution = new JobExecution(jobInstance, id, jobParameters); } - jobExecution.setStartTime(rs.getTimestamp(2)); - jobExecution.setEndTime(rs.getTimestamp(3)); + jobExecution.setStartTime(rs.getObject(2, OffsetDateTime.class)); + jobExecution.setEndTime(rs.getObject(3, OffsetDateTime.class)); jobExecution.setStatus(BatchStatus.valueOf(rs.getString(4))); jobExecution.setExitStatus(new ExitStatus(rs.getString(5), rs.getString(6))); - jobExecution.setCreateTime(rs.getTimestamp(7)); - jobExecution.setLastUpdated(rs.getTimestamp(8)); + jobExecution.setCreateTime(rs.getObject(7, OffsetDateTime.class)); + jobExecution.setLastUpdated(rs.getObject(8, OffsetDateTime.class)); jobExecution.setVersion(rs.getInt(9)); return jobExecution; } diff --git a/spring-batch-core/src/main/java/org/springframework/batch/core/repository/dao/JdbcStepExecutionDao.java b/spring-batch-core/src/main/java/org/springframework/batch/core/repository/dao/JdbcStepExecutionDao.java index 6a19d72fd3..f1a286ad1f 100644 --- a/spring-batch-core/src/main/java/org/springframework/batch/core/repository/dao/JdbcStepExecutionDao.java +++ b/spring-batch-core/src/main/java/org/springframework/batch/core/repository/dao/JdbcStepExecutionDao.java @@ -21,6 +21,7 @@ import java.sql.SQLException; import java.sql.Timestamp; import java.sql.Types; +import java.time.OffsetDateTime; import java.util.ArrayList; import java.util.Arrays; import java.util.Collection; @@ -183,14 +184,8 @@ public void setValues(PreparedStatement ps, int i) throws SQLException { case Types.VARCHAR: ps.setString(indx + 1, (String) parameterValues[indx]); break; - case Types.TIMESTAMP: - if (parameterValues[indx] != null) { - ps.setTimestamp(indx + 1, - new Timestamp(((java.util.Date) parameterValues[indx]).getTime())); - } - else { - ps.setNull(indx + 1, Types.TIMESTAMP); - } + case Types.TIMESTAMP_WITH_TIMEZONE: + ps.setObject(indx + 1, Types.TIMESTAMP_WITH_TIMEZONE); break; case Types.BIGINT: ps.setLong(indx + 1, (Long) parameterValues[indx]); @@ -223,9 +218,9 @@ private List buildStepExecutionParameters(StepExecution stepExecution) stepExecution.getWriteSkipCount(), stepExecution.getProcessSkipCount(), stepExecution.getRollbackCount(), stepExecution.getLastUpdated(), stepExecution.getCreateTime() }; Integer[] parameterTypes = new Integer[] { Types.BIGINT, Types.INTEGER, Types.VARCHAR, Types.BIGINT, - Types.TIMESTAMP, Types.TIMESTAMP, Types.VARCHAR, Types.BIGINT, Types.BIGINT, Types.BIGINT, Types.BIGINT, - Types.VARCHAR, Types.VARCHAR, Types.BIGINT, Types.BIGINT, Types.BIGINT, Types.BIGINT, Types.TIMESTAMP, - Types.TIMESTAMP }; + Types.TIMESTAMP_WITH_TIMEZONE, Types.TIMESTAMP_WITH_TIMEZONE, Types.VARCHAR, Types.BIGINT, Types.BIGINT, Types.BIGINT, Types.BIGINT, + Types.VARCHAR, Types.VARCHAR, Types.BIGINT, Types.BIGINT, Types.BIGINT, Types.BIGINT, Types.TIMESTAMP_WITH_TIMEZONE, + Types.TIMESTAMP_WITH_TIMEZONE }; parameters.add(0, Arrays.copyOf(parameterValues, parameterValues.length)); parameters.add(1, Arrays.copyOf(parameterTypes, parameterTypes.length)); return parameters; @@ -268,9 +263,9 @@ public void updateStepExecution(StepExecution stepExecution) { stepExecution.getWriteSkipCount(), stepExecution.getRollbackCount(), stepExecution.getLastUpdated(), stepExecution.getId(), stepExecution.getVersion() }; int count = getJdbcTemplate().update(getQuery(UPDATE_STEP_EXECUTION), parameters, - new int[] { Types.TIMESTAMP, Types.TIMESTAMP, Types.VARCHAR, Types.INTEGER, Types.INTEGER, + new int[] { Types.TIMESTAMP_WITH_TIMEZONE, Types.TIMESTAMP_WITH_TIMEZONE, Types.VARCHAR, Types.INTEGER, Types.INTEGER, Types.INTEGER, Types.INTEGER, Types.VARCHAR, Types.VARCHAR, Types.INTEGER, Types.INTEGER, - Types.INTEGER, Types.INTEGER, Types.INTEGER, Types.TIMESTAMP, Types.BIGINT, + Types.INTEGER, Types.INTEGER, Types.INTEGER, Types.TIMESTAMP_WITH_TIMEZONE, Types.BIGINT, Types.INTEGER }); // Avoid concurrent modifications... @@ -327,12 +322,12 @@ public StepExecution getLastStepExecution(JobInstance jobInstance, String stepNa List executions = getJdbcTemplate().query(getQuery(GET_LAST_STEP_EXECUTION), (rs, rowNum) -> { Long jobExecutionId = rs.getLong(19); JobExecution jobExecution = new JobExecution(jobExecutionId); - jobExecution.setStartTime(rs.getTimestamp(20)); - jobExecution.setEndTime(rs.getTimestamp(21)); + jobExecution.setStartTime(rs.getObject(20, OffsetDateTime.class)); + jobExecution.setEndTime(rs.getObject(21, OffsetDateTime.class)); jobExecution.setStatus(BatchStatus.valueOf(rs.getString(22))); jobExecution.setExitStatus(new ExitStatus(rs.getString(23), rs.getString(24))); - jobExecution.setCreateTime(rs.getTimestamp(25)); - jobExecution.setLastUpdated(rs.getTimestamp(26)); + jobExecution.setCreateTime(rs.getObject(25, OffsetDateTime.class)); + jobExecution.setLastUpdated(rs.getObject(26, OffsetDateTime.class)); jobExecution.setVersion(rs.getInt(27)); return new StepExecutionRowMapper(jobExecution).mapRow(rs, rowNum); }, jobInstance.getInstanceId(), stepName); @@ -375,8 +370,8 @@ public StepExecutionRowMapper(JobExecution jobExecution) { @Override public StepExecution mapRow(ResultSet rs, int rowNum) throws SQLException { StepExecution stepExecution = new StepExecution(rs.getString(2), jobExecution, rs.getLong(1)); - stepExecution.setStartTime(rs.getTimestamp(3)); - stepExecution.setEndTime(rs.getTimestamp(4)); + stepExecution.setStartTime(rs.getObject(3, OffsetDateTime.class)); + stepExecution.setEndTime(rs.getObject(4, OffsetDateTime.class)); stepExecution.setStatus(BatchStatus.valueOf(rs.getString(5))); stepExecution.setCommitCount(rs.getInt(6)); stepExecution.setReadCount(rs.getInt(7)); @@ -387,9 +382,9 @@ public StepExecution mapRow(ResultSet rs, int rowNum) throws SQLException { stepExecution.setWriteSkipCount(rs.getInt(13)); stepExecution.setProcessSkipCount(rs.getInt(14)); stepExecution.setRollbackCount(rs.getInt(15)); - stepExecution.setLastUpdated(rs.getTimestamp(16)); + stepExecution.setLastUpdated(rs.getObject(16, OffsetDateTime.class)); stepExecution.setVersion(rs.getInt(17)); - stepExecution.setCreateTime(rs.getTimestamp(18)); + stepExecution.setCreateTime(rs.getObject(18, OffsetDateTime.class)); return stepExecution; } diff --git a/spring-batch-core/src/main/java/org/springframework/batch/core/repository/support/SimpleJobRepository.java b/spring-batch-core/src/main/java/org/springframework/batch/core/repository/support/SimpleJobRepository.java index fc78ab3c78..549f65d6ea 100644 --- a/spring-batch-core/src/main/java/org/springframework/batch/core/repository/support/SimpleJobRepository.java +++ b/spring-batch-core/src/main/java/org/springframework/batch/core/repository/support/SimpleJobRepository.java @@ -36,8 +36,8 @@ import org.springframework.lang.Nullable; import org.springframework.util.Assert; +import java.time.OffsetDateTime; import java.util.Collection; -import java.util.Date; import java.util.List; /** @@ -151,7 +151,7 @@ public JobExecution createJobExecution(String jobName, JobParameters jobParamete JobExecution jobExecution = new JobExecution(jobInstance, jobParameters); jobExecution.setExecutionContext(executionContext); - jobExecution.setLastUpdated(new Date(System.currentTimeMillis())); + jobExecution.setLastUpdated(OffsetDateTime.now()); // Save the JobExecution so that it picks up an ID (useful for clients // monitoring asynchronous executions): @@ -169,7 +169,7 @@ public void update(JobExecution jobExecution) { Assert.notNull(jobExecution.getJobId(), "JobExecution must have a Job ID set."); Assert.notNull(jobExecution.getId(), "JobExecution must be already saved (have an id assigned)."); - jobExecution.setLastUpdated(new Date(System.currentTimeMillis())); + jobExecution.setLastUpdated(OffsetDateTime.now()); jobExecutionDao.synchronizeStatus(jobExecution); jobExecutionDao.updateJobExecution(jobExecution); @@ -179,7 +179,7 @@ public void update(JobExecution jobExecution) { public void add(StepExecution stepExecution) { validateStepExecution(stepExecution); - stepExecution.setLastUpdated(new Date(System.currentTimeMillis())); + stepExecution.setLastUpdated(OffsetDateTime.now()); stepExecutionDao.saveStepExecution(stepExecution); ecDao.saveExecutionContext(stepExecution); } @@ -189,7 +189,7 @@ public void addAll(Collection stepExecutions) { Assert.notNull(stepExecutions, "Attempt to save a null collection of step executions"); for (StepExecution stepExecution : stepExecutions) { validateStepExecution(stepExecution); - stepExecution.setLastUpdated(new Date(System.currentTimeMillis())); + stepExecution.setLastUpdated(OffsetDateTime.now()); } stepExecutionDao.saveStepExecutions(stepExecutions); ecDao.saveExecutionContexts(stepExecutions); @@ -200,7 +200,7 @@ public void update(StepExecution stepExecution) { validateStepExecution(stepExecution); Assert.notNull(stepExecution.getId(), "StepExecution must already be saved (have an id assigned)"); - stepExecution.setLastUpdated(new Date(System.currentTimeMillis())); + stepExecution.setLastUpdated(OffsetDateTime.now()); stepExecutionDao.updateStepExecution(stepExecution); checkForInterruption(stepExecution); } diff --git a/spring-batch-core/src/main/java/org/springframework/batch/core/step/AbstractStep.java b/spring-batch-core/src/main/java/org/springframework/batch/core/step/AbstractStep.java index 5b2e07c91e..6376277578 100644 --- a/spring-batch-core/src/main/java/org/springframework/batch/core/step/AbstractStep.java +++ b/spring-batch-core/src/main/java/org/springframework/batch/core/step/AbstractStep.java @@ -16,7 +16,7 @@ package org.springframework.batch.core.step; import java.time.Duration; -import java.util.Date; +import java.time.OffsetDateTime; import java.util.List; import java.util.stream.Collectors; @@ -197,7 +197,7 @@ public final void execute(StepExecution stepExecution) if (logger.isDebugEnabled()) { logger.debug("Executing: id=" + stepExecution.getId()); } - stepExecution.setStartTime(new Date()); + stepExecution.setStartTime(OffsetDateTime.now()); stepExecution.setStatus(BatchStatus.STARTED); Observation observation = BatchMetrics .createObservation(BatchStepObservation.BATCH_STEP_OBSERVATION.getName(), @@ -276,7 +276,7 @@ public final void execute(StepExecution stepExecution) name, stepExecution.getJobExecution().getJobInstance().getJobName()), e); } stopObservation(stepExecution, observation); - stepExecution.setEndTime(new Date()); + stepExecution.setEndTime(OffsetDateTime.now()); stepExecution.setExitStatus(exitStatus); Duration stepExecutionDuration = BatchMetrics.calculateDuration(stepExecution.getStartTime(), stepExecution.getEndTime()); diff --git a/spring-batch-core/src/main/resources/org/springframework/batch/core/migration/5.0/migration-derby.sql b/spring-batch-core/src/main/resources/org/springframework/batch/core/migration/5.0/migration-derby.sql index f8f69640b0..6db7a4a1e6 100644 --- a/spring-batch-core/src/main/resources/org/springframework/batch/core/migration/5.0/migration-derby.sql +++ b/spring-batch-core/src/main/resources/org/springframework/batch/core/migration/5.0/migration-derby.sql @@ -7,4 +7,7 @@ ALTER TABLE BATCH_JOB_EXECUTION_PARAMS DROP COLUMN DOUBLE_VAL; ALTER TABLE BATCH_JOB_EXECUTION_PARAMS MODIFY COLUMN TYPE_CD PARAMETER_TYPE VARCHAR(100); ALTER TABLE BATCH_JOB_EXECUTION_PARAMS MODIFY COLUMN KEY_NAME PARAMETER_NAME VARCHAR(100); -ALTER TABLE BATCH_JOB_EXECUTION_PARAMS MODIFY COLUMN STRING_VAL PARAMETER_VALUE VARCHAR(2500); \ No newline at end of file +ALTER TABLE BATCH_JOB_EXECUTION_PARAMS MODIFY COLUMN STRING_VAL PARAMETER_VALUE VARCHAR(2500); + +-- Derby does not seem to support timestamp with timezone +-- => no migration script to change column types to TIMESTAMP WITH TIME ZONE \ No newline at end of file diff --git a/spring-batch-core/src/main/resources/org/springframework/batch/core/migration/5.0/migration-h2.sql b/spring-batch-core/src/main/resources/org/springframework/batch/core/migration/5.0/migration-h2.sql index f8f69640b0..7761ce7846 100644 --- a/spring-batch-core/src/main/resources/org/springframework/batch/core/migration/5.0/migration-h2.sql +++ b/spring-batch-core/src/main/resources/org/springframework/batch/core/migration/5.0/migration-h2.sql @@ -7,4 +7,14 @@ ALTER TABLE BATCH_JOB_EXECUTION_PARAMS DROP COLUMN DOUBLE_VAL; ALTER TABLE BATCH_JOB_EXECUTION_PARAMS MODIFY COLUMN TYPE_CD PARAMETER_TYPE VARCHAR(100); ALTER TABLE BATCH_JOB_EXECUTION_PARAMS MODIFY COLUMN KEY_NAME PARAMETER_NAME VARCHAR(100); -ALTER TABLE BATCH_JOB_EXECUTION_PARAMS MODIFY COLUMN STRING_VAL PARAMETER_VALUE VARCHAR(2500); \ No newline at end of file +ALTER TABLE BATCH_JOB_EXECUTION_PARAMS MODIFY COLUMN STRING_VAL PARAMETER_VALUE VARCHAR(2500); + +ALTER TABLE BATCH_JOB_EXECUTION ALTER COLUMN CREATE_TIME SET DATA TYPE TIMESTAMP WITH TIME ZONE; +ALTER TABLE BATCH_JOB_EXECUTION ALTER COLUMN START_TIME SET DATA TYPE TIMESTAMP WITH TIME ZONE; +ALTER TABLE BATCH_JOB_EXECUTION ALTER COLUMN END_TIME SET DATA TYPE TIMESTAMP WITH TIME ZONE; +ALTER TABLE BATCH_JOB_EXECUTION ALTER COLUMN LAST_UPDATED SET DATA TYPE TIMESTAMP WITH TIME ZONE; + +ALTER TABLE BATCH_STEP_EXECUTION ALTER COLUMN CREATE_TIME SET DATA TYPE TIMESTAMP WITH TIME ZONE; +ALTER TABLE BATCH_STEP_EXECUTION ALTER COLUMN START_TIME SET DATA TYPE TIMESTAMP WITH TIME ZONE; +ALTER TABLE BATCH_STEP_EXECUTION ALTER COLUMN END_TIME SET DATA TYPE TIMESTAMP WITH TIME ZONE; +ALTER TABLE BATCH_STEP_EXECUTION ALTER COLUMN LAST_UPDATED SET DATA TYPE TIMESTAMP WITH TIME ZONE; \ No newline at end of file diff --git a/spring-batch-core/src/main/resources/org/springframework/batch/core/migration/5.0/migration-hsqldb.sql b/spring-batch-core/src/main/resources/org/springframework/batch/core/migration/5.0/migration-hsqldb.sql index 7d19eadb33..582b724dc3 100644 --- a/spring-batch-core/src/main/resources/org/springframework/batch/core/migration/5.0/migration-hsqldb.sql +++ b/spring-batch-core/src/main/resources/org/springframework/batch/core/migration/5.0/migration-hsqldb.sql @@ -7,4 +7,14 @@ ALTER TABLE BATCH_JOB_EXECUTION_PARAMS DROP COLUMN DOUBLE_VAL; ALTER TABLE BATCH_JOB_EXECUTION_PARAMS MODIFY COLUMN TYPE_CD PARAMETER_TYPE VARCHAR(100); ALTER TABLE BATCH_JOB_EXECUTION_PARAMS MODIFY COLUMN KEY_NAME PARAMETER_NAME VARCHAR(100); -ALTER TABLE BATCH_JOB_EXECUTION_PARAMS MODIFY COLUMN STRING_VAL PARAMETER_VALUE VARCHAR(2500); \ No newline at end of file +ALTER TABLE BATCH_JOB_EXECUTION_PARAMS MODIFY COLUMN STRING_VAL PARAMETER_VALUE VARCHAR(2500); + +ALTER TABLE BATCH_JOB_EXECUTION ALTER COLUMN CREATE_TIME SET DATA TYPE TIMESTAMP WITH TIME ZONE; +ALTER TABLE BATCH_JOB_EXECUTION ALTER COLUMN START_TIME SET DATA TYPE TIMESTAMP WITH TIME ZONE; +ALTER TABLE BATCH_JOB_EXECUTION ALTER COLUMN END_TIME SET DATA TYPE TIMESTAMP WITH TIME ZONE; +ALTER TABLE BATCH_JOB_EXECUTION ALTER COLUMN LAST_UPDATED SET DATA TYPE TIMESTAMP WITH TIME ZONE; + +ALTER TABLE BATCH_STEP_EXECUTION ALTER COLUMN CREATE_TIME SET DATA TYPE TIMESTAMP WITH TIME ZONE; +ALTER TABLE BATCH_STEP_EXECUTION ALTER COLUMN START_TIME SET DATA TYPE TIMESTAMP WITH TIME ZONE; +ALTER TABLE BATCH_STEP_EXECUTION ALTER COLUMN END_TIME SET DATA TYPE TIMESTAMP WITH TIME ZONE; +ALTER TABLE BATCH_STEP_EXECUTION ALTER COLUMN LAST_UPDATED SET DATA TYPE TIMESTAMP WITH TIME ZONE; \ No newline at end of file diff --git a/spring-batch-core/src/main/resources/org/springframework/batch/core/migration/5.0/migration-mysql.sql b/spring-batch-core/src/main/resources/org/springframework/batch/core/migration/5.0/migration-mysql.sql index 57fda0790d..d151387a3d 100644 --- a/spring-batch-core/src/main/resources/org/springframework/batch/core/migration/5.0/migration-mysql.sql +++ b/spring-batch-core/src/main/resources/org/springframework/batch/core/migration/5.0/migration-mysql.sql @@ -7,4 +7,14 @@ ALTER TABLE BATCH_JOB_EXECUTION_PARAMS DROP COLUMN DOUBLE_VAL; ALTER TABLE BATCH_JOB_EXECUTION_PARAMS CHANGE COLUMN TYPE_CD PARAMETER_TYPE VARCHAR(100); ALTER TABLE BATCH_JOB_EXECUTION_PARAMS CHANGE COLUMN KEY_NAME PARAMETER_NAME VARCHAR(100); -ALTER TABLE BATCH_JOB_EXECUTION_PARAMS CHANGE COLUMN STRING_VAL PARAMETER_VALUE VARCHAR(2500); \ No newline at end of file +ALTER TABLE BATCH_JOB_EXECUTION_PARAMS CHANGE COLUMN STRING_VAL PARAMETER_VALUE VARCHAR(2500); + +ALTER TABLE BATCH_JOB_EXECUTION CHANGE COLUMN CREATE_TIME TIMESTAMP WITH TIME ZONE; +ALTER TABLE BATCH_JOB_EXECUTION CHANGE COLUMN START_TIME TIMESTAMP WITH TIME ZONE; +ALTER TABLE BATCH_JOB_EXECUTION CHANGE COLUMN END_TIME TIMESTAMP WITH TIME ZONE; +ALTER TABLE BATCH_JOB_EXECUTION CHANGE COLUMN LAST_UPDATED TIMESTAMP WITH TIME ZONE; + +ALTER TABLE BATCH_STEP_EXECUTION CHANGE COLUMN CREATE_TIME TIMESTAMP WITH TIME ZONE; +ALTER TABLE BATCH_STEP_EXECUTION CHANGE COLUMN START_TIME TIMESTAMP WITH TIME ZONE; +ALTER TABLE BATCH_STEP_EXECUTION CHANGE COLUMN END_TIME TIMESTAMP WITH TIME ZONE; +ALTER TABLE BATCH_STEP_EXECUTION CHANGE COLUMN LAST_UPDATED TIMESTAMP WITH TIME ZONE; \ No newline at end of file diff --git a/spring-batch-core/src/main/resources/org/springframework/batch/core/migration/5.0/migration-oracle.sql b/spring-batch-core/src/main/resources/org/springframework/batch/core/migration/5.0/migration-oracle.sql index f61d2d93fc..eb5b89a5ef 100644 --- a/spring-batch-core/src/main/resources/org/springframework/batch/core/migration/5.0/migration-oracle.sql +++ b/spring-batch-core/src/main/resources/org/springframework/batch/core/migration/5.0/migration-oracle.sql @@ -11,4 +11,14 @@ ALTER TABLE BATCH_JOB_EXECUTION_PARAMS DROP COLUMN DOUBLE_VAL; ALTER TABLE BATCH_JOB_EXECUTION_PARAMS MODIFY COLUMN TYPE_CD PARAMETER_TYPE VARCHAR(100); ALTER TABLE BATCH_JOB_EXECUTION_PARAMS MODIFY COLUMN KEY_NAME PARAMETER_NAME VARCHAR(100); -ALTER TABLE BATCH_JOB_EXECUTION_PARAMS MODIFY COLUMN STRING_VAL PARAMETER_VALUE VARCHAR(2500); \ No newline at end of file +ALTER TABLE BATCH_JOB_EXECUTION_PARAMS MODIFY COLUMN STRING_VAL PARAMETER_VALUE VARCHAR(2500); + +ALTER TABLE BATCH_JOB_EXECUTION MODIFY COLUMN CREATE_TIME TIMESTAMP WITH TIME ZONE; +ALTER TABLE BATCH_JOB_EXECUTION MODIFY COLUMN START_TIME TIMESTAMP WITH TIME ZONE; +ALTER TABLE BATCH_JOB_EXECUTION MODIFY COLUMN END_TIME TIMESTAMP WITH TIME ZONE; +ALTER TABLE BATCH_JOB_EXECUTION MODIFY COLUMN LAST_UPDATED TIMESTAMP WITH TIME ZONE; + +ALTER TABLE BATCH_STEP_EXECUTION MODIFY COLUMN CREATE_TIME TIMESTAMP WITH TIME ZONE; +ALTER TABLE BATCH_STEP_EXECUTION MODIFY COLUMN START_TIME TIMESTAMP WITH TIME ZONE; +ALTER TABLE BATCH_STEP_EXECUTION MODIFY COLUMN END_TIME TIMESTAMP WITH TIME ZONE; +ALTER TABLE BATCH_STEP_EXECUTION MODIFY COLUMN LAST_UPDATED TIMESTAMP WITH TIME ZONE; \ No newline at end of file diff --git a/spring-batch-core/src/main/resources/org/springframework/batch/core/migration/5.0/migration-postgresql.sql b/spring-batch-core/src/main/resources/org/springframework/batch/core/migration/5.0/migration-postgresql.sql index f8f69640b0..7761ce7846 100644 --- a/spring-batch-core/src/main/resources/org/springframework/batch/core/migration/5.0/migration-postgresql.sql +++ b/spring-batch-core/src/main/resources/org/springframework/batch/core/migration/5.0/migration-postgresql.sql @@ -7,4 +7,14 @@ ALTER TABLE BATCH_JOB_EXECUTION_PARAMS DROP COLUMN DOUBLE_VAL; ALTER TABLE BATCH_JOB_EXECUTION_PARAMS MODIFY COLUMN TYPE_CD PARAMETER_TYPE VARCHAR(100); ALTER TABLE BATCH_JOB_EXECUTION_PARAMS MODIFY COLUMN KEY_NAME PARAMETER_NAME VARCHAR(100); -ALTER TABLE BATCH_JOB_EXECUTION_PARAMS MODIFY COLUMN STRING_VAL PARAMETER_VALUE VARCHAR(2500); \ No newline at end of file +ALTER TABLE BATCH_JOB_EXECUTION_PARAMS MODIFY COLUMN STRING_VAL PARAMETER_VALUE VARCHAR(2500); + +ALTER TABLE BATCH_JOB_EXECUTION ALTER COLUMN CREATE_TIME SET DATA TYPE TIMESTAMP WITH TIME ZONE; +ALTER TABLE BATCH_JOB_EXECUTION ALTER COLUMN START_TIME SET DATA TYPE TIMESTAMP WITH TIME ZONE; +ALTER TABLE BATCH_JOB_EXECUTION ALTER COLUMN END_TIME SET DATA TYPE TIMESTAMP WITH TIME ZONE; +ALTER TABLE BATCH_JOB_EXECUTION ALTER COLUMN LAST_UPDATED SET DATA TYPE TIMESTAMP WITH TIME ZONE; + +ALTER TABLE BATCH_STEP_EXECUTION ALTER COLUMN CREATE_TIME SET DATA TYPE TIMESTAMP WITH TIME ZONE; +ALTER TABLE BATCH_STEP_EXECUTION ALTER COLUMN START_TIME SET DATA TYPE TIMESTAMP WITH TIME ZONE; +ALTER TABLE BATCH_STEP_EXECUTION ALTER COLUMN END_TIME SET DATA TYPE TIMESTAMP WITH TIME ZONE; +ALTER TABLE BATCH_STEP_EXECUTION ALTER COLUMN LAST_UPDATED SET DATA TYPE TIMESTAMP WITH TIME ZONE; \ No newline at end of file diff --git a/spring-batch-core/src/main/resources/org/springframework/batch/core/migration/5.0/migration-sqlite.sql b/spring-batch-core/src/main/resources/org/springframework/batch/core/migration/5.0/migration-sqlite.sql index 2f68f5f891..bb1d8c7e38 100644 --- a/spring-batch-core/src/main/resources/org/springframework/batch/core/migration/5.0/migration-sqlite.sql +++ b/spring-batch-core/src/main/resources/org/springframework/batch/core/migration/5.0/migration-sqlite.sql @@ -7,6 +7,5 @@ ALTER TABLE BATCH_JOB_EXECUTION_PARAMS DROP COLUMN DATE_VAL; ALTER TABLE BATCH_JOB_EXECUTION_PARAMS DROP COLUMN LONG_VAL; ALTER TABLE BATCH_JOB_EXECUTION_PARAMS DROP COLUMN DOUBLE_VAL; -ALTER TABLE BATCH_JOB_EXECUTION_PARAMS MODIFY COLUMN TYPE_CD PARAMETER_TYPE VARCHAR(100); -ALTER TABLE BATCH_JOB_EXECUTION_PARAMS MODIFY COLUMN KEY_NAME PARAMETER_NAME VARCHAR(100); -ALTER TABLE BATCH_JOB_EXECUTION_PARAMS MODIFY COLUMN STRING_VAL PARAMETER_VALUE VARCHAR(2500); \ No newline at end of file +-- ALTER COLUMN is not supported in SQLITE: https://www.sqlite.org/lang_altertable.html +-- => migration scripts to change column types introduced in Spring Batch v5 are not provided diff --git a/spring-batch-core/src/main/resources/org/springframework/batch/core/migration/5.0/migration-sqlserver.sql b/spring-batch-core/src/main/resources/org/springframework/batch/core/migration/5.0/migration-sqlserver.sql index a03ae55ab2..0a6c1e07d2 100644 --- a/spring-batch-core/src/main/resources/org/springframework/batch/core/migration/5.0/migration-sqlserver.sql +++ b/spring-batch-core/src/main/resources/org/springframework/batch/core/migration/5.0/migration-sqlserver.sql @@ -10,4 +10,14 @@ ALTER TABLE BATCH_JOB_EXECUTION_PARAMS DROP COLUMN DOUBLE_VAL; ALTER TABLE BATCH_JOB_EXECUTION_PARAMS MODIFY COLUMN TYPE_CD PARAMETER_TYPE VARCHAR(100); ALTER TABLE BATCH_JOB_EXECUTION_PARAMS MODIFY COLUMN KEY_NAME PARAMETER_NAME VARCHAR(100); -ALTER TABLE BATCH_JOB_EXECUTION_PARAMS MODIFY COLUMN STRING_VAL PARAMETER_VALUE VARCHAR(2500); \ No newline at end of file +ALTER TABLE BATCH_JOB_EXECUTION_PARAMS MODIFY COLUMN STRING_VAL PARAMETER_VALUE VARCHAR(2500); + +ALTER TABLE BATCH_JOB_EXECUTION MODIFY COLUMN CREATE_TIME TIMESTAMP WITH TIME ZONE; +ALTER TABLE BATCH_JOB_EXECUTION MODIFY COLUMN START_TIME TIMESTAMP WITH TIME ZONE; +ALTER TABLE BATCH_JOB_EXECUTION MODIFY COLUMN END_TIME TIMESTAMP WITH TIME ZONE; +ALTER TABLE BATCH_JOB_EXECUTION MODIFY COLUMN LAST_UPDATED TIMESTAMP WITH TIME ZONE; + +ALTER TABLE BATCH_STEP_EXECUTION MODIFY COLUMN CREATE_TIME TIMESTAMP WITH TIME ZONE; +ALTER TABLE BATCH_STEP_EXECUTION MODIFY COLUMN START_TIME TIMESTAMP WITH TIME ZONE; +ALTER TABLE BATCH_STEP_EXECUTION MODIFY COLUMN END_TIME TIMESTAMP WITH TIME ZONE; +ALTER TABLE BATCH_STEP_EXECUTION MODIFY COLUMN LAST_UPDATED TIMESTAMP WITH TIME ZONE; \ No newline at end of file diff --git a/spring-batch-core/src/main/resources/org/springframework/batch/core/migration/5.0/migration-sybase.sql b/spring-batch-core/src/main/resources/org/springframework/batch/core/migration/5.0/migration-sybase.sql index b08921da0d..06d87f91b9 100644 --- a/spring-batch-core/src/main/resources/org/springframework/batch/core/migration/5.0/migration-sybase.sql +++ b/spring-batch-core/src/main/resources/org/springframework/batch/core/migration/5.0/migration-sybase.sql @@ -8,3 +8,13 @@ ALTER TABLE BATCH_JOB_EXECUTION_PARAMS DROP COLUMN DOUBLE_VAL; ALTER TABLE BATCH_JOB_EXECUTION_PARAMS MODIFY COLUMN TYPE_CD PARAMETER_TYPE VARCHAR(100); ALTER TABLE BATCH_JOB_EXECUTION_PARAMS MODIFY COLUMN KEY_NAME PARAMETER_NAME VARCHAR(100); ALTER TABLE BATCH_JOB_EXECUTION_PARAMS MODIFY COLUMN STRING_VAL PARAMETER_VALUE VARCHAR(2500); + +ALTER TABLE BATCH_JOB_EXECUTION MODIFY COLUMN CREATE_TIME TIMESTAMP WITH TIME ZONE; +ALTER TABLE BATCH_JOB_EXECUTION MODIFY COLUMN START_TIME TIMESTAMP WITH TIME ZONE; +ALTER TABLE BATCH_JOB_EXECUTION MODIFY COLUMN END_TIME TIMESTAMP WITH TIME ZONE; +ALTER TABLE BATCH_JOB_EXECUTION MODIFY COLUMN LAST_UPDATED TIMESTAMP WITH TIME ZONE; + +ALTER TABLE BATCH_STEP_EXECUTION MODIFY COLUMN CREATE_TIME TIMESTAMP WITH TIME ZONE; +ALTER TABLE BATCH_STEP_EXECUTION MODIFY COLUMN START_TIME TIMESTAMP WITH TIME ZONE; +ALTER TABLE BATCH_STEP_EXECUTION MODIFY COLUMN END_TIME TIMESTAMP WITH TIME ZONE; +ALTER TABLE BATCH_STEP_EXECUTION MODIFY COLUMN LAST_UPDATED TIMESTAMP WITH TIME ZONE; \ No newline at end of file diff --git a/spring-batch-core/src/main/resources/org/springframework/batch/core/schema-h2.sql b/spring-batch-core/src/main/resources/org/springframework/batch/core/schema-h2.sql index d38d051b86..8165927445 100644 --- a/spring-batch-core/src/main/resources/org/springframework/batch/core/schema-h2.sql +++ b/spring-batch-core/src/main/resources/org/springframework/batch/core/schema-h2.sql @@ -12,13 +12,13 @@ CREATE TABLE BATCH_JOB_EXECUTION ( JOB_EXECUTION_ID BIGINT GENERATED BY DEFAULT AS IDENTITY PRIMARY KEY , VERSION BIGINT , JOB_INSTANCE_ID BIGINT NOT NULL, - CREATE_TIME TIMESTAMP NOT NULL, - START_TIME TIMESTAMP DEFAULT NULL , - END_TIME TIMESTAMP DEFAULT NULL , + CREATE_TIME TIMESTAMP WITH TIME ZONE NOT NULL, + START_TIME TIMESTAMP WITH TIME ZONE DEFAULT NULL , + END_TIME TIMESTAMP WITH TIME ZONE DEFAULT NULL , STATUS VARCHAR(10) , EXIT_CODE VARCHAR(2500) , EXIT_MESSAGE VARCHAR(2500) , - LAST_UPDATED TIMESTAMP, + LAST_UPDATED TIMESTAMP WITH TIME ZONE, constraint JOB_INST_EXEC_FK foreign key (JOB_INSTANCE_ID) references BATCH_JOB_INSTANCE(JOB_INSTANCE_ID) ) ; @@ -38,9 +38,9 @@ CREATE TABLE BATCH_STEP_EXECUTION ( VERSION BIGINT NOT NULL, STEP_NAME VARCHAR(100) NOT NULL, JOB_EXECUTION_ID BIGINT NOT NULL, - CREATE_TIME TIMESTAMP NOT NULL, - START_TIME TIMESTAMP DEFAULT NULL , - END_TIME TIMESTAMP DEFAULT NULL , + CREATE_TIME TIMESTAMP WITH TIME ZONE NOT NULL, + START_TIME TIMESTAMP WITH TIME ZONE DEFAULT NULL , + END_TIME TIMESTAMP WITH TIME ZONE DEFAULT NULL , STATUS VARCHAR(10) , COMMIT_COUNT BIGINT , READ_COUNT BIGINT , @@ -52,7 +52,7 @@ CREATE TABLE BATCH_STEP_EXECUTION ( ROLLBACK_COUNT BIGINT , EXIT_CODE VARCHAR(2500) , EXIT_MESSAGE VARCHAR(2500) , - LAST_UPDATED TIMESTAMP, + LAST_UPDATED TIMESTAMP WITH TIME ZONE, constraint JOB_EXEC_STEP_FK foreign key (JOB_EXECUTION_ID) references BATCH_JOB_EXECUTION(JOB_EXECUTION_ID) ) ; diff --git a/spring-batch-core/src/main/resources/org/springframework/batch/core/schema-hsqldb.sql b/spring-batch-core/src/main/resources/org/springframework/batch/core/schema-hsqldb.sql index 0b3f0df08a..ea9b23e759 100644 --- a/spring-batch-core/src/main/resources/org/springframework/batch/core/schema-hsqldb.sql +++ b/spring-batch-core/src/main/resources/org/springframework/batch/core/schema-hsqldb.sql @@ -12,13 +12,13 @@ CREATE TABLE BATCH_JOB_EXECUTION ( JOB_EXECUTION_ID BIGINT IDENTITY NOT NULL PRIMARY KEY , VERSION BIGINT , JOB_INSTANCE_ID BIGINT NOT NULL, - CREATE_TIME TIMESTAMP NOT NULL, - START_TIME TIMESTAMP DEFAULT NULL , - END_TIME TIMESTAMP DEFAULT NULL , + CREATE_TIME TIMESTAMP WITH TIME ZONE NOT NULL, + START_TIME TIMESTAMP WITH TIME ZONE DEFAULT NULL , + END_TIME TIMESTAMP WITH TIME ZONE DEFAULT NULL , STATUS VARCHAR(10) , EXIT_CODE VARCHAR(2500) , EXIT_MESSAGE VARCHAR(2500) , - LAST_UPDATED TIMESTAMP, + LAST_UPDATED TIMESTAMP WITH TIME ZONE, constraint JOB_INST_EXEC_FK foreign key (JOB_INSTANCE_ID) references BATCH_JOB_INSTANCE(JOB_INSTANCE_ID) ) ; @@ -38,9 +38,9 @@ CREATE TABLE BATCH_STEP_EXECUTION ( VERSION BIGINT NOT NULL, STEP_NAME VARCHAR(100) NOT NULL, JOB_EXECUTION_ID BIGINT NOT NULL, - CREATE_TIME TIMESTAMP NOT NULL , - START_TIME TIMESTAMP DEFAULT NULL , - END_TIME TIMESTAMP DEFAULT NULL , + CREATE_TIME TIMESTAMP WITH TIME ZONE NOT NULL , + START_TIME TIMESTAMP WITH TIME ZONE DEFAULT NULL , + END_TIME TIMESTAMP WITH TIME ZONE DEFAULT NULL , STATUS VARCHAR(10) , COMMIT_COUNT BIGINT , READ_COUNT BIGINT , @@ -52,7 +52,7 @@ CREATE TABLE BATCH_STEP_EXECUTION ( ROLLBACK_COUNT BIGINT , EXIT_CODE VARCHAR(2500) , EXIT_MESSAGE VARCHAR(2500) , - LAST_UPDATED TIMESTAMP, + LAST_UPDATED TIMESTAMP WITH TIME ZONE, constraint JOB_EXEC_STEP_FK foreign key (JOB_EXECUTION_ID) references BATCH_JOB_EXECUTION(JOB_EXECUTION_ID) ) ; diff --git a/spring-batch-core/src/main/resources/org/springframework/batch/core/schema-oracle.sql b/spring-batch-core/src/main/resources/org/springframework/batch/core/schema-oracle.sql index efaacfbd4f..3dc4568436 100644 --- a/spring-batch-core/src/main/resources/org/springframework/batch/core/schema-oracle.sql +++ b/spring-batch-core/src/main/resources/org/springframework/batch/core/schema-oracle.sql @@ -12,13 +12,13 @@ CREATE TABLE BATCH_JOB_EXECUTION ( JOB_EXECUTION_ID NUMBER(19,0) NOT NULL PRIMARY KEY , VERSION NUMBER(19,0) , JOB_INSTANCE_ID NUMBER(19,0) NOT NULL, - CREATE_TIME TIMESTAMP NOT NULL, - START_TIME TIMESTAMP DEFAULT NULL , - END_TIME TIMESTAMP DEFAULT NULL , + CREATE_TIME TIMESTAMP WITH TIME ZONE NOT NULL, + START_TIME TIMESTAMP WITH TIME ZONE DEFAULT NULL , + END_TIME TIMESTAMP WITH TIME ZONE DEFAULT NULL , STATUS VARCHAR2(10 char) , EXIT_CODE VARCHAR2(2500 char) , EXIT_MESSAGE VARCHAR2(2500 char) , - LAST_UPDATED TIMESTAMP, + LAST_UPDATED TIMESTAMP WITH TIME ZONE, constraint JOB_INST_EXEC_FK foreign key (JOB_INSTANCE_ID) references BATCH_JOB_INSTANCE(JOB_INSTANCE_ID) ) SEGMENT CREATION IMMEDIATE; @@ -38,9 +38,9 @@ CREATE TABLE BATCH_STEP_EXECUTION ( VERSION NUMBER(19,0) NOT NULL, STEP_NAME VARCHAR2(100 char) NOT NULL, JOB_EXECUTION_ID NUMBER(19,0) NOT NULL, - CREATE_TIME TIMESTAMP NOT NULL, - START_TIME TIMESTAMP DEFAULT NULL , - END_TIME TIMESTAMP DEFAULT NULL , + CREATE_TIME TIMESTAMP WITH TIME ZONE NOT NULL, + START_TIME TIMESTAMP WITH TIME ZONE DEFAULT NULL , + END_TIME TIMESTAMP WITH TIME ZONE DEFAULT NULL , STATUS VARCHAR2(10 char) , COMMIT_COUNT NUMBER(19,0) , READ_COUNT NUMBER(19,0) , @@ -52,7 +52,7 @@ CREATE TABLE BATCH_STEP_EXECUTION ( ROLLBACK_COUNT NUMBER(19,0) , EXIT_CODE VARCHAR2(2500 char) , EXIT_MESSAGE VARCHAR2(2500 char) , - LAST_UPDATED TIMESTAMP, + LAST_UPDATED TIMESTAMP WITH TIME ZONE, constraint JOB_EXEC_STEP_FK foreign key (JOB_EXECUTION_ID) references BATCH_JOB_EXECUTION(JOB_EXECUTION_ID) ) SEGMENT CREATION IMMEDIATE; diff --git a/spring-batch-core/src/main/resources/org/springframework/batch/core/schema-postgresql.sql b/spring-batch-core/src/main/resources/org/springframework/batch/core/schema-postgresql.sql index dd146f1f0f..f3adf154d4 100644 --- a/spring-batch-core/src/main/resources/org/springframework/batch/core/schema-postgresql.sql +++ b/spring-batch-core/src/main/resources/org/springframework/batch/core/schema-postgresql.sql @@ -12,13 +12,13 @@ CREATE TABLE BATCH_JOB_EXECUTION ( JOB_EXECUTION_ID BIGINT NOT NULL PRIMARY KEY , VERSION BIGINT , JOB_INSTANCE_ID BIGINT NOT NULL, - CREATE_TIME TIMESTAMP NOT NULL, - START_TIME TIMESTAMP DEFAULT NULL , - END_TIME TIMESTAMP DEFAULT NULL , + CREATE_TIME TIMESTAMP WITH TIME ZONE NOT NULL, + START_TIME TIMESTAMP WITH TIME ZONE DEFAULT NULL , + END_TIME TIMESTAMP WITH TIME ZONE DEFAULT NULL , STATUS VARCHAR(10) , EXIT_CODE VARCHAR(2500) , EXIT_MESSAGE VARCHAR(2500) , - LAST_UPDATED TIMESTAMP, + LAST_UPDATED TIMESTAMP WITH TIME ZONE, constraint JOB_INST_EXEC_FK foreign key (JOB_INSTANCE_ID) references BATCH_JOB_INSTANCE(JOB_INSTANCE_ID) ) ; @@ -38,9 +38,9 @@ CREATE TABLE BATCH_STEP_EXECUTION ( VERSION BIGINT NOT NULL, STEP_NAME VARCHAR(100) NOT NULL, JOB_EXECUTION_ID BIGINT NOT NULL, - CREATE_TIME TIMESTAMP NOT NULL, - START_TIME TIMESTAMP DEFAULT NULL , - END_TIME TIMESTAMP DEFAULT NULL , + CREATE_TIME TIMESTAMP WITH TIME ZONE NOT NULL, + START_TIME TIMESTAMP WITH TIME ZONE DEFAULT NULL , + END_TIME TIMESTAMP WITH TIME ZONE DEFAULT NULL , STATUS VARCHAR(10) , COMMIT_COUNT BIGINT , READ_COUNT BIGINT , @@ -52,7 +52,7 @@ CREATE TABLE BATCH_STEP_EXECUTION ( ROLLBACK_COUNT BIGINT , EXIT_CODE VARCHAR(2500) , EXIT_MESSAGE VARCHAR(2500) , - LAST_UPDATED TIMESTAMP, + LAST_UPDATED TIMESTAMP WITH TIME ZONE, constraint JOB_EXEC_STEP_FK foreign key (JOB_EXECUTION_ID) references BATCH_JOB_EXECUTION(JOB_EXECUTION_ID) ) ; diff --git a/spring-batch-core/src/main/resources/org/springframework/batch/core/schema-sqlserver.sql b/spring-batch-core/src/main/resources/org/springframework/batch/core/schema-sqlserver.sql index 70c89664c0..1980764548 100644 --- a/spring-batch-core/src/main/resources/org/springframework/batch/core/schema-sqlserver.sql +++ b/spring-batch-core/src/main/resources/org/springframework/batch/core/schema-sqlserver.sql @@ -12,13 +12,13 @@ CREATE TABLE BATCH_JOB_EXECUTION ( JOB_EXECUTION_ID BIGINT NOT NULL PRIMARY KEY , VERSION BIGINT NULL, JOB_INSTANCE_ID BIGINT NOT NULL, - CREATE_TIME DATETIME NOT NULL, - START_TIME DATETIME DEFAULT NULL , - END_TIME DATETIME DEFAULT NULL , + CREATE_TIME DATETIMEOFFSET NOT NULL, + START_TIME DATETIMEOFFSET DEFAULT NULL , + END_TIME DATETIMEOFFSET DEFAULT NULL , STATUS VARCHAR(10) NULL, EXIT_CODE VARCHAR(2500) NULL, EXIT_MESSAGE VARCHAR(2500) NULL, - LAST_UPDATED DATETIME NULL, + LAST_UPDATED DATETIMEOFFSET NULL, constraint JOB_INST_EXEC_FK foreign key (JOB_INSTANCE_ID) references BATCH_JOB_INSTANCE(JOB_INSTANCE_ID) ) ; @@ -38,9 +38,9 @@ CREATE TABLE BATCH_STEP_EXECUTION ( VERSION BIGINT NOT NULL, STEP_NAME VARCHAR(100) NOT NULL, JOB_EXECUTION_ID BIGINT NOT NULL, - CREATE_TIME DATETIME NOT NULL, - START_TIME DATETIME DEFAULT NULL , - END_TIME DATETIME DEFAULT NULL , + CREATE_TIME DATETIMEOFFSET NOT NULL, + START_TIME DATETIMEOFFSET DEFAULT NULL , + END_TIME DATETIMEOFFSET DEFAULT NULL , STATUS VARCHAR(10) NULL, COMMIT_COUNT BIGINT NULL, READ_COUNT BIGINT NULL, @@ -52,7 +52,7 @@ CREATE TABLE BATCH_STEP_EXECUTION ( ROLLBACK_COUNT BIGINT NULL, EXIT_CODE VARCHAR(2500) NULL, EXIT_MESSAGE VARCHAR(2500) NULL, - LAST_UPDATED DATETIME NULL, + LAST_UPDATED DATETIMEOFFSET NULL, constraint JOB_EXEC_STEP_FK foreign key (JOB_EXECUTION_ID) references BATCH_JOB_EXECUTION(JOB_EXECUTION_ID) ) ; diff --git a/spring-batch-core/src/main/resources/org/springframework/batch/core/schema-sybase.sql b/spring-batch-core/src/main/resources/org/springframework/batch/core/schema-sybase.sql index 15b221970e..8b9528d92f 100644 --- a/spring-batch-core/src/main/resources/org/springframework/batch/core/schema-sybase.sql +++ b/spring-batch-core/src/main/resources/org/springframework/batch/core/schema-sybase.sql @@ -12,13 +12,13 @@ CREATE TABLE BATCH_JOB_EXECUTION ( JOB_EXECUTION_ID BIGINT NOT NULL PRIMARY KEY , VERSION BIGINT NULL, JOB_INSTANCE_ID BIGINT NOT NULL, - CREATE_TIME DATETIME NOT NULL, - START_TIME DATETIME DEFAULT NULL NULL, - END_TIME DATETIME DEFAULT NULL NULL, + CREATE_TIME TIMESTAMP WITH TIME ZONE NOT NULL, + START_TIME TIMESTAMP WITH TIME ZONE DEFAULT NULL NULL, + END_TIME TIMESTAMP WITH TIME ZONE DEFAULT NULL NULL, STATUS VARCHAR(10) NULL, EXIT_CODE VARCHAR(2500) NULL, EXIT_MESSAGE VARCHAR(2500) NULL, - LAST_UPDATED DATETIME, + LAST_UPDATED TIMESTAMP WITH TIME ZONE, constraint JOB_INST_EXEC_FK foreign key (JOB_INSTANCE_ID) references BATCH_JOB_INSTANCE(JOB_INSTANCE_ID) ) ; @@ -38,9 +38,9 @@ CREATE TABLE BATCH_STEP_EXECUTION ( VERSION BIGINT NOT NULL, STEP_NAME VARCHAR(100) NOT NULL, JOB_EXECUTION_ID BIGINT NOT NULL, - CREATE_TIME DATETIME NOT NULL, - START_TIME DATETIME DEFAULT NULL NULL, - END_TIME DATETIME DEFAULT NULL NULL, + CREATE_TIME TIMESTAMP WITH TIME ZONE NOT NULL, + START_TIME TIMESTAMP WITH TIME ZONE DEFAULT NULL NULL, + END_TIME TIMESTAMP WITH TIME ZONE DEFAULT NULL NULL, STATUS VARCHAR(10) NULL, COMMIT_COUNT BIGINT NULL, READ_COUNT BIGINT NULL, @@ -52,7 +52,7 @@ CREATE TABLE BATCH_STEP_EXECUTION ( ROLLBACK_COUNT BIGINT NULL, EXIT_CODE VARCHAR(2500) NULL, EXIT_MESSAGE VARCHAR(2500) NULL, - LAST_UPDATED DATETIME, + LAST_UPDATED TIMESTAMP WITH TIME ZONE, constraint JOB_EXEC_STEP_FK foreign key (JOB_EXECUTION_ID) references BATCH_JOB_EXECUTION(JOB_EXECUTION_ID) ) ; diff --git a/spring-batch-core/src/test/java/org/springframework/batch/core/JobExecutionTests.java b/spring-batch-core/src/test/java/org/springframework/batch/core/JobExecutionTests.java index 084f97e507..fb3877c811 100644 --- a/spring-batch-core/src/test/java/org/springframework/batch/core/JobExecutionTests.java +++ b/spring-batch-core/src/test/java/org/springframework/batch/core/JobExecutionTests.java @@ -21,8 +21,9 @@ import static org.junit.jupiter.api.Assertions.assertNull; import static org.junit.jupiter.api.Assertions.assertTrue; +import java.time.OffsetDateTime; +import java.time.temporal.ChronoUnit; import java.util.Arrays; -import java.util.Date; import java.util.List; import org.junit.jupiter.api.Test; @@ -49,8 +50,9 @@ void testJobExecution() { @Test void testGetEndTime() { assertNull(execution.getEndTime()); - execution.setEndTime(new Date(100L)); - assertEquals(100L, execution.getEndTime().getTime()); + OffsetDateTime now = OffsetDateTime.now(); + execution.setEndTime(now); + assertEquals(now, execution.getEndTime()); } /** @@ -58,9 +60,10 @@ void testGetEndTime() { */ @Test void testIsRunning() { - execution.setStartTime(new Date()); + OffsetDateTime now = OffsetDateTime.now(); + execution.setStartTime(now); assertTrue(execution.isRunning()); - execution.setEndTime(new Date(100L)); + execution.setEndTime(now.plus(10, ChronoUnit.SECONDS)); assertFalse(execution.isRunning()); } @@ -69,8 +72,9 @@ void testIsRunning() { */ @Test void testGetStartTime() { - execution.setStartTime(new Date(0L)); - assertEquals(0L, execution.getStartTime().getTime()); + OffsetDateTime now = OffsetDateTime.now(); + execution.setStartTime(now); + assertEquals(now, execution.getStartTime()); } /** diff --git a/spring-batch-core/src/test/java/org/springframework/batch/core/StepExecutionTests.java b/spring-batch-core/src/test/java/org/springframework/batch/core/StepExecutionTests.java index 69360ddabf..2f9380bcf0 100644 --- a/spring-batch-core/src/test/java/org/springframework/batch/core/StepExecutionTests.java +++ b/spring-batch-core/src/test/java/org/springframework/batch/core/StepExecutionTests.java @@ -23,6 +23,7 @@ import static org.junit.jupiter.api.Assertions.assertThrows; import static org.junit.jupiter.api.Assertions.assertTrue; +import java.time.OffsetDateTime; import java.util.Date; import java.util.HashSet; import java.util.Set; @@ -67,8 +68,9 @@ void testStepExecutionWithNullId() { @Test void testGetEndTime() { assertNull(execution.getEndTime()); - execution.setEndTime(new Date(0L)); - assertEquals(0L, execution.getEndTime().getTime()); + OffsetDateTime now = OffsetDateTime.now(); + execution.setEndTime(now); + assertEquals(now, execution.getEndTime()); } /** @@ -77,8 +79,9 @@ void testGetEndTime() { @Test void testGetCreateTime() { assertNotNull(execution.getCreateTime()); - execution.setCreateTime(new Date(10L)); - assertEquals(10L, execution.getCreateTime().getTime()); + OffsetDateTime now = OffsetDateTime.now(); + execution.setCreateTime(now); + assertEquals(now, execution.getCreateTime()); } /** diff --git a/spring-batch-core/src/test/java/org/springframework/batch/core/job/ExtendedAbstractJobTests.java b/spring-batch-core/src/test/java/org/springframework/batch/core/job/ExtendedAbstractJobTests.java index e76f0e86d5..4d9824b807 100644 --- a/spring-batch-core/src/test/java/org/springframework/batch/core/job/ExtendedAbstractJobTests.java +++ b/spring-batch-core/src/test/java/org/springframework/batch/core/job/ExtendedAbstractJobTests.java @@ -33,6 +33,7 @@ import org.springframework.jdbc.datasource.embedded.EmbeddedDatabaseBuilder; import org.springframework.lang.Nullable; +import java.time.OffsetDateTime; import java.util.Collection; import java.util.Collections; import java.util.Date; @@ -179,7 +180,7 @@ public void execute(StepExecution stepExecution) throws JobInterruptedException assertEquals(StubStep.value, execution.getExecutionContext().get(StubStep.key)); // simulate restart and check the job execution context's content survives - execution.setEndTime(new Date()); + execution.setEndTime(OffsetDateTime.now()); execution.setStatus(BatchStatus.FAILED); this.jobRepository.update(execution); diff --git a/spring-batch-core/src/test/java/org/springframework/batch/core/job/SimpleJobTests.java b/spring-batch-core/src/test/java/org/springframework/batch/core/job/SimpleJobTests.java index ca9715ce3c..b692cfb7d2 100644 --- a/spring-batch-core/src/test/java/org/springframework/batch/core/job/SimpleJobTests.java +++ b/spring-batch-core/src/test/java/org/springframework/batch/core/job/SimpleJobTests.java @@ -17,6 +17,7 @@ package org.springframework.batch.core.job; import java.io.Serializable; +import java.time.OffsetDateTime; import java.util.ArrayList; import java.util.Arrays; import java.util.Collections; @@ -356,7 +357,7 @@ void testStepShouldNotStart() { void testStepAlreadyComplete() throws Exception { stepExecution1.setStatus(BatchStatus.COMPLETED); jobRepository.add(stepExecution1); - jobExecution.setEndTime(new Date()); + jobExecution.setEndTime(OffsetDateTime.now()); jobRepository.update(jobExecution); jobExecution = jobRepository.createJobExecution(job.getName(), jobParameters); job.execute(jobExecution); diff --git a/spring-batch-core/src/test/java/org/springframework/batch/core/launch/support/CommandLineJobRunnerTests.java b/spring-batch-core/src/test/java/org/springframework/batch/core/launch/support/CommandLineJobRunnerTests.java index 92695de889..bd00d5a607 100644 --- a/spring-batch-core/src/test/java/org/springframework/batch/core/launch/support/CommandLineJobRunnerTests.java +++ b/spring-batch-core/src/test/java/org/springframework/batch/core/launch/support/CommandLineJobRunnerTests.java @@ -17,6 +17,7 @@ import java.io.IOException; import java.io.InputStream; +import java.time.OffsetDateTime; import java.util.ArrayList; import java.util.Arrays; import java.util.Date; @@ -502,9 +503,9 @@ public List getJobExecutions(JobInstance jobInstance) { private JobExecution createJobExecution(JobInstance jobInstance, BatchStatus status) { JobExecution jobExecution = new JobExecution(jobInstance, 1L, jobParameters); jobExecution.setStatus(status); - jobExecution.setStartTime(new Date()); + jobExecution.setStartTime(OffsetDateTime.now()); if (status != BatchStatus.STARTED) { - jobExecution.setEndTime(new Date()); + jobExecution.setEndTime(OffsetDateTime.now()); } return jobExecution; } diff --git a/spring-batch-core/src/test/java/org/springframework/batch/core/observability/BatchMetricsTests.java b/spring-batch-core/src/test/java/org/springframework/batch/core/observability/BatchMetricsTests.java index 54501be2d9..40142eda52 100644 --- a/spring-batch-core/src/test/java/org/springframework/batch/core/observability/BatchMetricsTests.java +++ b/spring-batch-core/src/test/java/org/springframework/batch/core/observability/BatchMetricsTests.java @@ -17,6 +17,7 @@ import java.time.Duration; import java.time.LocalDateTime; +import java.time.OffsetDateTime; import java.time.ZoneOffset; import java.time.temporal.ChronoUnit; import java.util.Arrays; @@ -64,31 +65,27 @@ class BatchMetricsTests { @Test void testCalculateDuration() { - LocalDateTime startTime = LocalDateTime.now(); - LocalDateTime endTime = startTime.plus(2, ChronoUnit.HOURS).plus(31, ChronoUnit.MINUTES) + OffsetDateTime startTime = OffsetDateTime.now(); + OffsetDateTime endTime = startTime.plus(2, ChronoUnit.HOURS).plus(31, ChronoUnit.MINUTES) .plus(12, ChronoUnit.SECONDS).plus(42, ChronoUnit.MILLIS); - Duration duration = BatchMetrics.calculateDuration(toDate(startTime), toDate(endTime)); + Duration duration = BatchMetrics.calculateDuration(startTime, endTime); Duration expectedDuration = Duration.ofMillis(42).plusSeconds(12).plusMinutes(31).plusHours(2); assertEquals(expectedDuration, duration); } @Test void testCalculateDurationWhenNoStartTime() { - Duration duration = BatchMetrics.calculateDuration(null, toDate(LocalDateTime.now())); + Duration duration = BatchMetrics.calculateDuration(null, OffsetDateTime.now()); assertNull(duration); } @Test void testCalculateDurationWhenNoEndTime() { - Duration duration = BatchMetrics.calculateDuration(toDate(LocalDateTime.now()), null); + Duration duration = BatchMetrics.calculateDuration(OffsetDateTime.now(), null); assertNull(duration); } - private Date toDate(LocalDateTime localDateTime) { - return Date.from(localDateTime.toInstant(ZoneOffset.UTC)); - } - @Test void testFormatValidDuration() { Duration duration = Duration.ofMillis(42).plusSeconds(12).plusMinutes(31).plusHours(2); diff --git a/spring-batch-core/src/test/java/org/springframework/batch/core/partition/support/PartitionStepTests.java b/spring-batch-core/src/test/java/org/springframework/batch/core/partition/support/PartitionStepTests.java index ecbcd721b4..720909b7e5 100644 --- a/spring-batch-core/src/test/java/org/springframework/batch/core/partition/support/PartitionStepTests.java +++ b/spring-batch-core/src/test/java/org/springframework/batch/core/partition/support/PartitionStepTests.java @@ -15,6 +15,7 @@ */ package org.springframework.batch.core.partition.support; +import java.time.OffsetDateTime; import java.util.Arrays; import java.util.Collection; import java.util.Date; @@ -153,7 +154,7 @@ public Collection handle(StepExecutionSplitter stepSplitter, Step jobRepository.add(stepExecution); step.execute(stepExecution); jobExecution.setStatus(BatchStatus.FAILED); - jobExecution.setEndTime(new Date()); + jobExecution.setEndTime(OffsetDateTime.now()); jobRepository.update(jobExecution); // Now restart... jobExecution = jobRepository.createJobExecution("vanillaJob", new JobParameters()); diff --git a/spring-batch-core/src/test/java/org/springframework/batch/core/partition/support/SimpleStepExecutionSplitterTests.java b/spring-batch-core/src/test/java/org/springframework/batch/core/partition/support/SimpleStepExecutionSplitterTests.java index 0c67dc9141..c33cb8db87 100644 --- a/spring-batch-core/src/test/java/org/springframework/batch/core/partition/support/SimpleStepExecutionSplitterTests.java +++ b/spring-batch-core/src/test/java/org/springframework/batch/core/partition/support/SimpleStepExecutionSplitterTests.java @@ -15,6 +15,7 @@ */ package org.springframework.batch.core.partition.support; +import java.time.OffsetDateTime; import java.util.Arrays; import java.util.Collection; import java.util.Collections; @@ -233,19 +234,19 @@ private StepExecution update(Set split, StepExecution stepExecuti ExecutionContext executionContext = stepExecution.getExecutionContext(); for (StepExecution child : split) { - child.setEndTime(new Date()); + child.setEndTime(OffsetDateTime.now()); child.setStatus(status); jobRepository.update(child); } - stepExecution.setEndTime(new Date()); + stepExecution.setEndTime(OffsetDateTime.now()); stepExecution.setStatus(status); jobRepository.update(stepExecution); JobExecution jobExecution = stepExecution.getJobExecution(); if (!sameJobExecution) { jobExecution.setStatus(BatchStatus.FAILED); - jobExecution.setEndTime(new Date()); + jobExecution.setEndTime(OffsetDateTime.now()); jobRepository.update(jobExecution); JobInstance jobInstance = jobExecution.getJobInstance(); jobExecution = jobRepository.createJobExecution(jobInstance.getJobName(), jobExecution.getJobParameters()); diff --git a/spring-batch-core/src/test/java/org/springframework/batch/core/repository/dao/AbstractExecutionContextDaoTests.java b/spring-batch-core/src/test/java/org/springframework/batch/core/repository/dao/AbstractExecutionContextDaoTests.java index 5935323322..b37c4aeed0 100644 --- a/spring-batch-core/src/test/java/org/springframework/batch/core/repository/dao/AbstractExecutionContextDaoTests.java +++ b/spring-batch-core/src/test/java/org/springframework/batch/core/repository/dao/AbstractExecutionContextDaoTests.java @@ -19,6 +19,7 @@ import static org.junit.jupiter.api.Assertions.assertNull; import static org.junit.jupiter.api.Assertions.assertThrows; +import java.time.OffsetDateTime; import java.util.ArrayList; import java.util.Collections; import java.util.Date; @@ -115,7 +116,7 @@ void testSaveAndFindExecutionContexts() { se.setWriteSkipCount(i); se.setProcessSkipCount(i); se.setRollbackCount(i); - se.setLastUpdated(new Date(System.currentTimeMillis())); + se.setLastUpdated(OffsetDateTime.now()); se.setReadCount(i); se.setFilterCount(i); se.setWriteCount(i); diff --git a/spring-batch-core/src/test/java/org/springframework/batch/core/repository/dao/AbstractJobDaoTests.java b/spring-batch-core/src/test/java/org/springframework/batch/core/repository/dao/AbstractJobDaoTests.java index 7acfc1439f..61890a07b8 100644 --- a/spring-batch-core/src/test/java/org/springframework/batch/core/repository/dao/AbstractJobDaoTests.java +++ b/spring-batch-core/src/test/java/org/springframework/batch/core/repository/dao/AbstractJobDaoTests.java @@ -21,6 +21,8 @@ import static org.junit.jupiter.api.Assertions.assertNull; import static org.junit.jupiter.api.Assertions.assertThrows; +import java.time.OffsetDateTime; +import java.time.temporal.ChronoUnit; import java.util.Date; import java.util.List; import java.util.Map; @@ -59,7 +61,7 @@ public abstract class AbstractJobDaoTests { protected JobExecution jobExecution; - protected Date jobExecutionStartTime = new Date(System.currentTimeMillis()); + protected OffsetDateTime jobExecutionStartTime = OffsetDateTime.now(); protected JdbcTemplate jdbcTemplate; @@ -88,7 +90,7 @@ void onSetUpInTransaction() { jobInstance = jobInstanceDao.createJobInstance(jobName, jobParameters); // Create an execution - jobExecutionStartTime = new Date(System.currentTimeMillis()); + jobExecutionStartTime = OffsetDateTime.now(); jobExecution = new JobExecution(jobInstance, jobParameters); jobExecution.setStartTime(jobExecutionStartTime); jobExecution.setStatus(BatchStatus.STARTED); @@ -165,7 +167,7 @@ void testUpdateJobExecution() { jobExecution.setStatus(BatchStatus.COMPLETED); jobExecution.setExitStatus(ExitStatus.COMPLETED); - jobExecution.setEndTime(new Date(System.currentTimeMillis())); + jobExecution.setEndTime(OffsetDateTime.now()); jobExecutionDao.updateJobExecution(jobExecution); List executions = jobExecutionDao.findJobExecutions(jobInstance); @@ -255,7 +257,7 @@ void testGetLastJobExecution() { lastExecution.setStatus(BatchStatus.STARTED); int JUMP_INTO_FUTURE = 1000; // makes sure start time is 'greatest' - lastExecution.setCreateTime(new Date(System.currentTimeMillis() + JUMP_INTO_FUTURE)); + lastExecution.setCreateTime(OffsetDateTime.now().plus(JUMP_INTO_FUTURE, ChronoUnit.MILLIS)); jobExecutionDao.saveJobExecution(lastExecution); assertEquals(lastExecution, jobExecutionDao.getLastJobExecution(jobInstance)); diff --git a/spring-batch-core/src/test/java/org/springframework/batch/core/repository/dao/AbstractJobExecutionDaoTests.java b/spring-batch-core/src/test/java/org/springframework/batch/core/repository/dao/AbstractJobExecutionDaoTests.java index 2851fa8b53..475efc85a9 100644 --- a/spring-batch-core/src/test/java/org/springframework/batch/core/repository/dao/AbstractJobExecutionDaoTests.java +++ b/spring-batch-core/src/test/java/org/springframework/batch/core/repository/dao/AbstractJobExecutionDaoTests.java @@ -15,6 +15,8 @@ */ package org.springframework.batch.core.repository.dao; +import java.time.OffsetDateTime; +import java.time.temporal.ChronoUnit; import java.util.ArrayList; import java.util.Collections; import java.util.Date; @@ -81,10 +83,11 @@ void onSetUp() { @Test void testSaveAndFind() { - execution.setStartTime(new Date(System.currentTimeMillis())); - execution.setLastUpdated(new Date(System.currentTimeMillis())); + OffsetDateTime now = OffsetDateTime.now(); + execution.setStartTime(now); + execution.setLastUpdated(now.plus(1, ChronoUnit.SECONDS)); execution.setExitStatus(ExitStatus.UNKNOWN); - execution.setEndTime(new Date(System.currentTimeMillis())); + execution.setEndTime(now.plus(10, ChronoUnit.SECONDS)); dao.saveJobExecution(execution); List executions = dao.findJobExecutions(jobInstance); @@ -102,9 +105,10 @@ void testFindExecutionsOrdering() { List execs = new ArrayList<>(); + OffsetDateTime now = OffsetDateTime.now(); for (int i = 0; i < 10; i++) { JobExecution exec = new JobExecution(jobInstance, jobParameters); - exec.setCreateTime(new Date(i)); + exec.setCreateTime(now.plus(i, ChronoUnit.SECONDS)); execs.add(exec); dao.saveJobExecution(exec); } @@ -151,7 +155,7 @@ void testUpdateExecution() { execution.setStatus(BatchStatus.STARTED); dao.saveJobExecution(execution); - execution.setLastUpdated(new Date(0)); + execution.setLastUpdated(OffsetDateTime.now()); execution.setStatus(BatchStatus.COMPLETED); dao.updateJobExecution(execution); @@ -168,10 +172,11 @@ void testUpdateExecution() { @Test void testGetLastExecution() { JobExecution exec1 = new JobExecution(jobInstance, jobParameters); - exec1.setCreateTime(new Date(0)); + OffsetDateTime now = OffsetDateTime.now(); + exec1.setCreateTime(now); JobExecution exec2 = new JobExecution(jobInstance, jobParameters); - exec2.setCreateTime(new Date(1)); + exec2.setCreateTime(now.plus(1, ChronoUnit.SECONDS)); dao.saveJobExecution(exec1); dao.saveJobExecution(exec2); @@ -198,10 +203,11 @@ void testGetMissingLastExecution() { void testFindRunningExecutions() { // Normally completed JobExecution as EndTime is populated JobExecution exec = new JobExecution(jobInstance, jobParameters); - exec.setCreateTime(new Date(0)); - exec.setStartTime(new Date(1L)); - exec.setEndTime(new Date(2L)); - exec.setLastUpdated(new Date(5L)); + OffsetDateTime now = OffsetDateTime.now(); + exec.setCreateTime(now); + exec.setStartTime(now.plus(1, ChronoUnit.SECONDS)); + exec.setEndTime(now.plus(10, ChronoUnit.SECONDS)); + exec.setLastUpdated(now.plus(10, ChronoUnit.SECONDS)); dao.saveJobExecution(exec); // BATCH-2675 @@ -209,13 +215,13 @@ void testFindRunningExecutions() { // This can occur when TaskExecutorJobLauncher#run() submission to taskExecutor // throws a TaskRejectedException exec = new JobExecution(jobInstance, jobParameters); - exec.setLastUpdated(new Date(5L)); + exec.setLastUpdated(now.plus(10, ChronoUnit.SECONDS)); dao.saveJobExecution(exec); // Running JobExecution as StartTime is populated but EndTime is null exec = new JobExecution(jobInstance, jobParameters); - exec.setStartTime(new Date(2L)); - exec.setLastUpdated(new Date(5L)); + exec.setStartTime(now.plus(10, ChronoUnit.SECONDS)); + exec.setLastUpdated(now.plus(10, ChronoUnit.SECONDS)); exec.createStepExecution("step"); dao.saveJobExecution(exec); @@ -231,7 +237,7 @@ void testFindRunningExecutions() { assertEquals(1, values.size()); JobExecution value = values.iterator().next(); assertEquals(exec, value); - assertEquals(5L, value.getLastUpdated().getTime()); + assertEquals(now.plus(10, ChronoUnit.SECONDS), value.getLastUpdated()); } @@ -252,7 +258,8 @@ void testNoRunningExecutions() { @Test void testGetExecution() { JobExecution exec = new JobExecution(jobInstance, jobParameters); - exec.setCreateTime(new Date(0)); + OffsetDateTime now = OffsetDateTime.now(); + exec.setCreateTime(now); exec.createStepExecution("step"); dao.saveJobExecution(exec); diff --git a/spring-batch-core/src/test/java/org/springframework/batch/core/repository/dao/AbstractStepExecutionDaoTests.java b/spring-batch-core/src/test/java/org/springframework/batch/core/repository/dao/AbstractStepExecutionDaoTests.java index ae3029e7fa..eef78b6caf 100644 --- a/spring-batch-core/src/test/java/org/springframework/batch/core/repository/dao/AbstractStepExecutionDaoTests.java +++ b/spring-batch-core/src/test/java/org/springframework/batch/core/repository/dao/AbstractStepExecutionDaoTests.java @@ -22,6 +22,7 @@ import static org.junit.jupiter.api.Assertions.assertThrows; import java.time.Instant; +import java.time.OffsetDateTime; import java.util.ArrayList; import java.util.Arrays; import java.util.Collection; @@ -102,7 +103,7 @@ void testSaveAndGetExecution() { stepExecution.setWriteSkipCount(5); stepExecution.setProcessSkipCount(11); stepExecution.setRollbackCount(3); - stepExecution.setLastUpdated(new Date(System.currentTimeMillis())); + stepExecution.setLastUpdated(OffsetDateTime.now()); stepExecution.setReadCount(17); stepExecution.setFilterCount(15); stepExecution.setWriteCount(13); @@ -132,7 +133,7 @@ void testSaveAndGetExecutions() { se.setWriteSkipCount(i); se.setProcessSkipCount(i); se.setRollbackCount(i); - se.setLastUpdated(new Date(System.currentTimeMillis())); + se.setLastUpdated(OffsetDateTime.now()); se.setReadCount(i); se.setFilterCount(i); se.setWriteCount(i); @@ -159,9 +160,9 @@ void testSaveAndGetExecutions() { void testSaveAndGetLastExecution() { Instant now = Instant.now(); StepExecution stepExecution1 = new StepExecution("step1", jobExecution); - stepExecution1.setStartTime(Date.from(now)); + stepExecution1.setStartTime(OffsetDateTime.from(now)); StepExecution stepExecution2 = new StepExecution("step1", jobExecution); - stepExecution2.setStartTime(Date.from(now.plusMillis(500))); + stepExecution2.setStartTime(OffsetDateTime.from(now.plusMillis(500))); dao.saveStepExecutions(Arrays.asList(stepExecution1, stepExecution2)); @@ -175,9 +176,9 @@ void testSaveAndGetLastExecution() { void testSaveAndGetLastExecutionWhenSameStartTime() { Instant now = Instant.now(); StepExecution stepExecution1 = new StepExecution("step1", jobExecution); - stepExecution1.setStartTime(Date.from(now)); + stepExecution1.setStartTime(OffsetDateTime.from(now)); StepExecution stepExecution2 = new StepExecution("step1", jobExecution); - stepExecution2.setStartTime(Date.from(now)); + stepExecution2.setStartTime(OffsetDateTime.from(now)); dao.saveStepExecutions(Arrays.asList(stepExecution1, stepExecution2)); StepExecution lastStepExecution = stepExecution1.getId() > stepExecution2.getId() ? stepExecution1 @@ -258,7 +259,7 @@ void testUpdateExecution() { Integer versionAfterSave = stepExecution.getVersion(); stepExecution.setStatus(BatchStatus.ABANDONED); - stepExecution.setLastUpdated(new Date(System.currentTimeMillis())); + stepExecution.setLastUpdated(OffsetDateTime.now()); dao.updateStepExecution(stepExecution); assertEquals(versionAfterSave + 1, stepExecution.getVersion().intValue()); diff --git a/spring-batch-core/src/test/java/org/springframework/batch/core/repository/support/SimpleJobRepositoryIntegrationTests.java b/spring-batch-core/src/test/java/org/springframework/batch/core/repository/support/SimpleJobRepositoryIntegrationTests.java index 3e5acac987..8681884e31 100644 --- a/spring-batch-core/src/test/java/org/springframework/batch/core/repository/support/SimpleJobRepositoryIntegrationTests.java +++ b/spring-batch-core/src/test/java/org/springframework/batch/core/repository/support/SimpleJobRepositoryIntegrationTests.java @@ -30,6 +30,8 @@ import org.springframework.test.context.junit.jupiter.SpringJUnitConfig; import org.springframework.transaction.annotation.Transactional; +import java.time.OffsetDateTime; +import java.time.temporal.ChronoUnit; import java.util.Arrays; import java.util.Date; @@ -69,13 +71,13 @@ void testCreateAndFind() throws Exception { JobParameters jobParams = builder.toJobParameters(); JobExecution firstExecution = jobRepository.createJobExecution(job.getName(), jobParams); - firstExecution.setStartTime(new Date()); + firstExecution.setStartTime(OffsetDateTime.now()); assertNotNull(firstExecution.getLastUpdated()); assertEquals(job.getName(), firstExecution.getJobInstance().getJobName()); jobRepository.update(firstExecution); - firstExecution.setEndTime(new Date()); + firstExecution.setEndTime(OffsetDateTime.now()); jobRepository.update(firstExecution); JobExecution secondExecution = jobRepository.createJobExecution(job.getName(), jobParams); @@ -93,8 +95,9 @@ void testCreateAndFindWithNoStartDate() throws Exception { job.setRestartable(true); JobExecution firstExecution = jobRepository.createJobExecution(job.getName(), jobParameters); - firstExecution.setStartTime(new Date(0)); - firstExecution.setEndTime(new Date(1)); + OffsetDateTime now = OffsetDateTime.now(); + firstExecution.setStartTime(now); + firstExecution.setEndTime(now.plus(1, ChronoUnit.SECONDS)); jobRepository.update(firstExecution); JobExecution secondExecution = jobRepository.createJobExecution(job.getName(), jobParameters); @@ -121,13 +124,14 @@ void testGetStepExecutionCountAndLastStepExecution() throws Exception { assertEquals(firstStepExec, jobRepository.getLastStepExecution(firstJobExec.getJobInstance(), step.getName())); // first execution failed - firstJobExec.setStartTime(new Date(4)); - firstStepExec.setStartTime(new Date(5)); + OffsetDateTime now = OffsetDateTime.now(); + firstJobExec.setStartTime(now); + firstStepExec.setStartTime(now.plus(1, ChronoUnit.SECONDS)); firstStepExec.setStatus(BatchStatus.FAILED); - firstStepExec.setEndTime(new Date(6)); + firstStepExec.setEndTime(now.plus(2, ChronoUnit.SECONDS)); jobRepository.update(firstStepExec); firstJobExec.setStatus(BatchStatus.FAILED); - firstJobExec.setEndTime(new Date(7)); + firstJobExec.setEndTime(now.plus(3, ChronoUnit.SECONDS)); jobRepository.update(firstJobExec); // second execution @@ -152,7 +156,7 @@ void testSaveExecutionContext() throws Exception { } }; JobExecution jobExec = jobRepository.createJobExecution(job.getName(), jobParameters); - jobExec.setStartTime(new Date(0)); + jobExec.setStartTime(OffsetDateTime.now()); jobExec.setExecutionContext(ctx); Step step = new StepSupport("step1"); StepExecution stepExec = new StepExecution(step.getName(), jobExec); @@ -181,7 +185,7 @@ void testOnlyOneJobExecutionAllowedRunning() throws Exception { JobExecution jobExecution = jobRepository.createJobExecution(job.getName(), jobParameters); // simulating a running job execution - jobExecution.setStartTime(new Date()); + jobExecution.setStartTime(OffsetDateTime.now()); jobRepository.update(jobExecution); assertThrows(JobExecutionAlreadyRunningException.class, @@ -193,7 +197,7 @@ void testOnlyOneJobExecutionAllowedRunning() throws Exception { void testGetLastJobExecution() throws Exception { JobExecution jobExecution = jobRepository.createJobExecution(job.getName(), jobParameters); jobExecution.setStatus(BatchStatus.FAILED); - jobExecution.setEndTime(new Date()); + jobExecution.setEndTime(OffsetDateTime.now()); jobRepository.update(jobExecution); Thread.sleep(10); jobExecution = jobRepository.createJobExecution(job.getName(), jobParameters); @@ -214,7 +218,7 @@ void testReExecuteWithSameJobParameters() throws Exception { JobParameters jobParameters = new JobParametersBuilder().addString("name", "foo", false).toJobParameters(); JobExecution jobExecution1 = jobRepository.createJobExecution(job.getName(), jobParameters); jobExecution1.setStatus(BatchStatus.COMPLETED); - jobExecution1.setEndTime(new Date()); + jobExecution1.setEndTime(OffsetDateTime.now()); jobRepository.update(jobExecution1); JobExecution jobExecution2 = jobRepository.createJobExecution(job.getName(), jobParameters); assertNotNull(jobExecution1); diff --git a/spring-batch-core/src/test/java/org/springframework/batch/core/repository/support/SimpleJobRepositoryTests.java b/spring-batch-core/src/test/java/org/springframework/batch/core/repository/support/SimpleJobRepositoryTests.java index fd35201fc5..0c1fd09874 100644 --- a/spring-batch-core/src/test/java/org/springframework/batch/core/repository/support/SimpleJobRepositoryTests.java +++ b/spring-batch-core/src/test/java/org/springframework/batch/core/repository/support/SimpleJobRepositoryTests.java @@ -25,6 +25,7 @@ import static org.mockito.Mockito.verify; import static org.mockito.Mockito.when; +import java.time.OffsetDateTime; import java.util.ArrayList; import java.util.Arrays; import java.util.Collections; @@ -162,14 +163,14 @@ void testSaveStepExecutionSetsLastUpdated() { StepExecution stepExecution = new StepExecution("stepName", jobExecution); - long before = System.currentTimeMillis(); + OffsetDateTime before = OffsetDateTime.now(); jobRepository.add(stepExecution); assertNotNull(stepExecution.getLastUpdated()); - long lastUpdated = stepExecution.getLastUpdated().getTime(); - assertTrue(lastUpdated > (before - 1000)); + OffsetDateTime lastUpdated = stepExecution.getLastUpdated(); + assertTrue(lastUpdated.isAfter(before)); } @Test @@ -196,14 +197,14 @@ void testUpdateStepExecutionSetsLastUpdated() { StepExecution stepExecution = new StepExecution("stepName", jobExecution); stepExecution.setId(2343L); - long before = System.currentTimeMillis(); + OffsetDateTime before = OffsetDateTime.now(); jobRepository.update(stepExecution); assertNotNull(stepExecution.getLastUpdated()); - long lastUpdated = stepExecution.getLastUpdated().getTime(); - assertTrue(lastUpdated > (before - 1000)); + OffsetDateTime lastUpdated = stepExecution.getLastUpdated(); + assertTrue(lastUpdated.isAfter(before)); } @Test @@ -233,7 +234,7 @@ void testIsJobInstanceTrue() { @Test void testCreateJobExecutionAlreadyRunning() { jobExecution.setStatus(BatchStatus.STARTED); - jobExecution.setStartTime(new Date()); + jobExecution.setStartTime(OffsetDateTime.now()); jobExecution.setEndTime(null); when(jobInstanceDao.getJobInstance("foo", new JobParameters())).thenReturn(jobInstance); @@ -246,7 +247,7 @@ void testCreateJobExecutionAlreadyRunning() { @Test void testCreateJobExecutionStatusUnknown() { jobExecution.setStatus(BatchStatus.UNKNOWN); - jobExecution.setEndTime(new Date()); + jobExecution.setEndTime(OffsetDateTime.now()); when(jobInstanceDao.getJobInstance("foo", new JobParameters())).thenReturn(jobInstance); when(jobExecutionDao.findJobExecutions(jobInstance)).thenReturn(Arrays.asList(jobExecution)); @@ -257,7 +258,7 @@ void testCreateJobExecutionStatusUnknown() { @Test void testCreateJobExecutionAlreadyComplete() { jobExecution.setStatus(BatchStatus.COMPLETED); - jobExecution.setEndTime(new Date()); + jobExecution.setEndTime(OffsetDateTime.now()); when(jobInstanceDao.getJobInstance("foo", new JobParameters())).thenReturn(jobInstance); when(jobExecutionDao.findJobExecutions(jobInstance)).thenReturn(Arrays.asList(jobExecution)); diff --git a/spring-batch-core/src/test/java/org/springframework/batch/core/step/item/FaultTolerantStepFactoryBeanRetryTests.java b/spring-batch-core/src/test/java/org/springframework/batch/core/step/item/FaultTolerantStepFactoryBeanRetryTests.java index 28e53caafe..5fd28af988 100644 --- a/spring-batch-core/src/test/java/org/springframework/batch/core/step/item/FaultTolerantStepFactoryBeanRetryTests.java +++ b/spring-batch-core/src/test/java/org/springframework/batch/core/step/item/FaultTolerantStepFactoryBeanRetryTests.java @@ -15,6 +15,7 @@ */ package org.springframework.batch.core.step.item; +import java.time.OffsetDateTime; import java.util.ArrayList; import java.util.Arrays; import java.util.Collections; @@ -126,7 +127,7 @@ void setUp() throws Exception { JobParameters jobParameters = new JobParametersBuilder().addString("statefulTest", "make_this_unique") .toJobParameters(); jobExecution = repository.createJobExecution("job", jobParameters); - jobExecution.setEndTime(new Date()); + jobExecution.setEndTime(OffsetDateTime.now()); } diff --git a/spring-batch-core/src/test/java/org/springframework/batch/core/step/job/JobStepTests.java b/spring-batch-core/src/test/java/org/springframework/batch/core/step/job/JobStepTests.java index 3cb2f82b3b..004a36d659 100644 --- a/spring-batch-core/src/test/java/org/springframework/batch/core/step/job/JobStepTests.java +++ b/spring-batch-core/src/test/java/org/springframework/batch/core/step/job/JobStepTests.java @@ -15,6 +15,7 @@ */ package org.springframework.batch.core.step.job; +import java.time.OffsetDateTime; import java.util.Date; import org.junit.jupiter.api.BeforeEach; @@ -96,7 +97,7 @@ void testExecuteSunnyDay() throws Exception { @Override public void execute(JobExecution execution) throws UnexpectedJobExecutionException { execution.setStatus(BatchStatus.COMPLETED); - execution.setEndTime(new Date()); + execution.setEndTime(OffsetDateTime.now()); } }); step.afterPropertiesSet(); @@ -112,7 +113,7 @@ void testExecuteFailure() throws Exception { @Override public void execute(JobExecution execution) throws UnexpectedJobExecutionException { execution.setStatus(BatchStatus.FAILED); - execution.setEndTime(new Date()); + execution.setEndTime(OffsetDateTime.now()); } }); step.afterPropertiesSet(); @@ -148,7 +149,7 @@ void testExecuteRestart() throws Exception { public void execute(JobExecution execution) throws UnexpectedJobExecutionException { assertEquals(1, execution.getJobParameters().getParameters().size()); execution.setStatus(BatchStatus.FAILED); - execution.setEndTime(new Date()); + execution.setEndTime(OffsetDateTime.now()); jobRepository.update(execution); throw new RuntimeException("FOO"); } @@ -162,7 +163,7 @@ public boolean isRestartable() { step.execute(stepExecution); assertEquals("FOO", stepExecution.getFailureExceptions().get(0).getMessage()); JobExecution jobExecution = stepExecution.getJobExecution(); - jobExecution.setEndTime(new Date()); + jobExecution.setEndTime(OffsetDateTime.now()); jobRepository.update(jobExecution); jobExecution = jobRepository.createJobExecution("job", new JobParameters()); @@ -189,7 +190,7 @@ void testStoppedChild() throws Exception { public void execute(JobExecution execution) { assertEquals(1, execution.getJobParameters().getParameters().size()); execution.setStatus(BatchStatus.STOPPED); - execution.setEndTime(new Date()); + execution.setEndTime(OffsetDateTime.now()); jobRepository.update(execution); } @@ -202,7 +203,7 @@ public boolean isRestartable() { step.afterPropertiesSet(); step.execute(stepExecution); JobExecution jobExecution = stepExecution.getJobExecution(); - jobExecution.setEndTime(new Date()); + jobExecution.setEndTime(OffsetDateTime.now()); jobRepository.update(jobExecution); assertEquals(BatchStatus.STOPPED, stepExecution.getStatus()); @@ -215,7 +216,7 @@ void testStepExecutionExitStatus() throws Exception { public void execute(JobExecution execution) throws UnexpectedJobExecutionException { execution.setStatus(BatchStatus.COMPLETED); execution.setExitStatus(new ExitStatus("CUSTOM")); - execution.setEndTime(new Date()); + execution.setEndTime(OffsetDateTime.now()); } }); step.afterPropertiesSet(); diff --git a/spring-batch-core/src/test/java/org/springframework/batch/core/test/repository/HANAJobRepositoryIntegrationTests.java b/spring-batch-core/src/test/java/org/springframework/batch/core/test/repository/HANAJobRepositoryIntegrationTests.java index 9e70291e31..dddcb44470 100644 --- a/spring-batch-core/src/test/java/org/springframework/batch/core/test/repository/HANAJobRepositoryIntegrationTests.java +++ b/spring-batch-core/src/test/java/org/springframework/batch/core/test/repository/HANAJobRepositoryIntegrationTests.java @@ -71,7 +71,7 @@ */ @Testcontainers @SpringJUnitConfig -@Disabled("Official Docker image for SAP HANA not publicly available and works only on Linux") +//@Disabled("Official Docker image for SAP HANA not publicly available and works only on Linux") class HANAJobRepositoryIntegrationTests { private static final DockerImageName HANA_IMAGE = DockerImageName diff --git a/spring-batch-core/src/test/java/org/springframework/batch/core/test/repository/JdbcJobRepositoryTests.java b/spring-batch-core/src/test/java/org/springframework/batch/core/test/repository/JdbcJobRepositoryTests.java index d8778602bb..c166f25cea 100644 --- a/spring-batch-core/src/test/java/org/springframework/batch/core/test/repository/JdbcJobRepositoryTests.java +++ b/spring-batch-core/src/test/java/org/springframework/batch/core/test/repository/JdbcJobRepositoryTests.java @@ -17,6 +17,7 @@ import java.io.Serializable; import java.sql.Timestamp; +import java.time.OffsetDateTime; import java.util.ArrayList; import java.util.Date; import java.util.HashSet; @@ -134,7 +135,7 @@ void testFindOrCreateJobConcurrentlyWhenJobAlreadyExists() throws Exception { JobExecution execution = repository.createJobExecution(job.getName(), new JobParameters()); cacheJobIds(execution); - execution.setEndTime(new Timestamp(System.currentTimeMillis())); + execution.setEndTime(OffsetDateTime.now()); repository.update(execution); execution.setStatus(BatchStatus.FAILED); @@ -170,7 +171,7 @@ public void run() { JobExecution execution = repository.createJobExecution(job.getName(), new JobParameters()); // simulate running execution - execution.setStartTime(new Date()); + execution.setStartTime(OffsetDateTime.now()); repository.update(execution); cacheJobIds(execution); diff --git a/spring-batch-test/src/test/java/org/springframework/batch/test/JobRepositoryTestUtilsTests.java b/spring-batch-test/src/test/java/org/springframework/batch/test/JobRepositoryTestUtilsTests.java index b17174bc32..a2cb5abcc8 100644 --- a/spring-batch-test/src/test/java/org/springframework/batch/test/JobRepositoryTestUtilsTests.java +++ b/spring-batch-test/src/test/java/org/springframework/batch/test/JobRepositoryTestUtilsTests.java @@ -18,6 +18,7 @@ import static org.junit.jupiter.api.Assertions.assertEquals; import static org.junit.jupiter.api.Assertions.assertThrows; +import java.time.OffsetDateTime; import java.util.ArrayList; import java.util.Date; import java.util.List; @@ -83,7 +84,7 @@ void testRemoveJobExecutionsWithSameJobInstance() throws Exception { utils = new JobRepositoryTestUtils(jobRepository); List list = new ArrayList<>(); JobExecution jobExecution = jobRepository.createJobExecution("job", new JobParameters()); - jobExecution.setEndTime(new Date()); + jobExecution.setEndTime(OffsetDateTime.now()); list.add(jobExecution); jobRepository.update(jobExecution); jobExecution = jobRepository.createJobExecution("job", new JobParameters());