forked from pgjdbc/pgjdbc
/
PGProperty.java
1026 lines (918 loc) · 35.8 KB
/
PGProperty.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;
import org.postgresql.util.DriverInfo;
import org.postgresql.util.GT;
import org.postgresql.util.PSQLException;
import org.postgresql.util.PSQLState;
import org.checkerframework.checker.nullness.qual.Nullable;
import java.sql.Connection;
import java.sql.DriverPropertyInfo;
import java.util.HashMap;
import java.util.Map;
import java.util.Properties;
/**
* All connection parameters that can be either set in JDBC URL, in Driver properties or in
* datasource setters.
*/
public enum PGProperty {
/**
* Specifies if number of rows, used during fetching rows of a result set, should be computed
* dynamically. Number of rows will be calculated by dividing maxResultBuffer size by max row size
* observed so far, rounded down. First fetch will have number of rows declared in
* defaultRowFetchSize. Number of rows can be limited by adaptiveFetchMinimum and
* adaptiveFetchMaximum. Requires declaring of maxResultBuffer and defaultRowFetchSize to work.
* Default value is false.
*/
ADAPTIVE_FETCH(
"adaptiveFetch",
"false",
"Specifies if number of rows fetched in ResultSet should be adaptive to maxResultBuffer and max row size."),
/**
* Specifies the highest number of rows which can be calculated by adaptiveFetch. Requires
* adaptiveFetch set to true to work. Default value is -1 (used as infinity).
*/
ADAPTIVE_FETCH_MAXIMUM(
"adaptiveFetchMaximum",
"-1",
"Specifies maximum number of rows used by adaptive fetch."),
/**
* Specifies the lowest number of rows which can be calculated by adaptiveFetch. Requires
* adaptiveFetch set to true to work. Default value is 0.
*/
ADAPTIVE_FETCH_MINIMUM(
"adaptiveFetchMinimum",
"0",
"Specifies minimum number of rows used by adaptive fetch."),
/**
* When using the V3 protocol the driver monitors changes in certain server configuration
* parameters that should not be touched by end users. The {@code client_encoding} setting is set
* by the driver and should not be altered. If the driver detects a change it will abort the
* connection.
*/
ALLOW_ENCODING_CHANGES(
"allowEncodingChanges",
"false",
"Allow for changes in client_encoding"),
/**
* The application name (require server version >= 9.0).
*/
APPLICATION_NAME(
"ApplicationName",
DriverInfo.DRIVER_NAME,
"Name of the Application (backend >= 9.0)"),
/**
* Assume the server is at least that version.
*/
ASSUME_MIN_SERVER_VERSION(
"assumeMinServerVersion",
null,
"Assume the server is at least that version"),
/**
* AuthenticationPluginClass
*/
AUTHENTICATION_PLUGIN_CLASS_NAME(
"authenticationPluginClassName",
null,
"Name of class which implements AuthenticationPlugin"
),
/**
* Specifies what the driver should do if a query fails. In {@code autosave=always} mode, JDBC driver sets a savepoint before each query,
* and rolls back to that savepoint in case of failure. In {@code autosave=never} mode (default), no savepoint dance is made ever.
* In {@code autosave=conservative} mode, savepoint is set for each query, however the rollback is done only for rare cases
* like 'cached statement cannot change return type' or 'statement XXX is not valid' so JDBC driver rollsback and retries
*/
AUTOSAVE(
"autosave",
"never",
"Specifies what the driver should do if a query fails. In autosave=always mode, JDBC driver sets a savepoint before each query, "
+ "and rolls back to that savepoint in case of failure. In autosave=never mode (default), no savepoint dance is made ever. "
+ "In autosave=conservative mode, safepoint is set for each query, however the rollback is done only for rare cases"
+ " like 'cached statement cannot change return type' or 'statement XXX is not valid' so JDBC driver rollsback and retries",
false,
new String[] {"always", "never", "conservative"}),
/**
* Use binary format for sending and receiving data if possible.
*/
BINARY_TRANSFER(
"binaryTransfer",
"true",
"Use binary format for sending and receiving data if possible"),
/**
* Comma separated list of types to disable binary transfer. Either OID numbers or names.
* Overrides values in the driver default set and values set with binaryTransferEnable.
*/
BINARY_TRANSFER_DISABLE(
"binaryTransferDisable",
"",
"Comma separated list of types to disable binary transfer. Either OID numbers or names. Overrides values in the driver default set and values set with binaryTransferEnable."),
/**
* Comma separated list of types to enable binary transfer. Either OID numbers or names
*/
BINARY_TRANSFER_ENABLE(
"binaryTransferEnable",
"",
"Comma separated list of types to enable binary transfer. Either OID numbers or names"),
/**
* Cancel command is sent out of band over its own connection, so cancel message can itself get
* stuck.
* This property controls "connect timeout" and "socket timeout" used for cancel commands.
* The timeout is specified in seconds. Default value is 10 seconds.
*/
CANCEL_SIGNAL_TIMEOUT(
"cancelSignalTimeout",
"10",
"The timeout that is used for sending cancel command."),
/**
* Determine whether SAVEPOINTS used in AUTOSAVE will be released per query or not
*/
CLEANUP_SAVEPOINTS(
"cleanupSavepoints",
"false",
"Determine whether SAVEPOINTS used in AUTOSAVE will be released per query or not",
false,
new String[] {"true", "false"}),
/**
* <p>The timeout value used for socket connect operations. If connecting to the server takes longer
* than this value, the connection is broken.</p>
*
* <p>The timeout is specified in seconds and a value of zero means that it is disabled.</p>
*/
CONNECT_TIMEOUT(
"connectTimeout",
"10",
"The timeout value used for socket connect operations."),
/**
* Specify the schema (or several schema separated by commas) to be set in the search-path. This schema will be used to resolve
* unqualified object names used in statements over this connection.
*/
CURRENT_SCHEMA(
"currentSchema",
null,
"Specify the schema (or several schema separated by commas) to be set in the search-path"),
/**
* Specifies the maximum number of fields to be cached per connection. A value of {@code 0} disables the cache.
*/
DATABASE_METADATA_CACHE_FIELDS(
"databaseMetadataCacheFields",
"65536",
"Specifies the maximum number of fields to be cached per connection. A value of {@code 0} disables the cache."),
/**
* Specifies the maximum size (in megabytes) of fields to be cached per connection. A value of {@code 0} disables the cache.
*/
DATABASE_METADATA_CACHE_FIELDS_MIB(
"databaseMetadataCacheFieldsMiB",
"5",
"Specifies the maximum size (in megabytes) of fields to be cached per connection. A value of {@code 0} disables the cache."),
/**
* Default parameter for {@link java.sql.Statement#getFetchSize()}. A value of {@code 0} means
* that need fetch all rows at once
*/
DEFAULT_ROW_FETCH_SIZE(
"defaultRowFetchSize",
"0",
"Positive number of rows that should be fetched from the database when more rows are needed for ResultSet by each fetch iteration"),
/**
* Enable optimization that disables column name sanitiser.
*/
DISABLE_COLUMN_SANITISER(
"disableColumnSanitiser",
"false",
"Enable optimization that disables column name sanitiser"),
/**
* Specifies how the driver transforms JDBC escape call syntax into underlying SQL, for invoking procedures or functions. (backend >= 11)
* In {@code escapeSyntaxCallMode=select} mode (the default), the driver always uses a SELECT statement (allowing function invocation only).
* In {@code escapeSyntaxCallMode=callIfNoReturn} mode, the driver uses a CALL statement (allowing procedure invocation) if there is no return parameter specified, otherwise the driver uses a SELECT statement.
* In {@code escapeSyntaxCallMode=call} mode, the driver always uses a CALL statement (allowing procedure invocation only).
*/
ESCAPE_SYNTAX_CALL_MODE(
"escapeSyntaxCallMode",
"select",
"Specifies how the driver transforms JDBC escape call syntax into underlying SQL, for invoking procedures or functions. (backend >= 11)"
+ "In escapeSyntaxCallMode=select mode (the default), the driver always uses a SELECT statement (allowing function invocation only)."
+ "In escapeSyntaxCallMode=callIfNoReturn mode, the driver uses a CALL statement (allowing procedure invocation) if there is no return parameter specified, otherwise the driver uses a SELECT statement."
+ "In escapeSyntaxCallMode=call mode, the driver always uses a CALL statement (allowing procedure invocation only).",
false,
new String[] {"select", "callIfNoReturn", "call"}),
/**
* Group startup parameters in a transaction
* This is important in pool-by-transaction scenarios in order to make sure that all the statements
* reaches the same connection that is being initialized. All of the startup parameters will be wrapped
* in a transaction
* Note this is off by default as pgbouncer in statement mode
*/
GROUP_STARTUP_PARAMETERS(
"groupStartupParameters",
"false",
"This is important in pool-by-transaction scenarios in order to make sure that all "
+ "the statements reaches the same connection that is being initialized."
),
GSS_ENC_MODE(
"gssEncMode",
"allow",
"Force Encoded GSS Mode",
false,
new String[] {"disable", "allow", "prefer", "require"}
),
/**
* Force one of
* <ul>
* <li>SSPI (Windows transparent single-sign-on)</li>
* <li>GSSAPI (Kerberos, via JSSE)</li>
* </ul>
* to be used when the server requests Kerberos or SSPI authentication.
*/
GSS_LIB(
"gsslib",
"auto",
"Force SSSPI or GSSAPI",
false,
new String[] {"auto", "sspi", "gssapi"}),
/**
* Enable mode to filter out the names of database objects for which the current user has no privileges
* granted from appearing in the DatabaseMetaData returned by the driver.
*/
HIDE_UNPRIVILEGED_OBJECTS(
"hideUnprivilegedObjects",
"false",
"Enable hiding of database objects for which the current user has no privileges granted from the DatabaseMetaData"),
HOST_RECHECK_SECONDS(
"hostRecheckSeconds",
"10",
"Specifies period (seconds) after which the host status is checked again in case it has changed"),
/**
* Specifies the name of the JAAS system or application login configuration.
*/
JAAS_APPLICATION_NAME(
"jaasApplicationName",
"pgjdbc",
"Specifies the name of the JAAS system or application login configuration."),
/**
* Flag to enable/disable obtaining a GSS credential via JAAS login before authenticating.
* Useful if setting system property javax.security.auth.useSubjectCredsOnly=false
* or using native GSS with system property sun.security.jgss.native=true
*/
JAAS_LOGIN(
"jaasLogin",
"true",
"Login with JAAS before doing GSSAPI authentication"),
/**
* The Kerberos service name to use when authenticating with GSSAPI. This is equivalent to libpq's
* PGKRBSRVNAME environment variable.
*/
KERBEROS_SERVER_NAME(
"kerberosServerName",
null,
"The Kerberos service name to use when authenticating with GSSAPI."),
LOAD_BALANCE_HOSTS(
"loadBalanceHosts",
"false",
"If disabled hosts are connected in the given order. If enabled hosts are chosen randomly from the set of suitable candidates"),
/**
* <p>If this is set then the client side will bind to this address. This is useful if you need
* to choose which interface to connect to.</p>
*/
LOCAL_SOCKET_ADDRESS(
"localSocketAddress",
null,
"Local Socket address, if set bind the client side of the socket to this address"),
/**
* This property is no longer used by the driver and will be ignored.
* @deprecated Logging is configured via java.util.logging.
*/
@Deprecated
LOGGER_FILE(
"loggerFile",
null,
"File name output of the Logger"),
/**
* This property is no longer used by the driver and will be ignored.
* @deprecated Logging is configured via java.util.logging.
*/
@Deprecated
LOGGER_LEVEL(
"loggerLevel",
null,
"Logger level of the driver",
false,
new String[] {"OFF", "DEBUG", "TRACE"}),
/**
* Specify how long to wait for establishment of a database connection. The timeout is specified
* in seconds.
*/
LOGIN_TIMEOUT(
"loginTimeout",
"0",
"Specify how long to wait for establishment of a database connection."),
/**
* Whether to include full server error detail in exception messages.
*/
LOG_SERVER_ERROR_DETAIL(
"logServerErrorDetail",
"true",
"Include full server error detail in exception messages. If disabled then only the error itself will be included."),
/**
* When connections that are not explicitly closed are garbage collected, log the stacktrace from
* the opening of the connection to trace the leak source.
*/
LOG_UNCLOSED_CONNECTIONS(
"logUnclosedConnections",
"false",
"When connections that are not explicitly closed are garbage collected, log the stacktrace from the opening of the connection to trace the leak source"),
/**
* Specifies size of buffer during fetching result set. Can be specified as specified size or
* percent of heap memory.
*/
MAX_RESULT_BUFFER(
"maxResultBuffer",
null,
"Specifies size of buffer during fetching result set. Can be specified as specified size or percent of heap memory."),
/**
* Specify 'options' connection initialization parameter.
* The value of this parameter may contain spaces and other special characters or their URL representation.
*/
OPTIONS(
"options",
null,
"Specify 'options' connection initialization parameter."),
/**
* Password to use when authenticating.
*/
PASSWORD(
"password",
null,
"Password to use when authenticating.",
false),
/**
* Database name to connect to (may be specified directly in the JDBC URL).
*/
PG_DBNAME(
"PGDBNAME",
null,
"Database name to connect to (may be specified directly in the JDBC URL)",
true),
/**
* Hostname of the PostgreSQL server (may be specified directly in the JDBC URL).
*/
PG_HOST(
"PGHOST",
"localhost",
"Hostname of the PostgreSQL server (may be specified directly in the JDBC URL)",
false),
/**
* Port of the PostgreSQL server (may be specified directly in the JDBC URL).
*/
PG_PORT(
"PGPORT",
"5432",
"Port of the PostgreSQL server (may be specified directly in the JDBC URL)"),
/**
* <p>Specifies which mode is used to execute queries to database: simple means ('Q' execute, no parse, no bind, text mode only),
* extended means always use bind/execute messages, extendedForPrepared means extended for prepared statements only,
* extendedCacheEverything means use extended protocol and try cache every statement (including Statement.execute(String sql)) in a query cache.</p>
*
* <p>This mode is meant for debugging purposes and/or for cases when extended protocol cannot be used (e.g. logical replication protocol)</p>
*/
PREFER_QUERY_MODE(
"preferQueryMode",
"extended",
"Specifies which mode is used to execute queries to database: simple means ('Q' execute, no parse, no bind, text mode only), "
+ "extended means always use bind/execute messages, extendedForPrepared means extended for prepared statements only, "
+ "extendedCacheEverything means use extended protocol and try cache every statement (including Statement.execute(String sql)) in a query cache.", false,
new String[] {"extended", "extendedForPrepared", "extendedCacheEverything", "simple"}),
/**
* Specifies the maximum number of entries in cache of prepared statements. A value of {@code 0}
* disables the cache.
*/
PREPARED_STATEMENT_CACHE_QUERIES(
"preparedStatementCacheQueries",
"256",
"Specifies the maximum number of entries in per-connection cache of prepared statements. A value of {@code 0} disables the cache."),
/**
* Specifies the maximum size (in megabytes) of the prepared statement cache. A value of {@code 0}
* disables the cache.
*/
PREPARED_STATEMENT_CACHE_SIZE_MIB(
"preparedStatementCacheSizeMiB",
"5",
"Specifies the maximum size (in megabytes) of a per-connection prepared statement cache. A value of {@code 0} disables the cache."),
/**
* Sets the default threshold for enabling server-side prepare. A value of {@code -1} stands for
* forceBinary
*/
PREPARE_THRESHOLD(
"prepareThreshold",
"5",
"Statement prepare threshold. A value of {@code -1} stands for forceBinary"),
/**
* Force use of a particular protocol version when connecting, if set, disables protocol version
* fallback.
*/
PROTOCOL_VERSION(
"protocolVersion",
null,
"Force use of a particular protocol version when connecting, currently only version 3 is supported.",
false,
new String[] {"3"}),
/**
* Quote returning columns.
* There are some ORM's that quote everything, including returning columns
* If we quote them, then we end up sending ""colname"" to the backend
* which will not be found
*/
QUOTE_RETURNING_IDENTIFIERS(
"quoteReturningIdentifiers",
"true",
"Quote identifiers provided in returning array",
false),
/**
* Puts this connection in read-only mode.
*/
READ_ONLY(
"readOnly",
"false",
"Puts this connection in read-only mode"),
/**
* Connection parameter to control behavior when
* {@link Connection#setReadOnly(boolean)} is set to {@code true}.
*/
READ_ONLY_MODE(
"readOnlyMode",
"transaction",
"Controls the behavior when a connection is set to be read only, one of 'ignore', 'transaction', or 'always' "
+ "When 'ignore', setting readOnly has no effect. "
+ "When 'transaction' setting readOnly to 'true' will cause transactions to BEGIN READ ONLY if autocommit is 'false'. "
+ "When 'always' setting readOnly to 'true' will set the session to READ ONLY if autoCommit is 'true' "
+ "and the transaction to BEGIN READ ONLY if autocommit is 'false'.",
false,
new String[] {"ignore", "transaction", "always"}),
/**
* Socket read buffer size (SO_RECVBUF). A value of {@code -1}, which is the default, means system
* default.
*/
RECEIVE_BUFFER_SIZE(
"receiveBufferSize",
"-1",
"Socket read buffer size"),
/**
* <p>Connection parameter passed in the startup message. This parameter accepts two values; "true"
* and "database". Passing "true" tells the backend to go into walsender mode, wherein a small set
* of replication commands can be issued instead of SQL statements. Only the simple query protocol
* can be used in walsender mode. Passing "database" as the value instructs walsender to connect
* to the database specified in the dbname parameter, which will allow the connection to be used
* for logical replication from that database.</p>
* <p>Parameter should be use together with {@link PGProperty#ASSUME_MIN_SERVER_VERSION} with
* parameter >= 9.4 (backend >= 9.4)</p>
*/
REPLICATION(
"replication",
null,
"Connection parameter passed in startup message, one of 'true' or 'database' "
+ "Passing 'true' tells the backend to go into walsender mode, "
+ "wherein a small set of replication commands can be issued instead of SQL statements. "
+ "Only the simple query protocol can be used in walsender mode. "
+ "Passing 'database' as the value instructs walsender to connect "
+ "to the database specified in the dbname parameter, "
+ "which will allow the connection to be used for logical replication "
+ "from that database. "
+ "(backend >= 9.4)"),
/**
* Configure optimization to enable batch insert re-writing.
*/
REWRITE_BATCHED_INSERTS(
"reWriteBatchedInserts",
"false",
"Enable optimization to rewrite and collapse compatible INSERT statements that are batched."),
/**
* Socket write buffer size (SO_SNDBUF). A value of {@code -1}, which is the default, means system
* default.
*/
SEND_BUFFER_SIZE(
"sendBufferSize",
"-1",
"Socket write buffer size"),
/**
* Service name to use for additional parameters. It specifies a service name in "pg_service
* .conf" that holds additional connection parameters. This allows applications to specify only
* a service name so connection parameters can be centrally maintained.
*/
SERVICE(
"service",
null,
"Service name to be searched in pg_service.conf resource"),
/**
* Socket factory used to create socket. A null value, which is the default, means system default.
*/
SOCKET_FACTORY(
"socketFactory",
null,
"Specify a socket factory for socket creation"),
/**
* The String argument to give to the constructor of the Socket Factory.
* @deprecated use {@code ..Factory(Properties)} constructor.
*/
@Deprecated
SOCKET_FACTORY_ARG(
"socketFactoryArg",
null,
"Argument forwarded to constructor of SocketFactory class."),
/**
* The timeout value used for socket read operations. If reading from the server takes longer than
* this value, the connection is closed. This can be used as both a brute force global query
* timeout and a method of detecting network problems. The timeout is specified in seconds and a
* value of zero means that it is disabled.
*/
SOCKET_TIMEOUT(
"socketTimeout",
"0",
"The timeout value used for socket read operations."),
/**
* Control use of SSL: empty or {@code true} values imply {@code sslmode==verify-full}
*/
SSL(
"ssl",
null,
"Control use of SSL (any non-null value causes SSL to be required)"),
/**
* File containing the SSL Certificate. Default will be the file {@code postgresql.crt} in {@code
* $HOME/.postgresql} (*nix) or {@code %APPDATA%\postgresql} (windows).
*/
SSL_CERT(
"sslcert",
null,
"The location of the client's SSL certificate"),
/**
* Classname of the SSL Factory to use (instance of {@link javax.net.ssl.SSLSocketFactory}).
*/
SSL_FACTORY(
"sslfactory",
null,
"Provide a SSLSocketFactory class when using SSL."),
/**
* The String argument to give to the constructor of the SSL Factory.
* @deprecated use {@code ..Factory(Properties)} constructor.
*/
@Deprecated
SSL_FACTORY_ARG(
"sslfactoryarg",
null,
"Argument forwarded to constructor of SSLSocketFactory class."),
/**
* Classname of the SSL HostnameVerifier to use (instance of {@link javax.net.ssl.HostnameVerifier}).
*/
SSL_HOSTNAME_VERIFIER(
"sslhostnameverifier",
null,
"A class, implementing javax.net.ssl.HostnameVerifier that can verify the server"),
/**
* File containing the SSL Key. Default will be the file {@code postgresql.pk8} in {@code $HOME/.postgresql} (*nix)
* or {@code %APPDATA%\postgresql} (windows).
*/
SSL_KEY(
"sslkey",
null,
"The location of the client's PKCS#8 SSL key"),
/**
* Parameter governing the use of SSL. The allowed values are {@code disable}, {@code allow},
* {@code prefer}, {@code require}, {@code verify-ca}, {@code verify-full}.
* If {@code ssl} property is empty or set to {@code true} it implies {@code verify-full}.
* Default mode is "require"
*/
SSL_MODE(
"sslmode",
null,
"Parameter governing the use of SSL",
false,
new String[] {"disable", "allow", "prefer", "require", "verify-ca", "verify-full"}),
/**
* The SSL password to use in the default CallbackHandler.
*/
SSL_PASSWORD(
"sslpassword",
null,
"The password for the client's ssl key (ignored if sslpasswordcallback is set)"),
/**
* The classname instantiating {@link javax.security.auth.callback.CallbackHandler} to use.
*/
SSL_PASSWORD_CALLBACK(
"sslpasswordcallback",
null,
"A class, implementing javax.security.auth.callback.CallbackHandler that can handle PasswordCallback for the ssl password."),
/**
* <p>After requesting an upgrade to SSL from the server there are reports of the server not responding due to a failover
* without a timeout here, the client can wait forever. This timeout will be set before the request and reset after </p>
*/
SSL_RESPONSE_TIMEOUT(
"sslResponseTimeout",
"5000",
"Time in milliseconds we wait for a response from the server after requesting SSL upgrade"),
/**
* File containing the root certificate when validating server ({@code sslmode} = {@code
* verify-ca} or {@code verify-full}). Default will be the file {@code root.crt} in {@code
* $HOME/.postgresql} (*nix) or {@code %APPDATA%\postgresql} (windows).
*/
SSL_ROOT_CERT(
"sslrootcert",
null,
"The location of the root certificate for authenticating the server."),
/**
* Specifies the name of the SSPI service class that forms the service class part of the SPN. The
* default, {@code POSTGRES}, is almost always correct.
*/
SSPI_SERVICE_CLASS(
"sspiServiceClass",
"POSTGRES",
"The Windows SSPI service class for SPN"),
/**
* Bind String to either {@code unspecified} or {@code varchar}. Default is {@code varchar} for
* 8.0+ backends.
*/
STRING_TYPE(
"stringtype",
null,
"The type to bind String parameters as (usually 'varchar', 'unspecified' allows implicit casting to other types)",
false,
new String[] {"unspecified", "varchar"}),
TARGET_SERVER_TYPE(
"targetServerType",
"any",
"Specifies what kind of server to connect",
false,
new String [] {"any", "primary", "master", "slave", "secondary", "preferSlave", "preferSecondary", "preferPrimary"}),
/**
* Enable or disable TCP keep-alive. The default is {@code false}.
*/
TCP_KEEP_ALIVE(
"tcpKeepAlive",
"false",
"Enable or disable TCP keep-alive. The default is {@code false}."),
TCP_NO_DELAY(
"tcpNoDelay",
"true",
"Enable or disable TCP no delay. The default is (@code true}."
),
/**
* Specifies the length to return for types of unknown length.
*/
UNKNOWN_LENGTH(
"unknownLength",
Integer.toString(Integer.MAX_VALUE),
"Specifies the length to return for types of unknown length"),
/**
* Username to connect to the database as.
*/
USER(
"user",
null,
"Username to connect to the database as.",
true),
/**
* Use SPNEGO in SSPI authentication requests.
*/
USE_SPNEGO(
"useSpnego",
"false",
"Use SPNEGO in SSPI authentication requests"),
/**
* Factory class to instantiate factories for XML processing.
* The default factory disables external entity processing.
* Legacy behavior with external entity processing can be enabled by specifying a value of LEGACY_INSECURE.
* Or specify a custom class that implements {@link org.postgresql.xml.PGXmlFactoryFactory}.
*/
XML_FACTORY_FACTORY(
"xmlFactoryFactory",
"",
"Factory class to instantiate factories for XML processing"),
;
private final String name;
private final @Nullable String defaultValue;
private final boolean required;
private final String description;
private final String @Nullable [] choices;
PGProperty(String name, @Nullable String defaultValue, String description) {
this(name, defaultValue, description, false);
}
PGProperty(String name, @Nullable String defaultValue, String description, boolean required) {
this(name, defaultValue, description, required, (String[]) null);
}
PGProperty(String name, @Nullable String defaultValue, String description, boolean required,
String @Nullable [] choices) {
this.name = name;
this.defaultValue = defaultValue;
this.required = required;
this.description = description;
this.choices = choices;
}
private static final Map<String, PGProperty> PROPS_BY_NAME = new HashMap<String, PGProperty>();
static {
for (PGProperty prop : PGProperty.values()) {
if (PROPS_BY_NAME.put(prop.getName(), prop) != null) {
throw new IllegalStateException("Duplicate PGProperty name: " + prop.getName());
}
}
}
/**
* Returns the name of the connection parameter. The name is the key that must be used in JDBC URL
* or in Driver properties
*
* @return the name of the connection parameter
*/
public String getName() {
return name;
}
/**
* Returns the default value for this connection parameter.
*
* @return the default value for this connection parameter or null
*/
public @Nullable String getDefaultValue() {
return defaultValue;
}
/**
* Returns whether this parameter is required.
*
* @return whether this parameter is required
*/
public boolean isRequired() {
return required;
}
/**
* Returns the description for this connection parameter.
*
* @return the description for this connection parameter
*/
public String getDescription() {
return description;
}
/**
* Returns the available values for this connection parameter.
*
* @return the available values for this connection parameter or null
*/
public String @Nullable [] getChoices() {
return choices;
}
/**
* Returns the value of the connection parameter from the given {@link Properties} or the
* default value.
*
* @param properties properties to take actual value from
* @return evaluated value for this connection parameter
*/
public @Nullable String getOrDefault(Properties properties) {
return properties.getProperty(name, defaultValue);
}
/**
* Returns the value of the connection parameter from the given {@link Properties} or the
* default value
* @deprecated use {@link #getOrDefault(Properties)} instead
* @param properties properties to take actual value from
* @return evaluated value for this connection parameter or null
*/
@Deprecated
public @Nullable String get(Properties properties) {
return getOrDefault(properties);
}
/**
* Returns the value of the connection parameter from the given {@link Properties} or null if there
* is no default value
* @param properties properties object to get value from
* @return evaluated value for this connection parameter
*/
public @Nullable String getOrNull(Properties properties) {
return properties.getProperty(name);
}
/**
* Set the value for this connection parameter in the given {@link Properties}.
*
* @param properties properties in which the value should be set
* @param value value for this connection parameter
*/
public void set(Properties properties, @Nullable String value) {
if (value == null) {
properties.remove(name);
} else {
properties.setProperty(name, value);
}
}
/**
* Return the boolean value for this connection parameter in the given {@link Properties}.
*
* @param properties properties to take actual value from
* @return evaluated value for this connection parameter converted to boolean
*/
public boolean getBoolean(Properties properties) {
return Boolean.parseBoolean(getOrDefault(properties));
}
/**
* Return the int value for this connection parameter in the given {@link Properties}. Prefer the
* use of {@link #getInt(Properties)} anywhere you can throw an {@link java.sql.SQLException}.
*
* @param properties properties to take actual value from
* @return evaluated value for this connection parameter converted to int
* @throws NumberFormatException if it cannot be converted to int.
*/
@SuppressWarnings("nullness:argument.type.incompatible")
public int getIntNoCheck(Properties properties) {
String value = getOrDefault(properties);
//noinspection ConstantConditions
return Integer.parseInt(value);
}
/**
* Return the int value for this connection parameter in the given {@link Properties}.
*
* @param properties properties to take actual value from
* @return evaluated value for this connection parameter converted to int
* @throws PSQLException if it cannot be converted to int.
*/
@SuppressWarnings("nullness:argument.type.incompatible")
public int getInt(Properties properties) throws PSQLException {
String value = getOrDefault(properties);
try {
//noinspection ConstantConditions
return Integer.parseInt(value);
} catch (NumberFormatException nfe) {
throw new PSQLException(GT.tr("{0} parameter value must be an integer but was: {1}",
getName(), value), PSQLState.INVALID_PARAMETER_VALUE, nfe);
}
}
/**
* Return the {@link Integer} value for this connection parameter in the given {@link Properties}.
*
* @param properties properties to take actual value from
* @return evaluated value for this connection parameter converted to Integer or null
* @throws PSQLException if unable to parse property as integer
*/
public @Nullable Integer getInteger(Properties properties) throws PSQLException {
String value = getOrDefault(properties);
if (value == null) {
return null;
}
try {
return Integer.parseInt(value);
} catch (NumberFormatException nfe) {
throw new PSQLException(GT.tr("{0} parameter value must be an integer but was: {1}",
getName(), value), PSQLState.INVALID_PARAMETER_VALUE, nfe);
}
}
/**
* Set the boolean value for this connection parameter in the given {@link Properties}.
*
* @param properties properties in which the value should be set
* @param value boolean value for this connection parameter
*/
public void set(Properties properties, boolean value) {
properties.setProperty(name, Boolean.toString(value));
}
/**
* Set the int value for this connection parameter in the given {@link Properties}.
*
* @param properties properties in which the value should be set
* @param value int value for this connection parameter
*/
public void set(Properties properties, int value) {
properties.setProperty(name, Integer.toString(value));
}
/**
* Test whether this property is present in the given {@link Properties}.
*
* @param properties set of properties to check current in
* @return true if the parameter is specified in the given properties
*/
public boolean isPresent(Properties properties) {
return getSetString(properties) != null;
}
/**
* Convert this connection parameter and the value read from the given {@link Properties} into a
* {@link DriverPropertyInfo}.
*
* @param properties properties to take actual value from
* @return a DriverPropertyInfo representing this connection parameter
*/
public DriverPropertyInfo toDriverPropertyInfo(Properties properties) {