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 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 Constructor Description SFSession()
SFSession(DefaultSFConnectionHandler sfConnectionHandler)
-
Method Summary
All Methods Instance Methods Concrete Methods Deprecated Methods Modifier and Type Method Description void
addQueryToActiveQueryList(String queryID)
Add async query to list of active async queries based on its query IDvoid
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 parametersvoid
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 connectionvoid
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()
Get network timeout in millisecondsQueryContextDTO
getQueryContextDTO()
QueryStatus
getQueryStatus(String queryID)
Deprecated.the returned enum is error-prone, usegetQueryStatusV2(java.lang.String)
insteadQueryStatusV2
getQueryStatusV2(String queryID)
String
getSessionToken()
get session tokenSFClientConfig
getSfClientConfig()
SnowflakeConnectString
getSnowflakeConnectionString()
Telemetry
getTelemetryClient()
protected void
heartbeat()
Send heartbeat for the sessionboolean
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 sessionvoid
overrideConsoleHandlerWhenNecessary()
void
setEnableCombineDescribe(boolean enable)
void
setInjectClientPause(int injectClientPause)
void
setInjectSocketTimeout(int injectSocketTimeout)
void
setQueryContext(String queryContext)
Set query contextvoid
setSfClientConfig(SFClientConfig sfClientConfig)
void
setSnowflakeConnectionString(SnowflakeConnectString connStr)
protected void
startHeartbeatForThisSession()
Start heartbeat for this sessionprotected void
stopHeartbeatForThisSession()
Stop heartbeat for this session-
Methods inherited from class net.snowflake.client.core.SFBaseSession
addProperty, addProperty, clearSqlWarnings, getArrayBindStage, getArrayBindStageThreshold, getAutoCommit, getClearBatchOnlyAfterSuccessfulExecution, getClientInfo, getClientInfo, getClientMemoryLimit, getClientPrefetchThreads, getClientResultChunkSize, getCommonParameters, getConnectionPropertiesMap, getConservativeMemoryAdjustStep, getDatabase, getDatabaseMajorVersion, getDatabaseMinorVersion, getDatabaseVersion, getDefaultFormatDateWithTimezone, getDisableGcsDefaultCredentials, getEnableHeartbeat, getEnablePatternSearch, getEnablePutGet, getEnableReturnTimestampWithTimeZone, getFormatDateWithTimezone, getGetDateUseNullTimezone, 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, isJdbcArrowTreatDecimalAsInt, isJdbcTreatDecimalAsInt, isResultColumnCaseInsensitive, isSfSQLMode, isStringQuoted, setArrayBindStage, setArrayBindStageThreshold, setAutoCommit, setClientMemoryLimit, setClientPrefetchThreads, setClientResultChunkSize, setClientTelemetryEnabled, setCommonParameters, setConservativeMemoryAdjustStep, setDatabase, setDatabaseMajorVersion, setDatabaseMinorVersion, setDatabaseVersion, setDefaultFormatDateWithTimezone, setDisableGcsDefaultCredentials, setEnableConservativeMemoryUsage, setEnableHeartbeat, setEnablePatternSearch, setEnablePutGet, setFormatDateWithTimezone, setGetDateUseNullTimezone, setHeartbeatFrequency, setInjectedDelay, setInjectFileUploadFailure, setJdbcArrowTreatDecimalAsInt, 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:
isSafeToClose
in 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
@Deprecated public QueryStatus getQueryStatus(String queryID) throws SQLException
Deprecated.the returned enum is error-prone, usegetQueryStatusV2(java.lang.String)
instead- Specified by:
getQueryStatus
in 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
- if an error is encountered
-
getQueryStatusV2
public QueryStatusV2 getQueryStatusV2(String queryID) throws SQLException
- Specified by:
getQueryStatusV2
in classSFBaseSession
- Parameters:
queryID
- query ID of the query whose status is being investigated- Returns:
- a QueryStatusV2 instance indicating the query's status
- Throws:
SQLException
- if an error is encountered
-
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
-
overrideConsoleHandlerWhenNecessary
@SnowflakeJdbcInternalApi public void overrideConsoleHandlerWhenNecessary()
-
containProperty
public boolean containProperty(String key)
-
open
public void open() throws SFException, SnowflakeSQLException
Open 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, SnowflakeSQLException
Close the connection- Specified by:
close
in classSFBaseSession
- Throws:
SnowflakeSQLException
- if failed to close the connectionSFException
- 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 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, SQLException
Send 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()
Description copied from class:SFBaseSession
Get network timeout in milliseconds- Specified by:
getNetworkTimeoutInMilli
in classSFBaseSession
- Returns:
- network timeout in milliseconds
-
getAuthTimeout
public int getAuthTimeout()
- Specified by:
getAuthTimeout
in classSFBaseSession
- Returns:
- auth timeout in seconds
-
getHttpClientSocketTimeout
public int getHttpClientSocketTimeout()
-
getHttpClientConnectionTimeout
public int getHttpClientConnectionTimeout()
-
isClosed
public boolean isClosed()
-
getInjectClientPause
public int getInjectClientPause()
-
getMaxHttpRetries
public int getMaxHttpRetries()
- Specified by:
getMaxHttpRetries
in classSFBaseSession
- Returns:
- max http retries
-
setInjectClientPause
public void setInjectClientPause(int injectClientPause)
-
getAndIncrementSequenceId
protected int getAndIncrementSequenceId()
-
getEnableCombineDescribe
public boolean getEnableCombineDescribe()
- Overrides:
getEnableCombineDescribe
in classSFBaseSession
-
setEnableCombineDescribe
public void setEnableCombineDescribe(boolean enable)
- Overrides:
setEnableCombineDescribe
in classSFBaseSession
-
getTelemetryClient
public Telemetry getTelemetryClient()
- Specified by:
getTelemetryClient
in classSFBaseSession
- Returns:
- Returns the telemetry client, if supported, by this session. If not, should return a NoOpTelemetryClient.
-
closeTelemetryClient
public void closeTelemetryClient()
-
getIdToken
public String getIdToken()
-
getMfaToken
public String getMfaToken()
-
getSnowflakeConnectionString
public SnowflakeConnectString getSnowflakeConnectionString()
- Specified by:
getSnowflakeConnectionString
in classSFBaseSession
- Returns:
SnowflakeConnectString
-
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 classSFBaseSession
- Returns:
- List of DriverPropertyInfo
-
isAsyncSession
public boolean isAsyncSession()
- Specified by:
isAsyncSession
in classSFBaseSession
- Returns:
- whether this session uses async queries
-
setQueryContext
public void setQueryContext(String queryContext)
Description copied from class:SFBaseSession
Set query context- Specified by:
setQueryContext
in classSFBaseSession
- Parameters:
queryContext
- the query context string
-
getQueryContextDTO
public QueryContextDTO getQueryContextDTO()
- Specified by:
getQueryContextDTO
in classSFBaseSession
- Returns:
- QueryContextDTO containing opaque information shared with the cloud service.
-
getSfClientConfig
public SFClientConfig getSfClientConfig()
-
setSfClientConfig
public void setSfClientConfig(SFClientConfig sfClientConfig)
-
-