diff --git a/src/main/java/com/microsoft/sqlserver/jdbc/IOBuffer.java b/src/main/java/com/microsoft/sqlserver/jdbc/IOBuffer.java index 01ad482566..ef50e71a03 100644 --- a/src/main/java/com/microsoft/sqlserver/jdbc/IOBuffer.java +++ b/src/main/java/com/microsoft/sqlserver/jdbc/IOBuffer.java @@ -2473,7 +2473,7 @@ private void findSocketUsingJavaNIO(InetAddress[] inetAddrs, try { selector = Selector.open(); - for (int i = 0; i < inetAddrs.length; i++) { + for (InetAddress inetAddr : inetAddrs) { SocketChannel sChannel = SocketChannel.open(); socketChannels.add(sChannel); @@ -2484,10 +2484,10 @@ private void findSocketUsingJavaNIO(InetAddress[] inetAddrs, int ops = SelectionKey.OP_CONNECT; SelectionKey key = sChannel.register(selector, ops); - sChannel.connect(new InetSocketAddress(inetAddrs[i], portNumber)); + sChannel.connect(new InetSocketAddress(inetAddr, portNumber)); if (logger.isLoggable(Level.FINER)) - logger.finer(this.toString() + " initiated connection to address: " + inetAddrs[i] + ", portNumber: " + portNumber); + logger.finer(this.toString() + " initiated connection to address: " + inetAddr + ", portNumber: " + portNumber); } long timerNow = System.currentTimeMillis(); @@ -5035,13 +5035,11 @@ void writeTVPColumnMetaData(TVP value) throws SQLServerException { writeShort((short) value.getTVPColumnCount()); Map columnMetadata = value.getColumnMetadata(); - Iterator> columnsIterator = columnMetadata.entrySet().iterator(); /* * TypeColumnMetaData = UserType Flags TYPE_INFO ColName ; */ - while (columnsIterator.hasNext()) { - Map.Entry pair = columnsIterator.next(); + for (Entry pair : columnMetadata.entrySet()) { JDBCType jdbcType = JDBCType.of(pair.getValue().javaSqlType); boolean useServerDefault = pair.getValue().useServerDefault; // ULONG ; UserType of column @@ -5114,13 +5112,12 @@ void writeTVPColumnMetaData(TVP value) throws SQLServerException { writeByte(TDSType.NVARCHAR.byteValue()); isShortValue = (2L * pair.getValue().precision) <= DataTypes.SHORT_VARTYPE_MAX_BYTES; // Use PLP encoding on Yukon and later with long values - if (!isShortValue) // PLP + if (!isShortValue) // PLP { // Handle Yukon v*max type header here. writeShort((short) 0xFFFF); con.getDatabaseCollation().writeCollation(this); - } - else // non PLP + } else // non PLP { writeShort((short) DataTypes.SHORT_VARTYPE_MAX_BYTES); con.getDatabaseCollation().writeCollation(this); @@ -5134,16 +5131,16 @@ void writeTVPColumnMetaData(TVP value) throws SQLServerException { writeByte(TDSType.BIGVARBINARY.byteValue()); isShortValue = pair.getValue().precision <= DataTypes.SHORT_VARTYPE_MAX_BYTES; // Use PLP encoding on Yukon and later with long values - if (!isShortValue) // PLP + if (!isShortValue) // PLP // Handle Yukon v*max type header here. writeShort((short) 0xFFFF); - else // non PLP + else // non PLP writeShort((short) DataTypes.SHORT_VARTYPE_MAX_BYTES); break; case SQL_VARIANT: writeByte(TDSType.SQL_VARIANT.byteValue()); writeInt(TDS.SQL_VARIANT_LENGTH);// write length of sql variant 8009 - + break; default: diff --git a/src/main/java/com/microsoft/sqlserver/jdbc/KerbCallback.java b/src/main/java/com/microsoft/sqlserver/jdbc/KerbCallback.java index 8cdc4cca96..6f861c4bbd 100644 --- a/src/main/java/com/microsoft/sqlserver/jdbc/KerbCallback.java +++ b/src/main/java/com/microsoft/sqlserver/jdbc/KerbCallback.java @@ -42,18 +42,15 @@ public String getUsernameRequested() { @Override public void handle(Callback[] callbacks) throws IOException, UnsupportedCallbackException { - for (int i = 0; i < callbacks.length; i++) { - Callback callback = callbacks[i]; + for (Callback callback : callbacks) { if (callback instanceof NameCallback) { usernameRequested = getAnyOf(callback, con.activeConnectionProperties, "user", SQLServerDriverStringProperty.USER.name()); ((NameCallback) callback).setName(usernameRequested); - } - else if (callback instanceof PasswordCallback) { + } else if (callback instanceof PasswordCallback) { String password = getAnyOf(callback, con.activeConnectionProperties, "password", SQLServerDriverStringProperty.PASSWORD.name()); - ((PasswordCallback) callbacks[i]).setPassword(password.toCharArray()); + ((PasswordCallback) callback).setPassword(password.toCharArray()); - } - else { + } else { throw new UnsupportedCallbackException(callback, "Unrecognized Callback type: " + callback.getClass()); } } diff --git a/src/main/java/com/microsoft/sqlserver/jdbc/SQLServerBulkCSVFileRecord.java b/src/main/java/com/microsoft/sqlserver/jdbc/SQLServerBulkCSVFileRecord.java index f208f7656a..59824cf6d8 100644 --- a/src/main/java/com/microsoft/sqlserver/jdbc/SQLServerBulkCSVFileRecord.java +++ b/src/main/java/com/microsoft/sqlserver/jdbc/SQLServerBulkCSVFileRecord.java @@ -16,6 +16,7 @@ import java.io.UnsupportedEncodingException; import java.math.BigDecimal; import java.math.RoundingMode; +import java.sql.Types; import java.text.DecimalFormat; import java.text.MessageFormat; import java.time.OffsetDateTime; @@ -525,9 +526,7 @@ public Object[] getRowData() throws SQLServerException { // Cannot go directly from String[] to Object[] and expect it to act as an array. Object[] dataRow = new Object[data.length]; - Iterator> it = columnMetadata.entrySet().iterator(); - while (it.hasNext()) { - Entry pair = it.next(); + for (Entry pair : columnMetadata.entrySet()) { ColumnMetadata cm = pair.getValue(); // Reading a column not available in csv @@ -556,7 +555,7 @@ public Object[] getRowData() throws SQLServerException { * Both BCP and BULK INSERT considers double quotes as part of the data and throws error if any data (say "10") is to be * inserted into an numeric column. Our implementation does the same. */ - case java.sql.Types.INTEGER: { + case Types.INTEGER: { // Formatter to remove the decimal part as SQL Server floors the decimal in integer types DecimalFormat decimalFormatter = new DecimalFormat("#"); String formatedfInput = decimalFormatter.format(Double.parseDouble(data[pair.getKey() - 1])); @@ -564,8 +563,8 @@ public Object[] getRowData() throws SQLServerException { break; } - case java.sql.Types.TINYINT: - case java.sql.Types.SMALLINT: { + case Types.TINYINT: + case Types.SMALLINT: { // Formatter to remove the decimal part as SQL Server floors the decimal in integer types DecimalFormat decimalFormatter = new DecimalFormat("#"); String formatedfInput = decimalFormatter.format(Double.parseDouble(data[pair.getKey() - 1])); @@ -573,52 +572,50 @@ public Object[] getRowData() throws SQLServerException { break; } - case java.sql.Types.BIGINT: { + case Types.BIGINT: { BigDecimal bd = new BigDecimal(data[pair.getKey() - 1].trim()); try { dataRow[pair.getKey() - 1] = bd.setScale(0, BigDecimal.ROUND_DOWN).longValueExact(); - } - catch (ArithmeticException ex) { + } catch (ArithmeticException ex) { String value = "'" + data[pair.getKey() - 1] + "'"; MessageFormat form = new MessageFormat(SQLServerException.getErrString("R_errorConvertingValue")); - throw new SQLServerException(form.format(new Object[] {value, JDBCType.of(cm.columnType)}), null, 0, ex); + throw new SQLServerException(form.format(new Object[]{value, JDBCType.of(cm.columnType)}), null, 0, ex); } break; } - case java.sql.Types.DECIMAL: - case java.sql.Types.NUMERIC: { + case Types.DECIMAL: + case Types.NUMERIC: { BigDecimal bd = new BigDecimal(data[pair.getKey() - 1].trim()); dataRow[pair.getKey() - 1] = bd.setScale(cm.scale, RoundingMode.HALF_UP); break; } - case java.sql.Types.BIT: { + case Types.BIT: { // "true" => 1, "false" => 0 // Any non-zero value (integer/double) => 1, 0/0.0 => 0 try { dataRow[pair.getKey() - 1] = (0 == Double.parseDouble(data[pair.getKey() - 1])) ? Boolean.FALSE : Boolean.TRUE; - } - catch (NumberFormatException e) { + } catch (NumberFormatException e) { dataRow[pair.getKey() - 1] = Boolean.parseBoolean(data[pair.getKey() - 1]); } break; } - case java.sql.Types.REAL: { + case Types.REAL: { dataRow[pair.getKey() - 1] = Float.parseFloat(data[pair.getKey() - 1]); break; } - case java.sql.Types.DOUBLE: { + case Types.DOUBLE: { dataRow[pair.getKey() - 1] = Double.parseDouble(data[pair.getKey() - 1]); break; } - case java.sql.Types.BINARY: - case java.sql.Types.VARBINARY: - case java.sql.Types.LONGVARBINARY: - case java.sql.Types.BLOB: { + case Types.BINARY: + case Types.VARBINARY: + case Types.LONGVARBINARY: + case Types.BLOB: { /* * For binary data, the value in file may or may not have the '0x' prefix. We will try to match our implementation with * 'BULK INSERT' except that we will allow 0x prefix whereas 'BULK INSERT' command does not allow 0x prefix. A BULK INSERT @@ -630,14 +627,13 @@ public Object[] getRowData() throws SQLServerException { String binData = data[pair.getKey() - 1].trim(); if (binData.startsWith("0x") || binData.startsWith("0X")) { dataRow[pair.getKey() - 1] = binData.substring(2); - } - else { + } else { dataRow[pair.getKey() - 1] = binData; } break; } - case 2013: // java.sql.Types.TIME_WITH_TIMEZONE + case 2013: // java.sql.Types.TIME_WITH_TIMEZONE { DriverJDBCVersion.checkSupportsJDBC42(); OffsetTime offsetTimeValue; @@ -671,19 +667,19 @@ else if (dateTimeFormatter != null) break; } - case java.sql.Types.NULL: { + case Types.NULL: { dataRow[pair.getKey() - 1] = null; break; } - case java.sql.Types.DATE: - case java.sql.Types.CHAR: - case java.sql.Types.NCHAR: - case java.sql.Types.VARCHAR: - case java.sql.Types.NVARCHAR: - case java.sql.Types.LONGVARCHAR: - case java.sql.Types.LONGNVARCHAR: - case java.sql.Types.CLOB: + case Types.DATE: + case Types.CHAR: + case Types.NCHAR: + case Types.VARCHAR: + case Types.NVARCHAR: + case Types.LONGVARCHAR: + case Types.LONGNVARCHAR: + case Types.CLOB: default: { // The string is copied as is. /* @@ -702,13 +698,11 @@ else if (dateTimeFormatter != null) break; } } - } - catch (IllegalArgumentException e) { + } catch (IllegalArgumentException e) { String value = "'" + data[pair.getKey() - 1] + "'"; MessageFormat form = new MessageFormat(SQLServerException.getErrString("R_errorConvertingValue")); - throw new SQLServerException(form.format(new Object[] {value, JDBCType.of(cm.columnType)}), null, 0, e); - } - catch (ArrayIndexOutOfBoundsException e) { + throw new SQLServerException(form.format(new Object[]{value, JDBCType.of(cm.columnType)}), null, 0, e); + } catch (ArrayIndexOutOfBoundsException e) { throw new SQLServerException(SQLServerException.getErrString("R_CSVDataSchemaMismatch"), e); } diff --git a/src/main/java/com/microsoft/sqlserver/jdbc/SQLServerBulkCopy.java b/src/main/java/com/microsoft/sqlserver/jdbc/SQLServerBulkCopy.java index 3076c90177..a4e1b2be37 100644 --- a/src/main/java/com/microsoft/sqlserver/jdbc/SQLServerBulkCopy.java +++ b/src/main/java/com/microsoft/sqlserver/jdbc/SQLServerBulkCopy.java @@ -1818,9 +1818,8 @@ else if (null != sourceBulkRecord) { } else { srcColumnCount = columnOrdinals.size(); - Iterator columnsIterator = columnOrdinals.iterator(); - while (columnsIterator.hasNext()) { - currentColumn = columnsIterator.next(); + for (Integer columnOrdinal : columnOrdinals) { + currentColumn = columnOrdinal; srcColumnMetadata.put(currentColumn, new BulkColumnMetaData(sourceBulkRecord.getColumnName(currentColumn), true, sourceBulkRecord.getPrecision(currentColumn), sourceBulkRecord.getScale(currentColumn), sourceBulkRecord.getColumnType(currentColumn), @@ -1944,9 +1943,7 @@ else if (0 > cm.destinationColumnOrdinal || destColumnCount < cm.destinationColu } else { Set columnOrdinals = sourceBulkRecord.getColumnOrdinals(); - Iterator columnsIterator = columnOrdinals.iterator(); - while (columnsIterator.hasNext()) { - int currentColumn = columnsIterator.next(); + for (Integer currentColumn : columnOrdinals) { if (sourceBulkRecord.getColumnName(currentColumn).equals(cm.sourceColumnName)) { foundColumn = true; cm.sourceColumnOrdinal = currentColumn; @@ -3535,13 +3532,13 @@ private boolean writeBatchData(TDSWriter tdsWriter, if (null != sourceResultSet) { // Loop for each destination column. The mappings is a many to one mapping // where multiple source columns can be mapped to one destination column. - for (int i = 0; i < mappingColumnCount; ++i) { - writeColumn(tdsWriter, columnMappings.get(i).sourceColumnOrdinal, columnMappings.get(i).destinationColumnOrdinal, null // cell - // value is - // retrieved - // inside - // writeRowData() - // method. + for (ColumnMapping columnMapping : columnMappings) { + writeColumn(tdsWriter, columnMapping.sourceColumnOrdinal, columnMapping.destinationColumnOrdinal, null // cell + // value is + // retrieved + // inside + // writeRowData() + // method. ); } } @@ -3558,11 +3555,11 @@ private boolean writeBatchData(TDSWriter tdsWriter, throw new SQLServerException(SQLServerException.getErrString("R_unableRetrieveSourceData"), ex); } - for (int i = 0; i < mappingColumnCount; ++i) { + for (ColumnMapping columnMapping : columnMappings) { // If the SQLServerBulkCSVRecord does not have metadata for columns, it returns strings in the object array. // COnvert the strings using destination table types. - writeColumn(tdsWriter, columnMappings.get(i).sourceColumnOrdinal, columnMappings.get(i).destinationColumnOrdinal, - rowObjects[columnMappings.get(i).sourceColumnOrdinal - 1]); + writeColumn(tdsWriter, columnMapping.sourceColumnOrdinal, columnMapping.destinationColumnOrdinal, + rowObjects[columnMapping.sourceColumnOrdinal - 1]); } } row++; diff --git a/src/main/java/com/microsoft/sqlserver/jdbc/SQLServerDriver.java b/src/main/java/com/microsoft/sqlserver/jdbc/SQLServerDriver.java index bfe9612202..c42077b8f9 100644 --- a/src/main/java/com/microsoft/sqlserver/jdbc/SQLServerDriver.java +++ b/src/main/java/com/microsoft/sqlserver/jdbc/SQLServerDriver.java @@ -485,8 +485,8 @@ static Properties mergeURLAndSuppliedProperties(Properties urlProps, return urlProps; Properties suppliedPropertiesFixed = fixupProperties(suppliedProperties); // Merge URL properties and supplied properties. - for (int i = 0; i < DRIVER_PROPERTIES.length; i++) { - String sProp = DRIVER_PROPERTIES[i].getName(); + 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 @@ -495,8 +495,8 @@ static Properties mergeURLAndSuppliedProperties(Properties urlProps, } // Merge URL properties with property-only properties - for (int i = 0; i < DRIVER_PROPERTIES_PROPERTY_ONLY.length; i++) { - String sProp = DRIVER_PROPERTIES_PROPERTY_ONLY[i].getName(); + 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 @@ -520,14 +520,14 @@ static String getNormalizedPropertyName(String name, if (null == name) return name; - for (int i = 0; i < driverPropertiesSynonyms.length; i++) { - if (driverPropertiesSynonyms[i][0].equalsIgnoreCase(name)) { - return driverPropertiesSynonyms[i][1]; + for (String[] driverPropertiesSynonym : driverPropertiesSynonyms) { + if (driverPropertiesSynonym[0].equalsIgnoreCase(name)) { + return driverPropertiesSynonym[1]; } } - for (int i = 0; i < DRIVER_PROPERTIES.length; i++) { - if (DRIVER_PROPERTIES[i].getName().equalsIgnoreCase(name)) { - return DRIVER_PROPERTIES[i].getName(); + for (SQLServerDriverPropertyInfo DRIVER_PROPERTY : DRIVER_PROPERTIES) { + if (DRIVER_PROPERTY.getName().equalsIgnoreCase(name)) { + return DRIVER_PROPERTY.getName(); } } @@ -549,9 +549,9 @@ static String getPropertyOnlyName(String name, if (null == name) return name; - for (int i = 0; i < DRIVER_PROPERTIES_PROPERTY_ONLY.length; i++) { - if (DRIVER_PROPERTIES_PROPERTY_ONLY[i].getName().equalsIgnoreCase(name)) { - return DRIVER_PROPERTIES_PROPERTY_ONLY[i].getName(); + for (SQLServerDriverPropertyInfo aDRIVER_PROPERTIES_PROPERTY_ONLY : DRIVER_PROPERTIES_PROPERTY_ONLY) { + if (aDRIVER_PROPERTIES_PROPERTY_ONLY.getName().equalsIgnoreCase(name)) { + return aDRIVER_PROPERTIES_PROPERTY_ONLY.getName(); } } diff --git a/src/main/java/com/microsoft/sqlserver/jdbc/SQLServerException.java b/src/main/java/com/microsoft/sqlserver/jdbc/SQLServerException.java index 2f4dfd06ca..e8ed55d5ab 100644 --- a/src/main/java/com/microsoft/sqlserver/jdbc/SQLServerException.java +++ b/src/main/java/com/microsoft/sqlserver/jdbc/SQLServerException.java @@ -103,14 +103,12 @@ final void setDriverErrorCode(int value) { if (exLogger.isLoggable(Level.FINE)) { StringBuilder sb = new StringBuilder(100); StackTraceElement st[] = this.getStackTrace(); - for (int i = 0; i < st.length; i++) - sb.append(st[i].toString()); + for (StackTraceElement aSt : st) sb.append(aSt.toString()); Throwable t = this.getCause(); if (t != null) { sb.append("\n caused by " + t + "\n"); StackTraceElement tst[] = t.getStackTrace(); - for (int i = 0; i < tst.length; i++) - sb.append(tst[i].toString()); + for (StackTraceElement aTst : tst) sb.append(aTst.toString()); } exLogger.fine(sb.toString()); } diff --git a/src/main/java/com/microsoft/sqlserver/jdbc/SQLServerPreparedStatement.java b/src/main/java/com/microsoft/sqlserver/jdbc/SQLServerPreparedStatement.java index 2b9350e490..e9ee9f6e8b 100644 --- a/src/main/java/com/microsoft/sqlserver/jdbc/SQLServerPreparedStatement.java +++ b/src/main/java/com/microsoft/sqlserver/jdbc/SQLServerPreparedStatement.java @@ -2417,10 +2417,9 @@ public int[] executeBatch() throws SQLServerException, BatchUpdateException { // // OUT and INOUT parameter checking is done here, before executing the batch. If any // OUT or INOUT are present, the entire batch fails. - for (int batch = 0; batch < batchParamValues.size(); ++batch) { - Parameter paramValues[] = batchParamValues.get(batch); - for (int param = 0; param < paramValues.length; ++param) { - if (paramValues[param].isOutput()) { + for (Parameter[] paramValues : batchParamValues) { + for (Parameter paramValue : paramValues) { + if (paramValue.isOutput()) { throw new BatchUpdateException(SQLServerException.getErrString("R_outParamsNotPermittedinBatch"), null, 0, null); } } @@ -2475,10 +2474,9 @@ public long[] executeLargeBatch() throws SQLServerException, BatchUpdateExceptio // // OUT and INOUT parameter checking is done here, before executing the batch. If any // OUT or INOUT are present, the entire batch fails. - for (int batch = 0; batch < batchParamValues.size(); ++batch) { - Parameter paramValues[] = batchParamValues.get(batch); - for (int param = 0; param < paramValues.length; ++param) { - if (paramValues[param].isOutput()) { + for (Parameter[] paramValues : batchParamValues) { + for (Parameter paramValue : paramValues) { + if (paramValue.isOutput()) { throw new BatchUpdateException(SQLServerException.getErrString("R_outParamsNotPermittedinBatch"), null, 0, null); } } @@ -2573,8 +2571,8 @@ final void doExecutePreparedStatementBatch(PrepStmtBatchExecCmd batchCommand) th buildPreparedStrings(batchParam, true); // Save the crypto metadata retrieved for the first batch. We will re-use these for the rest of the batches. - for (int i = 0; i < batchParam.length; i++) { - cryptoMetaBatch.add(batchParam[i].cryptoMeta); + for (Parameter aBatchParam : batchParam) { + cryptoMetaBatch.add(aBatchParam.cryptoMeta); } } diff --git a/src/main/java/com/microsoft/sqlserver/jdbc/SQLServerResultSet.java b/src/main/java/com/microsoft/sqlserver/jdbc/SQLServerResultSet.java index 936e4727e4..e937b27c36 100644 --- a/src/main/java/com/microsoft/sqlserver/jdbc/SQLServerResultSet.java +++ b/src/main/java/com/microsoft/sqlserver/jdbc/SQLServerResultSet.java @@ -1796,8 +1796,7 @@ private void cancelInsert() { /** Clear any updated column values for the current row in the result set. */ final void clearColumnsValues() { int l = columns.length; - for (int i = 0; i < l; i++) - columns[i].cancelUpdates(); + for (Column column : columns) column.cancelUpdates(); } /* L0 */ public SQLWarning getWarnings() throws SQLServerException { @@ -5684,14 +5683,14 @@ final boolean doExecute() throws SQLServerException { // If no values were set for any columns and no columns are updatable, // then the table name cannot be determined, so error. Column tableColumn = null; - for (int i = 0; i < columns.length; i++) { - if (columns[i].hasUpdates()) { - tableColumn = columns[i]; + for (Column column : columns) { + if (column.hasUpdates()) { + tableColumn = column; break; } - if (null == tableColumn && columns[i].isUpdatable()) - tableColumn = columns[i]; + if (null == tableColumn && column.isUpdatable()) + tableColumn = column; } if (null == tableColumn) { @@ -5726,8 +5725,7 @@ private void doInsertRowRPC(TDSCommand command, if (hasUpdatedColumns()) { tdsWriter.writeRPCStringUnicode(tableName); - for (int i = 0; i < columns.length; i++) - columns[i].sendByRPC(tdsWriter, stmt.connection); + for (Column column : columns) column.sendByRPC(tdsWriter, stmt.connection); } else { tdsWriter.writeRPCStringUnicode(""); @@ -5801,16 +5799,15 @@ private void doUpdateRowRPC(TDSCommand command) throws SQLServerException { assert hasUpdatedColumns(); - for (int i = 0; i < columns.length; i++) - columns[i].sendByRPC(tdsWriter, stmt.connection); + for (Column column : columns) column.sendByRPC(tdsWriter, stmt.connection); TDSParser.parse(command.startResponse(), command.getLogContext()); } /** Determines whether there are updated columns in this result set. */ final boolean hasUpdatedColumns() { - for (int i = 0; i < columns.length; i++) - if (columns[i].hasUpdates()) + for (Column column : columns) + if (column.hasUpdates()) return true; return false; diff --git a/src/main/java/com/microsoft/sqlserver/jdbc/StreamColInfo.java b/src/main/java/com/microsoft/sqlserver/jdbc/StreamColInfo.java index a5fcc1b2ff..e0d7eaeb5c 100644 --- a/src/main/java/com/microsoft/sqlserver/jdbc/StreamColInfo.java +++ b/src/main/java/com/microsoft/sqlserver/jdbc/StreamColInfo.java @@ -36,9 +36,7 @@ int applyTo(Column[] columns) throws SQLServerException { // Read and apply the column info for each column TDSReaderMark currentMark = tdsReader.mark(); tdsReader.reset(colInfoMark); - for (int i = 0; i < columns.length; i++) { - Column col = columns[i]; - + for (Column col : columns) { // Ignore the column number, per TDS spec. // Column info is returned for each column, ascending by column index, // so iterating through the column info is sufficient. diff --git a/src/main/java/com/microsoft/sqlserver/jdbc/StreamTabName.java b/src/main/java/com/microsoft/sqlserver/jdbc/StreamTabName.java index 1dc2a50851..6690990b1d 100644 --- a/src/main/java/com/microsoft/sqlserver/jdbc/StreamTabName.java +++ b/src/main/java/com/microsoft/sqlserver/jdbc/StreamTabName.java @@ -44,9 +44,7 @@ void applyTo(Column[] columns, tableNames[i] = tdsReader.readSQLIdentifier(); // Apply the table names to their appropriate columns - for (int i = 0; i < columns.length; i++) { - Column col = columns[i]; - + for (Column col : columns) { if (col.getTableNum() > 0) col.setTableName(tableNames[col.getTableNum() - 1]); } diff --git a/src/main/java/com/microsoft/sqlserver/jdbc/TVP.java b/src/main/java/com/microsoft/sqlserver/jdbc/TVP.java index 5113f1fc05..6088b75957 100644 --- a/src/main/java/com/microsoft/sqlserver/jdbc/TVP.java +++ b/src/main/java/com/microsoft/sqlserver/jdbc/TVP.java @@ -157,9 +157,7 @@ void populateMetadataFromDataTable() throws SQLServerException { if (null == dataTableMetaData || dataTableMetaData.isEmpty()) { throw new SQLServerException(SQLServerException.getErrString("R_TVPEmptyMetadata"), null); } - Iterator> columnsIterator = dataTableMetaData.entrySet().iterator(); - while (columnsIterator.hasNext()) { - Map.Entry pair = columnsIterator.next(); + for (Entry pair : dataTableMetaData.entrySet()) { // duplicate column names for the dataTable will be checked in the SQLServerDataTable. columnMetadata.put(pair.getKey(), new SQLServerMetaData(pair.getValue().columnName, pair.getValue().javaSqlType, pair.getValue().precision, pair.getValue().scale)); @@ -200,9 +198,7 @@ void validateOrderProperty() throws SQLServerException { int maxSortOrdinal = -1; int sortCount = 0; - Iterator> columnsIterator = columnMetadata.entrySet().iterator(); - while (columnsIterator.hasNext()) { - Map.Entry columnPair = columnsIterator.next(); + for (Entry columnPair : columnMetadata.entrySet()) { SQLServerSortOrder columnSortOrder = columnPair.getValue().sortOrder; int columnSortOrdinal = columnPair.getValue().sortOrdinal; @@ -210,13 +206,13 @@ void validateOrderProperty() throws SQLServerException { // check if there's no way sort order could be monotonically increasing if (columnCount <= columnSortOrdinal) { MessageFormat form = new MessageFormat(SQLServerException.getErrString("R_TVPSortOrdinalGreaterThanFieldCount")); - throw new SQLServerException(form.format(new Object[] {columnSortOrdinal, columnPair.getKey()}), null, 0, null); + throw new SQLServerException(form.format(new Object[]{columnSortOrdinal, columnPair.getKey()}), null, 0, null); } // Check to make sure we haven't seen this ordinal before if (sortOrdinalSpecified[columnSortOrdinal]) { MessageFormat form = new MessageFormat(SQLServerException.getErrString("R_TVPDuplicateSortOrdinal")); - throw new SQLServerException(form.format(new Object[] {columnSortOrdinal}), null, 0, null); + throw new SQLServerException(form.format(new Object[]{columnSortOrdinal}), null, 0, null); } sortOrdinalSpecified[columnSortOrdinal] = true; diff --git a/src/main/java/com/microsoft/sqlserver/jdbc/Util.java b/src/main/java/com/microsoft/sqlserver/jdbc/Util.java index d630d6e48a..db10ebce1e 100644 --- a/src/main/java/com/microsoft/sqlserver/jdbc/Util.java +++ b/src/main/java/com/microsoft/sqlserver/jdbc/Util.java @@ -626,8 +626,8 @@ static String byteToHexDisplayString(byte[] b) { int hexVal; StringBuilder sb = new StringBuilder(b.length * 2 + 2); sb.append("0x"); - for (int i = 0; i < b.length; i++) { - hexVal = b[i] & 0xFF; + for (byte aB : b) { + hexVal = aB & 0xFF; sb.append(hexChars[(hexVal & 0xF0) >> 4]); sb.append(hexChars[(hexVal & 0x0F)]); } diff --git a/src/main/java/mssql/googlecode/concurrentlinkedhashmap/Weighers.java b/src/main/java/mssql/googlecode/concurrentlinkedhashmap/Weighers.java index 29194547df..2dd4531d0c 100644 --- a/src/main/java/mssql/googlecode/concurrentlinkedhashmap/Weighers.java +++ b/src/main/java/mssql/googlecode/concurrentlinkedhashmap/Weighers.java @@ -247,10 +247,9 @@ public int weightOf(Iterable values) { return ((Collection) values).size(); } int size = 0; - for (Iterator i = values.iterator(); i.hasNext();) { - i.next(); - size++; - } + for (Object value : values) { + size++; + } return size; } } diff --git a/src/test/java/com/microsoft/sqlserver/jdbc/bulkCopy/BulkCopyConnectionTest.java b/src/test/java/com/microsoft/sqlserver/jdbc/bulkCopy/BulkCopyConnectionTest.java index 0e2718fe34..7075fac757 100644 --- a/src/test/java/com/microsoft/sqlserver/jdbc/bulkCopy/BulkCopyConnectionTest.java +++ b/src/test/java/com/microsoft/sqlserver/jdbc/bulkCopy/BulkCopyConnectionTest.java @@ -186,10 +186,10 @@ private List createTestData_testBulkCopyOption() { Class bulkOptions = SQLServerBulkCopyOptions.class; Method[] methods = bulkOptions.getDeclaredMethods(); - for (int i = 0; i < methods.length; i++) { + for (Method method : methods) { // set bulkCopy Option if return is void and input is boolean - if (0 != methods[i].getParameterTypes().length && boolean.class == methods[i].getParameterTypes()[0]) { + if (0 != method.getParameterTypes().length && boolean.class == method.getParameterTypes()[0]) { try { BulkCopyTestWrapper bulkWrapper = new BulkCopyTestWrapper(connectionString); @@ -197,16 +197,15 @@ private List createTestData_testBulkCopyOption() { bulkWrapper.setUsingConnection((0 == ThreadLocalRandom.current().nextInt(2)) ? true : false); SQLServerBulkCopyOptions option = new SQLServerBulkCopyOptions(); - if (!(methods[i].getName()).equalsIgnoreCase("setUseInternalTransaction") - && !(methods[i].getName()).equalsIgnoreCase("setAllowEncryptedValueModifications")) { - methods[i].invoke(option, true); + if (!(method.getName()).equalsIgnoreCase("setUseInternalTransaction") + && !(method.getName()).equalsIgnoreCase("setAllowEncryptedValueModifications")) { + method.invoke(option, true); bulkWrapper.useBulkCopyOptions(true); bulkWrapper.setBulkOptions(option); - bulkWrapper.testName += methods[i].getName() + ";"; + bulkWrapper.testName += method.getName() + ";"; testData.add(bulkWrapper); } - } - catch (Exception ex) { + } catch (Exception ex) { fail(ex.getMessage()); } } diff --git a/src/test/java/com/microsoft/sqlserver/jdbc/connection/ConnectionDriverTest.java b/src/test/java/com/microsoft/sqlserver/jdbc/connection/ConnectionDriverTest.java index d6d2c5cb41..9a1e73ac90 100644 --- a/src/test/java/com/microsoft/sqlserver/jdbc/connection/ConnectionDriverTest.java +++ b/src/test/java/com/microsoft/sqlserver/jdbc/connection/ConnectionDriverTest.java @@ -65,28 +65,28 @@ public void testConnectionDriver() throws SQLServerException { url.append("jdbc:sqlserver://" + randomServer + ";packetSize=512;"); // test defaults DriverPropertyInfo[] infoArray = d.getPropertyInfo(url.toString(), info); - for (int i = 0; i < infoArray.length; i++) { - logger.fine(infoArray[i].name); - logger.fine(infoArray[i].description); - logger.fine(new Boolean(infoArray[i].required).toString()); - logger.fine(infoArray[i].value); + for (DriverPropertyInfo anInfoArray1 : infoArray) { + logger.fine(anInfoArray1.name); + logger.fine(anInfoArray1.description); + logger.fine(new Boolean(anInfoArray1.required).toString()); + logger.fine(anInfoArray1.value); } url.append("encrypt=true; trustStore=someStore; trustStorePassword=somepassword;"); url.append("hostNameInCertificate=someHost; trustServerCertificate=true"); infoArray = d.getPropertyInfo(url.toString(), info); - for (int i = 0; i < infoArray.length; i++) { - if (infoArray[i].name.equals("encrypt")) { - assertTrue(infoArray[i].value.equals("true"), "Values are different"); + for (DriverPropertyInfo anInfoArray : infoArray) { + if (anInfoArray.name.equals("encrypt")) { + assertTrue(anInfoArray.value.equals("true"), "Values are different"); } - if (infoArray[i].name.equals("trustStore")) { - assertTrue(infoArray[i].value.equals("someStore"), "Values are different"); + if (anInfoArray.name.equals("trustStore")) { + assertTrue(anInfoArray.value.equals("someStore"), "Values are different"); } - if (infoArray[i].name.equals("trustStorePassword")) { - assertTrue(infoArray[i].value.equals("somepassword"), "Values are different"); + if (anInfoArray.name.equals("trustStorePassword")) { + assertTrue(anInfoArray.value.equals("somepassword"), "Values are different"); } - if (infoArray[i].name.equals("hostNameInCertificate")) { - assertTrue(infoArray[i].value.equals("someHost"), "Values are different"); + if (anInfoArray.name.equals("hostNameInCertificate")) { + assertTrue(anInfoArray.value.equals("someHost"), "Values are different"); } } } diff --git a/src/test/java/com/microsoft/sqlserver/jdbc/unit/lobs/lobsTest.java b/src/test/java/com/microsoft/sqlserver/jdbc/unit/lobs/lobsTest.java index 9a66905a54..69a8f07224 100644 --- a/src/test/java/com/microsoft/sqlserver/jdbc/unit/lobs/lobsTest.java +++ b/src/test/java/com/microsoft/sqlserver/jdbc/unit/lobs/lobsTest.java @@ -101,10 +101,10 @@ public Collection executeDynamicTests() { List isResultSetTypes = new ArrayList<>(Arrays.asList(true, false)); Collection dynamicTests = new ArrayList<>(); - for (int i = 0; i < classes.size(); i++) { - for (int j = 0; j < isResultSetTypes.size(); j++) { - final Class lobClass = classes.get(i); - final boolean isResultSet = isResultSetTypes.get(j); + for (Class aClass : classes) { + for (Boolean isResultSetType : isResultSetTypes) { + final Class lobClass = aClass; + final boolean isResultSet = isResultSetType; Executable exec = new Executable() { @Override public void execute() throws Throwable { @@ -572,8 +572,8 @@ private static DBTable createTable(DBTable table, DBStatement stmt = new DBConnection(connectionString).createStatement(); table = new DBTable(false); - for (int i = 0; i < types.length; i++) { - SqlType type = Utils.find(types[i]); + for (String type1 : types) { + SqlType type = Utils.find(type1); table.addColumn(type); } diff --git a/src/test/java/com/microsoft/sqlserver/jdbc/unit/statement/RegressionTest.java b/src/test/java/com/microsoft/sqlserver/jdbc/unit/statement/RegressionTest.java index 7748e998b2..2eec0cd70a 100644 --- a/src/test/java/com/microsoft/sqlserver/jdbc/unit/statement/RegressionTest.java +++ b/src/test/java/com/microsoft/sqlserver/jdbc/unit/statement/RegressionTest.java @@ -168,8 +168,8 @@ public void testUpdateQuery() throws SQLException { sql = "update " + tableName + " SET c1= ? where PK =1"; for (int i = 1; i <= rows; i++) { pstmt = (SQLServerPreparedStatement)con.prepareStatement(sql, ResultSet.TYPE_FORWARD_ONLY, ResultSet.CONCUR_READ_ONLY); - for (int t = 0; t < targets.length; t++) { - pstmt.setObject(1, 5 + i, targets[t]); + for (JDBCType target : targets) { + pstmt.setObject(1, 5 + i, target); pstmt.executeUpdate(); } } diff --git a/src/test/java/com/microsoft/sqlserver/testframework/DBCoercion.java b/src/test/java/com/microsoft/sqlserver/testframework/DBCoercion.java index e4cea5a53b..e367a94b87 100644 --- a/src/test/java/com/microsoft/sqlserver/testframework/DBCoercion.java +++ b/src/test/java/com/microsoft/sqlserver/testframework/DBCoercion.java @@ -46,8 +46,7 @@ public DBCoercion(Class type, int[] tempflags) { name = type.toString(); this.type = type; - for (int i = 0; i < tempflags.length; i++) - flags.set(tempflags[i]); + for (int tempflag : tempflags) flags.set(tempflag); } /** diff --git a/src/test/java/com/microsoft/sqlserver/testframework/DBItems.java b/src/test/java/com/microsoft/sqlserver/testframework/DBItems.java index a64386ac45..be2999a1b5 100644 --- a/src/test/java/com/microsoft/sqlserver/testframework/DBItems.java +++ b/src/test/java/com/microsoft/sqlserver/testframework/DBItems.java @@ -22,8 +22,7 @@ public DBItems() { } public DBCoercion find(Class type) { - for (int i = 0; i < coercionsList.size(); i++) { - DBCoercion item = coercionsList.get(i); + for (DBCoercion item : coercionsList) { if (item.type() == type) return item; } diff --git a/src/test/java/com/microsoft/sqlserver/testframework/Utils.java b/src/test/java/com/microsoft/sqlserver/testframework/Utils.java index 8db5e96e53..3c3509c206 100644 --- a/src/test/java/com/microsoft/sqlserver/testframework/Utils.java +++ b/src/test/java/com/microsoft/sqlserver/testframework/Utils.java @@ -131,8 +131,7 @@ public static String getConfiguredProperty(String key, public static SqlType find(Class javatype) { if (null != types) { types(); - for (int i = 0; i < types.size(); i++) { - SqlType type = types.get(i); + for (SqlType type : types) { if (type.getType() == javatype) return type; } @@ -149,8 +148,7 @@ public static SqlType find(String name) { if (null == types) types(); if (null != types) { - for (int i = 0; i < types.size(); i++) { - SqlType type = types.get(i); + for (SqlType type : types) { if (type.getName().equalsIgnoreCase(name)) return type; }