Skip to content

Commit

Permalink
Merge pull request #507 from Microsoft/dev
Browse files Browse the repository at this point in the history
Merging in Dev to Master for 6.3.3 release
  • Loading branch information
peterbae authored Sep 23, 2017
2 parents b9cdef4 + 33ff0e2 commit edc794c
Show file tree
Hide file tree
Showing 29 changed files with 707 additions and 41 deletions.
4 changes: 0 additions & 4 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,3 @@ script:
##Test for JDBC Specification 41 & 42 and submit coverage report.
- mvn test -B -Pbuild41 jacoco:report && bash <(curl -s https://codecov.io/bash) -cF JDBC41
- mvn test -B -Pbuild42 jacoco:report && bash <(curl -s https://codecov.io/bash) -cF JDBC42

#after_success:
# instead of after success we are using && operator for conditional submitting coverage report.
# - bash <(curl -s https://codecov.io/bash)
15 changes: 15 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,21 @@ All notable changes to this project will be documented in this file.

The format is based on [Keep a Changelog](http://keepachangelog.com/)

## [6.3.3] Preview Release
### Added
- Added connection properties for specifying custom TrustManager [#74](https://github.com/Microsoft/mssql-jdbc/pull/74)

### Fixed Issues
- Fixed exception thrown by getters on null columns [#488](https://github.com/Microsoft/mssql-jdbc/pull/488)
- Fixed issue with DatabaseMetaData#getImportedKeys() returns wrong value for DELETE_RULE [#490](https://github.com/Microsoft/mssql-jdbc/pull/490)
- Fixed issue with ActivityCorrelator causing a classloader leak [#465](https://github.com/Microsoft/mssql-jdbc/pull/465)

### Changed
- Removed explicit extends Object [#469](https://github.com/Microsoft/mssql-jdbc/pull/469)
- Removed unnecessary return statements [#471](https://github.com/Microsoft/mssql-jdbc/pull/471)
- Simplified overly complex boolean expressions [#472](https://github.com/Microsoft/mssql-jdbc/pull/472)
- Replaced explicit types with <> (the diamond operator) [#420](https://github.com/Microsoft/mssql-jdbc/pull/420)

## [6.3.2] Preview Release
### Added
- Added new connection property: sslProtocol [#422](https://github.com/Microsoft/mssql-jdbc/pull/422)
Expand Down
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ To get the latest preview version of the driver, add the following to your POM f
<dependency>
<groupId>com.microsoft.sqlserver</groupId>
<artifactId>mssql-jdbc</artifactId>
<version>6.3.2.jre8-preview</version>
<version>6.3.3.jre8-preview</version>
</dependency>
```

Expand Down Expand Up @@ -120,7 +120,7 @@ Projects that require either of the two features need to explicitly declare the
<dependency>
<groupId>com.microsoft.sqlserver</groupId>
<artifactId>mssql-jdbc</artifactId>
<version>6.3.2.jre8-preview</version>
<version>6.3.3.jre8-preview</version>
<scope>compile</scope>
</dependency>

Expand Down
1 change: 0 additions & 1 deletion appveyor.yml
Original file line number Diff line number Diff line change
Expand Up @@ -35,4 +35,3 @@ build_script:
test_script:
- mvn test -B -Pbuild41
- mvn test -B -Pbuild42

2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

<groupId>com.microsoft.sqlserver</groupId>
<artifactId>mssql-jdbc</artifactId>
<version>6.3.3-SNAPSHOT</version>
<version>6.3.3</version>

<packaging>jar</packaging>

Expand Down
2 changes: 1 addition & 1 deletion src/main/java/com/microsoft/sqlserver/jdbc/AE.java
Original file line number Diff line number Diff line change
Expand Up @@ -237,7 +237,7 @@ short getOrdinal() {
}

boolean IsAlgorithmInitialized() {
return (null != cipherAlgorithm) ? true : false;
return null != cipherAlgorithm;
}
}

Expand Down
29 changes: 19 additions & 10 deletions src/main/java/com/microsoft/sqlserver/jdbc/ActivityCorrelator.java
Original file line number Diff line number Diff line change
Expand Up @@ -8,32 +8,42 @@

package com.microsoft.sqlserver.jdbc;

import java.util.Map;
import java.util.UUID;
import java.util.concurrent.ConcurrentHashMap;

/**
* ActivityCorrelator provides the APIs to access the ActivityId in TLS
*/
final class ActivityCorrelator {

private static ThreadLocal<ActivityId> ActivityIdTls = new ThreadLocal<ActivityId>() {
protected ActivityId initialValue() {
return new ActivityId();
private static Map<Long, ActivityId> ActivityIdTlsMap = new ConcurrentHashMap<Long, ActivityId>();

static void cleanupActivityId() {
//remove the ActivityId that belongs to this thread.
long uniqueThreadId = Thread.currentThread().getId();

if (ActivityIdTlsMap.containsKey(uniqueThreadId)) {
ActivityIdTlsMap.remove(uniqueThreadId);
}
};
}

// Get the current ActivityId in TLS
static ActivityId getCurrent() {
// get the value in TLS, not reference
return ActivityIdTls.get();
long uniqueThreadId = Thread.currentThread().getId();

//Since the Id for each thread is unique, this assures that the below if statement is run only once per thread.
if (!ActivityIdTlsMap.containsKey(uniqueThreadId)) {
ActivityIdTlsMap.put(uniqueThreadId, new ActivityId());
}

return ActivityIdTlsMap.get(uniqueThreadId);
}

// Increment the Sequence number of the ActivityId in TLS
// and return the ActivityId with new Sequence number
static ActivityId getNext() {
// We need to call get() method on ThreadLocal to get
// the current value of ActivityId stored in TLS,
// then increment the sequence number.

// Get the current ActivityId in TLS
ActivityId activityId = getCurrent();

Expand All @@ -47,7 +57,6 @@ static void setCurrentActivityIdSentFlag() {
ActivityId activityId = getCurrent();
activityId.setSentFlag();
}

}

class ActivityId {
Expand Down
1 change: 0 additions & 1 deletion src/main/java/com/microsoft/sqlserver/jdbc/DDC.java
Original file line number Diff line number Diff line change
Expand Up @@ -1338,7 +1338,6 @@ public void mark(int readLimit) {
catch (IOException e) {
// unfortunately inputstream mark does not throw an exception so we have to eat any exception from the reader here
// likely to be a bug in the original InputStream spec.
return;
}
}

Expand Down
32 changes: 27 additions & 5 deletions src/main/java/com/microsoft/sqlserver/jdbc/IOBuffer.java
Original file line number Diff line number Diff line change
Expand Up @@ -1340,7 +1340,7 @@ public void setOOBInline(boolean on) throws SocketException {
* A PermissiveX509TrustManager is used to "verify" the authenticity of the server when the trustServerCertificate connection property is set to
* true.
*/
private final class PermissiveX509TrustManager extends Object implements X509TrustManager {
private final class PermissiveX509TrustManager implements X509TrustManager {
private final TDSChannel tdsChannel;
private final Logger logger;
private final String logContext;
Expand Down Expand Up @@ -1373,7 +1373,7 @@ public X509Certificate[] getAcceptedIssuers() {
*
* This validates the subject name in the certificate with the host name
*/
private final class HostNameOverrideX509TrustManager extends Object implements X509TrustManager {
private final class HostNameOverrideX509TrustManager implements X509TrustManager {
private final Logger logger;
private final String logContext;
private final X509TrustManager defaultTrustManager;
Expand Down Expand Up @@ -1622,7 +1622,22 @@ void enableSSL(String host,

tm = new TrustManager[] {new PermissiveX509TrustManager(this)};
}

// Otherwise, we'll check if a specific TrustManager implemenation has been requested and
// if so instantiate it, optionally specifying a constructor argument to customize it.
else if (con.getTrustManagerClass() != null) {
Class<?> tmClass = Class.forName(con.getTrustManagerClass());
if (!TrustManager.class.isAssignableFrom(tmClass)) {
throw new IllegalArgumentException(
"The class specified by the trustManagerClass property must implement javax.net.ssl.TrustManager");
}
String constructorArg = con.getTrustManagerConstructorArg();
if (constructorArg == null) {
tm = new TrustManager[] {(TrustManager) tmClass.getDeclaredConstructor().newInstance()};
}
else {
tm = new TrustManager[] {(TrustManager) tmClass.getDeclaredConstructor(String.class).newInstance(constructorArg)};
}
}
// Otherwise, we'll validate the certificate using a real TrustManager obtained
// from the a security provider that is capable of validating X.509 certificates.
else {
Expand Down Expand Up @@ -1798,7 +1813,14 @@ void enableSSL(String host,

// It is important to get the localized message here, otherwise error messages won't match for different locales.
String errMsg = e.getLocalizedMessage();

// If the message is null replace it with the non-localized message or a dummy string. This can happen if a custom
// TrustManager implementation is specified that does not provide localized messages.
if (errMsg == null) {
errMsg = e.getMessage();
}
if (errMsg == null) {
errMsg = "";
}
// The error message may have a connection id appended to it. Extract the message only for comparison.
// This client connection id is appended in method checkAndAppendClientConnId().
if (errMsg.contains(SQLServerException.LOG_CLIENT_CONNECTION_ID_PREFIX)) {
Expand Down Expand Up @@ -4974,7 +4996,7 @@ else if (DataTypes.UNKNOWN_STREAM_LENGTH == dataLength)
}
break;
case SQL_VARIANT:
boolean isShiloh = (8 >= con.getServerMajorVersion() ? true : false);
boolean isShiloh = (8 >= con.getServerMajorVersion());
if (isShiloh) {
MessageFormat form = new MessageFormat(SQLServerException.getErrString("R_SQLVariantSupport"));
throw new SQLServerException(null, form.format(new Object[] {}), null, 0, false);
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/com/microsoft/sqlserver/jdbc/Parameter.java
Original file line number Diff line number Diff line change
Expand Up @@ -399,7 +399,7 @@ boolean isNull() {
}

boolean isValueGotten() {
return (null != getterDTV) ? (true) : (false);
return null != getterDTV;

}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,6 @@
final class SQLJdbcVersion {
static final int major = 6;
static final int minor = 3;
static final int patch = 2;
static final int patch = 3;
static final int build = 0;
}
Original file line number Diff line number Diff line change
Expand Up @@ -1801,7 +1801,7 @@ private void getSourceMetadata() throws SQLServerException {
for (int i = 1; i <= srcColumnCount; ++i) {
srcColumnMetadata.put(i,
new BulkColumnMetaData(sourceResultSetMetaData.getColumnName(i),
((ResultSetMetaData.columnNoNulls == sourceResultSetMetaData.isNullable(i)) ? false : true),
(ResultSetMetaData.columnNoNulls != sourceResultSetMetaData.isNullable(i)),
sourceResultSetMetaData.getPrecision(i), sourceResultSetMetaData.getScale(i),
sourceResultSetMetaData.getColumnType(i), null));
}
Expand Down Expand Up @@ -2515,7 +2515,7 @@ else if (4 >= bulkScale)
}
break;
case microsoft.sql.Types.SQL_VARIANT:
boolean isShiloh = (8 >= connection.getServerMajorVersion() ? true : false);
boolean isShiloh = (8 >= connection.getServerMajorVersion());
if (isShiloh) {
MessageFormat form = new MessageFormat(SQLServerException.getErrString("R_SQLVariantSupport"));
throw new SQLServerException(null, form.format(new Object[] {}), null, 0, false);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -507,6 +507,20 @@ final byte getNegotiatedEncryptionLevel() {
return negotiatedEncryptionLevel;
}

private String trustManagerClass = null;

final String getTrustManagerClass() {
assert TDS.ENCRYPT_INVALID != requestedEncryptionLevel;
return trustManagerClass;
}

private String trustManagerConstructorArg = null;

final String getTrustManagerConstructorArg() {
assert TDS.ENCRYPT_INVALID != requestedEncryptionLevel;
return trustManagerConstructorArg;
}

static final String RESERVED_PROVIDER_NAME_PREFIX = "MSSQL_";
String columnEncryptionSetting = null;

Expand Down Expand Up @@ -1355,6 +1369,9 @@ Connection connectInternal(Properties propsIn,

trustServerCertificate = booleanPropertyOn(sPropKey, sPropValue);

trustManagerClass = activeConnectionProperties.getProperty(SQLServerDriverStringProperty.TRUST_MANAGER_CLASS.toString());
trustManagerConstructorArg = activeConnectionProperties.getProperty(SQLServerDriverStringProperty.TRUST_MANAGER_CONSTRUCTOR_ARG.toString());

sPropKey = SQLServerDriverStringProperty.SELECT_METHOD.toString();
sPropValue = activeConnectionProperties.getProperty(sPropKey);
if (sPropValue == null)
Expand Down Expand Up @@ -1801,7 +1818,7 @@ private void login(String primary,
long timerStart) throws SQLServerException {
// standardLogin would be false only for db mirroring scenarios. It would be true
// for all other cases, including multiSubnetFailover
final boolean isDBMirroring = (null == mirror && null == foActual) ? false : true;
final boolean isDBMirroring = null != mirror || null != foActual;
int sleepInterval = 100; // milliseconds to sleep (back off) between attempts.
long timeoutUnitInterval;

Expand Down Expand Up @@ -2605,7 +2622,7 @@ void Prelogin(String serverName,
// Or AccessToken is not null, mean token based authentication is used.
if (((null != authenticationString) && (!authenticationString.equalsIgnoreCase(SqlAuthentication.NotSpecified.toString())))
|| (null != accessTokenInByte)) {
fedAuthRequiredPreLoginResponse = (preloginResponse[optionOffset] == 1 ? true : false);
fedAuthRequiredPreLoginResponse = (preloginResponse[optionOffset] == 1);
}
break;

Expand Down Expand Up @@ -2992,6 +3009,8 @@ public void close() throws SQLServerException {

// Clean-up queue etc. related to batching of prepared statement discard actions (sp_unprepare).
cleanupPreparedStatementDiscardActions();

ActivityCorrelator.cleanupActivityId();

loggerExternal.exiting(getClassNameLogging(), "close");
}
Expand All @@ -3012,6 +3031,7 @@ final void poolCloseEventNotify() throws SQLServerException {
connectionCommand("IF @@TRANCOUNT > 0 ROLLBACK TRAN" /* +close connection */, "close connection");
}
notifyPooledConnection(null);
ActivityCorrelator.cleanupActivityId();
if (connectionlogger.isLoggable(Level.FINER)) {
connectionlogger.finer(toString() + " Connection closed and returned to connection pool");
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -595,6 +595,24 @@ public String getSSLProtocol() {
SQLServerDriverStringProperty.SSL_PROTOCOL.getDefaultValue());
}

public void setTrustManagerClass(String trustManagerClass) {
setStringProperty(connectionProps, SQLServerDriverStringProperty.TRUST_MANAGER_CLASS.toString(), trustManagerClass);
}

public String getTrustManagerClass() {
return getStringProperty(connectionProps, SQLServerDriverStringProperty.TRUST_MANAGER_CLASS.toString(),
SQLServerDriverStringProperty.TRUST_MANAGER_CLASS.getDefaultValue());
}

public void setTrustManagerConstructorArg(String trustManagerClass) {
setStringProperty(connectionProps, SQLServerDriverStringProperty.TRUST_MANAGER_CONSTRUCTOR_ARG.toString(), trustManagerClass);
}

public String getTrustManagerConstructorArg() {
return getStringProperty(connectionProps, SQLServerDriverStringProperty.TRUST_MANAGER_CONSTRUCTOR_ARG.toString(),
SQLServerDriverStringProperty.TRUST_MANAGER_CONSTRUCTOR_ARG.getDefaultValue());
}

// 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).
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ public synchronized void addRow(Object... values) throws SQLServerException {
Object val = null;

if ((null != values) && (currentColumn < values.length) && (null != values[currentColumn]))
val = (null == values[currentColumn]) ? null : values[currentColumn];
val = values[currentColumn];
currentColumn++;
Map.Entry<Integer, SQLServerDataColumn> pair = columnsIterator.next();
JDBCType jdbcType = JDBCType.of(pair.getValue().javaSqlType);
Expand Down
Loading

0 comments on commit edc794c

Please sign in to comment.