forked from microsoft/mssql-jdbc
/
SQLServerDriver.java
1012 lines (883 loc) · 47.4 KB
/
SQLServerDriver.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.sql.DriverManager;
import java.sql.DriverPropertyInfo;
import java.sql.SQLException;
import java.text.MessageFormat;
import java.util.Enumeration;
import java.util.Locale;
import java.util.Properties;
import java.util.concurrent.atomic.AtomicInteger;
import java.util.logging.Level;
import java.util.logging.Logger;
import org.ietf.jgss.GSSCredential;
/**
* Implements the java.sql.Driver for SQLServerConnect.
*
*/
final class SQLServerDriverPropertyInfo {
private final String name;
final String getName() {
return name;
}
private final String description;
private final String defaultValue;
private final boolean required;
private final String[] choices;
SQLServerDriverPropertyInfo(String name, String defaultValue, boolean required, String[] choices) {
this.name = name;
this.description = SQLServerResource.getResource("R_" + name + "PropertyDescription");
this.defaultValue = defaultValue;
this.required = required;
this.choices = choices;
}
DriverPropertyInfo build(Properties connProperties) {
String propValue = name.equals(SQLServerDriverStringProperty.PASSWORD.toString()) ? "" : connProperties
.getProperty(name);
if (null == propValue)
propValue = defaultValue;
DriverPropertyInfo info = new DriverPropertyInfo(name, propValue);
info.description = description;
info.required = required;
info.choices = choices;
return info;
}
}
enum SqlAuthentication {
NotSpecified,
SqlPassword,
ActiveDirectoryPassword,
ActiveDirectoryIntegrated,
ActiveDirectoryMSI,
ActiveDirectoryServicePrincipal,
ActiveDirectoryInteractive;
static SqlAuthentication valueOfString(String value) throws SQLServerException {
SqlAuthentication method = null;
if (value.toLowerCase(Locale.US).equalsIgnoreCase(SqlAuthentication.NotSpecified.toString())) {
method = SqlAuthentication.NotSpecified;
} else if (value.toLowerCase(Locale.US).equalsIgnoreCase(SqlAuthentication.SqlPassword.toString())) {
method = SqlAuthentication.SqlPassword;
} else if (value.toLowerCase(Locale.US)
.equalsIgnoreCase(SqlAuthentication.ActiveDirectoryPassword.toString())) {
method = SqlAuthentication.ActiveDirectoryPassword;
} else if (value.toLowerCase(Locale.US)
.equalsIgnoreCase(SqlAuthentication.ActiveDirectoryIntegrated.toString())) {
method = SqlAuthentication.ActiveDirectoryIntegrated;
} else if (value.toLowerCase(Locale.US).equalsIgnoreCase(SqlAuthentication.ActiveDirectoryMSI.toString())) {
method = SqlAuthentication.ActiveDirectoryMSI;
} else if (value.toLowerCase(Locale.US)
.equalsIgnoreCase(SqlAuthentication.ActiveDirectoryServicePrincipal.toString())) {
method = SqlAuthentication.ActiveDirectoryServicePrincipal;
} else if (value.toLowerCase(Locale.US)
.equalsIgnoreCase(SqlAuthentication.ActiveDirectoryInteractive.toString())) {
method = SqlAuthentication.ActiveDirectoryInteractive;
} else {
MessageFormat form = new MessageFormat(SQLServerException.getErrString("R_InvalidConnectionSetting"));
Object[] msgArgs = {"authentication", value};
throw new SQLServerException(null, form.format(msgArgs), null, 0, false);
}
return method;
}
}
enum ColumnEncryptionSetting {
Enabled,
Disabled;
static ColumnEncryptionSetting valueOfString(String value) throws SQLServerException {
ColumnEncryptionSetting method = null;
if (value.toLowerCase(Locale.US).equalsIgnoreCase(ColumnEncryptionSetting.Enabled.toString())) {
method = ColumnEncryptionSetting.Enabled;
} else if (value.toLowerCase(Locale.US).equalsIgnoreCase(ColumnEncryptionSetting.Disabled.toString())) {
method = ColumnEncryptionSetting.Disabled;
} else {
MessageFormat form = new MessageFormat(SQLServerException.getErrString("R_InvalidConnectionSetting"));
Object[] msgArgs = {"columnEncryptionSetting", value};
throw new SQLServerException(form.format(msgArgs), null);
}
return method;
}
}
enum AttestationProtocol {
HGS("HGS"),
AAS("AAS");
private final String protocol;
AttestationProtocol(String protocol) {
this.protocol = protocol;
}
static boolean isValidAttestationProtocol(String protocol) {
for (AttestationProtocol p : AttestationProtocol.values()) {
if (protocol.equalsIgnoreCase(p.toString())) {
return true;
}
}
return false;
}
@Override
public String toString() {
return protocol;
}
}
enum EnclaveType {
VBS("VBS"),
SGX("SGX");
private final String type;
EnclaveType(String type) {
this.type = type;
}
public int getValue() {
return ordinal() + 1;
}
static boolean isValidEnclaveType(String type) {
for (EnclaveType t : EnclaveType.values()) {
if (type.equalsIgnoreCase(t.toString())) {
return true;
}
}
return false;
}
@Override
public String toString() {
return type;
}
}
enum SSLProtocol {
TLS("TLS"),
TLS_V10("TLSv1"),
TLS_V11("TLSv1.1"),
TLS_V12("TLSv1.2"),;
private final String name;
private SSLProtocol(String name) {
this.name = name;
}
@Override
public String toString() {
return name;
}
static SSLProtocol valueOfString(String value) throws SQLServerException {
SSLProtocol protocol = null;
if (value.toLowerCase(Locale.ENGLISH).equalsIgnoreCase(SSLProtocol.TLS.toString())) {
protocol = SSLProtocol.TLS;
} else if (value.toLowerCase(Locale.ENGLISH).equalsIgnoreCase(SSLProtocol.TLS_V10.toString())) {
protocol = SSLProtocol.TLS_V10;
} else if (value.toLowerCase(Locale.ENGLISH).equalsIgnoreCase(SSLProtocol.TLS_V11.toString())) {
protocol = SSLProtocol.TLS_V11;
} else if (value.toLowerCase(Locale.ENGLISH).equalsIgnoreCase(SSLProtocol.TLS_V12.toString())) {
protocol = SSLProtocol.TLS_V12;
} else {
MessageFormat form = new MessageFormat(SQLServerException.getErrString("R_invalidSSLProtocol"));
Object[] msgArgs = {value};
throw new SQLServerException(null, form.format(msgArgs), null, 0, false);
}
return protocol;
}
}
enum KeyStoreAuthentication {
JavaKeyStorePassword,
KeyVaultClientSecret,
KeyVaultManagedIdentity;
static KeyStoreAuthentication valueOfString(String value) throws SQLServerException {
KeyStoreAuthentication method = null;
if (value.toLowerCase(Locale.US).equalsIgnoreCase(KeyStoreAuthentication.JavaKeyStorePassword.toString())) {
method = KeyStoreAuthentication.JavaKeyStorePassword;
} else if (value.toLowerCase(Locale.US)
.equalsIgnoreCase(KeyStoreAuthentication.KeyVaultClientSecret.toString())) {
method = KeyStoreAuthentication.KeyVaultClientSecret;
} else if (value.toLowerCase(Locale.US)
.equalsIgnoreCase(KeyStoreAuthentication.KeyVaultManagedIdentity.toString())) {
method = KeyStoreAuthentication.KeyVaultManagedIdentity;
} else {
MessageFormat form = new MessageFormat(SQLServerException.getErrString("R_InvalidConnectionSetting"));
Object[] msgArgs = {"keyStoreAuthentication", value};
throw new SQLServerException(form.format(msgArgs), null);
}
return method;
}
}
enum AuthenticationScheme {
nativeAuthentication,
ntlm,
javaKerberos;
static AuthenticationScheme valueOfString(String value) throws SQLServerException {
AuthenticationScheme scheme;
if (value.toLowerCase(Locale.US).equalsIgnoreCase(AuthenticationScheme.javaKerberos.toString())) {
scheme = AuthenticationScheme.javaKerberos;
} else if (value.toLowerCase(Locale.US)
.equalsIgnoreCase(AuthenticationScheme.nativeAuthentication.toString())) {
scheme = AuthenticationScheme.nativeAuthentication;
} else if (value.toLowerCase(Locale.US).equalsIgnoreCase(AuthenticationScheme.ntlm.toString())) {
scheme = AuthenticationScheme.ntlm;
} else {
MessageFormat form = new MessageFormat(SQLServerException.getErrString("R_invalidAuthenticationScheme"));
Object[] msgArgs = {value};
throw new SQLServerException(null, form.format(msgArgs), null, 0, false);
}
return scheme;
}
}
enum ApplicationIntent {
READ_WRITE("readwrite"),
READ_ONLY("readonly");
// the value of the enum
private final String value;
/**
* Constructs a ApplicationIntent that sets the string value of the enum.
*/
private ApplicationIntent(String value) {
this.value = value;
}
/**
* Returns the string value of enum.
*/
@Override
public String toString() {
return value;
}
static ApplicationIntent valueOfString(String value) throws SQLServerException {
ApplicationIntent applicationIntent = ApplicationIntent.READ_WRITE;
assert value != null;
// handling turkish i issues
value = value.toUpperCase(Locale.US).toLowerCase(Locale.US);
if (value.equalsIgnoreCase(ApplicationIntent.READ_ONLY.toString())) {
applicationIntent = ApplicationIntent.READ_ONLY;
} else if (value.equalsIgnoreCase(ApplicationIntent.READ_WRITE.toString())) {
applicationIntent = ApplicationIntent.READ_WRITE;
} else {
MessageFormat form = new MessageFormat(SQLServerException.getErrString("R_invalidapplicationIntent"));
Object[] msgArgs = {value};
throw new SQLServerException(null, form.format(msgArgs), null, 0, false);
}
return applicationIntent;
}
}
enum SQLServerDriverObjectProperty {
GSS_CREDENTIAL("gsscredential", null);
private final String name;
private final String defaultValue;
private SQLServerDriverObjectProperty(String name, String defaultValue) {
this.name = name;
this.defaultValue = defaultValue;
}
/**
* Returns string due to structure of DRIVER_PROPERTIES_PROPERTY_ONLY.
*
* @return
*/
public String getDefaultValue() {
return defaultValue;
}
@Override
public String toString() {
return name;
}
}
enum SQLServerDriverStringProperty {
APPLICATION_INTENT("applicationIntent", ApplicationIntent.READ_WRITE.toString()),
APPLICATION_NAME("applicationName", SQLServerDriver.DEFAULT_APP_NAME),
DATABASE_NAME("databaseName", ""),
FAILOVER_PARTNER("failoverPartner", ""),
HOSTNAME_IN_CERTIFICATE("hostNameInCertificate", ""),
INSTANCE_NAME("instanceName", ""),
JAAS_CONFIG_NAME("jaasConfigurationName", "SQLJDBCDriver"),
PASSWORD("password", ""),
RESPONSE_BUFFERING("responseBuffering", "adaptive"),
SELECT_METHOD("selectMethod", "direct"),
DOMAIN("domain", ""),
SERVER_NAME("serverName", ""),
SERVER_SPN("serverSpn", ""),
REALM("realm", ""),
SOCKET_FACTORY_CLASS("socketFactoryClass", ""),
SOCKET_FACTORY_CONSTRUCTOR_ARG("socketFactoryConstructorArg", ""),
TRUST_STORE_TYPE("trustStoreType", "JKS"),
TRUST_STORE("trustStore", ""),
TRUST_STORE_PASSWORD("trustStorePassword", ""),
TRUST_MANAGER_CLASS("trustManagerClass", ""),
TRUST_MANAGER_CONSTRUCTOR_ARG("trustManagerConstructorArg", ""),
USER("user", ""),
WORKSTATION_ID("workstationID", Util.WSIDNotAvailable),
AUTHENTICATION_SCHEME("authenticationScheme", AuthenticationScheme.nativeAuthentication.toString()),
AUTHENTICATION("authentication", SqlAuthentication.NotSpecified.toString()),
ACCESS_TOKEN("accessToken", ""),
COLUMN_ENCRYPTION("columnEncryptionSetting", ColumnEncryptionSetting.Disabled.toString()),
ENCLAVE_ATTESTATION_URL("enclaveAttestationUrl", ""),
ENCLAVE_ATTESTATION_PROTOCOL("enclaveAttestationProtocol", ""),
KEY_STORE_AUTHENTICATION("keyStoreAuthentication", ""),
KEY_STORE_SECRET("keyStoreSecret", ""),
KEY_STORE_LOCATION("keyStoreLocation", ""),
SSL_PROTOCOL("sslProtocol", SSLProtocol.TLS.toString()),
MSI_CLIENT_ID("msiClientId", ""),
KEY_VAULT_PROVIDER_CLIENT_ID("keyVaultProviderClientId", ""),
KEY_VAULT_PROVIDER_CLIENT_KEY("keyVaultProviderClientKey", ""),
KEY_STORE_PRINCIPAL_ID("keyStorePrincipalId", ""),
CLIENT_CERTIFICATE("clientCertificate", ""),
CLIENT_KEY("clientKey", ""),
CLIENT_KEY_PASSWORD("clientKeyPassword", ""),
AAD_SECURE_PRINCIPAL_ID("AADSecurePrincipalId", ""),
AAD_SECURE_PRINCIPAL_SECRET("AADSecurePrincipalSecret", ""),
MAX_RESULT_BUFFER("maxResultBuffer", "-1");
private final String name;
private final String defaultValue;
private SQLServerDriverStringProperty(String name, String defaultValue) {
this.name = name;
this.defaultValue = defaultValue;
}
String getDefaultValue() {
return defaultValue;
}
@Override
public String toString() {
return name;
}
}
enum SQLServerDriverIntProperty {
PACKET_SIZE("packetSize", TDS.DEFAULT_PACKET_SIZE),
LOCK_TIMEOUT("lockTimeout", -1),
LOGIN_TIMEOUT("loginTimeout", 15, 0, 65535),
QUERY_TIMEOUT("queryTimeout", -1),
PORT_NUMBER("portNumber", 1433),
SOCKET_TIMEOUT("socketTimeout", 0),
SERVER_PREPARED_STATEMENT_DISCARD_THRESHOLD("serverPreparedStatementDiscardThreshold", SQLServerConnection.DEFAULT_SERVER_PREPARED_STATEMENT_DISCARD_THRESHOLD),
STATEMENT_POOLING_CACHE_SIZE("statementPoolingCacheSize", SQLServerConnection.DEFAULT_STATEMENT_POOLING_CACHE_SIZE),
CANCEL_QUERY_TIMEOUT("cancelQueryTimeout", -1),
CONNECT_RETRY_COUNT("connectRetryCount", 1, 0, 255),
CONNECT_RETRY_INTERVAL("connectRetryInterval", 10, 1, 60);
private final String name;
private final int defaultValue;
private int minValue = -1; // not assigned
private int maxValue = -1; // not assigned
private SQLServerDriverIntProperty(String name, int defaultValue) {
this.name = name;
this.defaultValue = defaultValue;
}
private SQLServerDriverIntProperty(String name, int defaultValue, int minValue, int maxValue) {
this.name = name;
this.defaultValue = defaultValue;
this.minValue = minValue;
this.maxValue = maxValue;
}
int getDefaultValue() {
return defaultValue;
}
boolean isValidValue(int value) {
return (minValue == -1 && maxValue == -1) || (value >= minValue && value <= maxValue);
}
@Override
public String toString() {
return name;
}
}
enum SQLServerDriverBooleanProperty {
DISABLE_STATEMENT_POOLING("disableStatementPooling", true),
ENCRYPT("encrypt", false),
INTEGRATED_SECURITY("integratedSecurity", false),
LAST_UPDATE_COUNT("lastUpdateCount", true),
MULTI_SUBNET_FAILOVER("multiSubnetFailover", false),
REPLICATION("replication", false),
SERVER_NAME_AS_ACE("serverNameAsACE", false),
SEND_STRING_PARAMETERS_AS_UNICODE("sendStringParametersAsUnicode", true),
SEND_TIME_AS_DATETIME("sendTimeAsDatetime", true),
TRANSPARENT_NETWORK_IP_RESOLUTION("TransparentNetworkIPResolution", true),
TRUST_SERVER_CERTIFICATE("trustServerCertificate", false),
XOPEN_STATES("xopenStates", false),
FIPS("fips", false),
ENABLE_PREPARE_ON_FIRST_PREPARED_STATEMENT("enablePrepareOnFirstPreparedStatementCall", SQLServerConnection.DEFAULT_ENABLE_PREPARE_ON_FIRST_PREPARED_STATEMENT_CALL),
USE_BULK_COPY_FOR_BATCH_INSERT("useBulkCopyForBatchInsert", false),
USE_FMT_ONLY("useFmtOnly", false),
SEND_TEMPORAL_DATATYPES_AS_STRING_FOR_BULK_COPY("sendTemporalDataTypesAsStringForBulkCopy", true),
DELAY_LOADING_LOBS("delayLoadingLobs", true);
private final String name;
private final boolean defaultValue;
private SQLServerDriverBooleanProperty(String name, boolean defaultValue) {
this.name = name;
this.defaultValue = defaultValue;
}
boolean getDefaultValue() {
return defaultValue;
}
@Override
public String toString() {
return name;
}
}
/**
* Provides methods to connect to a SQL Server database and to obtain information about the JDBC driver.
*/
public final class SQLServerDriver implements java.sql.Driver {
static final String PRODUCT_NAME = "Microsoft JDBC Driver " + SQLJdbcVersion.major + "." + SQLJdbcVersion.minor
+ " for SQL Server";
static final String AUTH_DLL_NAME = "mssql-jdbc_auth-" + SQLJdbcVersion.major + "." + SQLJdbcVersion.minor + "."
+ SQLJdbcVersion.patch + "." + Util.getJVMArchOnWindows() + SQLJdbcVersion.releaseExt;
static final String DEFAULT_APP_NAME = "Microsoft JDBC Driver for SQL Server";
private static final String[] TRUE_FALSE = {"true", "false"};
private static final SQLServerDriverPropertyInfo[] DRIVER_PROPERTIES = {
// default required available choices
// property name value property (if appropriate)
new SQLServerDriverPropertyInfo(SQLServerDriverStringProperty.APPLICATION_INTENT.toString(),
SQLServerDriverStringProperty.APPLICATION_INTENT.getDefaultValue(), false,
new String[] {ApplicationIntent.READ_ONLY.toString(), ApplicationIntent.READ_WRITE.toString()}),
new SQLServerDriverPropertyInfo(SQLServerDriverStringProperty.APPLICATION_NAME.toString(),
SQLServerDriverStringProperty.APPLICATION_NAME.getDefaultValue(), false, null),
new SQLServerDriverPropertyInfo(SQLServerDriverStringProperty.COLUMN_ENCRYPTION.toString(),
SQLServerDriverStringProperty.COLUMN_ENCRYPTION.getDefaultValue(), false,
new String[] {ColumnEncryptionSetting.Disabled.toString(),
ColumnEncryptionSetting.Enabled.toString()}),
new SQLServerDriverPropertyInfo(SQLServerDriverStringProperty.ENCLAVE_ATTESTATION_URL.toString(),
SQLServerDriverStringProperty.ENCLAVE_ATTESTATION_URL.getDefaultValue(), false, null),
new SQLServerDriverPropertyInfo(SQLServerDriverStringProperty.ENCLAVE_ATTESTATION_PROTOCOL.toString(),
SQLServerDriverStringProperty.ENCLAVE_ATTESTATION_PROTOCOL.getDefaultValue(), false, null),
new SQLServerDriverPropertyInfo(SQLServerDriverStringProperty.DATABASE_NAME.toString(),
SQLServerDriverStringProperty.DATABASE_NAME.getDefaultValue(), false, null),
new SQLServerDriverPropertyInfo(SQLServerDriverBooleanProperty.DISABLE_STATEMENT_POOLING.toString(),
Boolean.toString(SQLServerDriverBooleanProperty.DISABLE_STATEMENT_POOLING.getDefaultValue()), false,
new String[] {"true"}),
new SQLServerDriverPropertyInfo(SQLServerDriverBooleanProperty.ENCRYPT.toString(),
Boolean.toString(SQLServerDriverBooleanProperty.ENCRYPT.getDefaultValue()), false, TRUE_FALSE),
new SQLServerDriverPropertyInfo(SQLServerDriverStringProperty.FAILOVER_PARTNER.toString(),
SQLServerDriverStringProperty.FAILOVER_PARTNER.getDefaultValue(), false, null),
new SQLServerDriverPropertyInfo(SQLServerDriverStringProperty.HOSTNAME_IN_CERTIFICATE.toString(),
SQLServerDriverStringProperty.HOSTNAME_IN_CERTIFICATE.getDefaultValue(), false, null),
new SQLServerDriverPropertyInfo(SQLServerDriverStringProperty.INSTANCE_NAME.toString(),
SQLServerDriverStringProperty.INSTANCE_NAME.getDefaultValue(), false, null),
new SQLServerDriverPropertyInfo(SQLServerDriverBooleanProperty.INTEGRATED_SECURITY.toString(),
Boolean.toString(SQLServerDriverBooleanProperty.INTEGRATED_SECURITY.getDefaultValue()), false,
TRUE_FALSE),
new SQLServerDriverPropertyInfo(SQLServerDriverStringProperty.KEY_STORE_AUTHENTICATION.toString(),
SQLServerDriverStringProperty.KEY_STORE_AUTHENTICATION.getDefaultValue(), false,
new String[] {KeyStoreAuthentication.JavaKeyStorePassword.toString()}),
new SQLServerDriverPropertyInfo(SQLServerDriverStringProperty.KEY_STORE_SECRET.toString(),
SQLServerDriverStringProperty.KEY_STORE_SECRET.getDefaultValue(), false, null),
new SQLServerDriverPropertyInfo(SQLServerDriverStringProperty.KEY_STORE_LOCATION.toString(),
SQLServerDriverStringProperty.KEY_STORE_LOCATION.getDefaultValue(), false, null),
new SQLServerDriverPropertyInfo(SQLServerDriverBooleanProperty.LAST_UPDATE_COUNT.toString(),
Boolean.toString(SQLServerDriverBooleanProperty.LAST_UPDATE_COUNT.getDefaultValue()), false,
TRUE_FALSE),
new SQLServerDriverPropertyInfo(SQLServerDriverIntProperty.LOCK_TIMEOUT.toString(),
Integer.toString(SQLServerDriverIntProperty.LOCK_TIMEOUT.getDefaultValue()), false, null),
new SQLServerDriverPropertyInfo(SQLServerDriverIntProperty.LOGIN_TIMEOUT.toString(),
Integer.toString(SQLServerDriverIntProperty.LOGIN_TIMEOUT.getDefaultValue()), false, null),
new SQLServerDriverPropertyInfo(SQLServerDriverBooleanProperty.MULTI_SUBNET_FAILOVER.toString(),
Boolean.toString(SQLServerDriverBooleanProperty.MULTI_SUBNET_FAILOVER.getDefaultValue()), false,
TRUE_FALSE),
new SQLServerDriverPropertyInfo(SQLServerDriverIntProperty.PACKET_SIZE.toString(),
Integer.toString(SQLServerDriverIntProperty.PACKET_SIZE.getDefaultValue()), false, null),
new SQLServerDriverPropertyInfo(SQLServerDriverStringProperty.PASSWORD.toString(),
SQLServerDriverStringProperty.PASSWORD.getDefaultValue(), true, null),
new SQLServerDriverPropertyInfo(SQLServerDriverIntProperty.PORT_NUMBER.toString(),
Integer.toString(SQLServerDriverIntProperty.PORT_NUMBER.getDefaultValue()), false, null),
new SQLServerDriverPropertyInfo(SQLServerDriverIntProperty.QUERY_TIMEOUT.toString(),
Integer.toString(SQLServerDriverIntProperty.QUERY_TIMEOUT.getDefaultValue()), false, null),
new SQLServerDriverPropertyInfo(SQLServerDriverStringProperty.RESPONSE_BUFFERING.toString(),
SQLServerDriverStringProperty.RESPONSE_BUFFERING.getDefaultValue(), false,
new String[] {"adaptive", "full"}),
new SQLServerDriverPropertyInfo(SQLServerDriverStringProperty.SELECT_METHOD.toString(),
SQLServerDriverStringProperty.SELECT_METHOD.getDefaultValue(), false,
new String[] {"direct", "cursor"}),
new SQLServerDriverPropertyInfo(SQLServerDriverBooleanProperty.SEND_STRING_PARAMETERS_AS_UNICODE.toString(),
Boolean.toString(
SQLServerDriverBooleanProperty.SEND_STRING_PARAMETERS_AS_UNICODE.getDefaultValue()),
false, TRUE_FALSE),
new SQLServerDriverPropertyInfo(SQLServerDriverBooleanProperty.SERVER_NAME_AS_ACE.toString(),
Boolean.toString(SQLServerDriverBooleanProperty.SERVER_NAME_AS_ACE.getDefaultValue()), false,
TRUE_FALSE),
new SQLServerDriverPropertyInfo(SQLServerDriverStringProperty.DOMAIN.toString(),
SQLServerDriverStringProperty.DOMAIN.getDefaultValue(), false, null),
new SQLServerDriverPropertyInfo(SQLServerDriverStringProperty.SERVER_NAME.toString(),
SQLServerDriverStringProperty.SERVER_NAME.getDefaultValue(), false, null),
new SQLServerDriverPropertyInfo(SQLServerDriverStringProperty.SERVER_SPN.toString(),
SQLServerDriverStringProperty.SERVER_SPN.getDefaultValue(), false, null),
new SQLServerDriverPropertyInfo(SQLServerDriverStringProperty.REALM.toString(),
SQLServerDriverStringProperty.REALM.getDefaultValue(), false, null),
new SQLServerDriverPropertyInfo(SQLServerDriverStringProperty.SOCKET_FACTORY_CLASS.toString(),
SQLServerDriverStringProperty.SOCKET_FACTORY_CLASS.getDefaultValue(), false, null),
new SQLServerDriverPropertyInfo(SQLServerDriverStringProperty.SOCKET_FACTORY_CONSTRUCTOR_ARG.toString(),
SQLServerDriverStringProperty.SOCKET_FACTORY_CONSTRUCTOR_ARG.getDefaultValue(), false, null),
new SQLServerDriverPropertyInfo(SQLServerDriverBooleanProperty.TRANSPARENT_NETWORK_IP_RESOLUTION.toString(),
Boolean.toString(
SQLServerDriverBooleanProperty.TRANSPARENT_NETWORK_IP_RESOLUTION.getDefaultValue()),
false, TRUE_FALSE),
new SQLServerDriverPropertyInfo(SQLServerDriverBooleanProperty.TRUST_SERVER_CERTIFICATE.toString(),
Boolean.toString(SQLServerDriverBooleanProperty.TRUST_SERVER_CERTIFICATE.getDefaultValue()), false,
TRUE_FALSE),
new SQLServerDriverPropertyInfo(SQLServerDriverStringProperty.TRUST_STORE_TYPE.toString(),
SQLServerDriverStringProperty.TRUST_STORE_TYPE.getDefaultValue(), false, null),
new SQLServerDriverPropertyInfo(SQLServerDriverStringProperty.TRUST_STORE.toString(),
SQLServerDriverStringProperty.TRUST_STORE.getDefaultValue(), false, null),
new SQLServerDriverPropertyInfo(SQLServerDriverStringProperty.TRUST_STORE_PASSWORD.toString(),
SQLServerDriverStringProperty.TRUST_STORE_PASSWORD.getDefaultValue(), false, null),
new SQLServerDriverPropertyInfo(SQLServerDriverStringProperty.TRUST_MANAGER_CLASS.toString(),
SQLServerDriverStringProperty.TRUST_MANAGER_CLASS.getDefaultValue(), false, null),
new SQLServerDriverPropertyInfo(SQLServerDriverStringProperty.TRUST_MANAGER_CONSTRUCTOR_ARG.toString(),
SQLServerDriverStringProperty.TRUST_MANAGER_CONSTRUCTOR_ARG.getDefaultValue(), false, null),
new SQLServerDriverPropertyInfo(SQLServerDriverBooleanProperty.REPLICATION.toString(),
Boolean.toString(SQLServerDriverBooleanProperty.REPLICATION.getDefaultValue()), false,
TRUE_FALSE),
new SQLServerDriverPropertyInfo(SQLServerDriverBooleanProperty.SEND_TIME_AS_DATETIME.toString(),
Boolean.toString(SQLServerDriverBooleanProperty.SEND_TIME_AS_DATETIME.getDefaultValue()), false,
TRUE_FALSE),
new SQLServerDriverPropertyInfo(SQLServerDriverStringProperty.USER.toString(),
SQLServerDriverStringProperty.USER.getDefaultValue(), true, null),
new SQLServerDriverPropertyInfo(SQLServerDriverStringProperty.WORKSTATION_ID.toString(),
SQLServerDriverStringProperty.WORKSTATION_ID.getDefaultValue(), false, null),
new SQLServerDriverPropertyInfo(SQLServerDriverBooleanProperty.XOPEN_STATES.toString(),
Boolean.toString(SQLServerDriverBooleanProperty.XOPEN_STATES.getDefaultValue()), false, TRUE_FALSE),
new SQLServerDriverPropertyInfo(SQLServerDriverStringProperty.AUTHENTICATION_SCHEME.toString(),
SQLServerDriverStringProperty.AUTHENTICATION_SCHEME.getDefaultValue(), false,
new String[] {AuthenticationScheme.javaKerberos.toString(),
AuthenticationScheme.nativeAuthentication.toString(),
AuthenticationScheme.ntlm.toString()}),
new SQLServerDriverPropertyInfo(SQLServerDriverStringProperty.AUTHENTICATION.toString(),
SQLServerDriverStringProperty.AUTHENTICATION.getDefaultValue(), false,
new String[] {SqlAuthentication.NotSpecified.toString(), SqlAuthentication.SqlPassword.toString(),
SqlAuthentication.ActiveDirectoryPassword.toString(),
SqlAuthentication.ActiveDirectoryIntegrated.toString(),
SqlAuthentication.ActiveDirectoryMSI.toString(),
SqlAuthentication.ActiveDirectoryServicePrincipal.toString(),
SqlAuthentication.ActiveDirectoryInteractive.toString()}),
new SQLServerDriverPropertyInfo(SQLServerDriverIntProperty.SOCKET_TIMEOUT.toString(),
Integer.toString(SQLServerDriverIntProperty.SOCKET_TIMEOUT.getDefaultValue()), false, null),
new SQLServerDriverPropertyInfo(SQLServerDriverBooleanProperty.FIPS.toString(),
Boolean.toString(SQLServerDriverBooleanProperty.FIPS.getDefaultValue()), false, TRUE_FALSE),
new SQLServerDriverPropertyInfo(
SQLServerDriverBooleanProperty.ENABLE_PREPARE_ON_FIRST_PREPARED_STATEMENT.toString(),
Boolean.toString(SQLServerDriverBooleanProperty.ENABLE_PREPARE_ON_FIRST_PREPARED_STATEMENT
.getDefaultValue()),
false, TRUE_FALSE),
new SQLServerDriverPropertyInfo(
SQLServerDriverIntProperty.SERVER_PREPARED_STATEMENT_DISCARD_THRESHOLD.toString(),
Integer.toString(
SQLServerDriverIntProperty.SERVER_PREPARED_STATEMENT_DISCARD_THRESHOLD.getDefaultValue()),
false, null),
new SQLServerDriverPropertyInfo(SQLServerDriverIntProperty.STATEMENT_POOLING_CACHE_SIZE.toString(),
Integer.toString(SQLServerDriverIntProperty.STATEMENT_POOLING_CACHE_SIZE.getDefaultValue()), false,
null),
new SQLServerDriverPropertyInfo(SQLServerDriverStringProperty.JAAS_CONFIG_NAME.toString(),
SQLServerDriverStringProperty.JAAS_CONFIG_NAME.getDefaultValue(), false, null),
new SQLServerDriverPropertyInfo(SQLServerDriverStringProperty.SSL_PROTOCOL.toString(),
SQLServerDriverStringProperty.SSL_PROTOCOL.getDefaultValue(), false,
new String[] {SSLProtocol.TLS.toString(), SSLProtocol.TLS_V10.toString(),
SSLProtocol.TLS_V11.toString(), SSLProtocol.TLS_V12.toString()}),
new SQLServerDriverPropertyInfo(SQLServerDriverIntProperty.CANCEL_QUERY_TIMEOUT.toString(),
Integer.toString(SQLServerDriverIntProperty.CANCEL_QUERY_TIMEOUT.getDefaultValue()), false, null),
new SQLServerDriverPropertyInfo(SQLServerDriverBooleanProperty.USE_BULK_COPY_FOR_BATCH_INSERT.toString(),
Boolean.toString(SQLServerDriverBooleanProperty.USE_BULK_COPY_FOR_BATCH_INSERT.getDefaultValue()),
false, TRUE_FALSE),
new SQLServerDriverPropertyInfo(SQLServerDriverStringProperty.MSI_CLIENT_ID.toString(),
SQLServerDriverStringProperty.MSI_CLIENT_ID.getDefaultValue(), false, null),
new SQLServerDriverPropertyInfo(SQLServerDriverStringProperty.KEY_VAULT_PROVIDER_CLIENT_ID.toString(),
SQLServerDriverStringProperty.KEY_VAULT_PROVIDER_CLIENT_ID.getDefaultValue(), false, null),
new SQLServerDriverPropertyInfo(SQLServerDriverStringProperty.KEY_VAULT_PROVIDER_CLIENT_KEY.toString(),
SQLServerDriverStringProperty.KEY_VAULT_PROVIDER_CLIENT_KEY.getDefaultValue(), false, null),
new SQLServerDriverPropertyInfo(SQLServerDriverBooleanProperty.USE_FMT_ONLY.toString(),
Boolean.toString(SQLServerDriverBooleanProperty.USE_FMT_ONLY.getDefaultValue()), false, TRUE_FALSE),
new SQLServerDriverPropertyInfo(SQLServerDriverStringProperty.KEY_STORE_PRINCIPAL_ID.toString(),
SQLServerDriverStringProperty.KEY_STORE_PRINCIPAL_ID.getDefaultValue(), false, null),
new SQLServerDriverPropertyInfo(SQLServerDriverStringProperty.CLIENT_CERTIFICATE.toString(),
SQLServerDriverStringProperty.CLIENT_CERTIFICATE.getDefaultValue(), false, null),
new SQLServerDriverPropertyInfo(SQLServerDriverStringProperty.CLIENT_KEY.toString(),
SQLServerDriverStringProperty.CLIENT_KEY.getDefaultValue(), false, null),
new SQLServerDriverPropertyInfo(SQLServerDriverStringProperty.CLIENT_KEY_PASSWORD.toString(),
SQLServerDriverStringProperty.CLIENT_KEY_PASSWORD.getDefaultValue(), false, null),
new SQLServerDriverPropertyInfo(SQLServerDriverBooleanProperty.DELAY_LOADING_LOBS.toString(),
Boolean.toString(SQLServerDriverBooleanProperty.DELAY_LOADING_LOBS.getDefaultValue()), false,
TRUE_FALSE),
new SQLServerDriverPropertyInfo(
SQLServerDriverBooleanProperty.SEND_TEMPORAL_DATATYPES_AS_STRING_FOR_BULK_COPY.toString(),
Boolean.toString(SQLServerDriverBooleanProperty.SEND_TEMPORAL_DATATYPES_AS_STRING_FOR_BULK_COPY
.getDefaultValue()),
false, TRUE_FALSE),
new SQLServerDriverPropertyInfo(SQLServerDriverStringProperty.AAD_SECURE_PRINCIPAL_ID.toString(),
SQLServerDriverStringProperty.AAD_SECURE_PRINCIPAL_ID.getDefaultValue(), false, null),
new SQLServerDriverPropertyInfo(SQLServerDriverStringProperty.AAD_SECURE_PRINCIPAL_SECRET.toString(),
SQLServerDriverStringProperty.AAD_SECURE_PRINCIPAL_SECRET.getDefaultValue(), false, null),
new SQLServerDriverPropertyInfo(SQLServerDriverStringProperty.MAX_RESULT_BUFFER.toString(),
SQLServerDriverStringProperty.MAX_RESULT_BUFFER.getDefaultValue(), false, null),
new SQLServerDriverPropertyInfo(SQLServerDriverIntProperty.CONNECT_RETRY_COUNT.toString(),
Integer.toString(SQLServerDriverIntProperty.CONNECT_RETRY_COUNT.getDefaultValue()), false, null),
new SQLServerDriverPropertyInfo(SQLServerDriverIntProperty.CONNECT_RETRY_INTERVAL.toString(),
Integer.toString(SQLServerDriverIntProperty.CONNECT_RETRY_INTERVAL.getDefaultValue()), false,
null),};
/**
* Properties that can only be set by using Properties. Cannot set in connection string
*/
private static final SQLServerDriverPropertyInfo[] DRIVER_PROPERTIES_PROPERTY_ONLY = {
// default required available choices
// property name value property (if appropriate)
new SQLServerDriverPropertyInfo(SQLServerDriverStringProperty.ACCESS_TOKEN.toString(),
SQLServerDriverStringProperty.ACCESS_TOKEN.getDefaultValue(), false, null),
new SQLServerDriverPropertyInfo(SQLServerDriverObjectProperty.GSS_CREDENTIAL.toString(),
SQLServerDriverObjectProperty.GSS_CREDENTIAL.getDefaultValue(), false, null),};
private static final String driverPropertiesSynonyms[][] = {
{"database", SQLServerDriverStringProperty.DATABASE_NAME.toString()},
{"userName", SQLServerDriverStringProperty.USER.toString()},
{"server", SQLServerDriverStringProperty.SERVER_NAME.toString()},
{"domainName", SQLServerDriverStringProperty.DOMAIN.toString()},
{"port", SQLServerDriverIntProperty.PORT_NUMBER.toString()}};
static private final AtomicInteger baseID = new AtomicInteger(0); // Unique id generator for each instance (used for
// logging).
final private int instanceID; // Unique id for this instance.
final private String traceID;
// Returns unique id for each instance.
private static int nextInstanceID() {
return baseID.incrementAndGet();
}
@Override
final public String toString() {
return traceID;
}
static final private java.util.logging.Logger loggerExternal = java.util.logging.Logger
.getLogger("com.microsoft.sqlserver.jdbc.Driver");
static final private java.util.logging.Logger parentLogger = java.util.logging.Logger
.getLogger("com.microsoft.sqlserver.jdbc");
final private String loggingClassName;
String getClassNameLogging() {
return loggingClassName;
}
private final static java.util.logging.Logger drLogger = java.util.logging.Logger
.getLogger("com.microsoft.sqlserver.jdbc.internals.SQLServerDriver");
private static java.sql.Driver mssqlDriver = null;
// Register with the DriverManager
static {
try {
register();
} catch (SQLException e) {
if (drLogger.isLoggable(Level.FINER) && Util.isActivityTraceOn()) {
drLogger.finer("Error registering driver: " + e);
}
}
}
/**
* Registers the driver with DriverManager. No-op if driver is already registered.
*
* @throws SQLException
* if error
*/
public static void register() throws SQLException {
if (!isRegistered()) {
mssqlDriver = new SQLServerDriver();
DriverManager.registerDriver(mssqlDriver);
}
}
/**
* De-registers the driver with the DriverManager. No-op if the driver is not registered.
*
* @throws SQLException
* if error
*/
public static void deregister() throws SQLException {
if (isRegistered()) {
DriverManager.deregisterDriver(mssqlDriver);
mssqlDriver = null;
}
}
/**
* Checks whether the driver has been registered with the driver manager.
*
* @return if the driver has been registered with the driver manager
*/
public static boolean isRegistered() {
return mssqlDriver != null;
}
/**
* Creates a SQLServerDriver object
*/
public SQLServerDriver() {
instanceID = nextInstanceID();
traceID = "SQLServerDriver:" + instanceID;
loggingClassName = "com.microsoft.sqlserver.jdbc." + "SQLServerDriver:" + instanceID;
}
/**
* Provides Helper function used to fix the case sensitivity, synonyms and remove unknown tokens from the
* properties.
*/
static Properties fixupProperties(Properties props) throws SQLServerException {
// assert props !=null
Properties fixedup = new Properties();
Enumeration<?> e = props.keys();
while (e.hasMoreElements()) {
String name = (String) e.nextElement();
String newname = getNormalizedPropertyName(name, drLogger);
if (null == newname) {
newname = getPropertyOnlyName(name, drLogger);
}
if (null != newname) {
String val = props.getProperty(name);
if (null != val) {
// replace with the driver approved name
fixedup.setProperty(newname, val);
} else if ("gsscredential".equalsIgnoreCase(newname) && (props.get(name) instanceof GSSCredential)) {
fixedup.put(newname, props.get(name));
} else {
MessageFormat form = new MessageFormat(SQLServerException.getErrString("R_invalidpropertyValue"));
Object[] msgArgs = {name};
throw new SQLServerException(null, form.format(msgArgs), null, 0, false);
}
}
}
return fixedup;
}
/**
* Provides Helper function used to merge together the property set extracted from the url and the user supplied
* property set passed in by the caller. This function is used by both SQLServerDriver.connect and
* SQLServerDataSource.getConnectionInternal to centralize this property merging code.
*/
static Properties mergeURLAndSuppliedProperties(Properties urlProps,
Properties suppliedProperties) throws SQLServerException {
if (null == suppliedProperties)
return urlProps;
if (suppliedProperties.isEmpty())
return urlProps;
Properties suppliedPropertiesFixed = fixupProperties(suppliedProperties);
// Merge URL properties and supplied properties.
for (SQLServerDriverPropertyInfo DRIVER_PROPERTY : DRIVER_PROPERTIES) {
String sProp = DRIVER_PROPERTY.getName();
String sPropVal = suppliedPropertiesFixed.getProperty(sProp); // supplied properties have precedence
if (null != sPropVal) {
// overwrite the property in urlprops if already exists. supp prop has more precedence
urlProps.put(sProp, sPropVal);
}
}
// Merge URL properties with property-only properties
for (SQLServerDriverPropertyInfo aDRIVER_PROPERTIES_PROPERTY_ONLY : DRIVER_PROPERTIES_PROPERTY_ONLY) {
String sProp = aDRIVER_PROPERTIES_PROPERTY_ONLY.getName();
Object oPropVal = suppliedPropertiesFixed.get(sProp); // supplied properties have precedence
if (null != oPropVal) {
// overwrite the property in urlprops if already exists. supp prop has more precedence
urlProps.put(sProp, oPropVal);
}
}
return urlProps;
}
/**
* Returns the normalized the property names.
*
* @param name
* name to normalize
* @param logger
* @return the normalized property name
*/
static String getNormalizedPropertyName(String name, Logger logger) {
if (null == name)
return name;
for (String[] driverPropertiesSynonym : driverPropertiesSynonyms) {
if (driverPropertiesSynonym[0].equalsIgnoreCase(name)) {
return driverPropertiesSynonym[1];
}
}
for (SQLServerDriverPropertyInfo DRIVER_PROPERTY : DRIVER_PROPERTIES) {
if (DRIVER_PROPERTY.getName().equalsIgnoreCase(name)) {
return DRIVER_PROPERTY.getName();
}
}
if (logger.isLoggable(Level.FINER))
logger.finer("Unknown property" + name);
return null;
}
/**
* Returns the property-only names that do not work with connection string.
*
* @param name
* to normalize
* @param logger
* @return the normalized property name
*/
static String getPropertyOnlyName(String name, Logger logger) {
if (null == name)
return name;
for (SQLServerDriverPropertyInfo aDRIVER_PROPERTIES_PROPERTY_ONLY : DRIVER_PROPERTIES_PROPERTY_ONLY) {
if (aDRIVER_PROPERTIES_PROPERTY_ONLY.getName().equalsIgnoreCase(name)) {
return aDRIVER_PROPERTIES_PROPERTY_ONLY.getName();
}
}
if (logger.isLoggable(Level.FINER))
logger.finer("Unknown property" + name);
return null;
}
@Override
public java.sql.Connection connect(String Url, Properties suppliedProperties) throws SQLServerException {
loggerExternal.entering(getClassNameLogging(), "connect", "Arguments not traced.");
SQLServerConnection result = null;
// Merge connectProperties (from URL) and supplied properties from user.
Properties connectProperties = parseAndMergeProperties(Url, suppliedProperties);
if (connectProperties != null) {
result = DriverJDBCVersion.getSQLServerConnection(toString());
result.connect(connectProperties, null);
}
loggerExternal.exiting(getClassNameLogging(), "connect", result);
return result;
}
private Properties parseAndMergeProperties(String Url, Properties suppliedProperties) throws SQLServerException {
if (Url == null) {
throw new SQLServerException(null, SQLServerException.getErrString("R_nullConnection"), null, 0, false);
}
// Pull the URL properties into the connection properties
Properties connectProperties = Util.parseUrl(Url, drLogger);
if (null == connectProperties)
return null; // If we are the wrong driver dont throw an exception
String loginTimeoutProp = connectProperties.getProperty(SQLServerDriverIntProperty.LOGIN_TIMEOUT.toString());
int dmLoginTimeout = DriverManager.getLoginTimeout();
// Use Driver Manager's login timeout if it exceeds 0 and loginTimeout connection property is not provided.
if (dmLoginTimeout > 0 && null == loginTimeoutProp) {
connectProperties.setProperty(SQLServerDriverIntProperty.LOGIN_TIMEOUT.toString(),
String.valueOf(dmLoginTimeout));
}
// Merge connectProperties (from URL) and supplied properties from user.
connectProperties = mergeURLAndSuppliedProperties(connectProperties, suppliedProperties);
return connectProperties;
}
@Override
public boolean acceptsURL(String url) throws SQLServerException {
loggerExternal.entering(getClassNameLogging(), "acceptsURL", "Arguments not traced.");
if (null == url) {
throw new SQLServerException(null, SQLServerException.getErrString("R_nullConnection"), null, 0, false);
}
boolean result = false;
try {
result = (Util.parseUrl(url, drLogger) != null);
} catch (SQLServerException e) {
// ignore the exception from the parse URL failure, if we cant parse the URL we do not accept em
result = false;
}
loggerExternal.exiting(getClassNameLogging(), "acceptsURL", result);
return result;
}
@Override
public DriverPropertyInfo[] getPropertyInfo(String Url, Properties Info) throws SQLServerException {
loggerExternal.entering(getClassNameLogging(), "getPropertyInfo", "Arguments not traced.");
Properties connProperties = parseAndMergeProperties(Url, Info);
// This means we are not the right driver throw an exception.
if (null == connProperties)
throw new SQLServerException(null, SQLServerException.getErrString("R_invalidConnection"), null, 0, false);
DriverPropertyInfo[] properties = getPropertyInfoFromProperties(connProperties);
loggerExternal.exiting(getClassNameLogging(), "getPropertyInfo");
return properties;
}
static final DriverPropertyInfo[] getPropertyInfoFromProperties(Properties props) {
DriverPropertyInfo[] properties = new DriverPropertyInfo[DRIVER_PROPERTIES.length];
for (int i = 0; i < DRIVER_PROPERTIES.length; i++)
properties[i] = DRIVER_PROPERTIES[i].build(props);
return properties;
}
@Override
public int getMajorVersion() {
loggerExternal.entering(getClassNameLogging(), "getMajorVersion");
loggerExternal.exiting(getClassNameLogging(), "getMajorVersion", SQLJdbcVersion.major);
return SQLJdbcVersion.major;
}
@Override
public int getMinorVersion() {
loggerExternal.entering(getClassNameLogging(), "getMinorVersion");
loggerExternal.exiting(getClassNameLogging(), "getMinorVersion", SQLJdbcVersion.minor);
return SQLJdbcVersion.minor;
}