|
16 | 16 |
|
17 | 17 | package org.springframework.integration.jdbc.lock;
|
18 | 18 |
|
19 |
| -import java.util.Date; |
| 19 | +import java.time.LocalDateTime; |
| 20 | +import java.time.ZoneOffset; |
| 21 | +import java.time.temporal.ChronoUnit; |
20 | 22 | import java.util.UUID;
|
21 | 23 |
|
22 | 24 | import javax.sql.DataSource;
|
@@ -223,40 +225,46 @@ public void delete(String lock) {
|
223 | 225 |
|
224 | 226 | @Override
|
225 | 227 | public boolean acquire(String lock) {
|
226 |
| - return this.serializableTransactionTemplate.execute(transactionStatus -> { |
227 |
| - if (this.template.update(this.updateQuery, this.id, new Date(), this.region, lock, this.id, |
228 |
| - new Date(System.currentTimeMillis() - this.ttl)) > 0) { |
229 |
| - return true; |
230 |
| - } |
231 |
| - try { |
232 |
| - return this.template.update(this.insertQuery, this.region, lock, this.id, new Date()) > 0; |
233 |
| - } |
234 |
| - catch (DataIntegrityViolationException ex) { |
235 |
| - return false; |
236 |
| - } |
237 |
| - }); |
| 228 | + return this.serializableTransactionTemplate.execute( |
| 229 | + transactionStatus -> { |
| 230 | + if (this.template.update(this.updateQuery, this.id, LocalDateTime.now(ZoneOffset.UTC), |
| 231 | + this.region, lock, this.id, |
| 232 | + LocalDateTime.now(ZoneOffset.UTC).minus(this.ttl, ChronoUnit.MILLIS)) > 0) { |
| 233 | + return true; |
| 234 | + } |
| 235 | + try { |
| 236 | + return this.template.update(this.insertQuery, this.region, lock, this.id, |
| 237 | + LocalDateTime.now(ZoneOffset.UTC)) > 0; |
| 238 | + } |
| 239 | + catch (DataIntegrityViolationException ex) { |
| 240 | + return false; |
| 241 | + } |
| 242 | + }); |
238 | 243 | }
|
239 | 244 |
|
240 | 245 | @Override
|
241 | 246 | public boolean isAcquired(String lock) {
|
242 |
| - return this.readOnlyTransactionTemplate.execute(transactionStatus -> |
243 |
| - this.template.queryForObject(this.countQuery, // NOSONAR query never returns null |
244 |
| - Integer.class, this.region, lock, this.id, new Date(System.currentTimeMillis() - this.ttl)) |
245 |
| - == 1); |
| 247 | + return this.readOnlyTransactionTemplate.execute( |
| 248 | + transactionStatus -> |
| 249 | + this.template.queryForObject(this.countQuery, // NOSONAR query never returns null |
| 250 | + Integer.class, this.region, lock, this.id, |
| 251 | + LocalDateTime.now(ZoneOffset.UTC).minus(this.ttl, ChronoUnit.MILLIS)) == 1); |
246 | 252 | }
|
247 | 253 |
|
248 | 254 | @Override
|
249 | 255 | public void deleteExpired() {
|
250 | 256 | this.defaultTransactionTemplate.executeWithoutResult(
|
251 | 257 | transactionStatus ->
|
252 | 258 | this.template.update(this.deleteExpiredQuery, this.region,
|
253 |
| - new Date(System.currentTimeMillis() - this.ttl))); |
| 259 | + LocalDateTime.now(ZoneOffset.UTC).minus(this.ttl, ChronoUnit.MILLIS))); |
254 | 260 | }
|
255 | 261 |
|
256 | 262 | @Override
|
257 | 263 | public boolean renew(String lock) {
|
258 | 264 | return this.defaultTransactionTemplate.execute(
|
259 |
| - transactionStatus -> this.template.update(this.renewQuery, new Date(), this.region, lock, this.id) > 0); |
| 265 | + transactionStatus -> |
| 266 | + this.template.update(this.renewQuery, LocalDateTime.now(ZoneOffset.UTC), |
| 267 | + this.region, lock, this.id) > 0); |
260 | 268 | }
|
261 | 269 |
|
262 | 270 | }
|
0 commit comments