forked from pgjdbc/pgjdbc
-
Notifications
You must be signed in to change notification settings - Fork 1
/
BaseDataSource.java
1743 lines (1522 loc) · 48.9 KB
/
BaseDataSource.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/*
* Copyright (c) 2004, PostgreSQL Global Development Group
* See the LICENSE file in the project root for more information.
*/
package org.postgresql.ds.common;
import static org.postgresql.util.internal.Nullness.castNonNull;
import org.postgresql.PGProperty;
import org.postgresql.jdbc.AutoSave;
import org.postgresql.jdbc.PreferQueryMode;
import org.postgresql.util.ExpressionProperties;
import org.postgresql.util.GT;
import org.postgresql.util.PSQLException;
import org.postgresql.util.PSQLState;
import org.postgresql.util.URLCoder;
import org.checkerframework.checker.nullness.qual.Nullable;
import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.io.ObjectInputStream;
import java.io.ObjectOutputStream;
import java.io.PrintWriter;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;
import java.util.Arrays;
import java.util.Properties;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.naming.NamingException;
import javax.naming.RefAddr;
import javax.naming.Reference;
import javax.naming.Referenceable;
import javax.naming.StringRefAddr;
import javax.sql.CommonDataSource;
/**
* Base class for data sources and related classes.
*
* @author Aaron Mulder (ammulder@chariotsolutions.com)
*/
public abstract class BaseDataSource implements CommonDataSource, Referenceable {
private static final Logger LOGGER = Logger.getLogger(BaseDataSource.class.getName());
// Standard properties, defined in the JDBC 2.0 Optional Package spec
private String[] serverNames = new String[] {"localhost"};
private @Nullable String databaseName = "";
private @Nullable String user;
private @Nullable String password;
private int[] portNumbers = new int[] {0};
// Map for all other properties
private Properties properties = new Properties();
/*
* Ensure the driver is loaded as JDBC Driver might be invisible to Java's ServiceLoader.
* Usually, {@code Class.forName(...)} is not required as {@link DriverManager} detects JDBC drivers
* via {@code META-INF/services/java.sql.Driver} entries. However there might be cases when the driver
* is located at the application level classloader, thus it might be required to perform manual
* registration of the driver.
*/
static {
try {
Class.forName("org.postgresql.Driver");
} catch (ClassNotFoundException e) {
throw new IllegalStateException(
"BaseDataSource is unable to load org.postgresql.Driver. Please check if you have proper PostgreSQL JDBC Driver jar on the classpath",
e);
}
}
/**
* Gets a connection to the PostgreSQL database. The database is identified by the DataSource
* properties serverName, databaseName, and portNumber. The user to connect as is identified by
* the DataSource properties user and password.
*
* @return A valid database connection.
* @throws SQLException Occurs when the database connection cannot be established.
*/
public Connection getConnection() throws SQLException {
return getConnection(user, password);
}
/**
* Gets a connection to the PostgreSQL database. The database is identified by the DataSource
* properties serverName, databaseName, and portNumber. The user to connect as is identified by
* the arguments user and password, which override the DataSource properties by the same name.
*
* @param user user
* @param password password
* @return A valid database connection.
* @throws SQLException Occurs when the database connection cannot be established.
*/
public Connection getConnection(@Nullable String user, @Nullable String password)
throws SQLException {
try {
Connection con = DriverManager.getConnection(getUrl(), user, password);
if (LOGGER.isLoggable(Level.FINE)) {
LOGGER.log(Level.FINE, "Created a {0} for {1} at {2}",
new Object[] {getDescription(), user, getUrl()});
}
return con;
} catch (SQLException e) {
LOGGER.log(Level.FINE, "Failed to create a {0} for {1} at {2}: {3}",
new Object[] {getDescription(), user, getUrl(), e});
throw e;
}
}
/**
* This implementation don't use a LogWriter.
*/
@Override
public @Nullable PrintWriter getLogWriter() {
return null;
}
/**
* This implementation don't use a LogWriter.
*
* @param printWriter Not used
*/
@Override
public void setLogWriter(@Nullable PrintWriter printWriter) {
// NOOP
}
/**
* Gets the name of the host the PostgreSQL database is running on.
*
* @return name of the host the PostgreSQL database is running on
* @deprecated use {@link #getServerNames()}
*/
@Deprecated
public String getServerName() {
return serverNames[0];
}
/**
* Gets the name of the host(s) the PostgreSQL database is running on.
*
* @return name of the host(s) the PostgreSQL database is running on
*/
public String[] getServerNames() {
return serverNames;
}
/**
* Sets the name of the host the PostgreSQL database is running on. If this is changed, it will
* only affect future calls to getConnection. The default value is {@code localhost}.
*
* @param serverName name of the host the PostgreSQL database is running on
* @deprecated use {@link #setServerNames(String[])}
*/
@Deprecated
public void setServerName(String serverName) {
this.setServerNames(new String[] { serverName });
}
/**
* Sets the name of the host(s) the PostgreSQL database is running on. If this is changed, it will
* only affect future calls to getConnection. The default value is {@code localhost}.
*
* @param serverNames name of the host(s) the PostgreSQL database is running on
*/
@SuppressWarnings("nullness")
public void setServerNames(@Nullable String @Nullable [] serverNames) {
if (serverNames == null || serverNames.length == 0) {
this.serverNames = new String[] {"localhost"};
} else {
serverNames = serverNames.clone();
for (int i = 0; i < serverNames.length; i++) {
String serverName = serverNames[i];
if (serverName == null || serverName.equals("")) {
serverNames[i] = "localhost";
}
}
this.serverNames = serverNames;
}
}
/**
* Gets the name of the PostgreSQL database, running on the server identified by the serverName
* property.
*
* @return name of the PostgreSQL database
*/
public @Nullable String getDatabaseName() {
return databaseName;
}
/**
* Sets the name of the PostgreSQL database, running on the server identified by the serverName
* property. If this is changed, it will only affect future calls to getConnection.
*
* @param databaseName name of the PostgreSQL database
*/
public void setDatabaseName(@Nullable String databaseName) {
this.databaseName = databaseName;
}
/**
* Gets a description of this DataSource-ish thing. Must be customized by subclasses.
*
* @return description of this DataSource-ish thing
*/
public abstract String getDescription();
/**
* Gets the user to connect as by default. If this is not specified, you must use the
* getConnection method which takes a user and password as parameters.
*
* @return user to connect as by default
*/
public @Nullable String getUser() {
return user;
}
/**
* Sets the user to connect as by default. If this is not specified, you must use the
* getConnection method which takes a user and password as parameters. If this is changed, it will
* only affect future calls to getConnection.
*
* @param user user to connect as by default
*/
public void setUser(@Nullable String user) {
this.user = user;
}
/**
* Gets the password to connect with by default. If this is not specified but a password is needed
* to log in, you must use the getConnection method which takes a user and password as parameters.
*
* @return password to connect with by default
*/
public @Nullable String getPassword() {
return password;
}
/**
* Sets the password to connect with by default. If this is not specified but a password is needed
* to log in, you must use the getConnection method which takes a user and password as parameters.
* If this is changed, it will only affect future calls to getConnection.
*
* @param password password to connect with by default
*/
public void setPassword(@Nullable String password) {
this.password = password;
}
/**
* Gets the port which the PostgreSQL server is listening on for TCP/IP connections.
*
* @return The port, or 0 if the default port will be used.
* @deprecated use {@link #getPortNumbers()}
*/
@Deprecated
public int getPortNumber() {
if (portNumbers == null || portNumbers.length == 0) {
return 0;
}
return portNumbers[0];
}
/**
* Gets the port(s) which the PostgreSQL server is listening on for TCP/IP connections.
*
* @return The port(s), or 0 if the default port will be used.
*/
public int[] getPortNumbers() {
return portNumbers;
}
/**
* Sets the port which the PostgreSQL server is listening on for TCP/IP connections. Be sure the
* -i flag is passed to postmaster when PostgreSQL is started. If this is not set, or set to 0,
* the default port will be used.
*
* @param portNumber port which the PostgreSQL server is listening on for TCP/IP
* @deprecated use {@link #setPortNumbers(int[])}
*/
@Deprecated
public void setPortNumber(int portNumber) {
setPortNumbers(new int[] { portNumber });
}
/**
* Sets the port(s) which the PostgreSQL server is listening on for TCP/IP connections. Be sure the
* -i flag is passed to postmaster when PostgreSQL is started. If this is not set, or set to 0,
* the default port will be used.
*
* @param portNumbers port(s) which the PostgreSQL server is listening on for TCP/IP
*/
public void setPortNumbers(int @Nullable [] portNumbers) {
if (portNumbers == null || portNumbers.length == 0) {
portNumbers = new int[] { 0 };
}
this.portNumbers = Arrays.copyOf(portNumbers, portNumbers.length);
}
/**
* @return command line options for this connection
*/
public @Nullable String getOptions() {
return PGProperty.OPTIONS.get(properties);
}
/**
* Set command line options for this connection
*
* @param options string to set options to
*/
public void setOptions(@Nullable String options) {
PGProperty.OPTIONS.set(properties, options);
}
/**
* @return login timeout
* @see PGProperty#LOGIN_TIMEOUT
*/
@Override
public int getLoginTimeout() {
return PGProperty.LOGIN_TIMEOUT.getIntNoCheck(properties);
}
/**
* @param loginTimeout login timeout
* @see PGProperty#LOGIN_TIMEOUT
*/
@Override
public void setLoginTimeout(int loginTimeout) {
PGProperty.LOGIN_TIMEOUT.set(properties, loginTimeout);
}
/**
* @return connect timeout
* @see PGProperty#CONNECT_TIMEOUT
*/
public int getConnectTimeout() {
return PGProperty.CONNECT_TIMEOUT.getIntNoCheck(properties);
}
/**
* @param connectTimeout connect timeout
* @see PGProperty#CONNECT_TIMEOUT
*/
public void setConnectTimeout(int connectTimeout) {
PGProperty.CONNECT_TIMEOUT.set(properties, connectTimeout);
}
/**
* @return protocol version
* @see PGProperty#PROTOCOL_VERSION
*/
public int getProtocolVersion() {
if (!PGProperty.PROTOCOL_VERSION.isPresent(properties)) {
return 0;
} else {
return PGProperty.PROTOCOL_VERSION.getIntNoCheck(properties);
}
}
/**
* @param protocolVersion protocol version
* @see PGProperty#PROTOCOL_VERSION
*/
public void setProtocolVersion(int protocolVersion) {
if (protocolVersion == 0) {
PGProperty.PROTOCOL_VERSION.set(properties, null);
} else {
PGProperty.PROTOCOL_VERSION.set(properties, protocolVersion);
}
}
/**
* @return quoteReturningIdentifiers
* @see PGProperty#QUOTE_RETURNING_IDENTIFIERS
*/
public boolean getQuoteReturningIdentifiers() {
return PGProperty.QUOTE_RETURNING_IDENTIFIERS.getBoolean(properties);
}
/**
* @param quoteIdentifiers indicate whether to quote identifiers
* @see PGProperty#QUOTE_RETURNING_IDENTIFIERS
*/
public void setQuoteReturningIdentifiers(boolean quoteIdentifiers) {
PGProperty.QUOTE_RETURNING_IDENTIFIERS.set(properties, quoteIdentifiers);
}
/**
* @return receive buffer size
* @see PGProperty#RECEIVE_BUFFER_SIZE
*/
public int getReceiveBufferSize() {
return PGProperty.RECEIVE_BUFFER_SIZE.getIntNoCheck(properties);
}
/**
* @param nbytes receive buffer size
* @see PGProperty#RECEIVE_BUFFER_SIZE
*/
public void setReceiveBufferSize(int nbytes) {
PGProperty.RECEIVE_BUFFER_SIZE.set(properties, nbytes);
}
/**
* @return send buffer size
* @see PGProperty#SEND_BUFFER_SIZE
*/
public int getSendBufferSize() {
return PGProperty.SEND_BUFFER_SIZE.getIntNoCheck(properties);
}
/**
* @param nbytes send buffer size
* @see PGProperty#SEND_BUFFER_SIZE
*/
public void setSendBufferSize(int nbytes) {
PGProperty.SEND_BUFFER_SIZE.set(properties, nbytes);
}
/**
* @param count prepare threshold
* @see PGProperty#PREPARE_THRESHOLD
*/
public void setPrepareThreshold(int count) {
PGProperty.PREPARE_THRESHOLD.set(properties, count);
}
/**
* @return prepare threshold
* @see PGProperty#PREPARE_THRESHOLD
*/
public int getPrepareThreshold() {
return PGProperty.PREPARE_THRESHOLD.getIntNoCheck(properties);
}
/**
* @return prepared statement cache size (number of statements per connection)
* @see PGProperty#PREPARED_STATEMENT_CACHE_QUERIES
*/
public int getPreparedStatementCacheQueries() {
return PGProperty.PREPARED_STATEMENT_CACHE_QUERIES.getIntNoCheck(properties);
}
/**
* @param cacheSize prepared statement cache size (number of statements per connection)
* @see PGProperty#PREPARED_STATEMENT_CACHE_QUERIES
*/
public void setPreparedStatementCacheQueries(int cacheSize) {
PGProperty.PREPARED_STATEMENT_CACHE_QUERIES.set(properties, cacheSize);
}
/**
* @return prepared statement cache size (number of megabytes per connection)
* @see PGProperty#PREPARED_STATEMENT_CACHE_SIZE_MIB
*/
public int getPreparedStatementCacheSizeMiB() {
return PGProperty.PREPARED_STATEMENT_CACHE_SIZE_MIB.getIntNoCheck(properties);
}
/**
* @param cacheSize statement cache size (number of megabytes per connection)
* @see PGProperty#PREPARED_STATEMENT_CACHE_SIZE_MIB
*/
public void setPreparedStatementCacheSizeMiB(int cacheSize) {
PGProperty.PREPARED_STATEMENT_CACHE_SIZE_MIB.set(properties, cacheSize);
}
/**
* @return database metadata cache fields size (number of fields cached per connection)
* @see PGProperty#DATABASE_METADATA_CACHE_FIELDS
*/
public int getDatabaseMetadataCacheFields() {
return PGProperty.DATABASE_METADATA_CACHE_FIELDS.getIntNoCheck(properties);
}
/**
* @param cacheSize database metadata cache fields size (number of fields cached per connection)
* @see PGProperty#DATABASE_METADATA_CACHE_FIELDS
*/
public void setDatabaseMetadataCacheFields(int cacheSize) {
PGProperty.DATABASE_METADATA_CACHE_FIELDS.set(properties, cacheSize);
}
/**
* @return database metadata cache fields size (number of megabytes per connection)
* @see PGProperty#DATABASE_METADATA_CACHE_FIELDS_MIB
*/
public int getDatabaseMetadataCacheFieldsMiB() {
return PGProperty.DATABASE_METADATA_CACHE_FIELDS_MIB.getIntNoCheck(properties);
}
/**
* @param cacheSize database metadata cache fields size (number of megabytes per connection)
* @see PGProperty#DATABASE_METADATA_CACHE_FIELDS_MIB
*/
public void setDatabaseMetadataCacheFieldsMiB(int cacheSize) {
PGProperty.DATABASE_METADATA_CACHE_FIELDS_MIB.set(properties, cacheSize);
}
/**
* @param fetchSize default fetch size
* @see PGProperty#DEFAULT_ROW_FETCH_SIZE
*/
public void setDefaultRowFetchSize(int fetchSize) {
PGProperty.DEFAULT_ROW_FETCH_SIZE.set(properties, fetchSize);
}
/**
* @return default fetch size
* @see PGProperty#DEFAULT_ROW_FETCH_SIZE
*/
public int getDefaultRowFetchSize() {
return PGProperty.DEFAULT_ROW_FETCH_SIZE.getIntNoCheck(properties);
}
/**
* @param unknownLength unknown length
* @see PGProperty#UNKNOWN_LENGTH
*/
public void setUnknownLength(int unknownLength) {
PGProperty.UNKNOWN_LENGTH.set(properties, unknownLength);
}
/**
* @return unknown length
* @see PGProperty#UNKNOWN_LENGTH
*/
public int getUnknownLength() {
return PGProperty.UNKNOWN_LENGTH.getIntNoCheck(properties);
}
/**
* @param seconds socket timeout
* @see PGProperty#SOCKET_TIMEOUT
*/
public void setSocketTimeout(int seconds) {
PGProperty.SOCKET_TIMEOUT.set(properties, seconds);
}
/**
* @return socket timeout
* @see PGProperty#SOCKET_TIMEOUT
*/
public int getSocketTimeout() {
return PGProperty.SOCKET_TIMEOUT.getIntNoCheck(properties);
}
/**
* @param seconds timeout that is used for sending cancel command
* @see PGProperty#CANCEL_SIGNAL_TIMEOUT
*/
public void setCancelSignalTimeout(int seconds) {
PGProperty.CANCEL_SIGNAL_TIMEOUT.set(properties, seconds);
}
/**
* @return timeout that is used for sending cancel command in seconds
* @see PGProperty#CANCEL_SIGNAL_TIMEOUT
*/
public int getCancelSignalTimeout() {
return PGProperty.CANCEL_SIGNAL_TIMEOUT.getIntNoCheck(properties);
}
/**
* @param enabled if SSL is enabled
* @see PGProperty#SSL
*/
public void setSsl(boolean enabled) {
if (enabled) {
PGProperty.SSL.set(properties, true);
} else {
PGProperty.SSL.set(properties, false);
}
}
/**
* @return true if SSL is enabled
* @see PGProperty#SSL
*/
public boolean getSsl() {
// "true" if "ssl" is set but empty
return PGProperty.SSL.getBoolean(properties) || "".equals(PGProperty.SSL.get(properties));
}
/**
* @param classname SSL factory class name
* @see PGProperty#SSL_FACTORY
*/
public void setSslfactory(String classname) {
PGProperty.SSL_FACTORY.set(properties, classname);
}
/**
* @return SSL factory class name
* @see PGProperty#SSL_FACTORY
*/
public @Nullable String getSslfactory() {
return PGProperty.SSL_FACTORY.get(properties);
}
/**
* @return SSL mode
* @see PGProperty#SSL_MODE
*/
public @Nullable String getSslMode() {
return PGProperty.SSL_MODE.get(properties);
}
/**
* @param mode SSL mode
* @see PGProperty#SSL_MODE
*/
public void setSslMode(@Nullable String mode) {
PGProperty.SSL_MODE.set(properties, mode);
}
/**
* @return SSL mode
* @see PGProperty#SSL_FACTORY_ARG
*/
public @Nullable String getSslFactoryArg() {
return PGProperty.SSL_FACTORY_ARG.get(properties);
}
/**
* @param arg argument forwarded to SSL factory
* @see PGProperty#SSL_FACTORY_ARG
*/
public void setSslFactoryArg(@Nullable String arg) {
PGProperty.SSL_FACTORY_ARG.set(properties, arg);
}
/**
* @return argument forwarded to SSL factory
* @see PGProperty#SSL_HOSTNAME_VERIFIER
*/
public @Nullable String getSslHostnameVerifier() {
return PGProperty.SSL_HOSTNAME_VERIFIER.get(properties);
}
/**
* @param className SSL hostname verifier
* @see PGProperty#SSL_HOSTNAME_VERIFIER
*/
public void setSslHostnameVerifier(@Nullable String className) {
PGProperty.SSL_HOSTNAME_VERIFIER.set(properties, className);
}
/**
* @return className SSL hostname verifier
* @see PGProperty#SSL_CERT
*/
public @Nullable String getSslCert() {
return PGProperty.SSL_CERT.get(properties);
}
/**
* @param file SSL certificate
* @see PGProperty#SSL_CERT
*/
public void setSslCert(@Nullable String file) {
PGProperty.SSL_CERT.set(properties, file);
}
/**
* @return SSL certificate
* @see PGProperty#SSL_KEY
*/
public @Nullable String getSslKey() {
return PGProperty.SSL_KEY.get(properties);
}
/**
* @param file SSL key
* @see PGProperty#SSL_KEY
*/
public void setSslKey(@Nullable String file) {
PGProperty.SSL_KEY.set(properties, file);
}
/**
* @return SSL root certificate
* @see PGProperty#SSL_ROOT_CERT
*/
public @Nullable String getSslRootCert() {
return PGProperty.SSL_ROOT_CERT.get(properties);
}
/**
* @param file SSL root certificate
* @see PGProperty#SSL_ROOT_CERT
*/
public void setSslRootCert(@Nullable String file) {
PGProperty.SSL_ROOT_CERT.set(properties, file);
}
/**
* @return SSL password
* @see PGProperty#SSL_PASSWORD
*/
public @Nullable String getSslPassword() {
return PGProperty.SSL_PASSWORD.get(properties);
}
/**
* @param password SSL password
* @see PGProperty#SSL_PASSWORD
*/
public void setSslPassword(@Nullable String password) {
PGProperty.SSL_PASSWORD.set(properties, password);
}
/**
* @return SSL password callback
* @see PGProperty#SSL_PASSWORD_CALLBACK
*/
public @Nullable String getSslPasswordCallback() {
return PGProperty.SSL_PASSWORD_CALLBACK.get(properties);
}
/**
* @param className SSL password callback class name
* @see PGProperty#SSL_PASSWORD_CALLBACK
*/
public void setSslPasswordCallback(@Nullable String className) {
PGProperty.SSL_PASSWORD_CALLBACK.set(properties, className);
}
/**
* @param applicationName application name
* @see PGProperty#APPLICATION_NAME
*/
public void setApplicationName(@Nullable String applicationName) {
PGProperty.APPLICATION_NAME.set(properties, applicationName);
}
/**
* @return application name
* @see PGProperty#APPLICATION_NAME
*/
public String getApplicationName() {
return castNonNull(PGProperty.APPLICATION_NAME.get(properties));
}
/**
* @param targetServerType target server type
* @see PGProperty#TARGET_SERVER_TYPE
*/
public void setTargetServerType(@Nullable String targetServerType) {
PGProperty.TARGET_SERVER_TYPE.set(properties, targetServerType);
}
/**
* @return target server type
* @see PGProperty#TARGET_SERVER_TYPE
*/
public String getTargetServerType() {
return castNonNull(PGProperty.TARGET_SERVER_TYPE.get(properties));
}
/**
* @param loadBalanceHosts load balance hosts
* @see PGProperty#LOAD_BALANCE_HOSTS
*/
public void setLoadBalanceHosts(boolean loadBalanceHosts) {
PGProperty.LOAD_BALANCE_HOSTS.set(properties, loadBalanceHosts);
}
/**
* @return load balance hosts
* @see PGProperty#LOAD_BALANCE_HOSTS
*/
public boolean getLoadBalanceHosts() {
return PGProperty.LOAD_BALANCE_HOSTS.isPresent(properties);
}
/**
* @param hostRecheckSeconds host recheck seconds
* @see PGProperty#HOST_RECHECK_SECONDS
*/
public void setHostRecheckSeconds(int hostRecheckSeconds) {
PGProperty.HOST_RECHECK_SECONDS.set(properties, hostRecheckSeconds);
}
/**
* @return host recheck seconds
* @see PGProperty#HOST_RECHECK_SECONDS
*/
public int getHostRecheckSeconds() {
return PGProperty.HOST_RECHECK_SECONDS.getIntNoCheck(properties);
}
/**
* @param enabled if TCP keep alive should be enabled
* @see PGProperty#TCP_KEEP_ALIVE
*/
public void setTcpKeepAlive(boolean enabled) {
PGProperty.TCP_KEEP_ALIVE.set(properties, enabled);
}
/**
* @return true if TCP keep alive is enabled
* @see PGProperty#TCP_KEEP_ALIVE
*/
public boolean getTcpKeepAlive() {
return PGProperty.TCP_KEEP_ALIVE.getBoolean(properties);
}
/**
* @param enabled if binary transfer should be enabled
* @see PGProperty#BINARY_TRANSFER
*/
public void setBinaryTransfer(boolean enabled) {
PGProperty.BINARY_TRANSFER.set(properties, enabled);
}
/**
* @return true if binary transfer is enabled
* @see PGProperty#BINARY_TRANSFER
*/
public boolean getBinaryTransfer() {
return PGProperty.BINARY_TRANSFER.getBoolean(properties);
}
/**
* @param oidList list of OIDs that are allowed to use binary transfer
* @see PGProperty#BINARY_TRANSFER_ENABLE
*/
public void setBinaryTransferEnable(@Nullable String oidList) {
PGProperty.BINARY_TRANSFER_ENABLE.set(properties, oidList);
}
/**
* @return list of OIDs that are allowed to use binary transfer
* @see PGProperty#BINARY_TRANSFER_ENABLE
*/
public String getBinaryTransferEnable() {
return castNonNull(PGProperty.BINARY_TRANSFER_ENABLE.get(properties));
}
/**
* @param oidList list of OIDs that are not allowed to use binary transfer
* @see PGProperty#BINARY_TRANSFER_DISABLE
*/
public void setBinaryTransferDisable(@Nullable String oidList) {
PGProperty.BINARY_TRANSFER_DISABLE.set(properties, oidList);
}
/**
* @return list of OIDs that are not allowed to use binary transfer
* @see PGProperty#BINARY_TRANSFER_DISABLE
*/
public String getBinaryTransferDisable() {
return castNonNull(PGProperty.BINARY_TRANSFER_DISABLE.get(properties));
}
/**
* @return string type
* @see PGProperty#STRING_TYPE
*/
public @Nullable String getStringType() {
return PGProperty.STRING_TYPE.get(properties);
}
/**
* @param stringType string type
* @see PGProperty#STRING_TYPE
*/
public void setStringType(@Nullable String stringType) {
PGProperty.STRING_TYPE.set(properties, stringType);
}
/**
* @return true if column sanitizer is disabled
* @see PGProperty#DISABLE_COLUMN_SANITISER
*/
public boolean isColumnSanitiserDisabled() {
return PGProperty.DISABLE_COLUMN_SANITISER.getBoolean(properties);
}
/**
* @return true if column sanitizer is disabled
* @see PGProperty#DISABLE_COLUMN_SANITISER
*/
public boolean getDisableColumnSanitiser() {
return PGProperty.DISABLE_COLUMN_SANITISER.getBoolean(properties);
}
/**
* @param disableColumnSanitiser if column sanitizer should be disabled
* @see PGProperty#DISABLE_COLUMN_SANITISER
*/
public void setDisableColumnSanitiser(boolean disableColumnSanitiser) {
PGProperty.DISABLE_COLUMN_SANITISER.set(properties, disableColumnSanitiser);
}
/**
* @return current schema
* @see PGProperty#CURRENT_SCHEMA
*/
public @Nullable String getCurrentSchema() {
return PGProperty.CURRENT_SCHEMA.get(properties);
}
/**
* @param currentSchema current schema
* @see PGProperty#CURRENT_SCHEMA
*/
public void setCurrentSchema(@Nullable String currentSchema) {
PGProperty.CURRENT_SCHEMA.set(properties, currentSchema);
}
/**
* @return true if connection is readonly
* @see PGProperty#READ_ONLY
*/
public boolean getReadOnly() {
return PGProperty.READ_ONLY.getBoolean(properties);
}
/**
* @param readOnly if connection should be readonly
* @see PGProperty#READ_ONLY
*/
public void setReadOnly(boolean readOnly) {
PGProperty.READ_ONLY.set(properties, readOnly);
}
/**
* @return The behavior when set read only
* @see PGProperty#READ_ONLY_MODE
*/
public String getReadOnlyMode() {
return castNonNull(PGProperty.READ_ONLY_MODE.get(properties));
}
/**
* @param mode the behavior when set read only
* @see PGProperty#READ_ONLY_MODE
*/
public void setReadOnlyMode(@Nullable String mode) {
PGProperty.READ_ONLY_MODE.set(properties, mode);
}
/**
* @return true if driver should log unclosed connections
* @see PGProperty#LOG_UNCLOSED_CONNECTIONS
*/
public boolean getLogUnclosedConnections() {
return PGProperty.LOG_UNCLOSED_CONNECTIONS.getBoolean(properties);
}
/**
* @param enabled true if driver should log unclosed connections
* @see PGProperty#LOG_UNCLOSED_CONNECTIONS
*/
public void setLogUnclosedConnections(boolean enabled) {
PGProperty.LOG_UNCLOSED_CONNECTIONS.set(properties, enabled);
}
/**
* @return true if driver should log include detail in server error messages
* @see PGProperty#LOG_SERVER_ERROR_DETAIL
*/
public boolean getLogServerErrorDetail() {
return PGProperty.LOG_SERVER_ERROR_DETAIL.getBoolean(properties);
}
/**
* @param enabled true if driver should include detail in server error messages
* @see PGProperty#LOG_SERVER_ERROR_DETAIL
*/
public void setLogServerErrorDetail(boolean enabled) {
PGProperty.LOG_SERVER_ERROR_DETAIL.set(properties, enabled);
}
/**
* @return assumed minimal server version
* @see PGProperty#ASSUME_MIN_SERVER_VERSION
*/
public @Nullable String getAssumeMinServerVersion() {
return PGProperty.ASSUME_MIN_SERVER_VERSION.get(properties);
}
/**
* @param minVersion assumed minimal server version
* @see PGProperty#ASSUME_MIN_SERVER_VERSION
*/
public void setAssumeMinServerVersion(@Nullable String minVersion) {
PGProperty.ASSUME_MIN_SERVER_VERSION.set(properties, minVersion);
}