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
`static int` `DEFAULT_HTTP_CLIENT_SOCKET_TIMEOUT`
`static String` `SF_HEADER_AUTHORIZATION`
`static String` `SF_HEADER_SNOWFLAKE_AUTHTYPE`
`static String` `SF_HEADER_TOKEN_TAG`
`static String` `SF_QUERY_REQUEST_ID`

### Fields inherited from class net.snowflake.client.core.SFBaseSession

`heartbeatFrequency, MEMORY_LIMIT_UNSET, sqlWarnings`

### Constructor Summary

Constructors
`SFSession()`
`SFSession​(DefaultSFConnectionHandler sfConnectionHandler)`

### Method Summary

All Methods Instance Methods Concrete Methods Deprecated Methods
`void` `addQueryToActiveQueryList​(String queryID)` Add async query to list of active async queries based on its query ID
`void` `addSFSessionProperty​(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 parameters
`void` `callHeartBeat​(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.
`void` `close()` Close the connection
`void` `closeTelemetryClient()`
`boolean` `containProperty​(String key)`
`protected int` `getAndIncrementSequenceId()`
`int` `getAuthTimeout()`
`boolean` `getEnableCombineDescribe()`
`int` `getHttpClientConnectionTimeout()`
`int` `getHttpClientSocketTimeout()`
`String` `getIdToken()`
`int` `getInjectClientPause()`
`int` `getInjectSocketTimeout()`
`int` `getMaxHttpRetries()`
`String` `getMfaToken()`
`int` `getNetworkTimeoutInMilli()`
`QueryContextDTO` `getQueryContextDTO()`
`QueryStatus` `getQueryStatus​(String queryID)` Deprecated. the returned enum is error-prone, use `getQueryStatusV2(java.lang.String)` instead
`QueryStatusV2` `getQueryStatusV2​(String queryID)`
`String` `getSessionToken()` get session token
`SFClientConfig` `getSfClientConfig()`
`SnowflakeConnectString` `getSnowflakeConnectionString()`
`Telemetry` `getTelemetryClient()` Returns the telemetry client, if supported, by this session.
`protected void` `heartbeat()` Send heartbeat for the session
`boolean` `isAsyncSession()`
`boolean` `isClosed()`
`boolean` `isSafeToClose()` Function that checks if the active session can be closed when the connection is closed.
`void` `open()` Open a new database session
`void` `setEnableCombineDescribe​(boolean enable)`
`void` `setInjectClientPause​(int injectClientPause)`
`void` `setInjectSocketTimeout​(int injectSocketTimeout)`
`void` `setQueryContext​(String queryContext)`
`void` `setSfClientConfig​(SFClientConfig sfClientConfig)`
`void` `setSnowflakeConnectionString​(SnowflakeConnectString connStr)`
`protected void` `startHeartbeatForThisSession()` Start heartbeat for this session
`protected void` `stopHeartbeatForThisSession()` 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`

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

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

### 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:
  `isSafeToClose` in class `SFBaseSession`
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

    @Deprecated
    public QueryStatus getQueryStatus​(String queryID)
                               throws SQLException

Deprecated.
the returned enum is error-prone, use `getQueryStatusV2(java.lang.String)` instead

Specified by:
  `getQueryStatus` in class `SFBaseSession`
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 QueryStatusV2 getQueryStatusV2​(String queryID)
                                   throws SQLException

Specified by:
  `getQueryStatusV2` in class `SFBaseSession`
Parameters:
  `queryID` - query ID of the query whose status is being investigated
Returns:
  a QueryStatusV2 instance 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 parameters

Make sure a property is not added more than once and the number of properties does not exceed limit.

Parameters:
  `propertyName` - property name
  `propertyValue` - property value
Throws:
  `SFException` - exception raised from Snowflake components

#### containProperty

    public boolean containProperty​(String key)

#### open

    public void open()
              throws SFException,
                     SnowflakeSQLException

Open a new database session

Throws:
  `SFException` - this is a runtime exception
  `SnowflakeSQLException` - exception raised from Snowflake components

#### getSessionToken

    public String getSessionToken()

get session token

Returns:
  session token

#### close

    public void close()
               throws SFException,
                      SnowflakeSQLException

Close the connection

Specified by:
  `close` in class `SFBaseSession`
Throws:
  `SnowflakeSQLException` - if failed to close the connection
  `SFException` - if failed to close the connection

#### callHeartBeat

    public void callHeartBeat​(int timeout)
                       throws Exception,
                              SFException

Makes a heartbeat call to check for session validity.

Specified by:
  `callHeartBeat` in class `SFBaseSession`
Parameters:
  `timeout` - the query timeout
Throws:
  `Exception` - if an error occurs
  `SFException` - 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,
                             SQLException

Send heartbeat for the session

Throws:
  `SFException` - exception raised from Snowflake
  `SQLException` - exception raised from SQL generic layers

#### getInjectSocketTimeout

    public int getInjectSocketTimeout()

#### setInjectSocketTimeout

    public void setInjectSocketTimeout​(int injectSocketTimeout)

#### getNetworkTimeoutInMilli

    public int getNetworkTimeoutInMilli()

Specified by:
  `getNetworkTimeoutInMilli` in class `SFBaseSession`

#### getAuthTimeout

    public int getAuthTimeout()

Specified by:
  `getAuthTimeout` in class `SFBaseSession`

#### getHttpClientSocketTimeout

    public int getHttpClientSocketTimeout()

#### getHttpClientConnectionTimeout

    public int getHttpClientConnectionTimeout()

#### isClosed

    public boolean isClosed()

#### getInjectClientPause

    public int getInjectClientPause()

#### getMaxHttpRetries

    public int getMaxHttpRetries()

Specified by:
  `getMaxHttpRetries` in class `SFBaseSession`

#### setInjectClientPause

    public void setInjectClientPause​(int injectClientPause)

#### getAndIncrementSequenceId

    protected int getAndIncrementSequenceId()

#### getEnableCombineDescribe

    public boolean getEnableCombineDescribe()

Overrides:
  `getEnableCombineDescribe` in class `SFBaseSession`

#### setEnableCombineDescribe

    public void setEnableCombineDescribe​(boolean enable)

Overrides:
  `setEnableCombineDescribe` in class `SFBaseSession`

#### getTelemetryClient

    public Telemetry getTelemetryClient()

Description copied from class: `SFBaseSession`
Returns the telemetry client, if supported, by this session. If not, should return a NoOpTelemetryClient.

Specified by:
  `getTelemetryClient` in class `SFBaseSession`

#### closeTelemetryClient

    public void closeTelemetryClient()

#### getIdToken

    public String getIdToken()

#### getMfaToken

    public String getMfaToken()

#### getSnowflakeConnectionString

    public SnowflakeConnectString getSnowflakeConnectionString()

Specified by:
  `getSnowflakeConnectionString` in class `SFBaseSession`

#### setSnowflakeConnectionString

    public void setSnowflakeConnectionString​(SnowflakeConnectString connStr)

#### checkProperties

    public List<DriverPropertyInfo> checkProperties()

Description copied from class: `SFBaseSession`
Validates the connection properties used by this session, and returns a list of missing properties.

Specified by:
  `checkProperties` in class `SFBaseSession`

#### isAsyncSession

    public boolean isAsyncSession()

Specified by:
  `isAsyncSession` in class `SFBaseSession`
Returns:
  whether this session uses async queries

#### setQueryContext

    public void setQueryContext​(String queryContext)

Specified by:
  `setQueryContext` in class `SFBaseSession`

#### getQueryContextDTO

    public QueryContextDTO getQueryContextDTO()

Specified by:
  `getQueryContextDTO` in class `SFBaseSession`

#### getSfClientConfig

    public SFClientConfig getSfClientConfig()

#### setSfClientConfig

    public void setSfClientConfig​(SFClientConfig sfClientConfig)