[#6447] Add Clock Configuration.clock()
This commit is contained in:
parent
4b8723fd5e
commit
9f5965feb7
@ -37,6 +37,7 @@ package org.jooq;
|
||||
import java.io.Serializable;
|
||||
import java.sql.Connection;
|
||||
import java.sql.Savepoint;
|
||||
import java.time.Clock;
|
||||
import java.util.Map;
|
||||
import java.util.concurrent.Executor;
|
||||
import java.util.concurrent.ForkJoinPool;
|
||||
@ -236,6 +237,14 @@ public interface Configuration extends Serializable {
|
||||
// Getters
|
||||
// -------------------------------------------------------------------------
|
||||
|
||||
|
||||
/**
|
||||
* Get this configuration's {@link Clock}, which is used for optimistic
|
||||
* locking, transaction time, and other time-depending features.
|
||||
*/
|
||||
Clock clock();
|
||||
|
||||
|
||||
/**
|
||||
* Get this configuration's underlying connection provider.
|
||||
*/
|
||||
@ -386,6 +395,20 @@ public interface Configuration extends Serializable {
|
||||
// Setters
|
||||
// -------------------------------------------------------------------------
|
||||
|
||||
|
||||
/**
|
||||
* Change this configuration to hold a new {@link Clock}.
|
||||
* <p>
|
||||
* This method is not thread-safe and should not be used in globally
|
||||
* available <code>Configuration</code> objects.
|
||||
*
|
||||
* @param newClock The new clock to be contained in the changed
|
||||
* configuration.
|
||||
* @return The changed configuration.
|
||||
*/
|
||||
Configuration set(Clock newClock);
|
||||
|
||||
|
||||
/**
|
||||
* Change this configuration to hold a new connection provider.
|
||||
* <p>
|
||||
@ -675,6 +698,17 @@ public interface Configuration extends Serializable {
|
||||
*/
|
||||
Configuration derive();
|
||||
|
||||
|
||||
/**
|
||||
* Create a derived configuration from this one, with a new {@link Clock}.
|
||||
*
|
||||
* @param newClock The new clock to be contained in the derived
|
||||
* configuration.
|
||||
* @return The derived configuration.
|
||||
*/
|
||||
Configuration derive(Clock newClock);
|
||||
|
||||
|
||||
/**
|
||||
* Create a derived configuration from this one, with a new connection
|
||||
* wrapped in a {@link DefaultConnectionProvider}.
|
||||
|
||||
@ -300,6 +300,7 @@ abstract class AbstractDMLQuery<R extends Record> extends AbstractQuery {
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
abstract void accept0(Context<?> ctx);
|
||||
|
||||
@ -43,6 +43,7 @@ import java.io.ObjectOutputStream;
|
||||
import java.io.Serializable;
|
||||
import java.io.StringWriter;
|
||||
import java.sql.Connection;
|
||||
import java.time.Clock;
|
||||
import java.util.Map;
|
||||
import java.util.concurrent.ConcurrentHashMap;
|
||||
import java.util.concurrent.Executor;
|
||||
@ -97,6 +98,9 @@ public class DefaultConfiguration implements Configuration {
|
||||
private Settings settings;
|
||||
private ConcurrentHashMap<Object, Object> data;
|
||||
|
||||
private Clock clock;
|
||||
|
||||
|
||||
// Non-serializable Configuration objects
|
||||
private transient ConnectionProvider connectionProvider;
|
||||
private transient ExecutorProvider executorProvider;
|
||||
@ -450,6 +454,9 @@ public class DefaultConfiguration implements Configuration {
|
||||
visitListenerProviders,
|
||||
transactionListenerProviders,
|
||||
converterProvider,
|
||||
|
||||
null,
|
||||
|
||||
dialect,
|
||||
settings,
|
||||
data
|
||||
@ -475,6 +482,9 @@ public class DefaultConfiguration implements Configuration {
|
||||
VisitListenerProvider[] visitListenerProviders,
|
||||
TransactionListenerProvider[] transactionListenerProviders,
|
||||
ConverterProvider converterProvider,
|
||||
|
||||
Clock clock,
|
||||
|
||||
SQLDialect dialect,
|
||||
Settings settings,
|
||||
Map<Object, Object> data)
|
||||
@ -489,6 +499,9 @@ public class DefaultConfiguration implements Configuration {
|
||||
set(visitListenerProviders);
|
||||
set(transactionListenerProviders);
|
||||
set(converterProvider);
|
||||
|
||||
set(clock);
|
||||
|
||||
set(dialect);
|
||||
set(settings);
|
||||
|
||||
@ -538,6 +551,9 @@ public class DefaultConfiguration implements Configuration {
|
||||
visitListenerProviders,
|
||||
transactionListenerProviders,
|
||||
converterProvider,
|
||||
|
||||
clock,
|
||||
|
||||
dialect,
|
||||
settings,
|
||||
data
|
||||
@ -562,6 +578,9 @@ public class DefaultConfiguration implements Configuration {
|
||||
visitListenerProviders,
|
||||
transactionListenerProviders,
|
||||
converterProvider,
|
||||
|
||||
clock,
|
||||
|
||||
dialect,
|
||||
settings,
|
||||
data
|
||||
@ -581,6 +600,9 @@ public class DefaultConfiguration implements Configuration {
|
||||
visitListenerProviders,
|
||||
transactionListenerProviders,
|
||||
converterProvider,
|
||||
|
||||
clock,
|
||||
|
||||
dialect,
|
||||
settings,
|
||||
data
|
||||
@ -605,6 +627,9 @@ public class DefaultConfiguration implements Configuration {
|
||||
visitListenerProviders,
|
||||
transactionListenerProviders,
|
||||
converterProvider,
|
||||
|
||||
clock,
|
||||
|
||||
dialect,
|
||||
settings,
|
||||
data
|
||||
@ -629,6 +654,9 @@ public class DefaultConfiguration implements Configuration {
|
||||
visitListenerProviders,
|
||||
transactionListenerProviders,
|
||||
converterProvider,
|
||||
|
||||
clock,
|
||||
|
||||
dialect,
|
||||
settings,
|
||||
data
|
||||
@ -653,6 +681,9 @@ public class DefaultConfiguration implements Configuration {
|
||||
visitListenerProviders,
|
||||
transactionListenerProviders,
|
||||
converterProvider,
|
||||
|
||||
clock,
|
||||
|
||||
dialect,
|
||||
settings,
|
||||
data
|
||||
@ -677,6 +708,9 @@ public class DefaultConfiguration implements Configuration {
|
||||
visitListenerProviders,
|
||||
transactionListenerProviders,
|
||||
converterProvider,
|
||||
|
||||
clock,
|
||||
|
||||
dialect,
|
||||
settings,
|
||||
data
|
||||
@ -701,6 +735,9 @@ public class DefaultConfiguration implements Configuration {
|
||||
newVisitListenerProviders,
|
||||
transactionListenerProviders,
|
||||
converterProvider,
|
||||
|
||||
clock,
|
||||
|
||||
dialect,
|
||||
settings,
|
||||
data
|
||||
@ -725,6 +762,9 @@ public class DefaultConfiguration implements Configuration {
|
||||
visitListenerProviders,
|
||||
newTransactionListenerProviders,
|
||||
converterProvider,
|
||||
|
||||
clock,
|
||||
|
||||
dialect,
|
||||
settings,
|
||||
data
|
||||
@ -744,12 +784,37 @@ public class DefaultConfiguration implements Configuration {
|
||||
visitListenerProviders,
|
||||
transactionListenerProviders,
|
||||
newConverterProvider,
|
||||
|
||||
clock,
|
||||
|
||||
dialect,
|
||||
settings,
|
||||
data
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public final Configuration derive(Clock newClock) {
|
||||
return new DefaultConfiguration(
|
||||
connectionProvider,
|
||||
executorProvider,
|
||||
transactionProvider,
|
||||
recordMapperProvider,
|
||||
recordUnmapperProvider,
|
||||
recordListenerProviders,
|
||||
executeListenerProviders,
|
||||
visitListenerProviders,
|
||||
transactionListenerProviders,
|
||||
converterProvider,
|
||||
newClock,
|
||||
dialect,
|
||||
settings,
|
||||
data
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public final Configuration derive(SQLDialect newDialect) {
|
||||
return new DefaultConfiguration(
|
||||
@ -763,6 +828,9 @@ public class DefaultConfiguration implements Configuration {
|
||||
visitListenerProviders,
|
||||
transactionListenerProviders,
|
||||
converterProvider,
|
||||
|
||||
clock,
|
||||
|
||||
newDialect,
|
||||
settings,
|
||||
data
|
||||
@ -782,6 +850,9 @@ public class DefaultConfiguration implements Configuration {
|
||||
visitListenerProviders,
|
||||
transactionListenerProviders,
|
||||
converterProvider,
|
||||
|
||||
clock,
|
||||
|
||||
dialect,
|
||||
newSettings,
|
||||
data
|
||||
@ -933,6 +1004,16 @@ public class DefaultConfiguration implements Configuration {
|
||||
return this;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public final Configuration set(Clock newClock) {
|
||||
|
||||
// [#6447] Defaulting to UTC system time
|
||||
this.clock = newClock == null ? Clock.systemUTC() : newClock;
|
||||
return this;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public final Configuration set(SQLDialect newDialect) {
|
||||
|
||||
@ -1127,6 +1208,13 @@ public class DefaultConfiguration implements Configuration {
|
||||
return converterProvider;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public final Clock clock() {
|
||||
return clock;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public final SQLDialect dialect() {
|
||||
return dialect;
|
||||
|
||||
Loading…
Reference in New Issue
Block a user