Package net.snowflake.client.jdbc
Class SnowflakeUtil
- java.lang.Object
-
- net.snowflake.client.jdbc.SnowflakeUtil
-
public class SnowflakeUtil extends Object
-
-
Field Summary
Fields Modifier and Type Field Description static StringBIG_DECIMAL_STRstatic StringBOOLEAN_STRstatic StringBYTE_STRstatic StringBYTES_STRstatic StringDATE_STRstatic StringDOUBLE_STRstatic StringDURATION_STRstatic intEXTRA_TYPES_DAY_TIME_INTERVALstatic intEXTRA_TYPES_DECFLOATstatic intEXTRA_TYPES_TIMESTAMP_LTZAdditional data types not covered by standard JDBCstatic intEXTRA_TYPES_TIMESTAMP_NTZstatic intEXTRA_TYPES_TIMESTAMP_TZstatic intEXTRA_TYPES_VECTORstatic intEXTRA_TYPES_YEAR_MONTH_INTERVALstatic StringFLOAT_STRstatic StringINT_STRstatic StringLONG_STRstatic StringPERIOD_STRstatic StringSHORT_STRstatic StringTIME_STRstatic StringTIMESTAMP_STR
-
Constructor Summary
Constructors Constructor Description SnowflakeUtil()
-
Method Summary
All Methods Static Methods Concrete Methods Deprecated Methods Modifier and Type Method Description static voidassureOnlyUserAccessibleFilePermissions(File file, boolean isOwnerOnlyStageFilePermissionsEnabled)static voidcheckErrorAndThrowException(com.fasterxml.jackson.databind.JsonNode rootNode)static voidcheckErrorAndThrowExceptionIncludingReauth(com.fasterxml.jackson.databind.JsonNode rootNode)static HttpClientSettingsKeyconvertProxyPropertiesToHttpClientKey(OCSPMode mode, Properties info)Setup JDBC proxy properties if necessary.static booleanconvertSystemGetEnvToBooleanValue(String envVariableKey, boolean defaultValue)Helper function to convert environment variable to booleanstatic booleanconvertSystemPropertyToBooleanValue(String systemProperty, boolean defaultValue)Helper function to convert system properties to booleanstatic Map<String,String>createCaseInsensitiveMap(Map<String,String> input)Method introduced to avoid inconsistencies in custom headers handling, since these are defined on drivers side e.g.static Map<String,String>createCaseInsensitiveMap(org.apache.http.Header[] headers)toCaseInsensitiveMap, but adjusted to Headers[] argument typestatic ThreadPoolExecutorcreateDefaultExecutorService(String threadNamePrefix, int parallel)Returns a new thread pool configured with the default settings.static booleancreateOwnerOnlyPermissionDir(String location)create a directory with Owner only permission (0600)static SnowflakeColumnMetadataextractColumnMetadata(com.fasterxml.jackson.databind.JsonNode colNode, boolean jdbcTreatDecimalAsInt, SFBaseSession session)Deprecated.static longgetEpochTimeInMicroSeconds()static StringgetJsonNodeStringValue(com.fasterxml.jackson.databind.JsonNode node)static ThrowablegetRootCause(Exception ex)static longgetSecondsFromMillis(long millis)Round the time value from milliseconds to seconds so the seconds can be used to create SimpleDateFormatter.static TimegetTimeInSessionTimezone(Long time, int nanos)Get the time value in session timezone instead of UTC calculation done by java.sql.Time.static booleanisBlank(String input)static booleanisNullOrEmpty(String str)static booleanisWindows()Check whether the OS is Windowsstatic SnowflakeTypejavaTypeToSFType(int javaType, SFBaseSession session)static voidlogResponseDetails(org.apache.http.HttpResponse response, SFLogger logger)A utility to log response details.static StringmapJson(Object ob)static <T> TmapSFExceptionToSQLException(ThrowingCallable<T,SFException> action)static StringrandomAlphaNumeric(int count)static StringsystemGetEnv(String env)System.getenv wrapper.static StringsystemGetProperty(String property)System.getProperty wrapper.static voidsystemSetEnv(String key, String value)System.setEnv function.static voidsystemUnsetEnv(String key)System.unsetEnv function to remove a system environment parameter in the map
-
-
-
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
-
EXTRA_TYPES_VECTOR
public static final int EXTRA_TYPES_VECTOR
- See Also:
- Constant Field Values
-
EXTRA_TYPES_DECFLOAT
public static final int EXTRA_TYPES_DECFLOAT
- See Also:
- Constant Field Values
-
EXTRA_TYPES_YEAR_MONTH_INTERVAL
public static final int EXTRA_TYPES_YEAR_MONTH_INTERVAL
- See Also:
- Constant Field Values
-
EXTRA_TYPES_DAY_TIME_INTERVAL
public static final int EXTRA_TYPES_DAY_TIME_INTERVAL
- 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
-
DURATION_STR
public static final String DURATION_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
-
PERIOD_STR
public static final String PERIOD_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
-
-
Method Detail
-
mapJson
public static String mapJson(Object ob) throws com.fasterxml.jackson.core.JsonProcessingException
- Throws:
com.fasterxml.jackson.core.JsonProcessingException
-
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
@Deprecated public static SnowflakeColumnMetadata extractColumnMetadata(com.fasterxml.jackson.databind.JsonNode colNode, boolean jdbcTreatDecimalAsInt, SFBaseSession session) throws SnowflakeSQLException
Deprecated.This method should only be used internally- Parameters:
colNode- JsonNodejdbcTreatDecimalAsInt- true if should treat Decimal as Intsession- SFBaseSession- Returns:
- SnowflakeColumnMetadata
- Throws:
SnowflakeSQLException- if an error occurs
-
javaTypeToSFType
@SnowflakeJdbcInternalApi public static SnowflakeType javaTypeToSFType(int javaType, 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 serverlogger- 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 nameparallel- the number of concurrency- Returns:
- A new thread pool configured with the default settings.
-
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.- Parameters:
key- keyvalue- value
-
systemUnsetEnv
public static void systemUnsetEnv(String key)
System.unsetEnv function to remove a system environment parameter in the map- Parameters:
key- key value
-
convertProxyPropertiesToHttpClientKey
public static HttpClientSettingsKey convertProxyPropertiesToHttpClientKey(OCSPMode mode, Properties info) throws SnowflakeSQLException
Setup JDBC proxy properties if necessary.- Parameters:
mode- OCSP modeinfo- proxy server properties.- Returns:
- HttpClientSettingsKey
- Throws:
SnowflakeSQLException- if an error occurs
-
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- milliseconds- Returns:
- seconds as long value
-
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 secondsnanos- nanoseconds- Returns:
- time in session timezone
-
convertSystemPropertyToBooleanValue
@SnowflakeJdbcInternalApi public static boolean convertSystemPropertyToBooleanValue(String systemProperty, boolean defaultValue)
Helper function to convert system properties to boolean- Parameters:
systemProperty- name of the system propertydefaultValue- default value used- Returns:
- the value of the system property as boolean, else the default value
-
convertSystemGetEnvToBooleanValue
@SnowflakeJdbcInternalApi public static boolean convertSystemGetEnvToBooleanValue(String envVariableKey, boolean defaultValue)
Helper function to convert environment variable to boolean- Parameters:
envVariableKey- property name of the environment variabledefaultValue- default value used- Returns:
- the value of the environment variable as boolean, else the default value
-
mapSFExceptionToSQLException
@SnowflakeJdbcInternalApi public static <T> T mapSFExceptionToSQLException(ThrowingCallable<T,SFException> action) throws SQLException
- Throws:
SQLException
-
getJsonNodeStringValue
public static String getJsonNodeStringValue(com.fasterxml.jackson.databind.JsonNode node) throws SFException
- Throws:
SFException
-
createCaseInsensitiveMap
@SnowflakeJdbcInternalApi public static Map<String,String> createCaseInsensitiveMap(Map<String,String> input)
Method introduced to avoid inconsistencies in custom headers handling, since these are defined on drivers side e.g. some drivers might internally convert headers to canonical form.- Parameters:
input- map input- Returns:
- case insensitive map
-
createCaseInsensitiveMap
@SnowflakeJdbcInternalApi public static Map<String,String> createCaseInsensitiveMap(org.apache.http.Header[] headers)
toCaseInsensitiveMap, but adjusted to Headers[] argument type- Parameters:
headers- array of headers- Returns:
- case insensitive map
-
createOwnerOnlyPermissionDir
@SnowflakeJdbcInternalApi public static boolean createOwnerOnlyPermissionDir(String location)
create a directory with Owner only permission (0600)
-
assureOnlyUserAccessibleFilePermissions
@SnowflakeJdbcInternalApi public static void assureOnlyUserAccessibleFilePermissions(File file, boolean isOwnerOnlyStageFilePermissionsEnabled) throws IOException
- Throws:
IOException
-
isWindows
@SnowflakeJdbcInternalApi public static boolean isWindows()
Check whether the OS is Windows- Returns:
- boolean
-
isNullOrEmpty
public static boolean isNullOrEmpty(String str)
-
-