Skip to content

Commit e5b8994

Browse files
authored
GH-10906: DefaultLockRepository: Use LocalDateTime directly (#10908)
Fixes: #10906 The `Timestamp.valueOf()` method uses the system default time zone which may lead to discrepancy when daylight saving happens According to JDBC 4.2+, we don't need to convert `LocalDateTime` to `Timestamp` anymore * Fix `DefaultLockRepository` to use `LocalDateTime` as values for SQL statements instead of wrapping them into `Timestamp` There are no any new tests since this internal change does not affect API logic, and existing working tests prove that everything is still right **Auto-cherry-pick to `7.0.x` & `6.5.x`**
1 parent 661974a commit e5b8994

1 file changed

Lines changed: 6 additions & 11 deletions

File tree

spring-integration-jdbc/src/main/java/org/springframework/integration/jdbc/lock/DefaultLockRepository.java

Lines changed: 6 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@
1616

1717
package org.springframework.integration.jdbc.lock;
1818

19-
import java.sql.Timestamp;
2019
import java.time.Duration;
2120
import java.time.LocalDateTime;
2221
import java.time.ZoneOffset;
@@ -391,12 +390,12 @@ public boolean acquire(String lock, Duration ttlDuration) {
391390
return this.readCommittedTransactionTemplate.<Boolean>execute(
392391
transactionStatus -> {
393392
if (this.template.update(this.updateQuery, this.id, ttlEpochMillis(ttlDuration),
394-
this.region, lock, this.id, epochMillis()) > 0) {
393+
this.region, lock, this.id, currentTime()) > 0) {
395394
return true;
396395
}
397396
try {
398397
return this.template.update(this.insertQuery, this.region, lock, this.id,
399-
epochMillis(), ttlEpochMillis(ttlDuration)) > 0;
398+
currentTime(), ttlEpochMillis(ttlDuration)) > 0;
400399
}
401400
catch (DataIntegrityViolationException ex) {
402401
return false;
@@ -410,14 +409,14 @@ public boolean isAcquired(String lock) {
410409
transactionStatus ->
411410
Integer.valueOf(1).equals(
412411
this.template.queryForObject(this.countQuery,
413-
Integer.class, this.region, lock, this.id, epochMillis())));
412+
Integer.class, this.region, lock, this.id, currentTime())));
414413
}
415414

416415
@Override
417416
public void deleteExpired() {
418417
this.defaultTransactionTemplate.executeWithoutResult(
419418
transactionStatus ->
420-
this.template.update(this.deleteExpiredQuery, this.region, epochMillis()));
419+
this.template.update(this.deleteExpiredQuery, this.region, currentTime()));
421420
}
422421

423422
@Override
@@ -427,12 +426,8 @@ public boolean renew(String lock, Duration ttlDuration) {
427426
this.template.update(this.renewQuery, ttlEpochMillis(ttlDuration), this.region, lock, this.id) == 1);
428427
}
429428

430-
private Timestamp ttlEpochMillis(Duration ttl) {
431-
return Timestamp.valueOf(currentTime().plus(ttl));
432-
}
433-
434-
private static Timestamp epochMillis() {
435-
return Timestamp.valueOf(currentTime());
429+
private static LocalDateTime ttlEpochMillis(Duration ttl) {
430+
return currentTime().plus(ttl);
436431
}
437432

438433
private static LocalDateTime currentTime() {

0 commit comments

Comments
 (0)