From c91f0b131d7db78b1d5d21e75a9860a3a3d89b78 Mon Sep 17 00:00:00 2001 From: Przemyslaw Motacki Date: Fri, 22 Mar 2024 12:33:36 +0100 Subject: [PATCH] SNOW-1259709 - add mapping for basic types for arrays and maps --- .../snowflake/client/core/JsonSqlInput.java | 24 +++++----- .../client/jdbc/SnowflakeBaseResultSet.java | 48 +++++++++---------- .../snowflake/client/jdbc/SnowflakeUtil.java | 2 +- 3 files changed, 37 insertions(+), 37 deletions(-) diff --git a/src/main/java/net/snowflake/client/core/JsonSqlInput.java b/src/main/java/net/snowflake/client/core/JsonSqlInput.java index d1d3deec4..bf210db02 100644 --- a/src/main/java/net/snowflake/client/core/JsonSqlInput.java +++ b/src/main/java/net/snowflake/client/core/JsonSqlInput.java @@ -3,7 +3,7 @@ */ package net.snowflake.client.core; -import static net.snowflake.client.jdbc.SnowflakeUtil.mapThrowingCallableExceptions; +import static net.snowflake.client.jdbc.SnowflakeUtil.mapSFExceptionToSQLException; import com.fasterxml.jackson.databind.JsonNode; import java.math.BigDecimal; @@ -56,7 +56,7 @@ public String readString() throws SQLException { int columnType = ColumnTypeHelper.getColumnType(fieldMetadata.getType(), session); int columnSubType = fieldMetadata.getType(); int scale = fieldMetadata.getScale(); - return mapThrowingCallableExceptions( + return mapSFExceptionToSQLException( () -> converters .getStringConverter() @@ -69,7 +69,7 @@ public boolean readBoolean() throws SQLException { return withNextValue( (value, jsonNode, fieldMetadata) -> { int columnType = ColumnTypeHelper.getColumnType(fieldMetadata.getType(), session); - return mapThrowingCallableExceptions( + return mapSFExceptionToSQLException( () -> converters.getBooleanConverter().getBoolean(value, columnType)); }); } @@ -78,7 +78,7 @@ public boolean readBoolean() throws SQLException { public byte readByte() throws SQLException { return withNextValue( (value, jsonNode, fieldMetadata) -> - mapThrowingCallableExceptions(() -> converters.getNumberConverter().getByte(value))); + mapSFExceptionToSQLException(() -> converters.getNumberConverter().getByte(value))); } @Override @@ -86,7 +86,7 @@ public short readShort() throws SQLException { return withNextValue( (value, jsonNode, fieldMetadata) -> { int columnType = ColumnTypeHelper.getColumnType(fieldMetadata.getType(), session); - return mapThrowingCallableExceptions( + return mapSFExceptionToSQLException( () -> converters.getNumberConverter().getShort(value, columnType)); }); } @@ -96,7 +96,7 @@ public int readInt() throws SQLException { return withNextValue( (value, jsonNode, fieldMetadata) -> { int columnType = ColumnTypeHelper.getColumnType(fieldMetadata.getType(), session); - return mapThrowingCallableExceptions( + return mapSFExceptionToSQLException( () -> converters.getNumberConverter().getInt(value, columnType)); }); } @@ -106,7 +106,7 @@ public long readLong() throws SQLException { return withNextValue( (value, jsonNode, fieldMetadata) -> { int columnType = ColumnTypeHelper.getColumnType(fieldMetadata.getType(), session); - return mapThrowingCallableExceptions( + return mapSFExceptionToSQLException( () -> converters.getNumberConverter().getLong(value, columnType)); }); } @@ -116,7 +116,7 @@ public float readFloat() throws SQLException { return withNextValue( (value, jsonNode, fieldMetadata) -> { int columnType = ColumnTypeHelper.getColumnType(fieldMetadata.getType(), session); - return mapThrowingCallableExceptions( + return mapSFExceptionToSQLException( () -> converters.getNumberConverter().getFloat(value, columnType)); }); } @@ -126,7 +126,7 @@ public double readDouble() throws SQLException { return withNextValue( (value, jsonNode, fieldMetadata) -> { int columnType = ColumnTypeHelper.getColumnType(fieldMetadata.getType(), session); - return mapThrowingCallableExceptions( + return mapSFExceptionToSQLException( () -> converters.getNumberConverter().getDouble(value, columnType)); }); } @@ -136,7 +136,7 @@ public BigDecimal readBigDecimal() throws SQLException { return withNextValue( (value, jsonNode, fieldMetadata) -> { int columnType = ColumnTypeHelper.getColumnType(fieldMetadata.getType(), session); - return mapThrowingCallableExceptions( + return mapSFExceptionToSQLException( () -> converters.getNumberConverter().getBigDecimal(value, columnType)); }); } @@ -148,7 +148,7 @@ public byte[] readBytes() throws SQLException { int columnType = ColumnTypeHelper.getColumnType(fieldMetadata.getType(), session); int columnSubType = fieldMetadata.getType(); int scale = fieldMetadata.getScale(); - return mapThrowingCallableExceptions( + return mapSFExceptionToSQLException( () -> converters.getBytesConverter().getBytes(value, columnType, columnSubType, scale)); }); @@ -197,7 +197,7 @@ public Timestamp readTimestamp(TimeZone tz) throws SQLException { if (result != null) { return result; } - return mapThrowingCallableExceptions( + return mapSFExceptionToSQLException( () -> converters .getDateTimeConverter() diff --git a/src/main/java/net/snowflake/client/jdbc/SnowflakeBaseResultSet.java b/src/main/java/net/snowflake/client/jdbc/SnowflakeBaseResultSet.java index 59ab72558..d3e67d49f 100644 --- a/src/main/java/net/snowflake/client/jdbc/SnowflakeBaseResultSet.java +++ b/src/main/java/net/snowflake/client/jdbc/SnowflakeBaseResultSet.java @@ -4,7 +4,7 @@ package net.snowflake.client.jdbc; -import static net.snowflake.client.jdbc.SnowflakeUtil.mapThrowingCallableExceptions; +import static net.snowflake.client.jdbc.SnowflakeUtil.mapSFExceptionToSQLException; import com.fasterxml.jackson.core.type.TypeReference; import com.fasterxml.jackson.databind.JsonNode; @@ -1419,7 +1419,7 @@ public T[] getArray(int columnIndex, Class type) throws SQLException { arr[counter++] = (T) instance; } else if (String.class.isAssignableFrom(type)) { arr[counter++] = - mapThrowingCallableExceptions( + mapSFExceptionToSQLException( () -> (T) sfBaseResultSet @@ -1428,7 +1428,7 @@ public T[] getArray(int columnIndex, Class type) throws SQLException { .getString(value, columnType, columnSubType, scale)); } else if (Boolean.class.isAssignableFrom(type)) { arr[counter++] = - mapThrowingCallableExceptions( + mapSFExceptionToSQLException( () -> (T) sfBaseResultSet @@ -1437,7 +1437,7 @@ public T[] getArray(int columnIndex, Class type) throws SQLException { .getBoolean(value, columnType)); } else if (Byte.class.isAssignableFrom(type)) { arr[counter++] = - mapThrowingCallableExceptions( + mapSFExceptionToSQLException( () -> (T) sfBaseResultSet @@ -1446,7 +1446,7 @@ public T[] getArray(int columnIndex, Class type) throws SQLException { .getBytes(value, columnType, columnSubType, scale)); } else if (Short.class.isAssignableFrom(type)) { arr[counter++] = - mapThrowingCallableExceptions( + mapSFExceptionToSQLException( () -> (T) Short.valueOf( @@ -1456,7 +1456,7 @@ public T[] getArray(int columnIndex, Class type) throws SQLException { .getShort(value, columnType))); } else if (Integer.class.isAssignableFrom(type)) { arr[counter++] = - mapThrowingCallableExceptions( + mapSFExceptionToSQLException( () -> (T) Integer.valueOf( @@ -1466,7 +1466,7 @@ public T[] getArray(int columnIndex, Class type) throws SQLException { .getInt(value, columnType))); } else if (Long.class.isAssignableFrom(type)) { arr[counter++] = - mapThrowingCallableExceptions( + mapSFExceptionToSQLException( () -> (T) Long.valueOf( @@ -1476,7 +1476,7 @@ public T[] getArray(int columnIndex, Class type) throws SQLException { .getLong(value, columnType))); } else if (Float.class.isAssignableFrom(type)) { arr[counter++] = - mapThrowingCallableExceptions( + mapSFExceptionToSQLException( () -> (T) Float.valueOf( @@ -1486,7 +1486,7 @@ public T[] getArray(int columnIndex, Class type) throws SQLException { .getFloat(value, columnType))); } else if (Double.class.isAssignableFrom(type)) { arr[counter++] = - mapThrowingCallableExceptions( + mapSFExceptionToSQLException( () -> (T) Double.valueOf( @@ -1496,7 +1496,7 @@ public T[] getArray(int columnIndex, Class type) throws SQLException { .getDouble(value, columnType))); } else if (Date.class.isAssignableFrom(type)) { arr[counter++] = - mapThrowingCallableExceptions( + mapSFExceptionToSQLException( () -> (T) sfBaseResultSet @@ -1505,7 +1505,7 @@ public T[] getArray(int columnIndex, Class type) throws SQLException { .getDate(value, columnType, columnSubType, tz, scale)); } else if (Time.class.isAssignableFrom(type)) { arr[counter++] = - mapThrowingCallableExceptions( + mapSFExceptionToSQLException( () -> (T) sfBaseResultSet @@ -1513,7 +1513,7 @@ public T[] getArray(int columnIndex, Class type) throws SQLException { .getDateTimeConverter() .getTime(value, columnType, columnSubType, tz, scale)); } else if (Timestamp.class.isAssignableFrom(type)) { - mapThrowingCallableExceptions( + mapSFExceptionToSQLException( () -> (T) sfBaseResultSet @@ -1572,7 +1572,7 @@ public Map getMap(int columnIndex, Class type) throws SQLExcep } else if (String.class.isAssignableFrom(type)) { resultMap.put( entry.getKey(), - mapThrowingCallableExceptions( + mapSFExceptionToSQLException( () -> (T) sfBaseResultSet @@ -1582,7 +1582,7 @@ public Map getMap(int columnIndex, Class type) throws SQLExcep } else if (Boolean.class.isAssignableFrom(type)) { resultMap.put( entry.getKey(), - mapThrowingCallableExceptions( + mapSFExceptionToSQLException( () -> (T) sfBaseResultSet @@ -1592,7 +1592,7 @@ public Map getMap(int columnIndex, Class type) throws SQLExcep } else if (Byte.class.isAssignableFrom(type)) { resultMap.put( entry.getKey(), - mapThrowingCallableExceptions( + mapSFExceptionToSQLException( () -> (T) sfBaseResultSet @@ -1602,7 +1602,7 @@ public Map getMap(int columnIndex, Class type) throws SQLExcep } else if (Short.class.isAssignableFrom(type)) { resultMap.put( entry.getKey(), - mapThrowingCallableExceptions( + mapSFExceptionToSQLException( () -> (T) (Short) @@ -1613,7 +1613,7 @@ public Map getMap(int columnIndex, Class type) throws SQLExcep } else if (Integer.class.isAssignableFrom(type)) { resultMap.put( entry.getKey(), - mapThrowingCallableExceptions( + mapSFExceptionToSQLException( () -> (T) (Integer) @@ -1624,7 +1624,7 @@ public Map getMap(int columnIndex, Class type) throws SQLExcep } else if (Long.class.isAssignableFrom(type)) { resultMap.put( entry.getKey(), - mapThrowingCallableExceptions( + mapSFExceptionToSQLException( () -> (T) (Long) @@ -1635,7 +1635,7 @@ public Map getMap(int columnIndex, Class type) throws SQLExcep } else if (Float.class.isAssignableFrom(type)) { resultMap.put( entry.getKey(), - mapThrowingCallableExceptions( + mapSFExceptionToSQLException( () -> (T) (Float) @@ -1646,7 +1646,7 @@ public Map getMap(int columnIndex, Class type) throws SQLExcep } else if (Double.class.isAssignableFrom(type)) { resultMap.put( entry.getKey(), - mapThrowingCallableExceptions( + mapSFExceptionToSQLException( () -> (T) (Double) @@ -1657,7 +1657,7 @@ public Map getMap(int columnIndex, Class type) throws SQLExcep } else if (BigDecimal.class.isAssignableFrom(type)) { resultMap.put( entry.getKey(), - mapThrowingCallableExceptions( + mapSFExceptionToSQLException( () -> (T) sfBaseResultSet @@ -1667,7 +1667,7 @@ public Map getMap(int columnIndex, Class type) throws SQLExcep } else if (Date.class.isAssignableFrom(type)) { resultMap.put( entry.getKey(), - mapThrowingCallableExceptions( + mapSFExceptionToSQLException( () -> (T) sfBaseResultSet @@ -1677,7 +1677,7 @@ public Map getMap(int columnIndex, Class type) throws SQLExcep } else if (Time.class.isAssignableFrom(type)) { resultMap.put( entry.getKey(), - mapThrowingCallableExceptions( + mapSFExceptionToSQLException( () -> (T) sfBaseResultSet @@ -1687,7 +1687,7 @@ public Map getMap(int columnIndex, Class type) throws SQLExcep } else if (Timestamp.class.isAssignableFrom(type)) { resultMap.put( entry.getKey(), - mapThrowingCallableExceptions( + mapSFExceptionToSQLException( () -> (T) sfBaseResultSet diff --git a/src/main/java/net/snowflake/client/jdbc/SnowflakeUtil.java b/src/main/java/net/snowflake/client/jdbc/SnowflakeUtil.java index 5365feaba..e3e58fa30 100644 --- a/src/main/java/net/snowflake/client/jdbc/SnowflakeUtil.java +++ b/src/main/java/net/snowflake/client/jdbc/SnowflakeUtil.java @@ -793,7 +793,7 @@ public static boolean convertSystemPropertyToBooleanValue( } @SnowflakeJdbcInternalApi - public static T mapThrowingCallableExceptions(ThrowingCallable action) + public static T mapSFExceptionToSQLException(ThrowingCallable action) throws SQLException { try { return action.call();