From be088703ae5561ebf0e39536b37b11fda472517a Mon Sep 17 00:00:00 2001 From: ptiurin Date: Fri, 18 Oct 2024 11:47:27 +0100 Subject: [PATCH] rename --- .../FireboltPreparedStatement.java | 6 ++--- .../type/JavaTypeToFireboltSQLString.java | 22 +++++++++---------- ...ireboltVersion.java => ParserVersion.java} | 2 +- .../type/JavaTypeToFireboltSQLStringTest.java | 12 +++++----- 4 files changed, 21 insertions(+), 21 deletions(-) rename src/main/java/com/firebolt/jdbc/type/{FireboltVersion.java => ParserVersion.java} (64%) diff --git a/src/main/java/com/firebolt/jdbc/statement/preparedstatement/FireboltPreparedStatement.java b/src/main/java/com/firebolt/jdbc/statement/preparedstatement/FireboltPreparedStatement.java index 62a4e4fa..61293c15 100644 --- a/src/main/java/com/firebolt/jdbc/statement/preparedstatement/FireboltPreparedStatement.java +++ b/src/main/java/com/firebolt/jdbc/statement/preparedstatement/FireboltPreparedStatement.java @@ -13,7 +13,7 @@ import com.firebolt.jdbc.statement.StatementInfoWrapper; import com.firebolt.jdbc.statement.StatementUtil; import com.firebolt.jdbc.statement.rawstatement.RawStatementWrapper; -import com.firebolt.jdbc.type.FireboltVersion; +import com.firebolt.jdbc.type.ParserVersion; import com.firebolt.jdbc.type.JavaTypeToFireboltSQLString; import com.firebolt.jdbc.util.InputStreamUtil; import lombok.CustomLog; @@ -160,7 +160,7 @@ public void setString(int parameterIndex, String x) throws SQLException { if (this.getConnection().getClass() == FireboltConnectionUserPassword.class){ // Old Firebolt required escaping additional characters in the string providedParameters.put(parameterIndex, - JavaTypeToFireboltSQLString.STRING.transform(x, FireboltVersion.LEGACY)); + JavaTypeToFireboltSQLString.STRING.transform(x, ParserVersion.LEGACY)); } else { providedParameters.put(parameterIndex, JavaTypeToFireboltSQLString.STRING.transform(x)); } @@ -210,7 +210,7 @@ public void setObject(int parameterIndex, Object x, int targetSqlType) throws SQ // We don't know the targetSqlType, so we let JavaTypeToFireboltSQLString deal // with legacy conversion providedParameters.put(parameterIndex, - JavaTypeToFireboltSQLString.transformAny(x, targetSqlType, FireboltVersion.LEGACY)); + JavaTypeToFireboltSQLString.transformAny(x, targetSqlType, ParserVersion.LEGACY)); } else { providedParameters.put(parameterIndex, JavaTypeToFireboltSQLString.transformAny(x, targetSqlType)); } diff --git a/src/main/java/com/firebolt/jdbc/type/JavaTypeToFireboltSQLString.java b/src/main/java/com/firebolt/jdbc/type/JavaTypeToFireboltSQLString.java index 8057a92d..cb3db7ba 100644 --- a/src/main/java/com/firebolt/jdbc/type/JavaTypeToFireboltSQLString.java +++ b/src/main/java/com/firebolt/jdbc/type/JavaTypeToFireboltSQLString.java @@ -35,7 +35,7 @@ public enum JavaTypeToFireboltSQLString { UUID(java.util.UUID.class, Object::toString), BYTE(Byte.class, value -> Byte.toString(((Number) value).byteValue())), SHORT(Short.class, value -> Short.toString(((Number) value).shortValue())), - STRING(String.class, getSQLStringValueOfString(FireboltVersion.CURRENT), getSQLStringValueOfStringVersioned()), + STRING(String.class, getSQLStringValueOfString(ParserVersion.CURRENT), getSQLStringValueOfStringVersioned()), LONG(Long.class, value -> Long.toString(((Number)value).longValue())), INTEGER(Integer.class, value -> Integer.toString(((Number)value).intValue())), BIG_INTEGER(BigInteger.class, value -> value instanceof BigInteger ? value.toString() : Long.toString(((Number)value).longValue())), @@ -103,31 +103,31 @@ public enum JavaTypeToFireboltSQLString { } public static String transformAny(Object object) throws SQLException { - return transformAny(object, FireboltVersion.CURRENT); + return transformAny(object, ParserVersion.CURRENT); } - public static String transformAny(Object object, FireboltVersion version) throws SQLException { + public static String transformAny(Object object, ParserVersion version) throws SQLException { return transformAny(object, () -> getType(object), version); } public static String transformAny(Object object, int sqlType) throws SQLException { - return transformAny(object, sqlType, FireboltVersion.CURRENT); + return transformAny(object, sqlType, ParserVersion.CURRENT); } - public static String transformAny(Object object, int sqlType, FireboltVersion version) throws SQLException { + public static String transformAny(Object object, int sqlType, ParserVersion version) throws SQLException { return transformAny(object, () -> getType(sqlType), version); } - private static String transformAny(Object object, CheckedSupplier> classSupplier, FireboltVersion version) throws SQLException { + private static String transformAny(Object object, CheckedSupplier> classSupplier, ParserVersion version) throws SQLException { return object == null ? NULL_VALUE : transformAny(object, classSupplier.get(), version); } - private static String transformAny(Object object, Class objectType, FireboltVersion version) throws SQLException { + private static String transformAny(Object object, Class objectType, ParserVersion version) throws SQLException { JavaTypeToFireboltSQLString converter = Optional.ofNullable(classToType.get(objectType)) .orElseThrow(() -> new FireboltException( format("Cannot convert type %s. The type is not supported.", objectType), TYPE_NOT_SUPPORTED)); - if (version == FireboltVersion.LEGACY && object instanceof String) { + if (version == ParserVersion.LEGACY && object instanceof String) { return converter.transform(object, version); } return converter.transform(object); @@ -148,13 +148,13 @@ private static Class getType(int sqlType) throws SQLException { } private static CheckedBiFunction getSQLStringValueOfStringVersioned() { - return (value, version) -> getSQLStringValueOfString((FireboltVersion) version).apply(value); + return (value, version) -> getSQLStringValueOfString((ParserVersion) version).apply(value); } - private static CheckedFunction getSQLStringValueOfString(FireboltVersion version) { + private static CheckedFunction getSQLStringValueOfString(ParserVersion version) { return value -> { String escaped = (String) value; - List> charactersToEscape = version == FireboltVersion.LEGACY ? legacyCharacterToEscapedCharacterPairs : characterToEscapedCharacterPairs; + List> charactersToEscape = version == ParserVersion.LEGACY ? legacyCharacterToEscapedCharacterPairs : characterToEscapedCharacterPairs; for (Entry specialCharacter : charactersToEscape) { escaped = escaped.replace(specialCharacter.getKey(), specialCharacter.getValue()); } diff --git a/src/main/java/com/firebolt/jdbc/type/FireboltVersion.java b/src/main/java/com/firebolt/jdbc/type/ParserVersion.java similarity index 64% rename from src/main/java/com/firebolt/jdbc/type/FireboltVersion.java rename to src/main/java/com/firebolt/jdbc/type/ParserVersion.java index e48e1a06..31a06121 100644 --- a/src/main/java/com/firebolt/jdbc/type/FireboltVersion.java +++ b/src/main/java/com/firebolt/jdbc/type/ParserVersion.java @@ -1,5 +1,5 @@ package com.firebolt.jdbc.type; -public enum FireboltVersion { +public enum ParserVersion { LEGACY, CURRENT } diff --git a/src/test/java/com/firebolt/jdbc/type/JavaTypeToFireboltSQLStringTest.java b/src/test/java/com/firebolt/jdbc/type/JavaTypeToFireboltSQLStringTest.java index 0feab586..7e7b24ff 100644 --- a/src/test/java/com/firebolt/jdbc/type/JavaTypeToFireboltSQLStringTest.java +++ b/src/test/java/com/firebolt/jdbc/type/JavaTypeToFireboltSQLStringTest.java @@ -84,15 +84,15 @@ void shouldEscapeCharactersWhenTransformingFromString() throws SQLException { void shouldEscapeCharactersWhenTransformingFromStringLegacy() throws SQLException { // quotes are escaped assertEquals("'105'' OR 1=1--'' '", - JavaTypeToFireboltSQLString.STRING.transform("105' OR 1=1--' ", FireboltVersion.LEGACY)); + JavaTypeToFireboltSQLString.STRING.transform("105' OR 1=1--' ", ParserVersion.LEGACY)); assertEquals("'105'' OR 1=1--'' '", - JavaTypeToFireboltSQLString.transformAny("105' OR 1=1--' ", FireboltVersion.LEGACY)); + JavaTypeToFireboltSQLString.transformAny("105' OR 1=1--' ", ParserVersion.LEGACY)); // \0 is escaped - assertEquals("'105\\\\0'", JavaTypeToFireboltSQLString.STRING.transform("105\0", FireboltVersion.LEGACY)); - assertEquals("'105\\\\0'", JavaTypeToFireboltSQLString.transformAny("105\0", FireboltVersion.LEGACY)); + assertEquals("'105\\\\0'", JavaTypeToFireboltSQLString.STRING.transform("105\0", ParserVersion.LEGACY)); + assertEquals("'105\\\\0'", JavaTypeToFireboltSQLString.transformAny("105\0", ParserVersion.LEGACY)); // backslashes are escaped - assertEquals("'105\\\\'", JavaTypeToFireboltSQLString.STRING.transform("105\\", FireboltVersion.LEGACY)); - assertEquals("'105\\\\'", JavaTypeToFireboltSQLString.transformAny("105\\", FireboltVersion.LEGACY)); + assertEquals("'105\\\\'", JavaTypeToFireboltSQLString.STRING.transform("105\\", ParserVersion.LEGACY)); + assertEquals("'105\\\\'", JavaTypeToFireboltSQLString.transformAny("105\\", ParserVersion.LEGACY)); } @Test