From 29e33c5769f3b5cba953d2e513d40ed6bd8bc00d Mon Sep 17 00:00:00 2001 From: Cheena Malhotra Date: Mon, 18 Jun 2018 15:32:56 -0700 Subject: [PATCH] Fix | Review comment changes --- .../microsoft/sqlserver/jdbc/IOBuffer.java | 7 ++-- .../sqlserver/jdbc/SQLServerConnection.java | 40 ++++++++----------- .../sqlserver/jdbc/SQLServerException.java | 8 ++-- .../sqlserver/jdbc/SQLServerResultSet.java | 8 ++-- .../sqlserver/jdbc/StreamColumns.java | 2 - .../microsoft/sqlserver/jdbc/tdsparser.java | 2 +- .../resultset/DataClassificationTest.java | 11 +++-- 7 files changed, 37 insertions(+), 41 deletions(-) diff --git a/src/main/java/com/microsoft/sqlserver/jdbc/IOBuffer.java b/src/main/java/com/microsoft/sqlserver/jdbc/IOBuffer.java index a7cba4158..62e39486a 100644 --- a/src/main/java/com/microsoft/sqlserver/jdbc/IOBuffer.java +++ b/src/main/java/com/microsoft/sqlserver/jdbc/IOBuffer.java @@ -6396,8 +6396,8 @@ final SQLServerConnection getConnection() { private final byte valueBytes[] = new byte[256]; protected SensitivityClassification sensitivityClassification; - - private static final AtomicInteger lastReaderID = new AtomicInteger(0); + + private static final AtomicInteger lastReaderID = new AtomicInteger(0); private static int nextReaderID() { return lastReaderID.incrementAndGet(); @@ -7139,9 +7139,8 @@ final void tryProcessFeatureExtAck(boolean featureExtAckReceived) throws SQLServ throw new SQLServerException(this, SQLServerException.getErrString("R_AE_NotSupportedByServer"), null, 0, false); } - boolean trySetSensitivityClassification(SensitivityClassification sensitivityClassification) { + final void trySetSensitivityClassification(SensitivityClassification sensitivityClassification) { this.sensitivityClassification = sensitivityClassification; - return true; } } diff --git a/src/main/java/com/microsoft/sqlserver/jdbc/SQLServerConnection.java b/src/main/java/com/microsoft/sqlserver/jdbc/SQLServerConnection.java index 3953ebfce..ba9f8b1af 100644 --- a/src/main/java/com/microsoft/sqlserver/jdbc/SQLServerConnection.java +++ b/src/main/java/com/microsoft/sqlserver/jdbc/SQLServerConnection.java @@ -561,7 +561,7 @@ boolean getServerSupportsColumnEncryption() { } private boolean serverSupportsDataClassification = false; - + boolean getServerSupportsDataClassification() { return serverSupportsDataClassification; } @@ -3437,15 +3437,15 @@ int writeFedAuthFeatureRequest(boolean write, return totalLen; } - int writeDataClassificationFeatureRequest (boolean write /* if false just calculates the length */, - TDSWriter tdsWriter) throws SQLServerException { + int writeDataClassificationFeatureRequest(boolean write /* if false just calculates the length */, + TDSWriter tdsWriter) throws SQLServerException { int len = 6; // 1byte = featureID, 4bytes = featureData length, 1 bytes = Version if (write) { // Write Feature ID, length of the version# field and Sensitivity Classification Version# - tdsWriter.writeByte(TDS.TDS_FEATURE_EXT_DATACLASSIFICATION); - tdsWriter.writeInt(1); - tdsWriter.writeByte(TDS.MAX_SUPPORTED_DATA_CLASSIFICATION_VERSION); + tdsWriter.writeByte(TDS.TDS_FEATURE_EXT_DATACLASSIFICATION); + tdsWriter.writeInt(1); + tdsWriter.writeByte(TDS.MAX_SUPPORTED_DATA_CLASSIFICATION_VERSION); } return len; // size of data written } @@ -4148,32 +4148,26 @@ private void onFeatureExtAck(byte featureId, break; } case TDS.TDS_FEATURE_EXT_DATACLASSIFICATION: { - if (connectionlogger.isLoggable(Level.FINER)) { + if (connectionlogger.isLoggable(Level.FINER)) { connectionlogger.fine(toString() + " Received feature extension acknowledgement for Data Classification."); } - if (1 > data.length) { - if (connectionlogger.isLoggable(Level.SEVERE)) { + if (2 != data.length) { + if (connectionlogger.isLoggable(Level.SEVERE)) { connectionlogger.severe(toString() + " Unknown token for Data Classification."); } throw new SQLServerException(SQLServerException.getErrString("R_UnknownDataClsTokenNumber"), null); } - + byte supportedDataClassificationVersion = data[0]; - if ((0 == supportedDataClassificationVersion) || (supportedDataClassificationVersion > TDS.MAX_SUPPORTED_DATA_CLASSIFICATION_VERSION)) { - if (connectionlogger.isLoggable(Level.SEVERE)) { + if ((0 == supportedDataClassificationVersion) + || (supportedDataClassificationVersion > TDS.MAX_SUPPORTED_DATA_CLASSIFICATION_VERSION)) { + if (connectionlogger.isLoggable(Level.SEVERE)) { connectionlogger.severe(toString() + " Invalid version number for Data Classification"); } throw new SQLServerException(SQLServerException.getErrString("R_InvalidDataClsVersionNumber"), null); } - if (data.length != 2) { - if (connectionlogger.isLoggable(Level.SEVERE)) { - connectionlogger.severe(toString() + " Unknown token for Data Classification"); - } - throw new SQLServerException(SQLServerException.getErrString("R_UnknownDataClsTokenNumber"), null); - } - byte enabled = data[1]; serverSupportsDataClassification = (enabled == 0) ? false : true; break; @@ -4463,8 +4457,8 @@ else if (serverMajorVersion >= 9) // Yukon (9.0) --> TDS 7.2 // Prelogin disconn if (federatedAuthenticationInfoRequested || federatedAuthenticationRequested) { len2 = len2 + writeFedAuthFeatureRequest(false, tdsWriter, fedAuthFeatureExtensionData); } - //Data Classification is always enabled (by default) - + + // Data Classification is always enabled (by default) len2 += writeDataClassificationFeatureRequest(false, tdsWriter); len2 = len2 + 1; // add 1 to length because of FeatureEx terminator @@ -4647,9 +4641,9 @@ else if (serverMajorVersion >= 9) // Yukon (9.0) --> TDS 7.2 // Prelogin disconn if (federatedAuthenticationInfoRequested || federatedAuthenticationRequested) { writeFedAuthFeatureRequest(true, tdsWriter, fedAuthFeatureExtensionData); } - + writeDataClassificationFeatureRequest(true, tdsWriter); - + tdsWriter.writeByte((byte) TDS.FEATURE_EXT_TERMINATOR); tdsWriter.setDataLoggable(true); diff --git a/src/main/java/com/microsoft/sqlserver/jdbc/SQLServerException.java b/src/main/java/com/microsoft/sqlserver/jdbc/SQLServerException.java index f55b2166b..e030a27f2 100644 --- a/src/main/java/com/microsoft/sqlserver/jdbc/SQLServerException.java +++ b/src/main/java/com/microsoft/sqlserver/jdbc/SQLServerException.java @@ -72,10 +72,10 @@ public final class SQLServerException extends java.sql.SQLException { static final int DRIVER_ERROR_INTERMITTENT_TLS_FAILED = 7; static final int ERROR_SOCKET_TIMEOUT = 8; static final int ERROR_QUERY_TIMEOUT = 9; - static final int DataClassificationInvalidVersion = 24; - static final int DataClassificationNotExpected = 25; - static final int DataClassificationInvalidLabelIndex = 26; - static final int DataClassificationInvalidInformationTypeIndex = 27; + static final int DATA_CLASSIFICATION_INVALID_VERSION = 24; + static final int DATA_CLASSIFICATION_NOT_EXPECTED = 25; + static final int DATA_CLASSIFICATION_INVALID_LABEL_INDEX = 26; + static final int DATA_CLASSIFICATION_INVALID_INFORMATION_TYPE_INDEX = 27; private int driverErrorCode = DRIVER_ERROR_NONE; diff --git a/src/main/java/com/microsoft/sqlserver/jdbc/SQLServerResultSet.java b/src/main/java/com/microsoft/sqlserver/jdbc/SQLServerResultSet.java index d4b9e62d9..31709297a 100644 --- a/src/main/java/com/microsoft/sqlserver/jdbc/SQLServerResultSet.java +++ b/src/main/java/com/microsoft/sqlserver/jdbc/SQLServerResultSet.java @@ -216,20 +216,20 @@ protected TDSReader getTDSReader() { private final FetchBuffer fetchBuffer; /** - * Exposes Data Classification information for the current ResultSet - * For SQL Servers that do not support Data Classification or results that do not fetch any classified columns, this data can be null + * Exposes Data Classification information for the current ResultSet For SQL Servers that do not support Data Classification or results that do + * not fetch any classified columns, this data can be null * * @return SensitivityClassification */ public SensitivityClassification getSensitivityClassification() { - return tdsReader.sensitivityClassification; + return tdsReader.sensitivityClassification; } /** * Make a new result set * * @param stmtIn - * the generating statement + * the generating statement */ SQLServerResultSet(SQLServerStatement stmtIn) throws SQLServerException { int resultSetID = nextResultSetID(); diff --git a/src/main/java/com/microsoft/sqlserver/jdbc/StreamColumns.java b/src/main/java/com/microsoft/sqlserver/jdbc/StreamColumns.java index d82624bd9..e0f5342d9 100644 --- a/src/main/java/com/microsoft/sqlserver/jdbc/StreamColumns.java +++ b/src/main/java/com/microsoft/sqlserver/jdbc/StreamColumns.java @@ -230,10 +230,8 @@ void setFromTDS(TDSReader tdsReader) throws SQLServerException { private String readByteString(TDSReader tdsReader) throws SQLServerException { String value = ""; - int byteLen = (int) tdsReader.readUnsignedByte(); value = tdsReader.readUnicodeString(byteLen); - return value; } diff --git a/src/main/java/com/microsoft/sqlserver/jdbc/tdsparser.java b/src/main/java/com/microsoft/sqlserver/jdbc/tdsparser.java index 8576a0a6d..54a56e3ae 100644 --- a/src/main/java/com/microsoft/sqlserver/jdbc/tdsparser.java +++ b/src/main/java/com/microsoft/sqlserver/jdbc/tdsparser.java @@ -166,7 +166,7 @@ final StreamError getDatabaseError() { return databaseError; } - TDSTokenHandler(String logContext) { + TDSTokenHandler(String logContext) { this.logContext = logContext; } diff --git a/src/test/java/com/microsoft/sqlserver/jdbc/resultset/DataClassificationTest.java b/src/test/java/com/microsoft/sqlserver/jdbc/resultset/DataClassificationTest.java index 7c22d1c01..759eb167d 100644 --- a/src/test/java/com/microsoft/sqlserver/jdbc/resultset/DataClassificationTest.java +++ b/src/test/java/com/microsoft/sqlserver/jdbc/resultset/DataClassificationTest.java @@ -1,3 +1,10 @@ +/* + * 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.resultset; import java.sql.Connection; @@ -42,7 +49,6 @@ public void testDataClassificationMetadata() throws Exception { * * @param connection * @param stmt - * @param tableName * @throws SQLException */ private void createTable(Connection connection, @@ -98,7 +104,6 @@ private void createTable(Connection connection, * Selects data from the table and triggers verifySensitivityClassification method * * @param stmt - * @param queries * @throws Exception */ private void runTestsForServer(Statement stmt) throws Exception { @@ -108,7 +113,7 @@ private void runTestsForServer(Statement stmt) throws Exception { } /** - * Verifies resultset recieved to contain data classification information as set. + * Verifies resultset received to contain data classification information as set. * * @param rs * @throws SQLException