Package net.snowflake.client.core
Class SFSession
- java.lang.Object
-
- net.snowflake.client.core.SFBaseSession
-
- net.snowflake.client.core.SFSession
-
public class SFSession extends SFBaseSession
Snowflake session implementation
-
-
Field Summary
Fields Modifier and Type Field Description static intDEFAULT_HTTP_CLIENT_SOCKET_TIMEOUTstatic StringSF_HEADER_AUTHORIZATIONstatic StringSF_HEADER_SNOWFLAKE_AUTHTYPEstatic StringSF_HEADER_TOKEN_TAGstatic StringSF_QUERY_REQUEST_ID-
Fields inherited from class net.snowflake.client.core.SFBaseSession
heartbeatFrequency, MEMORY_LIMIT_UNSET, sqlWarnings
-
-
Constructor Summary
Constructors Constructor Description SFSession()SFSession(DefaultSFConnectionHandler sfConnectionHandler)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description voidaddQueryToActiveQueryList(String queryID)Add async query to list of active async queries based on its query IDvoidaddSFSessionProperty(String propertyName, Object propertyValue)Add a property If a property is known for connection, add it to connection properties If not, add it as a dynamic session parametersvoidcallHeartBeat(int timeout)Makes a heartbeat call to check for session validity.List<DriverPropertyInfo>checkProperties()Validates the connection properties used by this session, and returns a list of missing properties.voidclose()Close the connectionvoidcloseTelemetryClient()booleancontainProperty(String key)protected intgetAndIncrementSequenceId()intgetAuthTimeout()booleangetEnableCombineDescribe()intgetHttpClientConnectionTimeout()intgetHttpClientSocketTimeout()StringgetIdToken()intgetInjectClientPause()intgetInjectSocketTimeout()intgetMaxHttpRetries()StringgetMfaToken()intgetNetworkTimeoutInMilli()QueryContextDTOgetQueryContextDTO()QueryStatusgetQueryStatus(String queryID)StringgetSessionToken()get session tokenSFClientConfiggetSfClientConfig()SnowflakeConnectStringgetSnowflakeConnectionString()TelemetrygetTelemetryClient()Returns the telemetry client, if supported, by this session.protected voidheartbeat()Send heartbeat for the sessionbooleanisAsyncSession()booleanisClosed()booleanisSafeToClose()Function that checks if the active session can be closed when the connection is closed.voidopen()Open a new database sessionvoidsetEnableCombineDescribe(boolean enable)voidsetInjectClientPause(int injectClientPause)voidsetInjectSocketTimeout(int injectSocketTimeout)voidsetQueryContext(String queryContext)voidsetSfClientConfig(SFClientConfig sfClientConfig)voidsetSnowflakeConnectionString(SnowflakeConnectString connStr)protected voidstartHeartbeatForThisSession()Start heartbeat for this sessionprotected voidstopHeartbeatForThisSession()Stop heartbeat for this session-
Methods inherited from class net.snowflake.client.core.SFBaseSession
addProperty, addProperty, clearSqlWarnings, getArrayBindStage, getArrayBindStageThreshold, getAutoCommit, getClientInfo, getClientInfo, getClientMemoryLimit, getClientPrefetchThreads, getClientResultChunkSize, getCommonParameters, getConnectionPropertiesMap, getConservativeMemoryAdjustStep, getDatabase, getDatabaseMajorVersion, getDatabaseMinorVersion, getDatabaseVersion, getEnableHeartbeat, getEnablePutGet, getEnableReturnTimestampWithTimeZone, getFormatDateWithTimezone, getHeartbeatFrequency, getHttpClientKey, getInjectFileUploadFailure, getInjectWaitInPut, getJdbcEnablePutGet, getMemoryLimitForTesting, getMetadataRequestUseConnectionCtx, getMetadataRequestUseSessionDatabase, getOCSPMode, getOtherParameter, getPreparedStatementLogging, getQueryContextCacheSize, getQueryTimeout, getRole, getSchema, getServerUrl, getServiceName, getSessionId, getSessionPropertyByKey, getSfConnectionHandler, getSqlWarnings, getStoreTemporaryCredential, getTimestampMappedType, getTreatNTZAsUTC, getUrl, getUser, getUseRegionalS3EndpointsForPresignedURL, getUseSessionTimezone, getValidateDefaultParameters, getWarehouse, isClientTelemetryEnabled, isConservativeMemoryUsageEnabled, isJdbcTreatDecimalAsInt, isResultColumnCaseInsensitive, isSfSQLMode, isStringQuoted, setArrayBindStage, setArrayBindStageThreshold, setAutoCommit, setClientMemoryLimit, setClientPrefetchThreads, setClientResultChunkSize, setClientTelemetryEnabled, setCommonParameters, setConservativeMemoryAdjustStep, setDatabase, setDatabaseMajorVersion, setDatabaseMinorVersion, setDatabaseVersion, setEnableConservativeMemoryUsage, setEnableHeartbeat, setEnablePutGet, setFormatDateWithTimezone, setHeartbeatFrequency, setInjectedDelay, setInjectFileUploadFailure, setJdbcEnablePutGet, setJdbcTreatDecimalAsInt, setMemoryLimitForTesting, setMetadataRequestUseConnectionCtx, setMetadataRequestUseSessionDatabase, setOtherParameter, setPreparedStatementLogging, setQueryContextCacheSize, setResultColumnCaseInsensitive, setRole, setSchema, setServiceName, setSessionId, setSessionPropertyByKey, setSfSQLMode, setStoreTemporaryCredential, setTimestampMappedType, setTreatNTZAsUTC, setUseRegionalS3EndpointsForPresignedURL, setUseSessionTimezone, setValidateDefaultParameters, setWarehouse, unsetInvalidProxyHostAndPort
-
-
-
-
Field Detail
-
SF_QUERY_REQUEST_ID
public static final String SF_QUERY_REQUEST_ID
- See Also:
- Constant Field Values
-
SF_HEADER_AUTHORIZATION
public static final String SF_HEADER_AUTHORIZATION
- See Also:
- Constant Field Values
-
SF_HEADER_SNOWFLAKE_AUTHTYPE
public static final String SF_HEADER_SNOWFLAKE_AUTHTYPE
- See Also:
- Constant Field Values
-
SF_HEADER_TOKEN_TAG
public static final String SF_HEADER_TOKEN_TAG
- See Also:
- Constant Field Values
-
DEFAULT_HTTP_CLIENT_SOCKET_TIMEOUT
public static final int DEFAULT_HTTP_CLIENT_SOCKET_TIMEOUT
- See Also:
- Constant Field Values
-
-
Constructor Detail
-
SFSession
public SFSession()
-
SFSession
public SFSession(DefaultSFConnectionHandler sfConnectionHandler)
-
-
Method Detail
-
isSafeToClose
public boolean isSafeToClose()
Function that checks if the active session can be closed when the connection is closed. If there are active asynchronous queries running, the session should stay open even if the connection closes so that the queries can finish running.- Specified by:
isSafeToClosein classSFBaseSession- Returns:
- true if it is safe to close this session, false if not
-
addQueryToActiveQueryList
public void addQueryToActiveQueryList(String queryID)
Add async query to list of active async queries based on its query ID- Parameters:
queryID- query ID
-
getQueryStatus
public QueryStatus getQueryStatus(String queryID) throws SQLException
- Specified by:
getQueryStatusin classSFBaseSession- Parameters:
queryID- query ID of the query whose status is being investigated- Returns:
- enum of type QueryStatus indicating the query's status
- Throws:
SQLException
-
addSFSessionProperty
public void addSFSessionProperty(String propertyName, Object propertyValue) throws SFException
Add a property If a property is known for connection, add it to connection properties If not, add it as a dynamic session parametersMake sure a property is not added more than once and the number of properties does not exceed limit.
- Parameters:
propertyName- property namepropertyValue- property value- Throws:
SFException- exception raised from Snowflake components
-
containProperty
public boolean containProperty(String key)
-
open
public void open() throws SFException, SnowflakeSQLExceptionOpen a new database session- Throws:
SFException- this is a runtime exceptionSnowflakeSQLException- exception raised from Snowflake components
-
getSessionToken
public String getSessionToken()
get session token- Returns:
- session token
-
close
public void close() throws SFException, SnowflakeSQLExceptionClose the connection- Specified by:
closein classSFBaseSession- Throws:
SnowflakeSQLException- if failed to close the connectionSFException- if failed to close the connection
-
callHeartBeat
public void callHeartBeat(int timeout) throws Exception, SFExceptionMakes a heartbeat call to check for session validity.- Specified by:
callHeartBeatin classSFBaseSession- Parameters:
timeout- the query timeout- Throws:
Exception- if an error occursSFException- exception raised from Snowflake
-
startHeartbeatForThisSession
protected void startHeartbeatForThisSession()
Start heartbeat for this session
-
stopHeartbeatForThisSession
protected void stopHeartbeatForThisSession()
Stop heartbeat for this session
-
heartbeat
protected void heartbeat() throws SFException, SQLExceptionSend heartbeat for the session- Throws:
SFException- exception raised from SnowflakeSQLException- exception raised from SQL generic layers
-
getInjectSocketTimeout
public int getInjectSocketTimeout()
-
setInjectSocketTimeout
public void setInjectSocketTimeout(int injectSocketTimeout)
-
getNetworkTimeoutInMilli
public int getNetworkTimeoutInMilli()
- Specified by:
getNetworkTimeoutInMilliin classSFBaseSession
-
getAuthTimeout
public int getAuthTimeout()
- Specified by:
getAuthTimeoutin classSFBaseSession
-
getHttpClientSocketTimeout
public int getHttpClientSocketTimeout()
-
getHttpClientConnectionTimeout
public int getHttpClientConnectionTimeout()
-
isClosed
public boolean isClosed()
-
getInjectClientPause
public int getInjectClientPause()
-
getMaxHttpRetries
public int getMaxHttpRetries()
- Specified by:
getMaxHttpRetriesin classSFBaseSession
-
setInjectClientPause
public void setInjectClientPause(int injectClientPause)
-
getAndIncrementSequenceId
protected int getAndIncrementSequenceId()
-
getEnableCombineDescribe
public boolean getEnableCombineDescribe()
- Overrides:
getEnableCombineDescribein classSFBaseSession
-
setEnableCombineDescribe
public void setEnableCombineDescribe(boolean enable)
- Overrides:
setEnableCombineDescribein classSFBaseSession
-
getTelemetryClient
public Telemetry getTelemetryClient()
Description copied from class:SFBaseSessionReturns the telemetry client, if supported, by this session. If not, should return a NoOpTelemetryClient.- Specified by:
getTelemetryClientin classSFBaseSession
-
closeTelemetryClient
public void closeTelemetryClient()
-
getIdToken
public String getIdToken()
-
getMfaToken
public String getMfaToken()
-
getSnowflakeConnectionString
public SnowflakeConnectString getSnowflakeConnectionString()
- Specified by:
getSnowflakeConnectionStringin classSFBaseSession
-
setSnowflakeConnectionString
public void setSnowflakeConnectionString(SnowflakeConnectString connStr)
-
checkProperties
public List<DriverPropertyInfo> checkProperties()
Description copied from class:SFBaseSessionValidates the connection properties used by this session, and returns a list of missing properties.- Specified by:
checkPropertiesin classSFBaseSession
-
isAsyncSession
public boolean isAsyncSession()
- Specified by:
isAsyncSessionin classSFBaseSession- Returns:
- whether this session uses async queries
-
setQueryContext
public void setQueryContext(String queryContext)
- Specified by:
setQueryContextin classSFBaseSession
-
getQueryContextDTO
public QueryContextDTO getQueryContextDTO()
- Specified by:
getQueryContextDTOin classSFBaseSession
-
getSfClientConfig
public SFClientConfig getSfClientConfig()
-
setSfClientConfig
public void setSfClientConfig(SFClientConfig sfClientConfig)
-
-