Package net.snowflake.client.core
Class SFBaseSession
- java.lang.Object
-
- net.snowflake.client.core.SFBaseSession
-
- Direct Known Subclasses:
SFSession
public abstract class SFBaseSession extends Object
Snowflake session implementation base. The methods and fields contained within this class are setters and getters for shared session properties, i.e., those that may be set via connection time, in properties, as well as those that may be parsed from response headers from Snowflake (i.e., session parameters).New connection properties and session parameters can be added here, as SFBaseSession contains the logic for storing, setting, and getting these session properties.
For logic that is specific to a particular type of Session, four methods need to be implemented:
open(), for establishing a connection. close(), for closing a connection. isSafeToClose(), for checking whether the connection can be closed. checkProperties(), invoked at connection time to verify if the requisite properties are set; and if not, returns a list of missing properties raiseError(), which handles exceptions that may be raised in the session isTelemetryEnabled(), which signals whether to enable client telemetry
-
-
Field Summary
Fields Modifier and Type Field Description protected intheartbeatFrequencystatic longMEMORY_LIMIT_UNSETprotected List<SFException>sqlWarnings
-
Constructor Summary
Constructors Modifier Constructor Description protectedSFBaseSession(SFConnectionHandler sfConnectionHandler)
-
Method Summary
All Methods Instance Methods Abstract Methods Concrete Methods Deprecated Methods Modifier and Type Method Description voidaddProperty(String propertyName, Object propertyValue)Adds a connection property to the connection-properties map.voidaddProperty(SFSessionProperty sfSessionProperty, Object propertyValue)Wrapper function for the other addProperty(String, Object) method that takes an SFSessionProperty instead of a String key.abstract voidcallHeartBeat(int timeout)Makes a heartbeat call to check for session validity.abstract List<DriverPropertyInfo>checkProperties()Validates the connection properties used by this session, and returns a list of missing properties.voidclearSqlWarnings()JDBC API.abstract voidclose()Close the connectionStringgetArrayBindStage()intgetArrayBindStageThreshold()abstract intgetAuthTimeout()booleangetAutoCommit()PropertiesgetClientInfo()Part of the JDBC API, where client applications may fetch a Map of Properties to set various attributes.StringgetClientInfo(String name)Gets the Property associated with the key 'name' in the ClientInfo map.intgetClientMemoryLimit()intgetClientPrefetchThreads()intgetClientResultChunkSize()Map<String,Object>getCommonParameters()Map<SFSessionProperty,Object>getConnectionPropertiesMap()intgetConservativeMemoryAdjustStep()StringgetDatabase()intgetDatabaseMajorVersion()intgetDatabaseMinorVersion()StringgetDatabaseVersion()booleangetEnableCombineDescribe()booleangetEnableHeartbeat()booleangetEnablePutGet()booleangetEnableReturnTimestampWithTimeZone()If true, JDBC will enable returning TIMESTAMP_WITH_TIMEZONE as column type, otherwise it will not.booleangetFormatDateWithTimezone()intgetHeartbeatFrequency()Retrieve session heartbeat frequency in secondsHttpClientSettingsKeygetHttpClientKey()StringgetInjectFileUploadFailure()intgetInjectWaitInPut()booleangetJdbcEnablePutGet()abstract intgetMaxHttpRetries()longgetMemoryLimitForTesting()booleangetMetadataRequestUseConnectionCtx()booleangetMetadataRequestUseSessionDatabase()abstract intgetNetworkTimeoutInMilli()OCSPModegetOCSPMode()ObjectgetOtherParameter(String key)booleangetPreparedStatementLogging()intgetQueryContextCacheSize()abstract QueryContextDTOgetQueryContextDTO()abstract QueryStatusgetQueryStatus(String queryID)Deprecated.abstract QueryStatusV2getQueryStatusV2(String queryID)IntegergetQueryTimeout()StringgetRole()StringgetSchema()StringgetServerUrl()StringgetServiceName()StringgetSessionId()Returns a unique id for this session.ObjectgetSessionPropertyByKey(String propertyName)Fetch the value for a custom session property.SFConnectionHandlergetSfConnectionHandler()abstract SnowflakeConnectStringgetSnowflakeConnectionString()List<SFException>getSqlWarnings()JDBC API.booleangetStoreTemporaryCredential()abstract TelemetrygetTelemetryClient()Returns the telemetry client, if supported, by this session.SnowflakeTypegetTimestampMappedType()booleangetTreatNTZAsUTC()StringgetUrl()StringgetUser()booleangetUseRegionalS3EndpointsForPresignedURL()booleangetUseSessionTimezone()booleangetValidateDefaultParameters()StringgetWarehouse()abstract booleanisAsyncSession()booleanisClientTelemetryEnabled()booleanisConservativeMemoryUsageEnabled()booleanisJdbcTreatDecimalAsInt()booleanisResultColumnCaseInsensitive()abstract booleanisSafeToClose()Function that checks if the active session can be closed when the connection is closed.booleanisSfSQLMode()booleanisStringQuoted()voidsetArrayBindStage(String arrayBindStage)voidsetArrayBindStageThreshold(int arrayBindStageThreshold)voidsetAutoCommit(boolean autoCommit)voidsetClientMemoryLimit(int clientMemoryLimit)voidsetClientPrefetchThreads(int clientPrefetchThreads)voidsetClientResultChunkSize(int clientResultChunkSize)voidsetClientTelemetryEnabled(boolean clientTelemetryEnabled)voidsetCommonParameters(Map<String,Object> parameters)voidsetConservativeMemoryAdjustStep(int conservativeMemoryAdjustStep)voidsetDatabase(String database)voidsetDatabaseMajorVersion(int databaseMajorVersion)voidsetDatabaseMinorVersion(int databaseMinorVersion)voidsetDatabaseVersion(String databaseVersion)voidsetEnableCombineDescribe(boolean enableCombineDescribe)voidsetEnableConservativeMemoryUsage(boolean enableConservativeMemoryUsage)voidsetEnableHeartbeat(boolean enableHeartbeat)booleansetEnablePutGet(boolean enablePutGet)voidsetFormatDateWithTimezone(boolean formatDateWithTimezone)voidsetHeartbeatFrequency(int frequency)Set the heartbeat frequency in seconds.voidsetInjectedDelay(int injectedDelay)voidsetInjectFileUploadFailure(String fileToFail)voidsetJdbcEnablePutGet(boolean jdbcEnablePutGet)voidsetJdbcTreatDecimalAsInt(boolean jdbcTreatDecimalAsInt)voidsetMemoryLimitForTesting(long memLimit)voidsetMetadataRequestUseConnectionCtx(boolean enabled)voidsetMetadataRequestUseSessionDatabase(boolean enabled)voidsetOtherParameter(String key, Object value)voidsetPreparedStatementLogging(boolean value)abstract voidsetQueryContext(String queryContext)voidsetQueryContextCacheSize(int queryContextCacheSize)voidsetResultColumnCaseInsensitive(boolean resultColumnCaseInsensitive)voidsetRole(String role)voidsetSchema(String schema)voidsetServiceName(String serviceName)voidsetSessionId(String sessionId)Sets the session-id attribute in this session.voidsetSessionPropertyByKey(String propertyName, Object propertyValue)Enables setting a value in the custom-properties map.voidsetSfSQLMode(boolean sfSQLMode)voidsetStoreTemporaryCredential(boolean storeTemporaryCredential)voidsetTimestampMappedType(SnowflakeType timestampMappedType)voidsetTreatNTZAsUTC(boolean treatNTZAsUTC)voidsetUseRegionalS3EndpointsForPresignedURL(boolean regionalS3Endpoint)voidsetUseSessionTimezone(boolean useSessionTimezone)voidsetValidateDefaultParameters(boolean validateDefaultParameters)voidsetWarehouse(String warehouse)voidunsetInvalidProxyHostAndPort()
-
-
-
Field Detail
-
sqlWarnings
protected List<SFException> sqlWarnings
-
heartbeatFrequency
protected int heartbeatFrequency
-
MEMORY_LIMIT_UNSET
public static long MEMORY_LIMIT_UNSET
-
-
Constructor Detail
-
SFBaseSession
protected SFBaseSession(SFConnectionHandler sfConnectionHandler)
-
-
Method Detail
-
setMemoryLimitForTesting
public void setMemoryLimitForTesting(long memLimit)
-
getMemoryLimitForTesting
public long getMemoryLimitForTesting()
-
getClientInfo
public Properties getClientInfo()
Part of the JDBC API, where client applications may fetch a Map of Properties to set various attributes. This is not used internally by any driver component, but should be maintained by the Session object.
-
getClientInfo
public String getClientInfo(String name)
Gets the Property associated with the key 'name' in the ClientInfo map.- Parameters:
name- The key from which to fetch the Property.
-
getSessionId
public String getSessionId()
Returns a unique id for this session.
-
setSessionId
public void setSessionId(String sessionId)
Sets the session-id attribute in this session.- Parameters:
sessionId- The session id as a string.
-
isSfSQLMode
public boolean isSfSQLMode()
-
setSfSQLMode
public void setSfSQLMode(boolean sfSQLMode)
-
getDatabaseVersion
public String getDatabaseVersion()
-
setDatabaseVersion
public void setDatabaseVersion(String databaseVersion)
-
getDatabaseMajorVersion
public int getDatabaseMajorVersion()
-
setDatabaseMajorVersion
public void setDatabaseMajorVersion(int databaseMajorVersion)
-
getDatabaseMinorVersion
public int getDatabaseMinorVersion()
-
setDatabaseMinorVersion
public void setDatabaseMinorVersion(int databaseMinorVersion)
-
getPreparedStatementLogging
public boolean getPreparedStatementLogging()
-
setPreparedStatementLogging
public void setPreparedStatementLogging(boolean value)
-
getInjectFileUploadFailure
public String getInjectFileUploadFailure()
-
setInjectFileUploadFailure
public void setInjectFileUploadFailure(String fileToFail)
-
getTimestampMappedType
public SnowflakeType getTimestampMappedType()
-
setTimestampMappedType
public void setTimestampMappedType(SnowflakeType timestampMappedType)
-
isResultColumnCaseInsensitive
public boolean isResultColumnCaseInsensitive()
-
setResultColumnCaseInsensitive
public void setResultColumnCaseInsensitive(boolean resultColumnCaseInsensitive)
-
isJdbcTreatDecimalAsInt
public boolean isJdbcTreatDecimalAsInt()
-
setJdbcTreatDecimalAsInt
public void setJdbcTreatDecimalAsInt(boolean jdbcTreatDecimalAsInt)
-
getServerUrl
public String getServerUrl()
-
isStringQuoted
public boolean isStringQuoted()
-
addProperty
public void addProperty(SFSessionProperty sfSessionProperty, Object propertyValue) throws SFException
Wrapper function for the other addProperty(String, Object) method that takes an SFSessionProperty instead of a String key.- Parameters:
sfSessionProperty- The property for which to set the value.propertyValue- The value to set for the property.- Throws:
SFException- If the value already exists for the given key (should only be set once), or if the value is invalid.
-
addProperty
public void addProperty(String propertyName, Object propertyValue) throws SFException
Adds a connection property to the connection-properties map. Connection properties are those that are defined in SFSessionProperty. They are set typically through instantiation of the Session.- Parameters:
propertyName- The name of the property, as a string. Recognized ones are defined in the SFSessionProperty enum.propertyValue- The value to set for this key.- Throws:
SFException- If the value already exists for the given key (should only be set once), or if the value is invalid.
-
getConnectionPropertiesMap
public Map<SFSessionProperty,Object> getConnectionPropertiesMap()
-
getHttpClientKey
public HttpClientSettingsKey getHttpClientKey() throws SnowflakeSQLException
- Throws:
SnowflakeSQLException
-
unsetInvalidProxyHostAndPort
public void unsetInvalidProxyHostAndPort()
-
getOCSPMode
public OCSPMode getOCSPMode()
-
getQueryTimeout
public Integer getQueryTimeout()
-
getUser
public String getUser()
-
getUrl
public String getUrl()
-
getInjectWaitInPut
public int getInjectWaitInPut()
-
getMetadataRequestUseSessionDatabase
public boolean getMetadataRequestUseSessionDatabase()
-
setMetadataRequestUseSessionDatabase
public void setMetadataRequestUseSessionDatabase(boolean enabled)
-
getMetadataRequestUseConnectionCtx
public boolean getMetadataRequestUseConnectionCtx()
-
setMetadataRequestUseConnectionCtx
public void setMetadataRequestUseConnectionCtx(boolean enabled)
-
setInjectedDelay
public void setInjectedDelay(int injectedDelay)
-
getTreatNTZAsUTC
public boolean getTreatNTZAsUTC()
-
setTreatNTZAsUTC
public void setTreatNTZAsUTC(boolean treatNTZAsUTC)
-
getEnableHeartbeat
public boolean getEnableHeartbeat()
-
setEnableHeartbeat
public void setEnableHeartbeat(boolean enableHeartbeat)
-
setHeartbeatFrequency
public void setHeartbeatFrequency(int frequency)
Set the heartbeat frequency in seconds. This is the frequency with which the session token is refreshed.- Parameters:
frequency- heartbeat frequency in seconds
-
getHeartbeatFrequency
public int getHeartbeatFrequency()
Retrieve session heartbeat frequency in seconds
-
getAutoCommit
public boolean getAutoCommit()
-
setAutoCommit
public void setAutoCommit(boolean autoCommit)
-
getFormatDateWithTimezone
public boolean getFormatDateWithTimezone()
-
setFormatDateWithTimezone
public void setFormatDateWithTimezone(boolean formatDateWithTimezone)
-
getUseSessionTimezone
public boolean getUseSessionTimezone()
-
setUseSessionTimezone
public void setUseSessionTimezone(boolean useSessionTimezone)
-
getEnableCombineDescribe
public boolean getEnableCombineDescribe()
-
setEnableCombineDescribe
public void setEnableCombineDescribe(boolean enableCombineDescribe)
-
isClientTelemetryEnabled
public boolean isClientTelemetryEnabled()
-
setClientTelemetryEnabled
public void setClientTelemetryEnabled(boolean clientTelemetryEnabled)
-
getArrayBindStageThreshold
public int getArrayBindStageThreshold()
-
setArrayBindStageThreshold
public void setArrayBindStageThreshold(int arrayBindStageThreshold)
-
getStoreTemporaryCredential
public boolean getStoreTemporaryCredential()
-
setStoreTemporaryCredential
public void setStoreTemporaryCredential(boolean storeTemporaryCredential)
-
getServiceName
public String getServiceName()
-
setServiceName
public void setServiceName(String serviceName)
-
setEnableConservativeMemoryUsage
public void setEnableConservativeMemoryUsage(boolean enableConservativeMemoryUsage)
-
isConservativeMemoryUsageEnabled
public boolean isConservativeMemoryUsageEnabled()
-
getConservativeMemoryAdjustStep
public int getConservativeMemoryAdjustStep()
-
setConservativeMemoryAdjustStep
public void setConservativeMemoryAdjustStep(int conservativeMemoryAdjustStep)
-
getClientMemoryLimit
public int getClientMemoryLimit()
-
setClientMemoryLimit
public void setClientMemoryLimit(int clientMemoryLimit)
-
getQueryContextCacheSize
public int getQueryContextCacheSize()
-
setQueryContextCacheSize
public void setQueryContextCacheSize(int queryContextCacheSize)
-
getJdbcEnablePutGet
public boolean getJdbcEnablePutGet()
-
setJdbcEnablePutGet
public void setJdbcEnablePutGet(boolean jdbcEnablePutGet)
-
getEnablePutGet
public boolean getEnablePutGet()
-
setEnablePutGet
public boolean setEnablePutGet(boolean enablePutGet)
-
getClientResultChunkSize
public int getClientResultChunkSize()
-
setClientResultChunkSize
public void setClientResultChunkSize(int clientResultChunkSize)
-
getClientPrefetchThreads
public int getClientPrefetchThreads()
-
setClientPrefetchThreads
public void setClientPrefetchThreads(int clientPrefetchThreads)
-
getValidateDefaultParameters
public boolean getValidateDefaultParameters()
-
setValidateDefaultParameters
public void setValidateDefaultParameters(boolean validateDefaultParameters)
-
getDatabase
public String getDatabase()
-
setDatabase
public void setDatabase(String database)
-
getSchema
public String getSchema()
-
setSchema
public void setSchema(String schema)
-
getRole
public String getRole()
-
setRole
public void setRole(String role)
-
getWarehouse
public String getWarehouse()
-
setWarehouse
public void setWarehouse(String warehouse)
-
setUseRegionalS3EndpointsForPresignedURL
public void setUseRegionalS3EndpointsForPresignedURL(boolean regionalS3Endpoint)
-
getUseRegionalS3EndpointsForPresignedURL
public boolean getUseRegionalS3EndpointsForPresignedURL()
-
getArrayBindStage
public String getArrayBindStage()
-
setArrayBindStage
public void setArrayBindStage(String arrayBindStage)
-
setSessionPropertyByKey
public void setSessionPropertyByKey(String propertyName, Object propertyValue)
Enables setting a value in the custom-properties map. This is used for properties that are implementation specific to the session, and not shared by the different implementations.- Parameters:
propertyName- A string key for the property to set.propertyValue- The property value.
-
getSessionPropertyByKey
public Object getSessionPropertyByKey(String propertyName)
Fetch the value for a custom session property.- Parameters:
propertyName- The key of the session property to fetch.
-
isSafeToClose
public abstract boolean isSafeToClose()
Function that checks if the active session can be closed when the connection is closed. Called by SnowflakeConnectionV1.
-
getQueryStatus
@Deprecated public abstract QueryStatus getQueryStatus(String queryID) throws SQLException
Deprecated.- Parameters:
queryID- query ID of the query whose status is being investigated- Returns:
- enum of type QueryStatus indicating the query's status
- Throws:
SQLException
-
getQueryStatusV2
public abstract QueryStatusV2 getQueryStatusV2(String queryID) throws SQLException
- Parameters:
queryID- query ID of the query whose status is being investigated- Returns:
- QueryStatusV2 indicating the query's status
- Throws:
SQLException
-
checkProperties
public abstract List<DriverPropertyInfo> checkProperties()
Validates the connection properties used by this session, and returns a list of missing properties.
-
close
public abstract void close() throws SFException, SnowflakeSQLExceptionClose the connection- Throws:
SnowflakeSQLException- if failed to close the connectionSFException- if failed to close the connection
-
getTelemetryClient
public abstract Telemetry getTelemetryClient()
Returns the telemetry client, if supported, by this session. If not, should return a NoOpTelemetryClient.
-
callHeartBeat
public abstract void callHeartBeat(int timeout) throws Exception, SFExceptionMakes a heartbeat call to check for session validity.- Throws:
ExceptionSFException
-
getSqlWarnings
public List<SFException> getSqlWarnings()
JDBC API. Returns a list of warnings generated since starting this session, or the last time it was cleared.
-
clearSqlWarnings
public void clearSqlWarnings()
JDBC API. Clears the list of warnings generated since the start of the session, or the last time it was cleared.
-
getSfConnectionHandler
public SFConnectionHandler getSfConnectionHandler()
-
getNetworkTimeoutInMilli
public abstract int getNetworkTimeoutInMilli()
-
getAuthTimeout
public abstract int getAuthTimeout()
-
getMaxHttpRetries
public abstract int getMaxHttpRetries()
-
getSnowflakeConnectionString
public abstract SnowflakeConnectString getSnowflakeConnectionString()
-
isAsyncSession
public abstract boolean isAsyncSession()
-
getQueryContextDTO
public abstract QueryContextDTO getQueryContextDTO()
-
setQueryContext
public abstract void setQueryContext(String queryContext)
-
getEnableReturnTimestampWithTimeZone
public boolean getEnableReturnTimestampWithTimeZone()
If true, JDBC will enable returning TIMESTAMP_WITH_TIMEZONE as column type, otherwise it will not. This function will always return true for JDBC client, so that the client JDBC will not have any behavior change. Stored proc JDBC will override this function to return the value of SP_JDBC_ENABLE_TIMESTAMP_WITH_TIMEZONE from server for backward compatibility.
-
-