Package liquibase
Class Scope
java.lang.Object
liquibase.Scope
This scope object is used to hold configuration and other parameters within a call without needing complex method signatures.
It also allows new parameters to be added by extensions without affecting standard method signatures.
Scope objects can be created in a hierarchical manner with the
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.-
Nested Class Summary
Modifier and TypeClassDescriptionstatic enum
Enumeration containing standard attributes.static interface
static interface
-
Field Summary
-
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionaddMdcValue
(String key, String value) Add a key value pair to the MDC using the MDC manager.addMdcValue
(String key, String value, boolean removeWhenScopeExits) Add a key value pair to the MDC using the MDC manager.addMdcValue
(String key, Map<String, Object> value) Add a key value pair to the MDC using the MDC manager.addMdcValue
(String key, Map<String, Object> value, boolean removeWhenScopeExits) Add a key value pair to the MDC using the MDC manager.addMdcValue
(String key, CustomMdcObject customMdcObject) Add a key value pair to the MDC using the MDC manager.addMdcValue
(String key, CustomMdcObject customMdcObject, 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
(String newValueKey, Object newValue, Scope.ScopedRunner runner) Creates a new scope that is a child of this scope.static void
child
(Map<String, Object> scopeValues, Scope.ScopedRunner runner) Creates a new scope that is a child of this scope.static <ReturnType>
ReturnTypechild
(Map<String, Object> scopeValues, Scope.ScopedRunnerWithReturn<ReturnType> runner) Creates a new scope that is a child of this scope.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 givenLiquibaseListener
.describe()
static String
Convenience version ofenter(LiquibaseListener, Map)
with noLiquibaseListener
static String
enter
(LiquibaseListener listener, Map<String, Object> scopeValues) Creates a new scope without passing a ScopedRunner.static void
Exits the scope started withenter(LiquibaseListener, Map)
<T> T
<T> T
<T> T
Return the value associated with the given key in this scope or any parent scope.<T> T
Return the value associated with the given key in this scope or any parent scope.Get the current analytics event.getClassLoader
(boolean fallbackToContextClassLoader) static Scope
Deprecated.<T extends LiquibaseListener>
Collection<T>getListeners
(Class<T> type) ReturnsLiquibaseListener
s defined in this scope and/or all its parents that are of the given type.Get the current MDC manager.Returns the parent scope to this scope.<T extends SingletonObject>
TgetSingleton
(Class<T> type) Looks up the singleton object of the given type.getUI()
boolean
Return true if the given key is defined.boolean
Return true if the given key is defined.boolean
isMdcKeyPresent
(String key) Check if the provided mdc key is presentstatic void
setScopeManager
(ScopeManager scopeManager) toString()
-
Field Details
-
JAVA_PROPERTIES
- See Also:
-
-
Constructor Details
-
Scope
- Parameters:
parent
- The new Scopes parent in the hierarchy of Scopes, not null.scopeValues
- The values for the new Scope.
-
-
Method Details
-
getCurrentScope
-
setScopeManager
-
getParent
Returns the parent scope to this scope. Returns null if this is a root scope. -
child
public static void child(Map<String, Object> scopeValues, Scope.ScopedRunner runner) throws ExceptionCreates a new scope that is a child of this scope.- Throws:
Exception
-
child
public static <ReturnType> ReturnType child(Map<String, Object> scopeValues, Scope.ScopedRunnerWithReturn<ReturnType> runner) throws ExceptionCreates a new scope that is a child of this scope.- Throws:
Exception
-
child
Creates a new child scope that includes the givenLiquibaseListener
. You cannot unassign a listener, they simply fall out of scope when the Scope does.- Throws:
Exception
- See Also:
-
child
public static void child(LiquibaseListener listener, Map<String, Object> scopeValues, Scope.ScopedRunner runner) throws Exception- Throws:
Exception
-
child
public static <T> T child(LiquibaseListener listener, Map<String, Object> scopeValues, Scope.ScopedRunnerWithReturn<T> runner) throws Exception- Throws:
Exception
-
enter
Convenience version ofenter(LiquibaseListener, Map)
with noLiquibaseListener
- Throws:
Exception
-
enter
public static String enter(LiquibaseListener listener, Map<String, Object> scopeValues) throws ExceptionCreates a new scope without passing a ScopedRunner. This mainly exists for tests where you have a setup/cleanup method pattern. The recommended way to create Scopes is the "child" methods. When done with the scope, callexit(String)
- Returns:
- Returns the scopeId to pass to to
exit(String)
- Throws:
Exception
-
exit
Exits the scope started withenter(LiquibaseListener, Map)
- Parameters:
scopeId
- The id of the scope to exit. Throws an exception if the name does not match the current scope.- Throws:
Exception
-
child
public static void child(String newValueKey, Object newValue, Scope.ScopedRunner runner) throws Exception Creates a new scope that is a child of this scope.- Throws:
Exception
-
child
public static void child(Enum newValueKey, Object newValue, Scope.ScopedRunner runner) throws Exception - Throws:
Exception
-
has
Return true if the given key is defined. -
has
Return true if the given key is defined. -
get
-
get
-
get
Return the value associated with the given key in this scope or any parent scope. The value is converted to the given type if necessary usingObjectUtil.convert(Object, Class)
. Returns null if key is not defined in this or any parent scopes. -
get
Return the value associated with the given key in this scope or any parent scope. If the value is not defined, the passed defaultValue is returned. The value is converted to the given type if necessary usingObjectUtil.convert(Object, Class)
. -
getSingleton
Looks up the singleton object of the given type. If the singleton has not been created yet, it will be instantiated. The singleton is a singleton based on the root scope and the same object will be returned for all child scopes of the root. -
getLog
-
getUI
-
getDatabase
-
getClassLoader
-
getClassLoader
-
getServiceLocator
-
getResourceAccessor
-
getChecksumVersion
-
getLineSeparator
-
getFileEncoding
Deprecated. -
getMdcManager
Get the current MDC manager. -
addMdcValue
Add a key value pair to the MDC using the MDC manager. This key value pair will be automatically removed from the MDC when this scope exits. -
addMdcValue
Add a key value pair to the MDC using the MDC manager.- Parameters:
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.
-
addMdcValue
Add a key value pair to the MDC using the MDC manager. This key value pair will be automatically removed from the MDC when this scope exits. -
addMdcValue
Add a key value pair to the MDC using the MDC manager.- Parameters:
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.
-
addMdcValue
Add a key value pair to the MDC using the MDC manager. This key value pair will be automatically removed from the MDC when this scope exits. -
addMdcValue
public MdcObject addMdcValue(String key, CustomMdcObject customMdcObject, boolean removeWhenScopeExits) Add a key value pair to the MDC using the MDC manager.- Parameters:
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.
-
isMdcKeyPresent
Check if the provided mdc key is present- Returns:
- true if there is an existing key, false otherwise
-
getListeners
ReturnsLiquibaseListener
s defined in this scope and/or all its parents that are of the given type. -
getAnalyticsEvent
Get the current analytics event. This can return null if analytics is not enabled.- Returns:
-
toString
-
describe
-
GlobalConfiguration.FILE_ENCODING