diff --git a/src/main/java/com/microsoft/sqlserver/jdbc/DataTypes.java b/src/main/java/com/microsoft/sqlserver/jdbc/DataTypes.java index d91c272aa..58ba0291e 100644 --- a/src/main/java/com/microsoft/sqlserver/jdbc/DataTypes.java +++ b/src/main/java/com/microsoft/sqlserver/jdbc/DataTypes.java @@ -72,6 +72,7 @@ enum TDSType { private final int intValue; private static final int MAXELEMENTS = 256; + private static final TDSType[] VALUES = values(); private static final TDSType valuesTypes[] = new TDSType[MAXELEMENTS]; byte byteValue() { @@ -79,7 +80,7 @@ byte byteValue() { } static { - for (TDSType s : values()) + for (TDSType s : VALUES) valuesTypes[s.intValue] = s; } @@ -152,6 +153,7 @@ enum SSType { final Category category; private final String name; private final JDBCType jdbcType; + private static final SSType[] VALUES = values(); static final BigDecimal MAX_VALUE_MONEY = new BigDecimal("922337203685477.5807"); static final BigDecimal MIN_VALUE_MONEY = new BigDecimal("-922337203685477.5808"); @@ -173,7 +175,7 @@ final JDBCType getJDBCType() { } static SSType of(String typeName) throws SQLServerException { - for (SSType ssType : values()) + for (SSType ssType : VALUES) if (ssType.name.equalsIgnoreCase(typeName)) return ssType; @@ -201,7 +203,9 @@ enum Category { TIMESTAMP, UDT, SQL_VARIANT, - XML + XML; + + private static final Category[] VALUES = values(); } enum GetterConversion { @@ -265,6 +269,7 @@ enum GetterConversion { private final SSType.Category from; private final EnumSet to; + private static final GetterConversion[] VALUES = values(); private GetterConversion(SSType.Category from, EnumSet to) { this.from = from; @@ -275,10 +280,10 @@ private GetterConversion(SSType.Category from, EnumSet to) { SSType.Category.class); static { - for (SSType.Category category : SSType.Category.values()) + for (SSType.Category category : SSType.Category.VALUES) conversionMap.put(category, EnumSet.noneOf(JDBCType.Category.class)); - for (GetterConversion conversion : values()) + for (GetterConversion conversion : VALUES) conversionMap.get(conversion.from).addAll(conversion.to); } @@ -473,6 +478,7 @@ JDBCType getJDBCType(SSType ssType, JDBCType jdbcTypeFromApp) { private final Class javaClass; private final JDBCType jdbcTypeFromJavaType; private static double jvmVersion = 0.0; + private static final JavaType[] VALUES = values(); private JavaType(Class javaClass, JDBCType jdbcTypeFromJavaType) { this.javaClass = javaClass; @@ -521,7 +527,7 @@ static JavaType of(Object obj) { if (obj instanceof SQLServerDataTable || obj instanceof ResultSet || obj instanceof ISQLServerDataRecord) return JavaType.TVP; if (null != obj) { - for (JavaType javaType : values()) + for (JavaType javaType : VALUES) // if JVM version is prior to Java 8, the javaClass variable can be // null if the java type is introduced in Java 8 if (null != javaType.javaClass) { @@ -578,6 +584,7 @@ enum SetterConversionAE { private final EnumSet to; private final JavaType from; + private static final SetterConversionAE[] VALUES = values(); private SetterConversionAE(JavaType from, EnumSet to) { this.from = from; @@ -587,10 +594,10 @@ private SetterConversionAE(JavaType from, EnumSet to) { private static final EnumMap> setterConversionAEMap = new EnumMap<>(JavaType.class); static { - for (JavaType javaType : JavaType.values()) + for (JavaType javaType : JavaType.VALUES) setterConversionAEMap.put(javaType, EnumSet.noneOf(JDBCType.class)); - for (SetterConversionAE conversion : values()) + for (SetterConversionAE conversion : VALUES) setterConversionAEMap.get(conversion.from).addAll(conversion.to); } @@ -668,6 +675,7 @@ enum JDBCType { final Category category; private final int intValue; private final String className; + private static final JDBCType[] VALUES = values(); final String className() { return className; @@ -711,7 +719,9 @@ enum Category { GUID, SQL_VARIANT, GEOMETRY, - GEOGRAPHY + GEOGRAPHY; + + private static final Category[] VALUES = values(); } // This SetterConversion enum is based on the Category enum @@ -786,6 +796,7 @@ enum SetterConversion { private final JDBCType.Category from; private final EnumSet to; + private static final SetterConversion[] VALUES = values(); private SetterConversion(JDBCType.Category from, EnumSet to) { this.from = from; @@ -796,10 +807,10 @@ private SetterConversion(JDBCType.Category from, EnumSet to) JDBCType.Category.class); static { - for (JDBCType.Category category : JDBCType.Category.values()) + for (JDBCType.Category category : JDBCType.Category.VALUES) conversionMap.put(category, EnumSet.noneOf(JDBCType.Category.class)); - for (SetterConversion conversion : values()) + for (SetterConversion conversion : VALUES) conversionMap.get(conversion.from).addAll(conversion.to); } @@ -885,6 +896,7 @@ enum UpdaterConversion { private final JDBCType.Category from; private final EnumSet to; + private static final UpdaterConversion[] VALUES = values(); private UpdaterConversion(JDBCType.Category from, EnumSet to) { this.from = from; @@ -895,10 +907,10 @@ private UpdaterConversion(JDBCType.Category from, EnumSet to) { JDBCType.Category.class); static { - for (JDBCType.Category category : JDBCType.Category.values()) + for (JDBCType.Category category : JDBCType.Category.VALUES) conversionMap.put(category, EnumSet.noneOf(SSType.Category.class)); - for (UpdaterConversion conversion : values()) + for (UpdaterConversion conversion : VALUES) conversionMap.get(conversion.from).addAll(conversion.to); } @@ -912,7 +924,7 @@ boolean convertsTo(SSType ssType) { } static JDBCType of(int intValue) throws SQLServerException { - for (JDBCType jdbcType : values()) + for (JDBCType jdbcType : VALUES) if (jdbcType.intValue == intValue) return jdbcType; @@ -1064,6 +1076,7 @@ enum NormalizationAE { private final JDBCType from; private final EnumSet to; + private static final NormalizationAE[] VALUES = values(); private NormalizationAE(JDBCType from, EnumSet to) { this.from = from; @@ -1073,10 +1086,10 @@ private NormalizationAE(JDBCType from, EnumSet to) { private static final EnumMap> normalizationMapAE = new EnumMap<>(JDBCType.class); static { - for (JDBCType jdbcType : JDBCType.values()) + for (JDBCType jdbcType : JDBCType.VALUES) normalizationMapAE.put(jdbcType, EnumSet.noneOf(SSType.class)); - for (NormalizationAE conversion : values()) + for (NormalizationAE conversion : VALUES) normalizationMapAE.get(conversion.from).addAll(conversion.to); } diff --git a/src/main/java/com/microsoft/sqlserver/jdbc/InternalSpatialDatatype.java b/src/main/java/com/microsoft/sqlserver/jdbc/InternalSpatialDatatype.java index dfbf6af68..ebd4404b8 100644 --- a/src/main/java/com/microsoft/sqlserver/jdbc/InternalSpatialDatatype.java +++ b/src/main/java/com/microsoft/sqlserver/jdbc/InternalSpatialDatatype.java @@ -24,6 +24,7 @@ public enum InternalSpatialDatatype { private byte typeCode; private String typeName; + private static final InternalSpatialDatatype[] VALUES = values(); private InternalSpatialDatatype(byte typeCode, String typeName) { this.typeCode = typeCode; @@ -39,7 +40,7 @@ String getTypeName() { } static InternalSpatialDatatype valueOf(byte typeCode) { - for (InternalSpatialDatatype internalType : values()) { + for (InternalSpatialDatatype internalType : VALUES) { if (internalType.typeCode == typeCode) { return internalType; } diff --git a/src/main/java/com/microsoft/sqlserver/jdbc/SQLServerEncryptionType.java b/src/main/java/com/microsoft/sqlserver/jdbc/SQLServerEncryptionType.java index 3205d471c..289215db2 100644 --- a/src/main/java/com/microsoft/sqlserver/jdbc/SQLServerEncryptionType.java +++ b/src/main/java/com/microsoft/sqlserver/jdbc/SQLServerEncryptionType.java @@ -19,6 +19,7 @@ enum SQLServerEncryptionType { PlainText((byte) 0); final byte value; + private static final SQLServerEncryptionType[] VALUES = values(); SQLServerEncryptionType(byte val) { this.value = val; @@ -29,7 +30,7 @@ byte getValue() { } static SQLServerEncryptionType of(byte val) throws SQLServerException { - for (SQLServerEncryptionType type : values()) + for (SQLServerEncryptionType type : VALUES) if (val == type.value) return type; diff --git a/src/samples/adaptive/src/main/java/ReadLargeData.java b/src/samples/adaptive/src/main/java/ReadLargeData.java index 92778da92..dc5e8d45d 100644 --- a/src/samples/adaptive/src/main/java/ReadLargeData.java +++ b/src/samples/adaptive/src/main/java/ReadLargeData.java @@ -12,6 +12,7 @@ import java.sql.PreparedStatement; import java.sql.ResultSet; import java.sql.SQLException; + import com.microsoft.sqlserver.jdbc.SQLServerStatement; /** diff --git a/src/samples/datatypes/src/main/java/SpatialDataTypes.java b/src/samples/datatypes/src/main/java/SpatialDataTypes.java index 8a3d145fe..0cc5305f7 100644 --- a/src/samples/datatypes/src/main/java/SpatialDataTypes.java +++ b/src/samples/datatypes/src/main/java/SpatialDataTypes.java @@ -9,6 +9,7 @@ import java.sql.Connection; import java.sql.SQLException; import java.sql.Statement; + import com.microsoft.sqlserver.jdbc.Geography; import com.microsoft.sqlserver.jdbc.Geometry; import com.microsoft.sqlserver.jdbc.SQLServerDataSource; diff --git a/src/test/java/com/microsoft/sqlserver/jdbc/tvp/SQLServerDataTableTest.java b/src/test/java/com/microsoft/sqlserver/jdbc/tvp/SQLServerDataTableTest.java index 88f36060e..fa8bb0c14 100644 --- a/src/test/java/com/microsoft/sqlserver/jdbc/tvp/SQLServerDataTableTest.java +++ b/src/test/java/com/microsoft/sqlserver/jdbc/tvp/SQLServerDataTableTest.java @@ -4,6 +4,7 @@ import java.math.BigDecimal; import java.sql.Types; + import org.junit.jupiter.api.Test; import org.junit.platform.runner.JUnitPlatform; import org.junit.runner.RunWith;