Package com.illumon.iris.db.util
Class IrisDbGroovySession
java.lang.Object
com.illumon.iris.db.util.IrisDbGroovySession
- All Implemented Interfaces:
ScriptSession
Note: This is *clearly* only intended to be used from one thread at a time.
-
Field Summary
Fields -
Constructor Summary
ConstructorsConstructorDescriptionIrisDbGroovySession(com.fishlib.io.logger.Logger log, Database db, boolean runInitScripts) -
Method Summary
Modifier and TypeMethodDescriptionvoidaddScriptImportClass(Class<?> c) voidvoidaddScriptImportStatic(Class<?> c) voidvoidRemoves the currently configured script path loader from this script.voidEvaluates command in the context of the current ScriptSession.voidEvaluates command in the context of the current ScriptSession.static InputStreamfindScript(String relativePath) groovy.lang.Bindingstatic byte[]getDynamicClass(String name) groovy.lang.GroovyShellgetShell()getVariable(String name) Retrieve a variable from the script session's bindings.<T> TgetVariable(String name, T defaultValue) Retrieve a variable from the script session's bindings.Retrieves all of the variable names present in the session's scopeRetrieves all of the variables present in the session's scope (e.g., Groovy binding, Python globals()).booleanhasExecutedScript(String scriptName) booleanhasVariableName(String name) Check if the scope has the given variable namestatic StringisValidImportString(com.fishlib.io.logger.Logger log, String importString) Ensure that the given importString is valid.voidonPersistentQueryInitializationBegin(Supplier<ScriptPathLoader> pathLoaderSupplier, ScriptPathLoaderState scriptLoaderState) Called before PersistentQuery initialization, should setup sourcing from the controller (as required).voidCalled after PersistentQuery initialization.static StringRemove comments from an import statement.voidvoidrunScriptOnce(String script) If this script session can throw unserializable exceptions, this method is responsible for turning those exceptions into something suitable for sending back to a client.voidsetScriptPathLoader(Supplier<ScriptPathLoader> pathLoaderSupplier, boolean caching) Sets the scriptPathLoader that is in use for this session.booleansetUseOriginalScriptLoaderState(boolean useOriginal) Informs the session whether or not we should be using the original ScriptLoaderState for source commands.voidsetVariable(String name, Object value) Inserts a value into the script's scope.Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface com.illumon.iris.db.util.ScriptSession
getWrappedSession, isInteractiveConsoleSession
-
Field Details
-
SCRIPT_TYPE
- See Also:
-
-
Constructor Details
-
IrisDbGroovySession
public IrisDbGroovySession(com.fishlib.io.logger.Logger log, Database db, boolean runInitScripts) throws IOException - Throws:
IOException
-
-
Method Details
-
findScript
- Throws:
IOException
-
runScript
- Throws:
IOException
-
hasExecutedScript
-
runScriptOnce
- Throws:
IOException
-
getVariable
Description copied from interface:ScriptSessionRetrieve a variable from the script session's bindings.- Specified by:
getVariablein interfaceScriptSession- Parameters:
name- the variable to retrieve- Returns:
- the variable
- Throws:
QueryScope.MissingVariableException- if the variable does not exist
-
getVariable
Description copied from interface:ScriptSessionRetrieve a variable from the script session's bindings. If the variable is not present, return defaultValue. If the variable is present, but is not of type (T), a ClassCastException may result.- Specified by:
getVariablein interfaceScriptSession- Type Parameters:
T- the type of the variable- Parameters:
name- the variable to retrievedefaultValue- the value to use when no value is present in the session's scope- Returns:
- the value of the variable, or defaultValue if not present
-
evaluate
Description copied from interface:ScriptSessionEvaluates command in the context of the current ScriptSession.- Specified by:
evaluatein interfaceScriptSession- Parameters:
command- the command to evaluate
-
evaluate
Description copied from interface:ScriptSessionEvaluates command in the context of the current ScriptSession.- Specified by:
evaluatein interfaceScriptSession- Parameters:
command- the command to evaluatescriptName- an optional script name, which may be ignored by the implementation, or used improve error messages or for other internal purposes
-
removeComments
Remove comments from an import statement. /* comments take precedence over eol (//) comments. This ignores escaping and quoting, as they are not valid in an import statement.- Parameters:
s- import statement string from which to remove comments- Returns:
- the input string with comments removed, and whitespace trimmed
-
isValidImportString
Ensure that the given importString is valid. Return a canonical version of the import string if it is valid.- Parameters:
importString- the string to check. importString is "[import] [static] package.class[.innerclass...][.field|.method][.*][;]".- Returns:
- null if importString is not valid, else a string of the form "import [static] package.class.part.part[.*];"
-
addScriptImportClass
-
addScriptImportClass
-
addScriptImportStatic
-
addScriptImportStatic
-
getDynamicClass
-
getVariables
Description copied from interface:ScriptSessionRetrieves all of the variables present in the session's scope (e.g., Groovy binding, Python globals()).- Specified by:
getVariablesin interfaceScriptSession- Returns:
- an unmodifiable map with variable names as the keys, and the Objects as the result
-
getVariableNames
Description copied from interface:ScriptSessionRetrieves all of the variable names present in the session's scope- Specified by:
getVariableNamesin interfaceScriptSession- Returns:
- an unmodifiable set of variable names
-
hasVariableName
Description copied from interface:ScriptSessionCheck if the scope has the given variable name- Specified by:
hasVariableNamein interfaceScriptSession- Parameters:
name- the variable name- Returns:
- True iff the scope has the given variable name
-
setVariable
Description copied from interface:ScriptSessionInserts a value into the script's scope.- Specified by:
setVariablein interfaceScriptSession- Parameters:
name- the variable name to setvalue- the new value of the variable
-
getBinding
public groovy.lang.Binding getBinding() -
getShell
public groovy.lang.GroovyShell getShell() -
scriptType
- Specified by:
scriptTypein interfaceScriptSession- Returns:
- a textual description of this script session's language for use in messages.
-
sanitizeThrowable
Description copied from interface:ScriptSessionIf this script session can throw unserializable exceptions, this method is responsible for turning those exceptions into something suitable for sending back to a client.- Specified by:
sanitizeThrowablein interfaceScriptSession- Parameters:
e- the exception to (possibly) sanitize- Returns:
- the sanitized exception
-
onPersistentQueryInitializationBegin
public void onPersistentQueryInitializationBegin(@NotNull Supplier<ScriptPathLoader> pathLoaderSupplier, @Nullable ScriptPathLoaderState scriptLoaderState) Description copied from interface:ScriptSessionCalled before PersistentQuery initialization, should setup sourcing from the controller (as required).- Specified by:
onPersistentQueryInitializationBeginin interfaceScriptSession
-
onPersistentQueryInitializationEnd
public void onPersistentQueryInitializationEnd()Description copied from interface:ScriptSessionCalled after PersistentQuery initialization.- Specified by:
onPersistentQueryInitializationEndin interfaceScriptSession
-
setScriptPathLoader
public void setScriptPathLoader(@NotNull Supplier<ScriptPathLoader> pathLoaderSupplier, boolean caching) Description copied from interface:ScriptSessionSets the scriptPathLoader that is in use for this session.- Specified by:
setScriptPathLoaderin interfaceScriptSession- Parameters:
pathLoaderSupplier- a supplier of a script path loadercaching- whether the source operation should cache results
-
setUseOriginalScriptLoaderState
public boolean setUseOriginalScriptLoaderState(boolean useOriginal) Description copied from interface:ScriptSessionInforms the session whether or not we should be using the original ScriptLoaderState for source commands.- Specified by:
setUseOriginalScriptLoaderStatein interfaceScriptSession- Parameters:
useOriginal- whether to use the script loader state at persistent query initialization
-
clearScriptPathLoader
public void clearScriptPathLoader()Description copied from interface:ScriptSessionRemoves the currently configured script path loader from this script.- Specified by:
clearScriptPathLoaderin interfaceScriptSession
-