Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

More code cleanup #2048

Merged
merged 2 commits into from
Jan 23, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 0 additions & 2 deletions src/main/java/com/microsoft/sqlserver/jdbc/IOBuffer.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@
import java.io.Serializable;
import java.io.UnsupportedEncodingException;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
import java.math.BigDecimal;
import java.math.BigInteger;
import java.math.RoundingMode;
Expand All @@ -27,7 +26,6 @@
import java.net.Socket;
import java.net.SocketAddress;
import java.net.SocketException;
import java.net.SocketOption;
import java.net.SocketTimeoutException;
import java.nio.Buffer;
import java.nio.ByteBuffer;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7722,7 +7722,7 @@ public void setStatementPoolingCacheSize(int value) {
* @deprecated Time-to-live is no longer supported for the cached Managed Identity tokens.
* This method will always return 0 and is for backwards compatibility only.
*/
@Deprecated
@Deprecated(since = "12.1.0", forRemoval = true)
@Override
public int getMsiTokenCacheTtl() {
return 0;
Expand All @@ -7732,7 +7732,7 @@ public int getMsiTokenCacheTtl() {
* @deprecated Time-to-live is no longer supported for the cached Managed Identity tokens.
* This method is a no-op for backwards compatibility only.
*/
@Deprecated
@Deprecated(since = "12.1.0", forRemoval = true)
@Override
public void setMsiTokenCacheTtl(int timeToLive) {}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -647,7 +647,7 @@ public String getIPAddressPreference() {
* @deprecated Time-to-live is no longer supported for the cached Managed Identity tokens.
* This method will always return 0 and is for backwards compatibility only.
*/
@Deprecated
@Deprecated(since = "12.1.0", forRemoval = true)
@Override
public int getMsiTokenCacheTtl() {
return 0;
Expand All @@ -657,7 +657,7 @@ public int getMsiTokenCacheTtl() {
* @deprecated Time-to-live is no longer supported for the cached Managed Identity tokens.
* This method is a no-op for backwards compatibility only.
*/
@Deprecated
@Deprecated(since = "12.1.0", forRemoval = true)
@Override
public void setMsiTokenCacheTtl(int timeToLive) {}
}
22 changes: 11 additions & 11 deletions src/main/java/com/microsoft/sqlserver/jdbc/SQLServerDataSource.java
Original file line number Diff line number Diff line change
Expand Up @@ -316,7 +316,7 @@ public void setEncrypt(String encryptOption) {
* @deprecated
*/
@Override
@Deprecated
@Deprecated(since = "10.1.0", forRemoval = true)
public void setEncrypt(boolean encryptOption) {
setStringProperty(connectionProps, SQLServerDriverStringProperty.ENCRYPT.toString(),
Boolean.toString(encryptOption));
Expand Down Expand Up @@ -1002,7 +1002,7 @@ public boolean getUseBulkCopyForBatchInsert() {
* @deprecated
*/
@Override
@Deprecated
@Deprecated(since = "9.3.0", forRemoval = true)
public void setJASSConfigurationName(String configurationName) {
setStringProperty(connectionProps, SQLServerDriverStringProperty.JAAS_CONFIG_NAME.toString(),
configurationName);
Expand All @@ -1012,7 +1012,7 @@ public void setJASSConfigurationName(String configurationName) {
* @deprecated
*/
@Override
@Deprecated
@Deprecated(since = "9.3.0", forRemoval = true)
public String getJASSConfigurationName() {
return getStringProperty(connectionProps, SQLServerDriverStringProperty.JAAS_CONFIG_NAME.toString(),
SQLServerDriverStringProperty.JAAS_CONFIG_NAME.getDefaultValue());
Expand All @@ -1038,7 +1038,7 @@ public String getJAASConfigurationName() {
* @param managedIdentityClientId
* Client ID of the user-assigned Managed Identity.
*/
@Deprecated
@Deprecated(since = "12.1.0", forRemoval = true)
@Override
public void setMSIClientId(String managedIdentityClientId) {
setStringProperty(connectionProps, SQLServerDriverStringProperty.MSI_CLIENT_ID.toString(),
Expand All @@ -1052,7 +1052,7 @@ public void setMSIClientId(String managedIdentityClientId) {
*
* @return msiClientId property value
*/
@Deprecated
@Deprecated(since = "12.1.0", forRemoval = true)
@Override
public String getMSIClientId() {
return getStringProperty(connectionProps, SQLServerDriverStringProperty.MSI_CLIENT_ID.toString(),
Expand Down Expand Up @@ -1154,7 +1154,7 @@ public void setClientKeyPassword(String password) {
* @deprecated
*/
@Override
@Deprecated
@Deprecated(since = "9.4.1", forRemoval = true)
public String getAADSecurePrincipalId() {
return getStringProperty(connectionProps, SQLServerDriverStringProperty.AAD_SECURE_PRINCIPAL_ID.toString(),
SQLServerDriverStringProperty.AAD_SECURE_PRINCIPAL_ID.getDefaultValue());
Expand All @@ -1164,7 +1164,7 @@ public String getAADSecurePrincipalId() {
* @deprecated
*/
@Override
@Deprecated
@Deprecated(since = "9.4.1", forRemoval = true)
public void setAADSecurePrincipalId(String AADSecurePrincipalId) {
setStringProperty(connectionProps, SQLServerDriverStringProperty.AAD_SECURE_PRINCIPAL_ID.toString(),
AADSecurePrincipalId);
Expand Down Expand Up @@ -1240,17 +1240,17 @@ public String getPrepareMethod() {

/**
* @deprecated Time-to-live is no longer supported for the cached Managed Identity tokens.
* This method will always return 0 and is for backwards compatibility only.
* This method will always return 0 and is for backwards compatibility only.
*/
@Deprecated
@Deprecated(since = "12.1.0", forRemoval = true)
@Override
public void setMsiTokenCacheTtl(int timeToLive) {}

/**
* @deprecated Time-to-live is no longer supported for the cached Managed Identity tokens.
* This method is a no-op for backwards compatibility only.
* This method is a no-op for backwards compatibility only.
*/
@Deprecated
@Deprecated(since = "12.1.0", forRemoval = true)
@Override
public int getMsiTokenCacheTtl() {
return 0;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -183,7 +183,6 @@ private void checkClosed() throws SQLServerException {
private static final String BUFFER_LENGTH = "BUFFER_LENGTH";
private static final String CARDINALITY = "CARDINALITY";
private static final String CHAR_OCTET_LENGTH = "CHAR_OCTET_LENGTH";
private static final String CLASS_NAME = "CLASS_NAME";
private static final String COLUMN_DEF = "COLUMN_DEF";
private static final String COLUMN_NAME = "COLUMN_NAME";
private static final String COLUMN_SIZE = "COLUMN_SIZE";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2739,7 +2739,7 @@ private boolean checkAndRemoveCommentsAndSpace(boolean checkForSemicolon) {
}

if ("--".equalsIgnoreCase(localUserSQL.substring(0, 2))) {
int temp = localUserSQL.indexOf("\n") + 1;
int temp = localUserSQL.indexOf('\n') + 1;
if (temp <= 0) {
localUserSQL = "";
return false;
Expand Down
45 changes: 36 additions & 9 deletions src/main/java/com/microsoft/sqlserver/jdbc/SQLServerResultSet.java
Original file line number Diff line number Diff line change
Expand Up @@ -370,16 +370,19 @@ final int getServerCursorId() {
super("ClientCursorInitializer");
}

@Override
boolean onRow(TDSReader tdsReader) throws SQLServerException {
// A ROW token indicates the start of the fetch buffer
return false;
}

@Override
boolean onNBCRow(TDSReader tdsReader) throws SQLServerException {
// A NBCROW token indicates the start of the fetch buffer
return false;
}

@Override
boolean onError(TDSReader tdsReader) throws SQLServerException {
// An ERROR token indicates a row error in lieu of a row.
// In this case, the row error is in lieu of the first row.
Expand All @@ -388,6 +391,7 @@ boolean onError(TDSReader tdsReader) throws SQLServerException {
return false;
}

@Override
boolean onDone(TDSReader tdsReader) throws SQLServerException {
// When initializing client-cursored ResultSets, a DONE token
// following the column metadata indicates an empty result set.
Expand All @@ -407,9 +411,11 @@ boolean onDone(TDSReader tdsReader) throws SQLServerException {
Object[] msgArgs = {status, (databaseError != null) ? databaseError.getErrorMessage() : ""};

if (null != databaseError) {
SQLServerException.makeFromDatabaseError(stmt.connection, null, form.format(msgArgs), databaseError, false);
SQLServerException.makeFromDatabaseError(stmt.connection, null, form.format(msgArgs),
databaseError, false);
} else {
SQLServerException.makeFromDriverError(stmt.connection, stmt, form.format(msgArgs), null, false);
SQLServerException.makeFromDriverError(stmt.connection, stmt, form.format(msgArgs), null,
false);
}
}

Expand Down Expand Up @@ -2156,7 +2162,10 @@ public java.io.InputStream getAsciiStream(String columnName) throws SQLServerExc
return value;
}

@Deprecated
/**
* @deprecated
*/
@Deprecated(since = "6.5.4")
@Override
public BigDecimal getBigDecimal(int columnIndex, int scale) throws SQLServerException {
if (loggerExternal.isLoggable(java.util.logging.Level.FINER))
Expand All @@ -2169,7 +2178,10 @@ public BigDecimal getBigDecimal(int columnIndex, int scale) throws SQLServerExce
return value;
}

@Deprecated
/**
* @deprecated
*/
@Deprecated(since = "6.5.4")
@Override
public BigDecimal getBigDecimal(String columnName, int scale) throws SQLServerException {
if (loggerExternal.isLoggable(java.util.logging.Level.FINER))
Expand Down Expand Up @@ -2803,16 +2815,22 @@ public microsoft.sql.DateTimeOffset getDateTimeOffset(String columnName) throws
return value;
}

/**
* @deprecated
*/
@Deprecated(since = "6.5.4")
@Override
@Deprecated
public java.io.InputStream getUnicodeStream(int columnIndex) throws SQLException {
loggerExternal.entering(getClassNameLogging(), "getUnicodeStream", columnIndex);
SQLServerException.throwNotSupportedException(stmt.connection, stmt);
return null;
}

/**
* @deprecated
*/
@Deprecated(since = "6.5.4")
@Override
@Deprecated
public java.io.InputStream getUnicodeStream(String columnName) throws SQLException {
loggerExternal.entering(getClassNameLogging(), "getUnicodeStream", columnName);
SQLServerException.throwNotSupportedException(stmt.connection, stmt);
Expand Down Expand Up @@ -5368,12 +5386,14 @@ private final class FetchBufferTokenHandler extends TDSTokenHandler {
// Even though the cursor fetch RPC call specified the "no metadata" option,
// the server still returns a COLMETADATA_TOKEN containing the magic NoMetaData
// value that we need to read through.
@Override
boolean onColMetaData(TDSReader tdsReader) throws SQLServerException {
(new StreamColumns(Util.shouldHonorAEForRead(stmt.stmtColumnEncriptionSetting, stmt.connection)))
.setFromTDS(tdsReader);
return true;
}

@Override
boolean onRow(TDSReader tdsReader) throws SQLServerException {
ensureStartMark();

Expand All @@ -5385,6 +5405,7 @@ boolean onRow(TDSReader tdsReader) throws SQLServerException {
return false;
}

@Override
boolean onNBCRow(TDSReader tdsReader) throws SQLServerException {
ensureStartMark();

Expand All @@ -5397,6 +5418,7 @@ boolean onNBCRow(TDSReader tdsReader) throws SQLServerException {
return false;
}

@Override
boolean onDone(TDSReader tdsReader) throws SQLServerException {
ensureStartMark();

Expand All @@ -5414,20 +5436,22 @@ boolean onDone(TDSReader tdsReader) throws SQLServerException {
Object[] msgArgs = {status, (databaseError != null) ? databaseError.getErrorMessage() : ""};

if (null != databaseError) {
SQLServerException.makeFromDatabaseError(stmt.connection, null, form.format(msgArgs), databaseError, false);
SQLServerException.makeFromDatabaseError(stmt.connection, null, form.format(msgArgs),
databaseError, false);
} else {
SQLServerException.makeFromDriverError(stmt.connection, stmt, form.format(msgArgs), null, false);
SQLServerException.makeFromDriverError(stmt.connection, stmt, form.format(msgArgs), null,
false);
}
}


// Done with all the rows in this fetch buffer and done with parsing
// unless it's a server cursor, in which case there is a RETSTAT and
// another DONE token to follow.
done = true;
return 0 != serverCursorId;
}

@Override
boolean onRetStatus(TDSReader tdsReader) throws SQLServerException {
// Check the return status for the bit indicating that
// "counter-intuitive" cursor behavior has happened and
Expand All @@ -5438,11 +5462,13 @@ boolean onRetStatus(TDSReader tdsReader) throws SQLServerException {
return true;
}

@Override
void onEOF(TDSReader tdsReader) throws SQLServerException {
super.onEOF(tdsReader);
done = true;
}

@Override
boolean onDataClassification(TDSReader tdsReader) throws SQLServerException {
if (tdsReader.getServerSupportsDataClassification()) {
tdsReader.trySetSensitivityClassification(new StreamColumns(
Expand Down Expand Up @@ -5571,6 +5597,7 @@ final boolean doExecute() throws SQLServerException {
return false;
}

@Override
final void processResponse(TDSReader responseTDSReader) throws SQLServerException {
tdsReader = responseTDSReader;
discardFetchBuffer();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
import java.time.Instant;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Hashtable;
import java.util.concurrent.ConcurrentHashMap;


/**
Expand Down Expand Up @@ -119,7 +119,7 @@ private void validateAttestationResponse() throws SQLServerException {
}
}

private static Hashtable<String, X509CertificateEntry> certificateCache = new Hashtable<>();
private static ConcurrentHashMap<String, X509CertificateEntry> certificateCache = new ConcurrentHashMap<>();

private byte[] getAttestationCertificates() throws IOException {
byte[] certData = null;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ private String findRealmFromHostname(RealmValidator realmValidator, String hostn
if (realmValidator.isRealmValid(realm)) {
return realm.toUpperCase();
}
index = hostname.indexOf(".", index + 1);
index = hostname.indexOf('.', index + 1);
if (-1 != index) {
index = index + 1;
}
Expand Down Expand Up @@ -166,7 +166,8 @@ String enrichSpnWithRealm(SQLServerConnection con, String spn, boolean allowHost
} else {
if (allowHostnameCanonicalization) {
if (logger.isLoggable(Level.FINER)) {
logger.finer("Since realm is provided, try to resolve canonical host name to host name with InetAddress");
logger.finer(
"Since realm is provided, try to resolve canonical host name to host name with InetAddress");
}
// Realm was provided, try to resolve cname to hostname
dnsName = InetAddress.getByName(dnsName).getCanonicalHostName();
Expand Down Expand Up @@ -212,7 +213,7 @@ String getSpn(SQLServerConnection con) {
if (null != userSuppliedServerSpn) {
// serverNameAsACE is true, translate the user supplied serverSPN to ASCII
if (con.serverNameAsACE()) {
int slashPos = userSuppliedServerSpn.indexOf("/");
int slashPos = userSuppliedServerSpn.indexOf('/');
spn = userSuppliedServerSpn.substring(0, slashPos + 1)
+ IDN.toASCII(userSuppliedServerSpn.substring(slashPos + 1));
} else {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,7 @@ final void checkClosed() throws IOException {
*
* @return true if mark and reset are supported.
*/
@Override
public boolean markSupported() {
return true;
}
Expand Down Expand Up @@ -146,6 +147,7 @@ final class SimpleInputStream extends BaseInputStream {
* @exception IOException
* if an I/O error occurs.
*/
@Override
public void close() throws IOException {
if (null == tdsReader)
return;
Expand Down Expand Up @@ -184,6 +186,7 @@ private boolean isEOS() {
* @exception IOException
* if an I/O error occurs.
*/
@Override
public long skip(long n) throws IOException {
checkClosed();
if (logger.isLoggable(java.util.logging.Level.FINER))
Expand Down
Loading