Skip to content

Commit 6a970e0

Browse files
committed
reverted unnecessary changes
1 parent e3df6f1 commit 6a970e0

File tree

2 files changed

+80
-54
lines changed

2 files changed

+80
-54
lines changed

src/main/java/com/microsoft/sqlserver/jdbc/FailOverInfo.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ private void setupInfo(SQLServerConnection con) throws SQLServerException {
6464
con.getConnectionLogger().fine(con.toString() + " Failover server :" + failoverPartner);
6565
instanceValue = failoverPartner.substring(px + 1, failoverPartner.length());
6666
failoverPartner = failoverPartner.substring(0, px);
67-
con.ValidateMaxSQLLoginName(SQLServerDriverStringProperty.INSTANCE_NAME.toString(), instanceValue);
67+
con.validateMaxSQLLoginName(SQLServerDriverStringProperty.INSTANCE_NAME.toString(), instanceValue);
6868
failoverInstance = instanceValue;
6969
instancePort = con.getInstancePort(failoverPartner, instanceValue);
7070

src/main/java/com/microsoft/sqlserver/jdbc/SQLServerConnection.java

+79-53
Original file line numberDiff line numberDiff line change
@@ -1138,7 +1138,7 @@ private boolean isBooleanPropertyOn(String propName, String propValue) throws SQ
11381138
* the value of the property.
11391139
* @throws SQLServerException
11401140
*/
1141-
void ValidateMaxSQLLoginName(String propName, String propValue) throws SQLServerException {
1141+
void validateMaxSQLLoginName(String propName, String propValue) throws SQLServerException {
11421142
if (propValue != null && propValue.length() > MAX_SQL_LOGIN_NAME_WCHARS) {
11431143
MessageFormat form = new MessageFormat(SQLServerException.getErrString("R_propertyMaximumExceedsChars"));
11441144
Object[] msgArgs = {propName, Integer.toString(MAX_SQL_LOGIN_NAME_WCHARS)};
@@ -1172,7 +1172,9 @@ Connection connect(Properties propsIn, SQLServerPooledConnection pooledConnectio
11721172
String sPropValue = propsIn.getProperty(SQLServerDriverIntProperty.LOGIN_TIMEOUT.toString());
11731173
if (null != sPropValue && sPropValue.length() > 0) {
11741174
int sPropValueInt = Integer.parseInt(sPropValue);
1175-
loginTimeoutSeconds = 0 != sPropValueInt ? sPropValueInt : loginTimeoutSeconds;
1175+
if (0 != sPropValueInt) { // Use the default timeout in case of a zero value
1176+
loginTimeoutSeconds = sPropValueInt;
1177+
}
11761178
}
11771179
}
11781180

@@ -1289,19 +1291,19 @@ Connection connectInternal(Properties propsIn,
12891291
sPropValue = SQLServerDriverStringProperty.USER.getDefaultValue();
12901292
activeConnectionProperties.setProperty(sPropKey, sPropValue);
12911293
}
1292-
ValidateMaxSQLLoginName(sPropKey, sPropValue);
1294+
validateMaxSQLLoginName(sPropKey, sPropValue);
12931295

12941296
sPropKey = SQLServerDriverStringProperty.PASSWORD.toString();
12951297
sPropValue = activeConnectionProperties.getProperty(sPropKey);
12961298
if (sPropValue == null) {
12971299
sPropValue = SQLServerDriverStringProperty.PASSWORD.getDefaultValue();
12981300
activeConnectionProperties.setProperty(sPropKey, sPropValue);
12991301
}
1300-
ValidateMaxSQLLoginName(sPropKey, sPropValue);
1302+
validateMaxSQLLoginName(sPropKey, sPropValue);
13011303

13021304
sPropKey = SQLServerDriverStringProperty.DATABASE_NAME.toString();
13031305
sPropValue = activeConnectionProperties.getProperty(sPropKey);
1304-
ValidateMaxSQLLoginName(sPropKey, sPropValue);
1306+
validateMaxSQLLoginName(sPropKey, sPropValue);
13051307

13061308
// if the user does not specify a default timeout, default is 15 per spec
13071309
int loginTimeoutSeconds = SQLServerDriverIntProperty.LOGIN_TIMEOUT.getDefaultValue();
@@ -1337,7 +1339,9 @@ Connection connectInternal(Properties propsIn,
13371339
sPropKey = SQLServerDriverStringProperty.SERVER_NAME.toString();
13381340
sPropValue = activeConnectionProperties.getProperty(sPropKey);
13391341

1340-
sPropValue = null == sPropValue ? "localhost" : sPropValue;
1342+
if (sPropValue == null) {
1343+
sPropValue = "localhost";
1344+
}
13411345

13421346
String sPropKeyPort = SQLServerDriverIntProperty.PORT_NUMBER.toString();
13431347
String sPropValuePort = activeConnectionProperties.getProperty(sPropKeyPort);
@@ -1350,7 +1354,7 @@ Connection connectInternal(Properties propsIn,
13501354
// found the instance name with the servername
13511355
if (px >= 0) {
13521356
instanceValue = sPropValue.substring(px + 1, sPropValue.length());
1353-
ValidateMaxSQLLoginName(instanceNameProperty, instanceValue);
1357+
validateMaxSQLLoginName(instanceNameProperty, instanceValue);
13541358
sPropValue = sPropValue.substring(0, px);
13551359
}
13561360
trustedServerNameAE = sPropValue;
@@ -1373,19 +1377,20 @@ Connection connectInternal(Properties propsIn,
13731377
instanceValue = instanceValueFromProp;
13741378

13751379
if (instanceValue != null) {
1376-
ValidateMaxSQLLoginName(instanceNameProperty, instanceValue);
1380+
validateMaxSQLLoginName(instanceNameProperty, instanceValue);
13771381
// only get port if the port is not specified
13781382
activeConnectionProperties.setProperty(instanceNameProperty, instanceValue);
13791383
trustedServerNameAE += "\\" + instanceValue;
13801384
}
13811385

1382-
trustedServerNameAE = null != sPropValuePort ? trustedServerNameAE + ":" + sPropValuePort
1383-
: trustedServerNameAE;
1386+
if (null != sPropValuePort) {
1387+
trustedServerNameAE += ":" + sPropValuePort;
1388+
}
13841389

13851390
sPropKey = SQLServerDriverStringProperty.APPLICATION_NAME.toString();
13861391
sPropValue = activeConnectionProperties.getProperty(sPropKey);
13871392
if (sPropValue != null)
1388-
ValidateMaxSQLLoginName(sPropKey, sPropValue);
1393+
validateMaxSQLLoginName(sPropKey, sPropValue);
13891394
else
13901395
activeConnectionProperties.setProperty(sPropKey, SQLServerDriver.DEFAULT_APP_NAME);
13911396

@@ -1406,16 +1411,21 @@ Connection connectInternal(Properties propsIn,
14061411

14071412
sPropKey = SQLServerDriverStringProperty.KEY_STORE_AUTHENTICATION.toString();
14081413
sPropValue = activeConnectionProperties.getProperty(sPropKey);
1409-
keyStoreAuthentication = null != sPropValue ? KeyStoreAuthentication.valueOfString(sPropValue).toString()
1410-
: keyStoreAuthentication;
1414+
if (null != sPropValue) {
1415+
keyStoreAuthentication = KeyStoreAuthentication.valueOfString(sPropValue).toString();
1416+
}
14111417

14121418
sPropKey = SQLServerDriverStringProperty.KEY_STORE_SECRET.toString();
14131419
sPropValue = activeConnectionProperties.getProperty(sPropKey);
1414-
keyStoreSecret = null != sPropValue ? sPropValue : keyStoreSecret;
1420+
if (null != sPropValue) {
1421+
keyStoreSecret = sPropValue;
1422+
}
14151423

14161424
sPropKey = SQLServerDriverStringProperty.KEY_STORE_LOCATION.toString();
14171425
sPropValue = activeConnectionProperties.getProperty(sPropKey);
1418-
keyStoreLocation = null != sPropValue ? sPropValue : keyStoreLocation;
1426+
if (null != sPropValue) {
1427+
keyStoreLocation = sPropValue;
1428+
}
14191429

14201430
registerKeyStoreProviderOnConnection(keyStoreAuthentication, keyStoreSecret, keyStoreLocation);
14211431

@@ -1464,8 +1474,9 @@ Connection connectInternal(Properties propsIn,
14641474

14651475
sPropKey = SQLServerDriverStringProperty.SELECT_METHOD.toString();
14661476
sPropValue = activeConnectionProperties.getProperty(sPropKey);
1467-
sPropValue = sPropValue == null ? SQLServerDriverStringProperty.SELECT_METHOD.getDefaultValue()
1468-
: sPropValue;
1477+
if (sPropValue == null) {
1478+
sPropValue = SQLServerDriverStringProperty.SELECT_METHOD.getDefaultValue();
1479+
}
14691480

14701481
if ("cursor".equalsIgnoreCase(sPropValue) || "direct".equalsIgnoreCase(sPropValue)) {
14711482
sPropValue = sPropValue.toLowerCase(Locale.ENGLISH);
@@ -1479,8 +1490,9 @@ Connection connectInternal(Properties propsIn,
14791490

14801491
sPropKey = SQLServerDriverStringProperty.RESPONSE_BUFFERING.toString();
14811492
sPropValue = activeConnectionProperties.getProperty(sPropKey);
1482-
sPropValue = sPropValue == null ? SQLServerDriverStringProperty.RESPONSE_BUFFERING.getDefaultValue()
1483-
: sPropValue;
1493+
if (sPropValue == null) {
1494+
sPropValue = SQLServerDriverStringProperty.RESPONSE_BUFFERING.getDefaultValue();
1495+
}
14841496

14851497
if ("full".equalsIgnoreCase(sPropValue) || "adaptive".equalsIgnoreCase(sPropValue)) {
14861498
activeConnectionProperties.setProperty(sPropKey, sPropValue.toLowerCase(Locale.ENGLISH));
@@ -1492,8 +1504,9 @@ Connection connectInternal(Properties propsIn,
14921504

14931505
sPropKey = SQLServerDriverStringProperty.APPLICATION_INTENT.toString();
14941506
sPropValue = activeConnectionProperties.getProperty(sPropKey);
1495-
sPropValue = sPropValue == null ? SQLServerDriverStringProperty.APPLICATION_INTENT.getDefaultValue()
1496-
: sPropValue;
1507+
if (sPropValue == null) {
1508+
sPropValue = SQLServerDriverStringProperty.APPLICATION_INTENT.getDefaultValue();
1509+
}
14971510

14981511
applicationIntent = ApplicationIntent.valueOfString(sPropValue);
14991512
activeConnectionProperties.setProperty(sPropKey, applicationIntent.toString());
@@ -1531,13 +1544,17 @@ Connection connectInternal(Properties propsIn,
15311544

15321545
sPropKey = SQLServerDriverBooleanProperty.INTEGRATED_SECURITY.toString();
15331546
sPropValue = activeConnectionProperties.getProperty(sPropKey);
1534-
integratedSecurity = sPropValue != null ? isBooleanPropertyOn(sPropKey, sPropValue) : integratedSecurity;
1547+
if (sPropValue != null) {
1548+
integratedSecurity = isBooleanPropertyOn(sPropKey, sPropValue);
1549+
}
15351550

15361551
// Ignore authenticationScheme setting if integrated authentication not specified
15371552
if (integratedSecurity) {
15381553
sPropKey = SQLServerDriverStringProperty.AUTHENTICATION_SCHEME.toString();
15391554
sPropValue = activeConnectionProperties.getProperty(sPropKey);
1540-
intAuthScheme = sPropValue != null ? AuthenticationScheme.valueOfString(sPropValue) : intAuthScheme;
1555+
if (sPropValue != null) {
1556+
intAuthScheme = AuthenticationScheme.valueOfString(sPropValue);
1557+
}
15411558
}
15421559

15431560
if (intAuthScheme == AuthenticationScheme.javaKerberos) {
@@ -1550,8 +1567,9 @@ Connection connectInternal(Properties propsIn,
15501567

15511568
sPropKey = SQLServerDriverStringProperty.AUTHENTICATION.toString();
15521569
sPropValue = activeConnectionProperties.getProperty(sPropKey);
1553-
sPropValue = sPropValue == null ? SQLServerDriverStringProperty.AUTHENTICATION.getDefaultValue()
1554-
: sPropValue;
1570+
if (sPropValue == null) {
1571+
sPropValue = SQLServerDriverStringProperty.AUTHENTICATION.getDefaultValue();
1572+
}
15551573
authenticationString = SqlAuthentication.valueOfString(sPropValue).toString().trim();
15561574

15571575
if (integratedSecurity
@@ -1617,7 +1635,9 @@ Connection connectInternal(Properties propsIn,
16171635

16181636
sPropKey = SQLServerDriverStringProperty.ACCESS_TOKEN.toString();
16191637
sPropValue = activeConnectionProperties.getProperty(sPropKey);
1620-
accessTokenInByte = null != sPropValue ? sPropValue.getBytes(UTF_16LE) : accessTokenInByte;
1638+
if (null != sPropValue) {
1639+
accessTokenInByte = sPropValue.getBytes(UTF_16LE);
1640+
}
16211641

16221642
if ((null != accessTokenInByte) && 0 == accessTokenInByte.length) {
16231643
if (connectionlogger.isLoggable(Level.SEVERE)) {
@@ -1665,7 +1685,7 @@ Connection connectInternal(Properties propsIn,
16651685

16661686
sPropKey = SQLServerDriverStringProperty.WORKSTATION_ID.toString();
16671687
sPropValue = activeConnectionProperties.getProperty(sPropKey);
1668-
ValidateMaxSQLLoginName(sPropKey, sPropValue);
1688+
validateMaxSQLLoginName(sPropKey, sPropValue);
16691689

16701690
int nPort = 0;
16711691
sPropKey = SQLServerDriverIntProperty.PORT_NUMBER.toString();
@@ -1849,8 +1869,9 @@ else if (0 == requestedPacketSize)
18491869

18501870
sPropKey = SQLServerDriverBooleanProperty.USE_BULK_COPY_FOR_BATCH_INSERT.toString();
18511871
sPropValue = activeConnectionProperties.getProperty(sPropKey);
1852-
useBulkCopyForBatchInsert = null != sPropValue ? isBooleanPropertyOn(sPropKey, sPropValue)
1853-
: useBulkCopyForBatchInsert;
1872+
if (null != sPropValue) {
1873+
useBulkCopyForBatchInsert = isBooleanPropertyOn(sPropKey, sPropValue);
1874+
}
18541875

18551876
sPropKey = SQLServerDriverStringProperty.SSL_PROTOCOL.toString();
18561877
sPropValue = activeConnectionProperties.getProperty(sPropKey);
@@ -2052,9 +2073,9 @@ private void login(String primary, String primaryInstanceName, int primaryPortNu
20522073
}
20532074

20542075
// Attempt login. Use Place holder to make sure that the failoverdemand is done.
2055-
connectHelper(currentConnectPlaceHolder, TimerRemaining(intervalExpire), timeout, useParallel, useTnir,
2076+
connectHelper(currentConnectPlaceHolder, timerRemaining(intervalExpire), timeout, useParallel, useTnir,
20562077
(0 == attemptNumber), // is this the TNIR first attempt
2057-
TimerRemaining(intervalExpireFullTimeout)); // Only used when host resolves to >64 IPs
2078+
timerRemaining(intervalExpireFullTimeout)); // Only used when host resolves to >64 IPs
20582079

20592080
if (isRoutedInCurrentAttempt) {
20602081
// we ignore the failoverpartner ENVCHANGE if we got routed so no error needs to be thrown
@@ -2156,7 +2177,7 @@ private void login(String primary, String primaryInstanceName, int primaryPortNu
21562177
if (!isDBMirroring || 1 == attemptNumber % 2) {
21572178
// Check sleep interval to make sure we won't exceed the timeout
21582179
// Do this in the catch block so we can re-throw the current exception
2159-
long remainingMilliseconds = TimerRemaining(timerExpire);
2180+
long remainingMilliseconds = timerRemaining(timerExpire);
21602181
if (remainingMilliseconds <= sleepInterval) {
21612182
throw sqlex;
21622183
}
@@ -2202,10 +2223,14 @@ private void login(String primary, String primaryInstanceName, int primaryPortNu
22022223
// Due to the below condition and the timerHasExpired check in catch block,
22032224
// the multiSubnetFailover case or any other standardLogin case where timeOutInterval is full timeout would
22042225
// also be handled correctly.
2205-
intervalExpire = intervalExpire > timerExpire ? timerExpire : intervalExpire;
2226+
if (intervalExpire > timerExpire) {
2227+
intervalExpire = timerExpire;
2228+
}
22062229

22072230
// try again, this time swapping primary/secondary servers
2208-
useFailoverHost = isDBMirroring ? !useFailoverHost : useFailoverHost;
2231+
if (isDBMirroring) {
2232+
useFailoverHost = !useFailoverHost;
2233+
}
22092234
}
22102235

22112236
// If we get here, connection/login succeeded! Just a few more checks & record-keeping
@@ -2324,13 +2349,16 @@ static boolean timerHasExpired(long timerExpire) {
23242349
return System.currentTimeMillis() > timerExpire;
23252350
}
23262351

2327-
static int TimerRemaining(long timerExpire) {
2328-
long result = timerExpire - System.currentTimeMillis();
2329-
// maximum timeout the socket takes is int max.
2330-
result = result > Integer.MAX_VALUE ? Integer.MAX_VALUE : result;
2331-
// we have to make sure that we return at least one ms
2332-
// we want at least one attempt to happen with a positive timeout passed by the user.
2333-
return result <= 0 ? 1 : (int) result;
2352+
/**
2353+
* Get time remaining to timer expiry
2354+
*
2355+
* @param timerExpire
2356+
* @return remaining time to expiry
2357+
*/
2358+
static int timerRemaining(long timerExpire) {
2359+
long remaining = timerExpire - System.currentTimeMillis();
2360+
// maximum timeout the socket takes is int max, minimum is at least 1 ms
2361+
return (int) ((remaining > Integer.MAX_VALUE) ? Integer.MAX_VALUE : (remaining <= 0) ? 1 : remaining);
23342362
}
23352363

23362364
/**
@@ -2366,7 +2394,9 @@ private void connectHelper(ServerPortPlaceHolder serverInfo, int timeOutsliceInM
23662394
// as the InetAddress.getLocalHost() takes more than usual time in certain OS and JVM combination, it avoids
23672395
// connection loss
23682396
hostName = activeConnectionProperties.getProperty(SQLServerDriverStringProperty.WORKSTATION_ID.toString());
2369-
hostName = StringUtils.isEmpty(hostName) ? Util.lookupHostName() : hostName;
2397+
if (StringUtils.isEmpty(hostName)) {
2398+
hostName = Util.lookupHostName();
2399+
}
23702400

23712401
// if the timeout is infinite slices are infinite too.
23722402
tdsChannel = new TDSChannel(this);
@@ -4114,7 +4144,7 @@ private SqlFedAuthToken getFedAuthToken(SqlFedAuthInfo fedAuthInfo) throws SQLSe
41144144
throw new SQLServerException(form.format(msgArgs), null);
41154145
}
41164146

4117-
int millisecondsRemaining = TimerRemaining(timerExpire);
4147+
int millisecondsRemaining = timerRemaining(timerExpire);
41184148
if (ActiveDirectoryAuthentication.GET_ACCESS_TOKEN_TANSISENT_ERROR != errorCategory
41194149
|| timerHasExpired(timerExpire) || (sleepInterval >= millisecondsRemaining)) {
41204150

@@ -4704,7 +4734,9 @@ final boolean complete(LogonCommand logonCommand, TDSReader tdsReader) throws SQ
47044734
: activeConnectionProperties.getProperty(
47054735
SQLServerDriverStringProperty.SERVER_NAME
47064736
.toString());
4707-
serverName = (serverName != null && serverName.length() > 128) ? serverName.substring(0, 128) : serverName;
4737+
if (serverName != null && serverName.length() > 128) {
4738+
serverName = serverName.substring(0, 128);
4739+
}
47084740

47094741
byte[] secBlob = new byte[0];
47104742
boolean[] done = {false};
@@ -4798,16 +4830,10 @@ final boolean complete(LogonCommand logonCommand, TDSReader tdsReader) throws SQ
47984830
{
47994831
colEncSetting = TDS.LOGIN_OPTION3_FEATURE_EXTENSION;
48004832
}
4833+
4834+
// Accept unknown collations from Katmai & later servers
48014835
tdsWriter.writeByte((byte) (TDS.LOGIN_OPTION3_DEFAULT | colEncSetting
4802-
| ((serverMajorVersion >= 10) ? TDS.LOGIN_OPTION3_UNKNOWN_COLLATION_HANDLING : 0) // Accept
4803-
// unknown
4804-
// collations
4805-
// from
4806-
// Katmai
4807-
// &
4808-
// later
4809-
// servers
4810-
));
4836+
| ((serverMajorVersion >= 10) ? TDS.LOGIN_OPTION3_UNKNOWN_COLLATION_HANDLING : 0)));
48114837

48124838
tdsWriter.writeInt((byte) 0); // Client time zone
48134839
tdsWriter.writeInt((byte) 0); // Client LCID

0 commit comments

Comments
 (0)