Skip to content

[WIP] Change timestamps type to OffsetDateTime in Job/Step Execution #4209

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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;

Expand Down Expand Up @@ -140,7 +140,7 @@ public JobParameters getJobParameters() {
* @return The current end time.
*/
@Nullable
public Date getEndTime() {
public OffsetDateTime getEndTime() {
return endTime;
}

Expand All @@ -154,25 +154,25 @@ 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;
}

/**
* @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;
}

Expand Down Expand Up @@ -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;
}

Expand All @@ -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;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -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();

Expand Down Expand Up @@ -156,15 +156,15 @@ 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;
}

/**
* 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;
}

Expand Down Expand Up @@ -236,15 +236,15 @@ 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;
}

/**
* 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;
}

Expand All @@ -253,15 +253,15 @@ public void setCreateTime(Date createTime) {
* @return the time when this execution started.
*/
@Nullable
public Date getStartTime() {
public OffsetDateTime getStartTime() {
return startTime;
}

/**
* 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;
}

Expand Down Expand Up @@ -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;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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());
}
Expand Down Expand Up @@ -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) {
Expand Down Expand Up @@ -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;
}
Expand Down
Loading