Skip to content

Commit d91d473

Browse files
artembilanspring-builds
authored andcommitted
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 (cherry picked from commit e5b8994)
1 parent 727a11a commit d91d473

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;
@@ -414,12 +413,12 @@ public boolean acquire(String lock, Duration ttlDuration) {
414413
return this.readCommittedTransactionTemplate.<Boolean>execute(
415414
transactionStatus -> {
416415
if (this.template.update(this.updateQuery, this.id, ttlEpochMillis(ttlDuration),
417-
this.region, lock, this.id, epochMillis()) > 0) {
416+
this.region, lock, this.id, currentTime()) > 0) {
418417
return true;
419418
}
420419
try {
421420
return this.template.update(this.insertQuery, this.region, lock, this.id,
422-
epochMillis(), ttlEpochMillis(ttlDuration)) > 0;
421+
currentTime(), ttlEpochMillis(ttlDuration)) > 0;
423422
}
424423
catch (DataIntegrityViolationException ex) {
425424
return false;
@@ -433,14 +432,14 @@ public boolean isAcquired(String lock) {
433432
transactionStatus ->
434433
Integer.valueOf(1).equals(
435434
this.template.queryForObject(this.countQuery,
436-
Integer.class, this.region, lock, this.id, epochMillis())));
435+
Integer.class, this.region, lock, this.id, currentTime())));
437436
}
438437

439438
@Override
440439
public void deleteExpired() {
441440
this.defaultTransactionTemplate.executeWithoutResult(
442441
transactionStatus ->
443-
this.template.update(this.deleteExpiredQuery, this.region, epochMillis()));
442+
this.template.update(this.deleteExpiredQuery, this.region, currentTime()));
444443
}
445444

446445
@Override
@@ -456,12 +455,8 @@ public boolean renew(String lock, Duration ttlDuration) {
456455
this.template.update(this.renewQuery, ttlEpochMillis(ttlDuration), this.region, lock, this.id) == 1);
457456
}
458457

459-
private Timestamp ttlEpochMillis(Duration ttl) {
460-
return Timestamp.valueOf(currentTime().plus(ttl));
461-
}
462-
463-
private static Timestamp epochMillis() {
464-
return Timestamp.valueOf(currentTime());
458+
private static LocalDateTime ttlEpochMillis(Duration ttl) {
459+
return currentTime().plus(ttl);
465460
}
466461

467462
private static LocalDateTime currentTime() {

0 commit comments

Comments
 (0)