Class QueryScope
java.lang.Object
com.illumon.iris.db.tables.select.QueryScope
- All Implemented Interfaces:
com.fishlib.base.log.LogOutputAppendable
- Direct Known Subclasses:
QueryScope.StandaloneImpl
,QueryScope.SynchronizedScriptSessionImpl
,QueryScope.UnsynchronizedScriptSessionImpl
public abstract class QueryScope extends Object implements com.fishlib.base.log.LogOutputAppendable
Variable scope used to resolve parameter values during query execution.
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static class
QueryScope.MissingVariableException
A type of RuntimeException thrown when a variable referenced within theQueryScope
is not defined or, more likely, has not been added to the scope.static class
QueryScope.StandaloneImpl
static class
QueryScope.SynchronizedScriptSessionImpl
static class
QueryScope.UnsynchronizedScriptSessionImpl
-
Field Summary
Fields Modifier and Type Field Description static String
CLIENT_HOST_PARAM_NAME
Parameter name for the client host.static String
QUERY_NAME_PARAM_NAME
Parameter name for the query name. -
Constructor Summary
Constructors Constructor Description QueryScope()
-
Method Summary
Modifier and Type Method Description static void
addObjectFields(Object object)
Adds an object's declared fields to the scope.static <T> void
addParam(String name, T value)
Adds a parameter to the default instanceQueryScope
, or updates the value of an existing parameter.com.fishlib.base.log.LogOutput
append(com.fishlib.base.log.LogOutput logOutput)
protected abstract <T> Param<T>
createParam(String name)
Get a Param by name.String
getClientHost()
Gets the client host value.static QueryScope
getDefaultInstance()
Retrieve the defaultQueryScope
instance which will be used by static methods.abstract Map<String,Object>
getLocalValuesForRemoteParams()
Get a snapshot of local values for remote parameters, for scopes that support this.abstract Set<String>
getParamNames()
Get all known scope variable names.Param[]
getParams(Collection<String> names)
Get an array of Params by name.static <T> T
getParamValue(String name)
Gets a parameter from the default instanceQueryScope
.String
getQueryName()
Gets the query name.abstract boolean
hasParamName(String name)
Check if the scope has the given name.static QueryScope
makeScriptSessionImpl(ScriptSession scriptSession)
Creates a query scope for an interactive console script session.abstract void
putObjectFields(Object object)
Add an object's public members (referenced reflectively, not a shallow copy!) to this scope if supported.abstract <T> void
putParam(String name, T value)
Add a parameter to the scope.abstract void
putRemoteParams(Map<String,Class> remoteParamMetadata)
Add remote parameter metadata, for scopes that support this.abstract <T> T
readParamValue(String name)
Get the value of a given scope parameter by name.abstract <T> T
readParamValue(String name, T defaultValue)
Get the value of a given scope parameter by name.void
setClientHost(String clientHost)
Sets the client host value.static void
setDefaultInstance(QueryScope queryScope)
Sets the defaultQueryScope
to be used in the current context.void
setQueryName(String queryName)
Sets the query name.
-
Field Details
-
CLIENT_HOST_PARAM_NAME
Parameter name for the client host.- See Also:
- Constant Field Values
-
QUERY_NAME_PARAM_NAME
Parameter name for the query name.- See Also:
- Constant Field Values
-
-
Constructor Details
-
QueryScope
public QueryScope()
-
-
Method Details
-
setDefaultInstance
Sets the defaultQueryScope
to be used in the current context. By default there is aQueryScope.StandaloneImpl
created by the static initializer and set as the defaultInstance. The method allows the use of a new or separate instance as the default instance for static methods.- Parameters:
queryScope
-QueryScope
to set as the new default instance.
-
getDefaultInstance
Retrieve the defaultQueryScope
instance which will be used by static methods.- Returns:
QueryScope
-
addParam
Adds a parameter to the default instanceQueryScope
, or updates the value of an existing parameter.- Type Parameters:
T
- type of the parameter/value.- Parameters:
name
- String name of the parameter to add.value
- value to assign to the parameter.
-
addObjectFields
Adds an object's declared fields to the scope.- Parameters:
object
- object whose fields will be added.
-
getParamValue
Gets a parameter from the default instanceQueryScope
.- Type Parameters:
T
- parameter type.- Parameters:
name
- parameter name.- Returns:
- parameter value.
- Throws:
QueryScope.MissingVariableException
- variable name is not defined.
-
getParams
public final Param[] getParams(Collection<String> names) throws QueryScope.MissingVariableExceptionGet an array of Params by name. See createParam(name) implementations for details.- Parameters:
names
- parameter names- Returns:
- A newly-constructed array of newly-constructed Params.
- Throws:
QueryScope.MissingVariableException
- If any of the named scope variables does not exist.
-
getParamNames
Get all known scope variable names.- Returns:
- A collection of scope variable names.
-
hasParamName
Check if the scope has the given name.- Parameters:
name
- param name- Returns:
- True iff the scope has the given param name
-
createParam
protected abstract <T> Param<T> createParam(String name) throws QueryScope.MissingVariableExceptionGet a Param by name.- Parameters:
name
- parameter name- Returns:
- newly-constructed Param (name + value-snapshot pair).
- Throws:
QueryScope.MissingVariableException
- If any of the named scope variables does not exist.
-
readParamValue
Get the value of a given scope parameter by name.- Parameters:
name
- parameter name.- Returns:
- parameter value.
- Throws:
QueryScope.MissingVariableException
- If no such scope parameter exists.
-
readParamValue
Get the value of a given scope parameter by name.- Parameters:
name
- parameter name.defaultValue
- default parameter value.- Returns:
- parameter value, or the default parameter value, if the value is not present.
-
putParam
Add a parameter to the scope.- Parameters:
name
- parameter name.value
- parameter value.
-
putRemoteParams
Add remote parameter metadata, for scopes that support this. Note: This is an optional method.- Parameters:
remoteParamMetadata
- remote parameter metadata.
-
getLocalValuesForRemoteParams
Get a snapshot of local values for remote parameters, for scopes that support this. Note: This is an optional method.- Returns:
- A map from name to the current local value for all remote params.
-
putObjectFields
Add an object's public members (referenced reflectively, not a shallow copy!) to this scope if supported. Note: This is an optional method.- Parameters:
object
- object to add public members from.
-
getClientHost
Gets the client host value.- Returns:
- client host value.
-
setClientHost
Sets the client host value.- Parameters:
clientHost
- client host value.
-
getQueryName
Gets the query name.- Returns:
- query name.
-
setQueryName
Sets the query name.- Parameters:
queryName
- query name.
-
append
public com.fishlib.base.log.LogOutput append(@NotNull com.fishlib.base.log.LogOutput logOutput)- Specified by:
append
in interfacecom.fishlib.base.log.LogOutputAppendable
-
makeScriptSessionImpl
Creates a query scope for an interactive console script session.- Parameters:
scriptSession
- script session- Returns:
- query scope
-