-
Notifications
You must be signed in to change notification settings - Fork 435
/
Copy pathSQLServerDataSource.java
1861 lines (1611 loc) · 73.4 KB
/
SQLServerDataSource.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
/*
* Microsoft JDBC Driver for SQL Server Copyright(c) Microsoft Corporation All rights reserved. This program is made
* available under the terms of the MIT License. See the LICENSE file in the project root for more information.
*/
package com.microsoft.sqlserver.jdbc;
import java.io.PrintWriter;
import java.sql.Connection;
import java.sql.SQLException;
import java.util.Enumeration;
import java.util.Properties;
import java.util.concurrent.atomic.AtomicInteger;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.naming.Reference;
import javax.naming.StringRefAddr;
import org.ietf.jgss.GSSCredential;
/**
* Contains a list of properties specific for the {@link SQLServerConnection} class.
*/
public class SQLServerDataSource
implements ISQLServerDataSource, javax.sql.DataSource, java.io.Serializable, javax.naming.Referenceable {
// dsLogger is logger used for all SQLServerDataSource instances.
static final java.util.logging.Logger dsLogger = java.util.logging.Logger
.getLogger("com.microsoft.sqlserver.jdbc.internals.SQLServerDataSource");
static final java.util.logging.Logger loggerExternal = java.util.logging.Logger
.getLogger("com.microsoft.sqlserver.jdbc.DataSource");
static final private java.util.logging.Logger parentLogger = java.util.logging.Logger
.getLogger("com.microsoft.sqlserver.jdbc");
static final String TRUSTSTORE_PASSWORD_STRIPPED = "trustStorePasswordStripped";
/** logging class name */
final private String loggingClassName;
/**
* trustStorePasswordStripped flag
*/
private boolean trustStorePasswordStripped = false;
/**
* Always refresh SerialVersionUID when prompted
*/
private static final long serialVersionUID = 654861379544314296L;
/**
* Properties passed to SQLServerConnection class
*/
private Properties connectionProps;
/**
* URL for datasource
*/
private String dataSourceURL;
/**
* Description for datasource.
*/
private String dataSourceDescription;
/**
* Unique id generator for each DataSource instance (used for logging).
*/
static private final AtomicInteger baseDataSourceID = new AtomicInteger(0);
/**
* trace ID
*/
final private String traceID;
/**
* Constructs a SQLServerDataSource.
*/
public SQLServerDataSource() {
connectionProps = new Properties();
traceID = getClass().getSimpleName() + ':' + nextDataSourceID();
loggingClassName = "com.microsoft.sqlserver.jdbc." + traceID;
}
String getClassNameLogging() {
return loggingClassName;
}
@Override
public String toString() {
return traceID;
}
// DataSource interface public methods
@Override
public Connection getConnection() throws SQLServerException {
loggerExternal.entering(getClassNameLogging(), "getConnection");
Connection con = getConnectionInternal(null, null, null);
loggerExternal.exiting(getClassNameLogging(), "getConnection", con);
return con;
}
@Override
public Connection getConnection(String username, String password) throws SQLServerException {
if (loggerExternal.isLoggable(Level.FINER))
loggerExternal.entering(getClassNameLogging(), "getConnection",
new Object[] {username, "Password not traced"});
Connection con = getConnectionInternal(username, password, null);
loggerExternal.exiting(getClassNameLogging(), "getConnection", con);
return con;
}
/**
* Sets the maximum time in seconds that this data source will wait while attempting to connect to a database. Note
* default value is 0.
*/
@Override
public void setLoginTimeout(int loginTimeout) {
setIntProperty(connectionProps, SQLServerDriverIntProperty.LOGIN_TIMEOUT.toString(), loginTimeout);
}
@Override
public int getLoginTimeout() {
int defaultTimeOut = SQLServerDriverIntProperty.LOGIN_TIMEOUT.getDefaultValue();
final int logintimeout = getIntProperty(connectionProps, SQLServerDriverIntProperty.LOGIN_TIMEOUT.toString(),
defaultTimeOut);
// even if the user explicitly sets the timeout to zero, convert to 15
return (logintimeout == 0) ? defaultTimeOut : logintimeout;
}
/**
* Sets the log writer for this DataSource. Currently we just hold onto this logWriter and pass it back to callers,
* nothing else.
*/
private transient PrintWriter logWriter;
@Override
public void setLogWriter(PrintWriter out) {
loggerExternal.entering(getClassNameLogging(), "setLogWriter", out);
logWriter = out;
loggerExternal.exiting(getClassNameLogging(), "setLogWriter");
}
/**
* Returns the log writer for this DataSource.
*/
@Override
public PrintWriter getLogWriter() {
loggerExternal.entering(getClassNameLogging(), "getLogWriter");
loggerExternal.exiting(getClassNameLogging(), "getLogWriter", logWriter);
return logWriter;
}
@Override
public Logger getParentLogger() throws java.sql.SQLFeatureNotSupportedException {
return parentLogger;
}
// Core Connection property setters/getters.
/**
* Sets the specific application in various SQL Server profiling and logging tools.
*/
@Override
public void setApplicationName(String applicationName) {
setStringProperty(connectionProps, SQLServerDriverStringProperty.APPLICATION_NAME.toString(), applicationName);
}
@Override
public String getApplicationName() {
return getStringProperty(connectionProps, SQLServerDriverStringProperty.APPLICATION_NAME.toString(),
SQLServerDriverStringProperty.APPLICATION_NAME.getDefaultValue());
}
/**
* Sets the the database to connect to.
*
* @param databaseName
* if not set, returns the default value of null.
*/
@Override
public void setDatabaseName(String databaseName) {
setStringProperty(connectionProps, SQLServerDriverStringProperty.DATABASE_NAME.toString(), databaseName);
}
@Override
public String getDatabaseName() {
return getStringProperty(connectionProps, SQLServerDriverStringProperty.DATABASE_NAME.toString(), null);
}
/**
* Sets the the SQL Server instance name to connect to.
*
* @param instanceName
* if not set, returns the default value of null.
*/
@Override
public void setInstanceName(String instanceName) {
setStringProperty(connectionProps, SQLServerDriverStringProperty.INSTANCE_NAME.toString(), instanceName);
}
@Override
public String getInstanceName() {
return getStringProperty(connectionProps, SQLServerDriverStringProperty.INSTANCE_NAME.toString(), null);
}
@Override
public void setIntegratedSecurity(boolean enable) {
setBooleanProperty(connectionProps, SQLServerDriverBooleanProperty.INTEGRATED_SECURITY.toString(), enable);
}
@Override
public void setAuthenticationScheme(String authenticationScheme) {
setStringProperty(connectionProps, SQLServerDriverStringProperty.AUTHENTICATION_SCHEME.toString(),
authenticationScheme);
}
@Override
public void setAuthentication(String authentication) {
setStringProperty(connectionProps, SQLServerDriverStringProperty.AUTHENTICATION.toString(), authentication);
}
@Override
public String getAuthentication() {
return getStringProperty(connectionProps, SQLServerDriverStringProperty.AUTHENTICATION.toString(),
SQLServerDriverStringProperty.AUTHENTICATION.getDefaultValue());
}
@Override
public void setGSSCredentials(GSSCredential userCredential) {
setObjectProperty(connectionProps, SQLServerDriverObjectProperty.GSS_CREDENTIAL.toString(), userCredential);
}
@Override
public GSSCredential getGSSCredentials() {
return (GSSCredential) getObjectProperty(connectionProps,
SQLServerDriverObjectProperty.GSS_CREDENTIAL.toString(),
SQLServerDriverObjectProperty.GSS_CREDENTIAL.getDefaultValue());
}
@Override
public void setUseDefaultGSSCredential(boolean enable) {
setBooleanProperty(connectionProps, SQLServerDriverBooleanProperty.USE_DEFAULT_GSS_CREDENTIAL.toString(),
enable);
}
@Override
public boolean getUseDefaultGSSCredential() {
return getBooleanProperty(connectionProps, SQLServerDriverBooleanProperty.USE_DEFAULT_GSS_CREDENTIAL.toString(),
SQLServerDriverBooleanProperty.USE_DEFAULT_GSS_CREDENTIAL.getDefaultValue());
}
@Override
public void setAccessToken(String accessToken) {
setStringProperty(connectionProps, SQLServerDriverStringProperty.ACCESS_TOKEN.toString(), accessToken);
}
@Override
public String getAccessToken() {
return getStringProperty(connectionProps, SQLServerDriverStringProperty.ACCESS_TOKEN.toString(), null);
}
/**
* Sets the Column Encryption setting. If lastUpdateCount is set to true, the driver will return only the last
* update count from all the update counts returned by a batch. The default of false will return all update counts.
* If lastUpdateCount is not set, getLastUpdateCount returns the default value of false.
*/
@Override
public void setColumnEncryptionSetting(String columnEncryptionSetting) {
setStringProperty(connectionProps, SQLServerDriverStringProperty.COLUMN_ENCRYPTION.toString(),
columnEncryptionSetting);
}
@Override
public String getColumnEncryptionSetting() {
return getStringProperty(connectionProps, SQLServerDriverStringProperty.COLUMN_ENCRYPTION.toString(),
SQLServerDriverStringProperty.COLUMN_ENCRYPTION.getDefaultValue());
}
@Override
public void setKeyStoreAuthentication(String keyStoreAuthentication) {
setStringProperty(connectionProps, SQLServerDriverStringProperty.KEY_STORE_AUTHENTICATION.toString(),
keyStoreAuthentication);
}
@Override
public String getKeyStoreAuthentication() {
return getStringProperty(connectionProps, SQLServerDriverStringProperty.KEY_STORE_AUTHENTICATION.toString(),
SQLServerDriverStringProperty.KEY_STORE_AUTHENTICATION.getDefaultValue());
}
@Override
public void setKeyStoreSecret(String keyStoreSecret) {
setStringProperty(connectionProps, SQLServerDriverStringProperty.KEY_STORE_SECRET.toString(), keyStoreSecret);
}
@Override
public void setKeyStoreLocation(String keyStoreLocation) {
setStringProperty(connectionProps, SQLServerDriverStringProperty.KEY_STORE_LOCATION.toString(),
keyStoreLocation);
}
@Override
public String getKeyStoreLocation() {
return getStringProperty(connectionProps, SQLServerDriverStringProperty.KEY_STORE_LOCATION.toString(),
SQLServerDriverStringProperty.KEY_STORE_LOCATION.getDefaultValue());
}
@Override
public void setLastUpdateCount(boolean lastUpdateCount) {
setBooleanProperty(connectionProps, SQLServerDriverBooleanProperty.LAST_UPDATE_COUNT.toString(),
lastUpdateCount);
}
@Override
public boolean getLastUpdateCount() {
return getBooleanProperty(connectionProps, SQLServerDriverBooleanProperty.LAST_UPDATE_COUNT.toString(),
SQLServerDriverBooleanProperty.LAST_UPDATE_COUNT.getDefaultValue());
}
@Override
public void setEncrypt(String encryptOption) {
setStringProperty(connectionProps, SQLServerDriverStringProperty.ENCRYPT.toString(), encryptOption);
}
/**
* @deprecated
*/
@Override
@Deprecated(since = "10.1.0", forRemoval = true)
public void setEncrypt(boolean encryptOption) {
setStringProperty(connectionProps, SQLServerDriverStringProperty.ENCRYPT.toString(),
Boolean.toString(encryptOption));
}
@Override
public String getEncrypt() {
return getStringProperty(connectionProps, SQLServerDriverStringProperty.ENCRYPT.toString(),
SQLServerDriverStringProperty.ENCRYPT.getDefaultValue());
}
@Override
public void setServerCertificate(String cert) {
setStringProperty(connectionProps, SQLServerDriverStringProperty.SERVER_CERTIFICATE.toString(), cert);
}
@Override
public String getServerCertificate() {
return getStringProperty(connectionProps, SQLServerDriverStringProperty.SERVER_CERTIFICATE.toString(), null);
}
@Override
public void setTransparentNetworkIPResolution(boolean tnir) {
setBooleanProperty(connectionProps, SQLServerDriverBooleanProperty.TRANSPARENT_NETWORK_IP_RESOLUTION.toString(),
tnir);
}
@Override
public boolean getTransparentNetworkIPResolution() {
return getBooleanProperty(connectionProps,
SQLServerDriverBooleanProperty.TRANSPARENT_NETWORK_IP_RESOLUTION.toString(),
SQLServerDriverBooleanProperty.TRANSPARENT_NETWORK_IP_RESOLUTION.getDefaultValue());
}
@Override
public void setTrustServerCertificate(boolean e) {
setBooleanProperty(connectionProps, SQLServerDriverBooleanProperty.TRUST_SERVER_CERTIFICATE.toString(), e);
}
@Override
public boolean getTrustServerCertificate() {
return getBooleanProperty(connectionProps, SQLServerDriverBooleanProperty.TRUST_SERVER_CERTIFICATE.toString(),
SQLServerDriverBooleanProperty.TRUST_SERVER_CERTIFICATE.getDefaultValue());
}
@Override
public void setTrustStoreType(String trustStoreType) {
setStringProperty(connectionProps, SQLServerDriverStringProperty.TRUST_STORE_TYPE.toString(), trustStoreType);
}
@Override
public String getTrustStoreType() {
return getStringProperty(connectionProps, SQLServerDriverStringProperty.TRUST_STORE_TYPE.toString(),
SQLServerDriverStringProperty.TRUST_STORE_TYPE.getDefaultValue());
}
@Override
public void setTrustStore(String trustStore) {
setStringProperty(connectionProps, SQLServerDriverStringProperty.TRUST_STORE.toString(), trustStore);
}
@Override
public String getTrustStore() {
return getStringProperty(connectionProps, SQLServerDriverStringProperty.TRUST_STORE.toString(), null);
}
@Override
public void setTrustStorePassword(String trustStorePassword) {
// if a non value property is set
if (trustStorePassword != null)
trustStorePasswordStripped = false;
setStringProperty(connectionProps, SQLServerDriverStringProperty.TRUST_STORE_PASSWORD.toString(),
trustStorePassword);
}
String getTrustStorePassword() {
return getStringProperty(connectionProps, SQLServerDriverStringProperty.TRUST_STORE_PASSWORD.toString(), null);
}
@Override
public void setHostNameInCertificate(String hostName) {
setStringProperty(connectionProps, SQLServerDriverStringProperty.HOSTNAME_IN_CERTIFICATE.toString(), hostName);
}
@Override
public String getHostNameInCertificate() {
return getStringProperty(connectionProps, SQLServerDriverStringProperty.HOSTNAME_IN_CERTIFICATE.toString(),
null);
}
/**
* Sets the lock timeout value.
*
* @param lockTimeout
* the number of milliseconds to wait before the database reports a lock timeout. The default value of -1
* means wait forever. If specified, this value will be the default for all statements on the connection.
* Note a value of 0 means no wait. If lockTimeout is not set, getLockTimeout returns the default of -1.
*/
@Override
public void setLockTimeout(int lockTimeout) {
setIntProperty(connectionProps, SQLServerDriverIntProperty.LOCK_TIMEOUT.toString(), lockTimeout);
}
@Override
public int getLockTimeout() {
return getIntProperty(connectionProps, SQLServerDriverIntProperty.LOCK_TIMEOUT.toString(),
SQLServerDriverIntProperty.LOCK_TIMEOUT.getDefaultValue());
}
/**
* Sets the password that will be used when connecting to SQL Server.
*
* @param password
* Note getPassword is deliberately declared non-public for security reasons. If the password is not set,
* getPassword returns the default value of null.
*/
@Override
public void setPassword(String password) {
setStringProperty(connectionProps, SQLServerDriverStringProperty.PASSWORD.toString(), password);
}
String getPassword() {
return getStringProperty(connectionProps, SQLServerDriverStringProperty.PASSWORD.toString(), null);
}
/**
* Sets the TCP-IP port number used when opening a socket connection to SQL Server.
*
* @param portNumber
* if not set, getPortNumber returns the default of 1433. Note as mentioned above, setPortNumber does not do
* any range checking on the port value passed in,\ invalid port numbers like 99999 can be passed in without
* triggering any error.
*/
@Override
public void setPortNumber(int portNumber) {
setIntProperty(connectionProps, SQLServerDriverIntProperty.PORT_NUMBER.toString(), portNumber);
}
@Override
public int getPortNumber() {
return getIntProperty(connectionProps, SQLServerDriverIntProperty.PORT_NUMBER.toString(),
SQLServerDriverIntProperty.PORT_NUMBER.getDefaultValue());
}
/**
* Sets the default cursor type used for the result set.
*
* @param selectMethod
* This(non-Javadoc) @see com.microsoft.sqlserver.jdbc.ISQLServerDataSource#setSelectMethod(java.lang.String)
* property is useful when you are dealing with large result sets and do not want to store the whole result
* set in memory on the client side. By setting the property to "cursor" you will be able to create a server
* side cursor that can fetch smaller chunks of data at a time. If selectMethod is not set, getSelectMethod
* returns the default value of "direct".
*/
@Override
public void setSelectMethod(String selectMethod) {
setStringProperty(connectionProps, SQLServerDriverStringProperty.SELECT_METHOD.toString(), selectMethod);
}
@Override
public String getSelectMethod() {
return getStringProperty(connectionProps, SQLServerDriverStringProperty.SELECT_METHOD.toString(),
SQLServerDriverStringProperty.SELECT_METHOD.getDefaultValue());
}
@Override
public void setResponseBuffering(String bufferingMode) {
setStringProperty(connectionProps, SQLServerDriverStringProperty.RESPONSE_BUFFERING.toString(), bufferingMode);
}
@Override
public String getResponseBuffering() {
return getStringProperty(connectionProps, SQLServerDriverStringProperty.RESPONSE_BUFFERING.toString(),
SQLServerDriverStringProperty.RESPONSE_BUFFERING.getDefaultValue());
}
@Override
public void setApplicationIntent(String applicationIntent) {
setStringProperty(connectionProps, SQLServerDriverStringProperty.APPLICATION_INTENT.toString(),
applicationIntent);
}
@Override
public String getApplicationIntent() {
return getStringProperty(connectionProps, SQLServerDriverStringProperty.APPLICATION_INTENT.toString(),
SQLServerDriverStringProperty.APPLICATION_INTENT.getDefaultValue());
}
@Override
public void setReplication(boolean replication) {
setBooleanProperty(connectionProps, SQLServerDriverBooleanProperty.REPLICATION.toString(), replication);
}
@Override
public boolean getReplication() {
return getBooleanProperty(connectionProps, SQLServerDriverBooleanProperty.REPLICATION.toString(),
SQLServerDriverBooleanProperty.REPLICATION.getDefaultValue());
}
@Override
public void setSendTimeAsDatetime(boolean sendTimeAsDatetime) {
setBooleanProperty(connectionProps, SQLServerDriverBooleanProperty.SEND_TIME_AS_DATETIME.toString(),
sendTimeAsDatetime);
}
@Override
public boolean getSendTimeAsDatetime() {
return getBooleanProperty(connectionProps, SQLServerDriverBooleanProperty.SEND_TIME_AS_DATETIME.toString(),
SQLServerDriverBooleanProperty.SEND_TIME_AS_DATETIME.getDefaultValue());
}
@Override
public void setDatetimeParameterType(String datetimeParameterType) {
setStringProperty(connectionProps, SQLServerDriverStringProperty.DATETIME_DATATYPE.toString(),
datetimeParameterType);
}
@Override
public String getDatetimeParameterType() {
return getStringProperty(connectionProps, SQLServerDriverStringProperty.DATETIME_DATATYPE.toString(),
SQLServerDriverStringProperty.DATETIME_DATATYPE.getDefaultValue());
}
@Override
public void setUseFmtOnly(boolean useFmtOnly) {
setBooleanProperty(connectionProps, SQLServerDriverBooleanProperty.USE_FMT_ONLY.toString(), useFmtOnly);
}
@Override
public boolean getUseFmtOnly() {
return getBooleanProperty(connectionProps, SQLServerDriverBooleanProperty.USE_FMT_ONLY.toString(),
SQLServerDriverBooleanProperty.USE_FMT_ONLY.getDefaultValue());
}
@Override
public void setDelayLoadingLobs(boolean delayLoadingLobs) {
setBooleanProperty(connectionProps, SQLServerDriverBooleanProperty.DELAY_LOADING_LOBS.toString(),
delayLoadingLobs);
}
@Override
public boolean getDelayLoadingLobs() {
return getBooleanProperty(connectionProps, SQLServerDriverBooleanProperty.DELAY_LOADING_LOBS.toString(),
SQLServerDriverBooleanProperty.DELAY_LOADING_LOBS.getDefaultValue());
}
/**
* Sets whether string parameters are sent to the server in UNICODE format.
*
* @param sendStringParametersAsUnicode
* if true (default), string parameters are sent to the server in UNICODE format. if false, string parameters
* are sent to the server in the native TDS collation format of the database, not in UNICODE. if set, returns
* the default of true.
*/
@Override
public void setSendStringParametersAsUnicode(boolean sendStringParametersAsUnicode) {
setBooleanProperty(connectionProps, SQLServerDriverBooleanProperty.SEND_STRING_PARAMETERS_AS_UNICODE.toString(),
sendStringParametersAsUnicode);
}
@Override
public boolean getSendStringParametersAsUnicode() {
return getBooleanProperty(connectionProps,
SQLServerDriverBooleanProperty.SEND_STRING_PARAMETERS_AS_UNICODE.toString(),
SQLServerDriverBooleanProperty.SEND_STRING_PARAMETERS_AS_UNICODE.getDefaultValue());
}
@Override
public void setServerNameAsACE(boolean serverNameAsACE) {
setBooleanProperty(connectionProps, SQLServerDriverBooleanProperty.SERVER_NAME_AS_ACE.toString(),
serverNameAsACE);
}
@Override
public boolean getServerNameAsACE() {
return getBooleanProperty(connectionProps, SQLServerDriverBooleanProperty.SERVER_NAME_AS_ACE.toString(),
SQLServerDriverBooleanProperty.SERVER_NAME_AS_ACE.getDefaultValue());
}
/**
* Sets the host name of the target SQL Server.
*
* @param serverName
* if not set, returns the default value of null is returned.
*/
@Override
public void setServerName(String serverName) {
setStringProperty(connectionProps, SQLServerDriverStringProperty.SERVER_NAME.toString(), serverName);
}
@Override
public String getServerName() {
return getStringProperty(connectionProps, SQLServerDriverStringProperty.SERVER_NAME.toString(), null);
}
/**
* Set the preferred type of IP Address
*
* @param iPAddressPreference
* Preferred IP Address type
*/
@Override
public void setIPAddressPreference(String iPAddressPreference) {
setStringProperty(connectionProps, SQLServerDriverStringProperty.IPADDRESS_PREFERENCE.toString(),
iPAddressPreference);
}
/**
* Gets the preferred type of IP Address
*/
@Override
public String getIPAddressPreference() {
return getStringProperty(connectionProps, SQLServerDriverStringProperty.IPADDRESS_PREFERENCE.toString(),
SQLServerDriverStringProperty.IPADDRESS_PREFERENCE.getDefaultValue());
}
/**
* Sets the realm for Kerberos authentication.
*
* @param realm
* realm
*/
@Override
public void setRealm(String realm) {
setStringProperty(connectionProps, SQLServerDriverStringProperty.REALM.toString(), realm);
}
@Override
public String getRealm() {
return getStringProperty(connectionProps, SQLServerDriverStringProperty.REALM.toString(), null);
}
/**
* Sets the Service Principal Name (SPN) of the target SQL Server.
* https://msdn.microsoft.com/en-us/library/cc280459.aspx
*
* @param serverSpn
* service principal name
*/
@Override
public void setServerSpn(String serverSpn) {
setStringProperty(connectionProps, SQLServerDriverStringProperty.SERVER_SPN.toString(), serverSpn);
}
@Override
public String getServerSpn() {
return getStringProperty(connectionProps, SQLServerDriverStringProperty.SERVER_SPN.toString(), null);
}
/**
* Sets the fail over partner of the target SQL Server.
*
* @param serverName
* if not set, returns the default value of null.
*/
@Override
public void setFailoverPartner(String serverName) {
setStringProperty(connectionProps, SQLServerDriverStringProperty.FAILOVER_PARTNER.toString(), serverName);
}
@Override
public String getFailoverPartner() {
return getStringProperty(connectionProps, SQLServerDriverStringProperty.FAILOVER_PARTNER.toString(), null);
}
@Override
public void setMultiSubnetFailover(boolean multiSubnetFailover) {
setBooleanProperty(connectionProps, SQLServerDriverBooleanProperty.MULTI_SUBNET_FAILOVER.toString(),
multiSubnetFailover);
}
@Override
public boolean getMultiSubnetFailover() {
return getBooleanProperty(connectionProps, SQLServerDriverBooleanProperty.MULTI_SUBNET_FAILOVER.toString(),
SQLServerDriverBooleanProperty.MULTI_SUBNET_FAILOVER.getDefaultValue());
}
/**
* Sets the user name that will be used when connecting to SQL Server.
*
* @param user
* if not set, returns the default value of null.
*/
@Override
public void setUser(String user) {
setStringProperty(connectionProps, SQLServerDriverStringProperty.USER.toString(), user);
}
@Override
public String getUser() {
return getStringProperty(connectionProps, SQLServerDriverStringProperty.USER.toString(), null);
}
/**
* Sets the name of the client machine (or client workstation).
*
* @param workstationID
* host name of the client. if not set, the default value is constructed by calling
* InetAddress.getLocalHost().getHostName() or if getHostName() returns blank then
* getHostAddress().toString().
*/
@Override
public void setWorkstationID(String workstationID) {
setStringProperty(connectionProps, SQLServerDriverStringProperty.WORKSTATION_ID.toString(), workstationID);
}
@Override
public String getWorkstationID() {
if (loggerExternal.isLoggable(java.util.logging.Level.FINER))
loggerExternal.entering(getClassNameLogging(), "getWorkstationID");
String getWSID = connectionProps.getProperty(SQLServerDriverStringProperty.WORKSTATION_ID.toString());
// Per spec, return what the logon will send here if workstationID
// property is not set.
if (null == getWSID) {
getWSID = Util.lookupHostName();
}
loggerExternal.exiting(getClassNameLogging(), "getWorkstationID", getWSID);
return getWSID;
}
/**
* Sets whether the driver will convert SQL states to XOPEN compliant states.
*
* @param xopenStates
* if true, the driver will convert SQL states to XOPEN compliant states. The default is false which causes
* the driver to generate SQL 99 state codes. If not set, getXopenStates returns the default value of false.
*/
@Override
public void setXopenStates(boolean xopenStates) {
setBooleanProperty(connectionProps, SQLServerDriverBooleanProperty.XOPEN_STATES.toString(), xopenStates);
}
@Override
public boolean getXopenStates() {
return getBooleanProperty(connectionProps, SQLServerDriverBooleanProperty.XOPEN_STATES.toString(),
SQLServerDriverBooleanProperty.XOPEN_STATES.getDefaultValue());
}
@Override
public void setFIPS(boolean fips) {
setBooleanProperty(connectionProps, SQLServerDriverBooleanProperty.FIPS.toString(), fips);
}
@Override
public boolean getFIPS() {
return getBooleanProperty(connectionProps, SQLServerDriverBooleanProperty.FIPS.toString(),
SQLServerDriverBooleanProperty.FIPS.getDefaultValue());
}
@Override
public String getSocketFactoryClass() {
return getStringProperty(connectionProps, SQLServerDriverStringProperty.SOCKET_FACTORY_CLASS.toString(), null);
}
@Override
public void setSocketFactoryClass(String socketFactoryClass) {
setStringProperty(connectionProps, SQLServerDriverStringProperty.SOCKET_FACTORY_CLASS.toString(),
socketFactoryClass);
}
@Override
public String getSocketFactoryConstructorArg() {
return getStringProperty(connectionProps,
SQLServerDriverStringProperty.SOCKET_FACTORY_CONSTRUCTOR_ARG.toString(), null);
}
@Override
public void setSocketFactoryConstructorArg(String socketFactoryConstructorArg) {
setStringProperty(connectionProps, SQLServerDriverStringProperty.SOCKET_FACTORY_CONSTRUCTOR_ARG.toString(),
socketFactoryConstructorArg);
}
@Override
public void setSSLProtocol(String sslProtocol) {
setStringProperty(connectionProps, SQLServerDriverStringProperty.SSL_PROTOCOL.toString(), sslProtocol);
}
@Override
public String getSSLProtocol() {
return getStringProperty(connectionProps, SQLServerDriverStringProperty.SSL_PROTOCOL.toString(),
SQLServerDriverStringProperty.SSL_PROTOCOL.getDefaultValue());
}
@Override
public void setTrustManagerClass(String trustManagerClass) {
setStringProperty(connectionProps, SQLServerDriverStringProperty.TRUST_MANAGER_CLASS.toString(),
trustManagerClass);
}
@Override
public String getTrustManagerClass() {
return getStringProperty(connectionProps, SQLServerDriverStringProperty.TRUST_MANAGER_CLASS.toString(),
SQLServerDriverStringProperty.TRUST_MANAGER_CLASS.getDefaultValue());
}
@Override
public void setTrustManagerConstructorArg(String trustManagerConstructorArg) {
setStringProperty(connectionProps, SQLServerDriverStringProperty.TRUST_MANAGER_CONSTRUCTOR_ARG.toString(),
trustManagerConstructorArg);
}
@Override
public String getTrustManagerConstructorArg() {
return getStringProperty(connectionProps,
SQLServerDriverStringProperty.TRUST_MANAGER_CONSTRUCTOR_ARG.toString(),
SQLServerDriverStringProperty.TRUST_MANAGER_CONSTRUCTOR_ARG.getDefaultValue());
}
/**
* Sets the datasource URL.
*
* @param url
* The URL property is exposed for backwards compatibility reasons. Also, several Java Application servers
* expect a setURL function on the DataSource and set it by default (JBoss and WebLogic) Note for security
* reasons we do not recommend that customers include the password in the url supplied to setURL. The reason
* for this is third-party Java Application Servers will very often display the value set to URL property in
* their DataSource configuration GUI. We recommend instead that clients use the setPassword method to set
* the password value. The Java Application Servers will not display a password that is set on the DataSource
* in the configuration GUI. Note if setURL is not called, getURL returns the default value of
* "jdbc:sqlserver://".
*/
@Override
public void setURL(String url) {
loggerExternal.entering(getClassNameLogging(), "setURL", url);
// URL is not stored in a property set, it is maintained separately.
dataSourceURL = url;
loggerExternal.exiting(getClassNameLogging(), "setURL");
}
@Override
public String getURL() {
String url = dataSourceURL;
loggerExternal.entering(getClassNameLogging(), "getURL");
if (null == dataSourceURL)
url = "jdbc:sqlserver://";
loggerExternal.exiting(getClassNameLogging(), "getURL", url);
return url;
}
/**
* Sets the DataSource description. Per JDBC specification 16.1.1 "...the only property that all DataSource
* implementations are required to support is the description property".
*/
@Override
public void setDescription(String description) {
loggerExternal.entering(getClassNameLogging(), "setDescription", description);
dataSourceDescription = description;
loggerExternal.exiting(getClassNameLogging(), "setDescription");
}
/**
* Returns the DataSource description
*/
@Override
public String getDescription() {
loggerExternal.entering(getClassNameLogging(), "getDescription");
loggerExternal.exiting(getClassNameLogging(), "getDescription", dataSourceDescription);
return dataSourceDescription;
}
/**
* Sets the packet size.
*
* @param packetSize
* the size (in bytes) to use for the TCP/IP send and receive buffer. It is also the value used for the TDS
* packet size (SQL Server Network Packet Size). Validity of the value is checked at connect time. If no
* value is set for this property, its default value is 4KB.
*/
@Override
public void setPacketSize(int packetSize) {
setIntProperty(connectionProps, SQLServerDriverIntProperty.PACKET_SIZE.toString(), packetSize);
}
@Override
public int getPacketSize() {
return getIntProperty(connectionProps, SQLServerDriverIntProperty.PACKET_SIZE.toString(),
SQLServerDriverIntProperty.PACKET_SIZE.getDefaultValue());
}
@Override
public void setQueryTimeout(int queryTimeout) {
setIntProperty(connectionProps, SQLServerDriverIntProperty.QUERY_TIMEOUT.toString(), queryTimeout);
}
@Override
public int getQueryTimeout() {
return getIntProperty(connectionProps, SQLServerDriverIntProperty.QUERY_TIMEOUT.toString(),
SQLServerDriverIntProperty.QUERY_TIMEOUT.getDefaultValue());
}
@Override
public void setCancelQueryTimeout(int cancelQueryTimeout) {
setIntProperty(connectionProps, SQLServerDriverIntProperty.CANCEL_QUERY_TIMEOUT.toString(), cancelQueryTimeout);
}
@Override
public int getCancelQueryTimeout() {
return getIntProperty(connectionProps, SQLServerDriverIntProperty.CANCEL_QUERY_TIMEOUT.toString(),
SQLServerDriverIntProperty.CANCEL_QUERY_TIMEOUT.getDefaultValue());
}
@Override
public void setEnablePrepareOnFirstPreparedStatementCall(boolean enablePrepareOnFirstPreparedStatementCall) {
setBooleanProperty(connectionProps,
SQLServerDriverBooleanProperty.ENABLE_PREPARE_ON_FIRST_PREPARED_STATEMENT.toString(),
enablePrepareOnFirstPreparedStatementCall);
}
@Override
public boolean getEnablePrepareOnFirstPreparedStatementCall() {
boolean defaultValue = SQLServerDriverBooleanProperty.ENABLE_PREPARE_ON_FIRST_PREPARED_STATEMENT
.getDefaultValue();
return getBooleanProperty(connectionProps,
SQLServerDriverBooleanProperty.ENABLE_PREPARE_ON_FIRST_PREPARED_STATEMENT.toString(), defaultValue);
}
@Override
public void setcacheBulkCopyMetadata(boolean cacheBulkCopyMetadata) {
setBooleanProperty(connectionProps,
SQLServerDriverBooleanProperty.ENABLE_BULK_COPY_CACHE.toString(),
cacheBulkCopyMetadata);
}
@Override
public boolean getcacheBulkCopyMetadata() {
boolean defaultValue = SQLServerDriverBooleanProperty.ENABLE_BULK_COPY_CACHE
.getDefaultValue();
return getBooleanProperty(connectionProps,
SQLServerDriverBooleanProperty.ENABLE_BULK_COPY_CACHE.toString(), defaultValue);
}
@Override
public void setServerPreparedStatementDiscardThreshold(int serverPreparedStatementDiscardThreshold) {
setIntProperty(connectionProps,
SQLServerDriverIntProperty.SERVER_PREPARED_STATEMENT_DISCARD_THRESHOLD.toString(),
serverPreparedStatementDiscardThreshold);
}
@Override
public int getServerPreparedStatementDiscardThreshold() {
int defaultSize = SQLServerDriverIntProperty.SERVER_PREPARED_STATEMENT_DISCARD_THRESHOLD.getDefaultValue();
return getIntProperty(connectionProps,
SQLServerDriverIntProperty.SERVER_PREPARED_STATEMENT_DISCARD_THRESHOLD.toString(), defaultSize);
}
@Override
public void setStatementPoolingCacheSize(int statementPoolingCacheSize) {
setIntProperty(connectionProps, SQLServerDriverIntProperty.STATEMENT_POOLING_CACHE_SIZE.toString(),
statementPoolingCacheSize);
}
@Override
public int getStatementPoolingCacheSize() {
int defaultSize = SQLServerDriverIntProperty.STATEMENT_POOLING_CACHE_SIZE.getDefaultValue();
return getIntProperty(connectionProps, SQLServerDriverIntProperty.STATEMENT_POOLING_CACHE_SIZE.toString(),
defaultSize);
}
@Override
public void setDisableStatementPooling(boolean disableStatementPooling) {
setBooleanProperty(connectionProps, SQLServerDriverBooleanProperty.DISABLE_STATEMENT_POOLING.toString(),
disableStatementPooling);
}
@Override
public boolean getDisableStatementPooling() {
boolean defaultValue = SQLServerDriverBooleanProperty.DISABLE_STATEMENT_POOLING.getDefaultValue();
return getBooleanProperty(connectionProps, SQLServerDriverBooleanProperty.DISABLE_STATEMENT_POOLING.toString(),