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 int
heartbeatFrequency
static long
MEMORY_LIMIT_UNSET
protected List<SFException>
sqlWarnings
-
Constructor Summary
Constructors Modifier Constructor Description protected
SFBaseSession(SFConnectionHandler sfConnectionHandler)
-
Method Summary
All Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description void
addProperty(String propertyName, Object propertyValue)
Adds a connection property to the connection-properties map.void
addProperty(SFSessionProperty sfSessionProperty, Object propertyValue)
Wrapper function for the other addProperty(String, Object) method that takes an SFSessionProperty instead of a String key.abstract void
callHeartBeat(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.void
clearSqlWarnings()
JDBC API.abstract void
close()
Close the connectionString
getArrayBindStage()
int
getArrayBindStageThreshold()
abstract int
getAuthTimeout()
boolean
getAutoCommit()
Properties
getClientInfo()
Part of the JDBC API, where client applications may fetch a Map of Properties to set various attributes.String
getClientInfo(String name)
Gets the Property associated with the key 'name' in the ClientInfo map.int
getClientMemoryLimit()
int
getClientPrefetchThreads()
int
getClientResultChunkSize()
Map<String,Object>
getCommonParameters()
Map<SFSessionProperty,Object>
getConnectionPropertiesMap()
int
getConservativeMemoryAdjustStep()
String
getDatabase()
int
getDatabaseMajorVersion()
int
getDatabaseMinorVersion()
String
getDatabaseVersion()
boolean
getEnableCombineDescribe()
boolean
getEnableHeartbeat()
boolean
getEnableReturnTimestampWithTimeZone()
If true, JDBC will enable returning TIMESTAMP_WITH_TIMEZONE as column type, otherwise it will not.boolean
getFormatDateWithTimezone()
int
getHeartbeatFrequency()
Retrieve session heartbeat frequency in secondsHttpClientSettingsKey
getHttpClientKey()
String
getInjectFileUploadFailure()
int
getInjectWaitInPut()
abstract int
getMaxHttpRetries()
long
getMemoryLimitForTesting()
boolean
getMetadataRequestUseConnectionCtx()
boolean
getMetadataRequestUseSessionDatabase()
abstract int
getNetworkTimeoutInMilli()
OCSPMode
getOCSPMode()
Object
getOtherParameter(String key)
boolean
getPreparedStatementLogging()
int
getQueryContextCacheSize()
abstract QueryContextDTO
getQueryContextDTO()
Integer
getQueryTimeout()
String
getRole()
String
getSchema()
String
getServerUrl()
String
getServiceName()
String
getSessionId()
Returns a unique id for this session.Object
getSessionPropertyByKey(String propertyName)
Fetch the value for a custom session property.SFConnectionHandler
getSfConnectionHandler()
abstract SnowflakeConnectString
getSnowflakeConnectionString()
List<SFException>
getSqlWarnings()
JDBC API.boolean
getStoreTemporaryCredential()
abstract Telemetry
getTelemetryClient()
Returns the telemetry client, if supported, by this session.SnowflakeType
getTimestampMappedType()
boolean
getTreatNTZAsUTC()
String
getUrl()
String
getUser()
boolean
getUseRegionalS3EndpointsForPresignedURL()
boolean
getUseSessionTimezone()
boolean
getValidateDefaultParameters()
String
getWarehouse()
abstract boolean
isAsyncSession()
boolean
isClientTelemetryEnabled()
boolean
isConservativeMemoryUsageEnabled()
boolean
isJdbcTreatDecimalAsInt()
boolean
isResultColumnCaseInsensitive()
abstract boolean
isSafeToClose()
Function that checks if the active session can be closed when the connection is closed.boolean
isSfSQLMode()
boolean
isStringQuoted()
void
setArrayBindStage(String arrayBindStage)
void
setArrayBindStageThreshold(int arrayBindStageThreshold)
void
setAutoCommit(boolean autoCommit)
void
setClientMemoryLimit(int clientMemoryLimit)
void
setClientPrefetchThreads(int clientPrefetchThreads)
void
setClientResultChunkSize(int clientResultChunkSize)
void
setClientTelemetryEnabled(boolean clientTelemetryEnabled)
void
setCommonParameters(Map<String,Object> parameters)
void
setConservativeMemoryAdjustStep(int conservativeMemoryAdjustStep)
void
setDatabase(String database)
void
setDatabaseMajorVersion(int databaseMajorVersion)
void
setDatabaseMinorVersion(int databaseMinorVersion)
void
setDatabaseVersion(String databaseVersion)
void
setEnableCombineDescribe(boolean enableCombineDescribe)
void
setEnableConservativeMemoryUsage(boolean enableConservativeMemoryUsage)
void
setEnableHeartbeat(boolean enableHeartbeat)
void
setFormatDateWithTimezone(boolean formatDateWithTimezone)
void
setHeartbeatFrequency(int frequency)
Set the heartbeat frequency in seconds.void
setInjectedDelay(int injectedDelay)
void
setInjectFileUploadFailure(String fileToFail)
void
setJdbcTreatDecimalAsInt(boolean jdbcTreatDecimalAsInt)
void
setMemoryLimitForTesting(long memLimit)
void
setMetadataRequestUseConnectionCtx(boolean enabled)
void
setMetadataRequestUseSessionDatabase(boolean enabled)
void
setOtherParameter(String key, Object value)
void
setPreparedStatementLogging(boolean value)
abstract void
setQueryContext(String queryContext)
void
setQueryContextCacheSize(int queryContextCacheSize)
void
setResultColumnCaseInsensitive(boolean resultColumnCaseInsensitive)
void
setRole(String role)
void
setSchema(String schema)
void
setServiceName(String serviceName)
void
setSessionId(String sessionId)
Sets the session-id attribute in this session.void
setSessionPropertyByKey(String propertyName, Object propertyValue)
Enables setting a value in the custom-properties map.void
setSfSQLMode(boolean sfSQLMode)
void
setStoreTemporaryCredential(boolean storeTemporaryCredential)
void
setTimestampMappedType(SnowflakeType timestampMappedType)
void
setTreatNTZAsUTC(boolean treatNTZAsUTC)
void
setUseRegionalS3EndpointsForPresignedURL(boolean regionalS3Endpoint)
void
setUseSessionTimezone(boolean useSessionTimezone)
void
setValidateDefaultParameters(boolean validateDefaultParameters)
void
setWarehouse(String warehouse)
void
unsetInvalidProxyHostAndPort()
-
-
-
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)
-
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.
-
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, SnowflakeSQLException
Close 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, SFException
Makes a heartbeat call to check for session validity.- Throws:
Exception
SFException
-
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.
-
-