Skip to content

Commit

Permalink
rename
Browse files Browse the repository at this point in the history
  • Loading branch information
ptiurin committed Oct 18, 2024
1 parent a9e785a commit be08870
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 21 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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));
}
Expand Down Expand Up @@ -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));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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())),
Expand Down Expand Up @@ -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<Class<?>> classSupplier, FireboltVersion version) throws SQLException {
private static String transformAny(Object object, CheckedSupplier<Class<?>> 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);
Expand All @@ -148,13 +148,13 @@ private static Class<?> getType(int sqlType) throws SQLException {
}

private static CheckedBiFunction<Object, Object, String> getSQLStringValueOfStringVersioned() {
return (value, version) -> getSQLStringValueOfString((FireboltVersion) version).apply(value);
return (value, version) -> getSQLStringValueOfString((ParserVersion) version).apply(value);
}

private static CheckedFunction<Object, String> getSQLStringValueOfString(FireboltVersion version) {
private static CheckedFunction<Object, String> getSQLStringValueOfString(ParserVersion version) {
return value -> {
String escaped = (String) value;
List<Entry<String, String>> charactersToEscape = version == FireboltVersion.LEGACY ? legacyCharacterToEscapedCharacterPairs : characterToEscapedCharacterPairs;
List<Entry<String, String>> charactersToEscape = version == ParserVersion.LEGACY ? legacyCharacterToEscapedCharacterPairs : characterToEscapedCharacterPairs;
for (Entry<String, String> specialCharacter : charactersToEscape) {
escaped = escaped.replace(specialCharacter.getKey(), specialCharacter.getValue());
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
package com.firebolt.jdbc.type;

public enum FireboltVersion {
public enum ParserVersion {
LEGACY, CURRENT
}
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit be08870

Please sign in to comment.