Package net.snowflake.client.jdbc

## Class SnowflakeUtil

- java.lang.Object
- - net.snowflake.client.jdbc.SnowflakeUtil

    public class SnowflakeUtil
    extends Object

Author:
  jhuang

### Field Summary

Fields
`static String` `BIG_DECIMAL_STR`
`static String` `BOOLEAN_STR`
`static String` `BYTE_STR`
`static String` `BYTES_STR`
`static String` `DATE_STR`
`static String` `DOUBLE_STR`
`static int` `EXTRA_TYPES_TIMESTAMP_LTZ` Additional data types not covered by standard JDBC
`static int` `EXTRA_TYPES_TIMESTAMP_NTZ`
`static int` `EXTRA_TYPES_TIMESTAMP_TZ`
`static String` `FLOAT_STR`
`static String` `INT_STR`
`static String` `LONG_STR`
`static String` `SHORT_STR`
`static String` `TIME_STR`
`static String` `TIMESTAMP_STR`

### Constructor Summary

Constructors
`SnowflakeUtil()`

### Method Summary

All Methods Static Methods Concrete Methods
`static void` `checkErrorAndThrowException​(com.fasterxml.jackson.databind.JsonNode rootNode)`
`static void` `checkErrorAndThrowExceptionIncludingReauth​(com.fasterxml.jackson.databind.JsonNode rootNode)`
`static HttpClientSettingsKey` `convertProxyPropertiesToHttpClientKey​(OCSPMode mode, Properties info)` Setup JDBC proxy properties if necessary.
`static ThreadPoolExecutor` `createDefaultExecutorService​(String threadNamePrefix, int parallel)` Returns a new thread pool configured with the default settings.
`static SnowflakeColumnMetadata` `extractColumnMetadata​(com.fasterxml.jackson.databind.JsonNode colNode, boolean jdbcTreatDecimalAsInt, SFBaseSession session)`
`static long` `getEpochTimeInMicroSeconds()`
`static Throwable` `getRootCause​(Exception ex)`
`static long` `getSecondsFromMillis​(long millis)` Round the time value from milliseconds to seconds so the seconds can be used to create SimpleDateFormatter.
`static Time` `getTimeInSessionTimezone​(Long time, int nanos)` Get the time value in session timezone instead of UTC calculation done by java.sql.Time.
`static boolean` `isBlank​(String input)`
`static void` `logResponseDetails​(org.apache.http.HttpResponse response, SFLogger logger)` A utility to log response details.
`static String` `randomAlphaNumeric​(int count)`
`static String` `systemGetEnv​(String env)` System.getenv wrapper.
`static String` `systemGetProperty​(String property)` System.getProperty wrapper.
`static void` `systemSetEnv​(String key, String value)` System.setEnv function.
`static void` `systemUnsetEnv​(String key)` System.unsetEnv function to remove a system environment parameter in the map

### Methods inherited from class java.lang.Object

`clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

### Field Detail

#### EXTRA_TYPES_TIMESTAMP_LTZ

    public static final int EXTRA_TYPES_TIMESTAMP_LTZ

Additional data types not covered by standard JDBC

See Also:
  Constant Field Values

#### EXTRA_TYPES_TIMESTAMP_TZ

    public static final int EXTRA_TYPES_TIMESTAMP_TZ

See Also:
  Constant Field Values

#### EXTRA_TYPES_TIMESTAMP_NTZ

    public static final int EXTRA_TYPES_TIMESTAMP_NTZ

See Also:
  Constant Field Values

#### BIG_DECIMAL_STR

    public static final String BIG_DECIMAL_STR

See Also:
  Constant Field Values

#### FLOAT_STR

    public static final String FLOAT_STR

See Also:
  Constant Field Values

#### DOUBLE_STR

    public static final String DOUBLE_STR

See Also:
  Constant Field Values

#### BOOLEAN_STR

    public static final String BOOLEAN_STR

See Also:
  Constant Field Values

#### SHORT_STR

    public static final String SHORT_STR

See Also:
  Constant Field Values

#### INT_STR

    public static final String INT_STR

See Also:
  Constant Field Values

#### LONG_STR

    public static final String LONG_STR

See Also:
  Constant Field Values

#### TIME_STR

    public static final String TIME_STR

See Also:
  Constant Field Values

#### TIMESTAMP_STR

    public static final String TIMESTAMP_STR

See Also:
  Constant Field Values

#### DATE_STR

    public static final String DATE_STR

See Also:
  Constant Field Values

#### BYTE_STR

    public static final String BYTE_STR

See Also:
  Constant Field Values

#### BYTES_STR

    public static final String BYTES_STR

See Also:
  Constant Field Values

### Constructor Detail

#### SnowflakeUtil

    public SnowflakeUtil()

### Method Detail

#### checkErrorAndThrowExceptionIncludingReauth

    public static void checkErrorAndThrowExceptionIncludingReauth​(com.fasterxml.jackson.databind.JsonNode rootNode)
                                                           throws SnowflakeSQLException

Throws:
  `SnowflakeSQLException`

#### checkErrorAndThrowException

    public static void checkErrorAndThrowException​(com.fasterxml.jackson.databind.JsonNode rootNode)
                                            throws SnowflakeSQLException

Throws:
  `SnowflakeSQLException`

#### getEpochTimeInMicroSeconds

    public static long getEpochTimeInMicroSeconds()

#### extractColumnMetadata

    public static SnowflakeColumnMetadata extractColumnMetadata​(com.fasterxml.jackson.databind.JsonNode colNode,
                                                                boolean jdbcTreatDecimalAsInt,
                                                                SFBaseSession session)
                                                         throws SnowflakeSQLException

Throws:
  `SnowflakeSQLException`

#### logResponseDetails

    public static void logResponseDetails​(org.apache.http.HttpResponse response,
                                          SFLogger logger)

A utility to log response details.

Used when there is an error in http response

Parameters:
  `response` - http response get from server
  `logger` - logger object

#### createDefaultExecutorService

    public static ThreadPoolExecutor createDefaultExecutorService​(String threadNamePrefix,
                                                                  int parallel)

Returns a new thread pool configured with the default settings.

Parameters:
  `threadNamePrefix` - prefix of the thread name
  `parallel` - the number of concurrency
Returns:
  A new thread pool configured with the default settings.

#### getRootCause

    public static Throwable getRootCause​(Exception ex)

#### isBlank

    public static boolean isBlank​(String input)

#### randomAlphaNumeric

    public static String randomAlphaNumeric​(int count)

#### systemGetProperty

    public static String systemGetProperty​(String property)

System.getProperty wrapper. If System.getProperty raises an SecurityException, it is ignored and returns null.

Parameters:
  `property` - the property name
Returns:
  the property value if set, otherwise null.

#### systemGetEnv

    public static String systemGetEnv​(String env)

System.getenv wrapper. If System.getenv raises an SecurityException, it is ignored and returns null.

Parameters:
  `env` - the environment variable name.
Returns:
  the environment variable value if set, otherwise null.

#### systemSetEnv

    public static void systemSetEnv​(String key,
                                    String value)

System.setEnv function. Can be used for unit tests.

#### systemUnsetEnv

    public static void systemUnsetEnv​(String key)

System.unsetEnv function to remove a system environment parameter in the map

Parameters:
  `key` -

#### convertProxyPropertiesToHttpClientKey

    public static HttpClientSettingsKey convertProxyPropertiesToHttpClientKey​(OCSPMode mode,
                                                                              Properties info)
                                                                       throws SnowflakeSQLException

Setup JDBC proxy properties if necessary.

Parameters:
  `mode` - OCSP mode
  `info` - proxy server properties.
Throws:
  `SnowflakeSQLException`

#### getSecondsFromMillis

    public static long getSecondsFromMillis​(long millis)

Round the time value from milliseconds to seconds so the seconds can be used to create SimpleDateFormatter. Negative values have to be rounded to the next negative value, while positive values should be cut off with no rounding.

Parameters:
  `millis` -
Returns:

#### getTimeInSessionTimezone

    public static Time getTimeInSessionTimezone​(Long time,
                                                int nanos)

Get the time value in session timezone instead of UTC calculation done by java.sql.Time.

Parameters:
  `time` - time in seconds
  `nanos` - nanoseconds
Returns:
  time in session timezone