Interface QueryScope

All Superinterfaces:
LivenessManager, LivenessNode, LivenessReferent, LogOutputAppendable
All Known Implementing Classes:
AbstractScriptSession.ScriptSessionQueryScope, EmptyQueryScope, PoisonedQueryScope, StandaloneQueryScope

public interface QueryScope extends LivenessNode, LogOutputAppendable
Variable scope used to resolve parameter values during query execution and to expose named objects to users. Objects passed in will have their liveness managed by the scope.
  • Method Details

    • addParam

      static <T> void addParam(String name, T value)
      Adds a parameter to the default instance QueryScope, or updates the value of an existing parameter. Objects passed in will have their liveness managed by the scope.
      Type Parameters:
      T - type of the parameter/value.
      Parameters:
      name - String name of the parameter to add.
      value - value to assign to the parameter.
    • getParamValue

      static <T> T getParamValue(String name) throws QueryScope.MissingVariableException
      Gets a parameter from the default instance QueryScope.
      Type Parameters:
      T - parameter type.
      Parameters:
      name - parameter name.
      Returns:
      parameter value.
      Throws:
      QueryScope.MissingVariableException - variable name is not defined.
    • getParams

      default QueryScopeParam<?>[] getParams(Collection<String> names) throws QueryScope.MissingVariableException
      Get 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

      Set<String> getParamNames()
      Get all known scope variable names.
      Returns:
      A caller-owned mutable collection of scope variable names.
    • hasParamName

      boolean hasParamName(String name)
      Check if the scope has the given name.
      Parameters:
      name - param name
      Returns:
      True iff the scope has the given param name
    • createParam

      Get a QueryScopeParam by name.
      Parameters:
      name - parameter name
      Returns:
      newly-constructed QueryScopeParam (name + value-snapshot pair).
      Throws:
      QueryScope.MissingVariableException - If any of the named scope variables does not exist.
    • readParamValue

      <T> T readParamValue(String name) throws QueryScope.MissingVariableException
      Get the value of a given scope parameter by name. Callers may want to unwrap language-specific values using unwrapObject(Object) before using them.
      Parameters:
      name - parameter name.
      Returns:
      parameter value.
      Throws:
      QueryScope.MissingVariableException - If no such scope parameter exists.
    • readParamValue

      <T> T readParamValue(String name, T defaultValue)
      Get the value of a given scope parameter by name. Callers may want to unwrap language-specific values using unwrapObject(Object) before using them.
      Parameters:
      name - parameter name.
      defaultValue - default parameter value.
      Returns:
      parameter value, or the default parameter value, if the value is not present.
    • putParam

      <T> void putParam(String name, T value)
      Add a parameter to the scope. Objects passed in will have their liveness managed by the scope.
      Parameters:
      name - parameter name.
      value - parameter value.
    • toMap

      Map<String,Object> toMap(@NotNull @NotNull QueryScope.ParamFilter<Object> filter)
      Returns a mutable map with all objects in the scope. Callers may want to unwrap language-specific values using unwrapObject(Object) before using them. This returned map is owned by the caller.
      Parameters:
      filter - a predicate to filter the map entries
      Returns:
      a caller-owned mutable map with all known variables and their values.
    • toMap

      <T> Map<String,T> toMap(@NotNull @NotNull Function<Object,T> valueMapper, @NotNull @NotNull QueryScope.ParamFilter<T> filter)
      Returns a mutable map with all objects in the scope.

      Callers may want to pass in a valueMapper of unwrapObject(Object) which would unwrap values before filtering. The returned map is owned by the caller.

      Type Parameters:
      T - the type of the mapped values
      Parameters:
      valueMapper - a function to map the values
      filter - a predicate to filter the map entries
      Returns:
      a caller-owned mutable map with all known variables and their values.
    • unwrapObject

      default Object unwrapObject(@Nullable @Nullable Object object)
      Removes any wrapping that exists on a scope param object so that clients can fetch them. Defaults to returning the object itself.
      Parameters:
      object - the scoped object
      Returns:
      an obj which can be consumed by a client
    • append

      default LogOutput append(@NotNull @NotNull LogOutput logOutput)
      Specified by:
      append in interface LogOutputAppendable