public class Scope extends Object
child(Map, ScopedRunner)
or child(String, Object, ScopedRunner)
methods.
Values set in parent scopes are visible in child scopes, but values in child scopes are not visible to parent scopes.
Values with the same key in different scopes "mask" each other with the value furthest down the scope chain being returned.Modifier and Type | Class and Description |
---|---|
static class |
Scope.Attr
Enumeration containing standard attributes.
|
static interface |
Scope.ScopedRunner<T> |
static interface |
Scope.ScopedRunnerWithReturn<T> |
Modifier | Constructor and Description |
---|---|
protected |
Scope(Scope parent,
Map<String,Object> scopeValues) |
Modifier and Type | Method and Description |
---|---|
MdcObject |
addMdcValue(String key,
CustomMdcObject customMdcObject)
Add a key value pair to the MDC using the MDC manager.
|
MdcObject |
addMdcValue(String key,
CustomMdcObject customMdcObject,
boolean removeWhenScopeExits)
Add a key value pair to the MDC using the MDC manager.
|
MdcObject |
addMdcValue(String key,
Map<String,String> value)
Add a key value pair to the MDC using the MDC manager.
|
MdcObject |
addMdcValue(String key,
Map<String,String> value,
boolean removeWhenScopeExits)
Add a key value pair to the MDC using the MDC manager.
|
MdcObject |
addMdcValue(String key,
String value)
Add a key value pair to the MDC using the MDC manager.
|
MdcObject |
addMdcValue(String key,
String value,
boolean removeWhenScopeExits)
Add a key value pair to the MDC using the MDC manager.
|
static void |
child(Enum newValueKey,
Object newValue,
Scope.ScopedRunner runner) |
static void |
child(LiquibaseListener listener,
Map<String,Object> scopeValues,
Scope.ScopedRunner runner) |
static <T> T |
child(LiquibaseListener listener,
Map<String,Object> scopeValues,
Scope.ScopedRunnerWithReturn<T> runner) |
static void |
child(LiquibaseListener listener,
Scope.ScopedRunner runner)
Creates a new child scope that includes the given
LiquibaseListener . |
static void |
child(Map<String,Object> scopeValues,
Scope.ScopedRunner runner)
Creates a new scope that is a child of this scope.
|
static <ReturnType> |
child(Map<String,Object> scopeValues,
Scope.ScopedRunnerWithReturn<ReturnType> runner)
Creates a new scope that is a child of this scope.
|
static void |
child(String newValueKey,
Object newValue,
Scope.ScopedRunner runner)
Creates a new scope that is a child of this scope.
|
String |
describe() |
static String |
enter(LiquibaseListener listener,
Map<String,Object> scopeValues)
Creates a new scope without passing a ScopedRunner.
|
static String |
enter(Map<String,Object> scopeValues)
Convenience version of
enter(LiquibaseListener, Map) with no LiquibaseListener |
static void |
exit(String scopeId)
Exits the scope started with
enter(LiquibaseListener, Map) |
<T> T |
get(Enum key,
Class<T> type) |
<T> T |
get(Enum key,
T defaultValue) |
<T> T |
get(String key,
Class<T> type)
Return the value associated with the given key in this scope or any parent scope.
|
<T> T |
get(String key,
T defaultValue)
Return the value associated with the given key in this scope or any parent scope.
|
ClassLoader |
getClassLoader() |
ClassLoader |
getClassLoader(boolean fallbackToContextClassLoader) |
static Scope |
getCurrentScope() |
Database |
getDatabase() |
Charset |
getFileEncoding()
Deprecated.
|
String |
getLineSeparator() |
<T extends LiquibaseListener> |
getListeners(Class<T> type)
Returns
LiquibaseListener s defined in this scope and/or all its parents that are of the given type. |
Logger |
getLog(Class clazz) |
MdcManager |
getMdcManager()
Get the current MDC manager.
|
Scope |
getParent()
Returns the parent scope to this scope.
|
ResourceAccessor |
getResourceAccessor() |
ServiceLocator |
getServiceLocator() |
<T extends SingletonObject> |
getSingleton(Class<T> type)
Looks up the singleton object of the given type.
|
UIService |
getUI() |
boolean |
has(Enum key)
Return true if the given key is defined.
|
boolean |
has(String key)
Return true if the given key is defined.
|
static void |
setScopeManager(ScopeManager scopeManager) |
String |
toString() |
public static Scope getCurrentScope()
public static void setScopeManager(ScopeManager scopeManager)
public Scope getParent()
public static void child(Map<String,Object> scopeValues, Scope.ScopedRunner runner) throws Exception
Exception
public static <ReturnType> ReturnType child(Map<String,Object> scopeValues, Scope.ScopedRunnerWithReturn<ReturnType> runner) throws Exception
Exception
public static void child(LiquibaseListener listener, Scope.ScopedRunner runner) throws Exception
LiquibaseListener
.
You cannot unassign a listener, they simply fall out of scope when the Scope does.Exception
getListeners(Class)
public static void child(LiquibaseListener listener, Map<String,Object> scopeValues, Scope.ScopedRunner runner) throws Exception
Exception
public static <T> T child(LiquibaseListener listener, Map<String,Object> scopeValues, Scope.ScopedRunnerWithReturn<T> runner) throws Exception
Exception
public static String enter(Map<String,Object> scopeValues) throws Exception
enter(LiquibaseListener, Map)
with no LiquibaseListener
Exception
public static String enter(LiquibaseListener listener, Map<String,Object> scopeValues) throws Exception
exit(String)
exit(String)
Exception
public static void exit(String scopeId) throws Exception
enter(LiquibaseListener, Map)
scopeId
- The id of the scope to exit. Throws an exception if the name does not match the current scope.Exception
public static void child(String newValueKey, Object newValue, Scope.ScopedRunner runner) throws Exception
Exception
public static void child(Enum newValueKey, Object newValue, Scope.ScopedRunner runner) throws Exception
Exception
public boolean has(String key)
public boolean has(Enum key)
public <T> T get(Enum key, T defaultValue)
public <T> T get(String key, Class<T> type)
ObjectUtil.convert(Object, Class)
.
Returns null if key is not defined in this or any parent scopes.public <T> T get(String key, T defaultValue)
ObjectUtil.convert(Object, Class)
.public <T extends SingletonObject> T getSingleton(Class<T> type)
public UIService getUI()
public Database getDatabase()
public ClassLoader getClassLoader()
public ClassLoader getClassLoader(boolean fallbackToContextClassLoader)
public ServiceLocator getServiceLocator()
public ResourceAccessor getResourceAccessor()
public String getLineSeparator()
public Charset getFileEncoding()
GlobalConfiguration.FILE_ENCODING
public MdcManager getMdcManager()
public MdcObject addMdcValue(String key, String value)
public MdcObject addMdcValue(String key, String value, boolean removeWhenScopeExits)
removeWhenScopeExits
- if true, this key value pair will be automatically removed from the MDC when this
scope exits. If there is not a demonstrable reason for setting this parameter to false
then it should be set to true.public MdcObject addMdcValue(String key, Map<String,String> value)
public MdcObject addMdcValue(String key, Map<String,String> value, boolean removeWhenScopeExits)
removeWhenScopeExits
- if true, this key value pair will be automatically removed from the MDC when this
scope exits. If there is not a demonstrable reason for setting this parameter to false
then it should be set to true.public MdcObject addMdcValue(String key, CustomMdcObject customMdcObject)
public MdcObject addMdcValue(String key, CustomMdcObject customMdcObject, boolean removeWhenScopeExits)
removeWhenScopeExits
- if true, this key value pair will be automatically removed from the MDC when this
scope exits. If there is not a demonstrable reason for setting this parameter to false
then it should be set to true.public <T extends LiquibaseListener> Collection<T> getListeners(Class<T> type)
LiquibaseListener
s defined in this scope and/or all its parents that are of the given type.public String describe()
Copyright © 2023 Liquibase.org. All rights reserved.