Package org.teiid.query.util
Class CommandContext
- java.lang.Object
-
- org.teiid.query.util.CommandContext
-
- All Implemented Interfaces:
Cloneable
,CommandContext
public class CommandContext extends Object implements Cloneable, CommandContext
Defines the context that a command is processing in. For example, this defines who is processing the command and why. Also, this class (or subclasses) provide a means to pass context-specific information between users of the query processor framework.
-
-
Constructor Summary
Constructors Constructor Description CommandContext()
CommandContext(Object processorID, String connectionID, String userName, String vdbName, Object vdbVersion)
Construct a new context.CommandContext(String connectionID, String userName, Serializable commandPayload, String vdbName, Object vdbVersion, boolean collectNodeStatistics)
Construct a new context.
-
Method Summary
-
-
-
Constructor Detail
-
CommandContext
public CommandContext(String connectionID, String userName, Serializable commandPayload, String vdbName, Object vdbVersion, boolean collectNodeStatistics)
Construct a new context.
-
CommandContext
public CommandContext(Object processorID, String connectionID, String userName, String vdbName, Object vdbVersion)
Construct a new context.
-
CommandContext
public CommandContext()
-
-
Method Detail
-
getDeterminismLevel
public FunctionMethod.Determinism getDeterminismLevel()
-
resetDeterminismLevel
public FunctionMethod.Determinism resetDeterminismLevel(boolean detach)
-
resetDeterminismLevel
public FunctionMethod.Determinism resetDeterminismLevel()
-
setDeterminismLevel
public void setDeterminismLevel(FunctionMethod.Determinism level)
-
getWorkItem
public RequestWorkItem getWorkItem()
- Returns:
-
setWorkItem
public void setWorkItem(RequestWorkItem object)
- Parameters:
object
-
-
clone
public CommandContext clone()
-
setNewVDBState
public void setNewVDBState(DQPWorkContext newWorkContext)
-
getConnectionId
public String getConnectionId()
Description copied from interface:CommandContext
Get the connection id- Specified by:
getConnectionId
in interfaceCommandContext
- Returns:
-
getConnectionID
public String getConnectionID()
Description copied from interface:CommandContext
Get the connection id- Specified by:
getConnectionID
in interfaceCommandContext
- Returns:
-
getUserName
public String getUserName()
Description copied from interface:CommandContext
Get the current user name, which will just be the base user name and not include the security domain. See alsoCommandContext.getSession()
-SessionBean.getSecurityDomain()
- Specified by:
getUserName
in interfaceCommandContext
- Returns:
-
getVdbName
public String getVdbName()
Description copied from interface:CommandContext
Get the current vdb name- Specified by:
getVdbName
in interfaceCommandContext
- Returns:
-
getVdbVersion
public String getVdbVersion()
Description copied from interface:CommandContext
Get the current vdb version- Specified by:
getVdbVersion
in interfaceCommandContext
- Returns:
-
setConnectionID
public void setConnectionID(String connectionID)
Sets the connectionID.- Parameters:
connectionID
- The connectionID to set
-
setUserName
public void setUserName(String userName)
Sets the userName.- Parameters:
userName
- The userName to set
-
setVdbName
public void setVdbName(String vdbName)
Sets the vdbName.- Parameters:
vdbName
- The vdbName to set
-
setVdbVersion
public void setVdbVersion(Object vdbVersion)
Sets the vdbVersion.- Parameters:
vdbVersion
- The vdbVersion to set
-
getCommandPayload
public Serializable getCommandPayload()
Description copied from interface:CommandContext
Get the current command payload- Specified by:
getCommandPayload
in interfaceCommandContext
- Returns:
- may be null if the client did not set a payload
-
setCommandPayload
public void setCommandPayload(Serializable commandPayload)
-
setCollectNodeStatistics
public void setCollectNodeStatistics(boolean collectNodeStatistics)
- Parameters:
collectNodeStatistics
- The collectNodeStatistics to set.- Since:
- 4.2
-
getCollectNodeStatistics
public boolean getCollectNodeStatistics()
-
getProcessorBatchSize
public int getProcessorBatchSize()
Description copied from interface:CommandContext
Get the processor batch size set on the BufferManager- Specified by:
getProcessorBatchSize
in interfaceCommandContext
- Returns:
- - the nominal batch size target. actual batch sizes will vary based upon the column types
-
getProcessorBatchSize
public int getProcessorBatchSize(List<Expression> schema)
-
setProcessorBatchSize
public void setProcessorBatchSize(int processorBatchSize)
-
getNextRand
public double getNextRand()
Description copied from interface:CommandContext
Get the next random double value- Specified by:
getNextRand
in interfaceCommandContext
- Returns:
-
getNextRand
public double getNextRand(long seed)
Description copied from interface:CommandContext
Sets the seed value and returns the next random double value. Additional calls toCommandContext.getNextRand()
will be based upon the seed value.- Specified by:
getNextRand
in interfaceCommandContext
- Returns:
-
pushCall
public void pushCall(String value) throws QueryProcessingException
- Throws:
QueryProcessingException
-
getCallStackDepth
public int getCallStackDepth()
-
popCall
public void popCall()
-
setAuthoriziationValidator
public void setAuthoriziationValidator(AuthorizationValidator authorizationValidator)
-
getTempTableStore
public TempTableStore getTempTableStore()
-
setTempTableStore
public void setTempTableStore(TempTableStore tempTableStore)
-
getSessionTempTableStore
public TempTableStore getSessionTempTableStore()
-
setSessionTempTableStore
public void setSessionTempTableStore(TempTableStore tempTableStore)
-
getServerTimeZone
public TimeZone getServerTimeZone()
Description copied from interface:CommandContext
Get the serverTimeZone
- Specified by:
getServerTimeZone
in interfaceCommandContext
- Returns:
-
getQueryProcessorFactory
public QueryProcessor.ProcessorFactory getQueryProcessorFactory()
-
setQueryProcessorFactory
public void setQueryProcessorFactory(QueryProcessor.ProcessorFactory queryProcessorFactory)
-
getVariableContext
public VariableContext getVariableContext()
-
setVariableContext
public void setVariableContext(VariableContext variableContext)
-
pushVariableContext
public void pushVariableContext(VariableContext toPush)
-
getFromContext
public Object getFromContext(Expression expression) throws TeiidComponentException
- Throws:
TeiidComponentException
-
getTimeSliceEnd
public long getTimeSliceEnd()
-
getTimeoutEnd
public long getTimeoutEnd()
-
setTimeSliceEnd
public void setTimeSliceEnd(long timeSliceEnd)
-
setTimeoutEnd
public void setTimeoutEnd(long timeoutEnd)
-
setMetadata
public void setMetadata(QueryMetadataInterface metadata)
-
getMetadata
public QueryMetadataInterface getMetadata()
-
getBufferManager
public BufferManager getBufferManager()
-
setBufferManager
public void setBufferManager(BufferManager bm)
-
getGlobalTableStore
public GlobalTableStore getGlobalTableStore()
-
setGlobalTableStore
public void setGlobalTableStore(GlobalTableStore tempTableStore)
-
isNonBlocking
public boolean isNonBlocking()
-
setNonBlocking
public void setNonBlocking(boolean nonBlocking)
-
setPreparedPlanCache
public void setPreparedPlanCache(SessionAwareCache<PreparedPlan> cache)
-
getPlan
public PreparedPlan getPlan(String key)
-
putPlan
public void putPlan(String key, PreparedPlan plan, FunctionMethod.Determinism determinismLevel)
-
isResultSetCacheEnabled
public boolean isResultSetCacheEnabled()
-
setResultSetCacheEnabled
public void setResultSetCacheEnabled(boolean resultSetCacheEnabled)
-
getUserRequestSourceConcurrency
public int getUserRequestSourceConcurrency()
-
setUserRequestSourceConcurrency
public void setUserRequestSourceConcurrency(int userRequestSourceConcurrency)
-
getSubject
public Subject getSubject()
Description copied from interface:CommandContext
Get the current subject- Specified by:
getSubject
in interfaceCommandContext
- Returns:
-
setSubject
public void setSubject(Subject subject)
-
accessedPlanningObject
public void accessedPlanningObject(Object id)
-
accessedDataObject
public void accessedDataObject(Object id)
-
getSession
public SessionMetadata getSession()
Description copied from interface:CommandContext
Get the current session- Specified by:
getSession
in interfaceCommandContext
- Returns:
-
setSession
public void setSession(SessionMetadata session)
-
getRequestId
public String getRequestId()
Description copied from interface:CommandContext
Get the current request id- Specified by:
getRequestId
in interfaceCommandContext
- Returns:
-
setRequestId
public void setRequestId(RequestID requestId)
-
setDQPWorkContext
public void setDQPWorkContext(DQPWorkContext workContext)
-
getAllowedDataPolicies
public Map<String,DataPolicy> getAllowedDataPolicies()
Description copied from interface:CommandContext
Get the user's data policies, never null- Specified by:
getAllowedDataPolicies
in interfaceCommandContext
- Returns:
-
getVdb
public VDBMetaData getVdb()
Description copied from interface:CommandContext
Get the current vdb- Specified by:
getVdb
in interfaceCommandContext
- Returns:
-
getDQPWorkContext
public DQPWorkContext getDQPWorkContext()
-
getTransactionContext
public TransactionContext getTransactionContext()
-
setTransactionContext
public void setTransactionContext(TransactionContext transactionContext)
-
getTransactionServer
public TransactionService getTransactionServer()
-
setTransactionService
public void setTransactionService(TransactionService transactionService)
-
getExecutor
public Executor getExecutor()
-
submit
public <V> Future<V> submit(Callable<V> callable)
Submit work that will notify the request work item of more work when complete- Parameters:
callable
-- Returns:
-
setExecutor
public void setExecutor(Executor e)
-
getReusableExecution
public ReusableExecution<?> getReusableExecution(Object key)
-
putReusableExecution
public void putReusableExecution(Object key, ReusableExecution<?> execution)
-
close
public void close()
-
addListener
public void addListener(CommandListener listener)
Description copied from interface:CommandContext
Add a listener for command events- Specified by:
addListener
in interfaceCommandContext
-
removeListener
public void removeListener(CommandListener listener)
Description copied from interface:CommandContext
Add a listener for command events- Specified by:
removeListener
in interfaceCommandContext
-
getDecimalFormat
public static DecimalFormat getDecimalFormat(CommandContext context, String format)
-
getDateFormat
public static SimpleDateFormat getDateFormat(CommandContext context, String format)
-
getPattern
public static Pattern getPattern(CommandContext context, String regex, int flags)
Compile a regular expression into aPattern
and cache it in theCommandContext
for future use.- Parameters:
context
-regex
- Regular expression.flags
- Bitmask flags likePattern.CASE_INSENSITIVE
.- Returns:
- Compiled regex.
-
incrementReuseCount
public void incrementReuseCount()
-
getReuseCount
public long getReuseCount()
Description copied from interface:CommandContext
Get the number of times this command has been reused. Useful in continuous executions.- Specified by:
getReuseCount
in interfaceCommandContext
- Returns:
- See Also:
CommandContext.isContinuous()
-
isContinuous
public boolean isContinuous()
- Specified by:
isContinuous
in interfaceCommandContext
- Returns:
- true if this is a continuous query
-
setContinuous
public void setContinuous()
-
getVDBClassLoader
public ClassLoader getVDBClassLoader()
Description copied from interface:CommandContext
Get class loader for VDB.- Specified by:
getVDBClassLoader
in interfaceCommandContext
- Returns:
-
setVDBClassLoader
public void setVDBClassLoader(ClassLoader classLoader)
-
getAndClearWarnings
public List<Exception> getAndClearWarnings()
Get all warnings found while processing this plan. These warnings may be detected throughout the plan lifetime, which means new ones may arrive at any time. This method returns all current warnings and clears the current warnings list. The warnings are in order they were detected.- Returns:
- Current list of warnings, never null
-
addWarning
public void addWarning(Exception warning)
Description copied from interface:CommandContext
Add an exception as a warning. The exception will be wrapped by aTeiidSQLWarning
for the client. The warnings can be consumed through theStatement.getWarnings()
method.- Specified by:
addWarning
in interfaceCommandContext
-
getTupleSourceCache
public TupleSourceCache getTupleSourceCache()
-
setTupleSourceCache
public void setTupleSourceCache(TupleSourceCache tupleSourceCache)
-
getOptions
public Options getOptions()
-
setOptions
public void setOptions(Options options)
-
isReturnAutoGeneratedKeys
public boolean isReturnAutoGeneratedKeys()
Description copied from interface:CommandContext
Whether to return the keys generated by an insert.- Specified by:
isReturnAutoGeneratedKeys
in interfaceCommandContext
- Returns:
- true
-
setReturnAutoGeneratedKeys
public void setReturnAutoGeneratedKeys(List<ElementSymbol> variables)
-
getReturnAutoGeneratedKeys
public List<ElementSymbol> getReturnAutoGeneratedKeys()
-
returnGeneratedKeys
public GeneratedKeysImpl returnGeneratedKeys(String[] columnNames, Class<?>[] columnDataTypes)
Description copied from interface:CommandContext
Creates a holder for generated keys.- Specified by:
returnGeneratedKeys
in interfaceCommandContext
- Returns:
-
getGeneratedKeys
public GeneratedKeysImpl getGeneratedKeys()
Description copied from interface:CommandContext
Returns the last set of generated keys for the current command or null if no keys have been generated.- Specified by:
getGeneratedKeys
in interfaceCommandContext
-
getThreadLocalContext
public static CommandContext getThreadLocalContext()
-
pushThreadLocalContext
public static void pushThreadLocalContext(CommandContext context)
-
popThreadLocalContext
public static void popThreadLocalContext()
-
addAndGetReservedBuffers
public long addAndGetReservedBuffers(int i)
-
setSessionVariable
public Object setSessionVariable(String key, Object value)
Description copied from interface:CommandContext
Set the session variable and return the old value if any- Specified by:
setSessionVariable
in interfaceCommandContext
- Returns:
-
getSessionVariable
public Object getSessionVariable(String key)
Description copied from interface:CommandContext
Get the session variable- Specified by:
getSessionVariable
in interfaceCommandContext
- Returns:
-
getAuthorizationValidator
public AuthorizationValidator getAuthorizationValidator()
-
getCodeLookup
public TupleSource getCodeLookup(String matTableName, Object keyValue)
-
putCodeLookup
public void putCodeLookup(String matTableName, Object keyValue, TupleSource ts)
-
getConnection
public TeiidConnection getConnection() throws TeiidSQLException
Description copied from interface:CommandContext
Gets a connection to the current session.
WARNING be careful with blocking/recursive operations.
The returned connection is considered to be derived and is not allowed to alter the transaction state or close the session.
Each call to this method will return a new connection.
Client side execution/connection properties are specific to each connection instance- Specified by:
getConnection
in interfaceCommandContext
- Returns:
- a Connection to the current session
- Throws:
TeiidSQLException
-
getSpatialRefSys
public Clob getSpatialRefSys()
Used by the system table logic- Returns:
-
addCreatedLob
public void addCreatedLob(FileStoreInputStreamFactory isf)
-
disableAutoCleanLobs
public void disableAutoCleanLobs()
-
requestCancelled
public void requestCancelled()
-
isCancelled
public boolean isCancelled()
Check if this context or the parent has been cancelled. If the parent has been, then we'll propagate.- Returns:
-
clearGeneratedKeys
public void clearGeneratedKeys()
-
isAccessible
public Boolean isAccessible(AbstractMetadataRecord record)
-
setAccessible
public void setAccessible(AbstractMetadataRecord record, Boolean result)
-
getBatchUpdateException
public Throwable getBatchUpdateException()
-
setBatchUpdateException
public void setBatchUpdateException(Throwable t)
-
isParallel
public boolean isParallel()
-
setParallel
public boolean setParallel(boolean value)
-
currentDate
public Date currentDate()
-
currentTime
public Time currentTime()
-
currentTimestamp
public Timestamp currentTimestamp()
-
setCurrentTimestamp
public void setCurrentTimestamp(long currentTimeMillis)
-
isAtomicBlock
public boolean isAtomicBlock()
Used by transaction detection logic when starting an atomic block transaction- Returns:
-
setAtomicBlock
public void setAtomicBlock(boolean atomicBlock)
-
addAccessed
public void addAccessed(TempMetadataID id)
Used by the planner to track only what is accessed by the plan
-
setAccessed
public void setAccessed(Collection<TempMetadataID> accessed)
-
isReadOnly
public boolean isReadOnly()
-
setReadOnly
public void setReadOnly(boolean b)
-
-