54
54
import java .util .List ;
55
55
import java .util .Map ;
56
56
import java .util .ServiceLoader ;
57
+ import java .util .TimeZone ;
57
58
import java .util .function .Function ;
58
59
import java .util .function .Supplier ;
59
60
import java .util .function .ToIntFunction ;
@@ -120,6 +121,8 @@ public final class PostgresqlConnectionConfiguration {
120
121
121
122
private final boolean tcpNoDelay ;
122
123
124
+ private final TimeZone timeZone ;
125
+
123
126
private final String username ;
124
127
125
128
private PostgresqlConnectionConfiguration (String applicationName , boolean autodetectExtensions , @ Nullable boolean compatibilityMode , @ Nullable Duration connectTimeout , @ Nullable String database ,
@@ -130,7 +133,7 @@ private PostgresqlConnectionConfiguration(String applicationName, boolean autode
130
133
LogLevel noticeLogLevel , @ Nullable Map <String , String > options , @ Nullable CharSequence password , boolean preferAttachedBuffers ,
131
134
int preparedStatementCacheQueries , @ Nullable String schema ,
132
135
@ Nullable SingleHostConfiguration singleHostConfiguration , SSLConfig sslConfig , @ Nullable Duration statementTimeout ,
133
- boolean tcpKeepAlive , boolean tcpNoDelay ,
136
+ boolean tcpKeepAlive , boolean tcpNoDelay , TimeZone timeZone ,
134
137
String username ) {
135
138
this .applicationName = Assert .requireNonNull (applicationName , "applicationName must not be null" );
136
139
this .autodetectExtensions = autodetectExtensions ;
@@ -167,6 +170,7 @@ private PostgresqlConnectionConfiguration(String applicationName, boolean autode
167
170
this .sslConfig = sslConfig ;
168
171
this .tcpKeepAlive = tcpKeepAlive ;
169
172
this .tcpNoDelay = tcpNoDelay ;
173
+ this .timeZone = timeZone ;
170
174
this .username = Assert .requireNonNull (username , "username must not be null" );
171
175
}
172
176
@@ -202,6 +206,7 @@ public String toString() {
202
206
", statementTimeout=" + this .statementTimeout +
203
207
", tcpKeepAlive=" + this .tcpKeepAlive +
204
208
", tcpNoDelay=" + this .tcpNoDelay +
209
+ ", timeZone=" + this .timeZone +
205
210
", username='" + this .username + '\'' +
206
211
'}' ;
207
212
}
@@ -305,6 +310,10 @@ boolean isTcpNoDelay() {
305
310
return this .tcpNoDelay ;
306
311
}
307
312
313
+ TimeZone getTimeZone () {
314
+ return this .timeZone ;
315
+ }
316
+
308
317
SSLConfig getSslConfig () {
309
318
return this .sslConfig ;
310
319
}
@@ -408,6 +417,8 @@ public static final class Builder {
408
417
409
418
private boolean tcpNoDelay = true ;
410
419
420
+ private TimeZone timeZone = TimeZone .getDefault ();
421
+
411
422
@ Nullable
412
423
private LoopResources loopResources = null ;
413
424
@@ -467,7 +478,7 @@ public PostgresqlConnectionConfiguration build() {
467
478
this .extensions , this .fetchSize , this .forceBinary , this .lockWaitTimeout , this .loopResources , multiHostConfiguration ,
468
479
this .noticeLogLevel , this .options , this .password , this .preferAttachedBuffers ,
469
480
this .preparedStatementCacheQueries , this .schema , singleHostConfiguration ,
470
- this .createSslConfig (), this .statementTimeout , this .tcpKeepAlive , this .tcpNoDelay , this .username );
481
+ this .createSslConfig (), this .statementTimeout , this .tcpKeepAlive , this .tcpNoDelay , this .timeZone , this . username );
471
482
}
472
483
473
484
/**
@@ -977,6 +988,33 @@ public Builder tcpNoDelay(boolean enabled) {
977
988
return this ;
978
989
}
979
990
991
+ /**
992
+ * Configure the session timezone.
993
+ *
994
+ * @param timeZone the timeZone identifier
995
+ * @return this {@link Builder}
996
+ * @throws IllegalArgumentException if {@code timeZone} is empty or {@code null}
997
+ * @see TimeZone#getTimeZone(String)
998
+ * @since 1.0
999
+ */
1000
+ public Builder timeZone (String timeZone ) {
1001
+ return timeZone (TimeZone .getTimeZone (Assert .requireNotEmpty (timeZone , "timeZone must not be empty" )));
1002
+ }
1003
+
1004
+ /**
1005
+ * Configure the session timezone.
1006
+ *
1007
+ * @param timeZone the timeZone identifier
1008
+ * @return this {@link Builder}
1009
+ * @throws IllegalArgumentException if {@code timeZone} is {@code null}
1010
+ * @see TimeZone#getTimeZone(String)
1011
+ * @since 1.0
1012
+ */
1013
+ public Builder timeZone (TimeZone timeZone ) {
1014
+ this .timeZone = Assert .requireNonNull (timeZone , "timeZone must not be null" );
1015
+ return this ;
1016
+ }
1017
+
980
1018
/**
981
1019
* Configure the username.
982
1020
*
@@ -1019,6 +1057,7 @@ public String toString() {
1019
1057
", sslHostnameVerifier='" + this .sslHostnameVerifier + '\'' +
1020
1058
", tcpKeepAlive='" + this .tcpKeepAlive + '\'' +
1021
1059
", tcpNoDelay='" + this .tcpNoDelay + '\'' +
1060
+ ", timeZone='" + this .timeZone + '\'' +
1022
1061
", username='" + this .username + '\'' +
1023
1062
'}' ;
1024
1063
}
0 commit comments