Package liquibase
Class Scope
- java.lang.Object
-
- liquibase.Scope
-
public class Scope extends Object
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 thechild(Map, ScopedRunner)orchild(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
Nested Classes Modifier and Type Class Description static classScope.AttrEnumeration containing standard attributes.static interfaceScope.ScopedRunner<T>static interfaceScope.ScopedRunnerWithReturn<T>
-
Field Summary
Fields Modifier and Type Field Description static StringJAVA_PROPERTIES
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Deprecated Methods Modifier and Type Method Description MdcObjectaddMdcValue(String key, String value)Add a key value pair to the MDC using the MDC manager.MdcObjectaddMdcValue(String key, String value, boolean removeWhenScopeExits)Add a key value pair to the MDC using the MDC manager.MdcObjectaddMdcValue(String key, Map<String,Object> value)Add a key value pair to the MDC using the MDC manager.MdcObjectaddMdcValue(String key, Map<String,Object> value, boolean removeWhenScopeExits)Add a key value pair to the MDC using the MDC manager.MdcObjectaddMdcValue(String key, CustomMdcObject customMdcObject)Add a key value pair to the MDC using the MDC manager.MdcObjectaddMdcValue(String key, CustomMdcObject customMdcObject, boolean removeWhenScopeExits)Add a key value pair to the MDC using the MDC manager.static voidchild(Enum newValueKey, Object newValue, Scope.ScopedRunner runner)static voidchild(String newValueKey, Object newValue, Scope.ScopedRunner runner)Creates a new scope that is a child of this scope.static voidchild(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 voidchild(LiquibaseListener listener, Map<String,Object> scopeValues, Scope.ScopedRunner runner)static <T> Tchild(LiquibaseListener listener, Map<String,Object> scopeValues, Scope.ScopedRunnerWithReturn<T> runner)static voidchild(LiquibaseListener listener, Scope.ScopedRunner runner)Creates a new child scope that includes the givenLiquibaseListener.Stringdescribe()static Stringenter(Map<String,Object> scopeValues)Convenience version ofenter(LiquibaseListener, Map)with noLiquibaseListenerstatic Stringenter(LiquibaseListener listener, Map<String,Object> scopeValues)Creates a new scope without passing a ScopedRunner.static voidexit(String scopeId)Exits the scope started withenter(LiquibaseListener, Map)<T> Tget(Enum key, Class<T> type)<T> Tget(Enum key, T defaultValue)<T> Tget(String key, Class<T> type)Return the value associated with the given key in this scope or any parent scope.<T> Tget(String key, T defaultValue)Return the value associated with the given key in this scope or any parent scope.ChecksumVersiongetChecksumVersion()ClassLoadergetClassLoader()ClassLoadergetClassLoader(boolean fallbackToContextClassLoader)static ScopegetCurrentScope()DatabasegetDatabase()CharsetgetFileEncoding()Deprecated.StringgetLineSeparator()<T extends LiquibaseListener>
Collection<T>getListeners(Class<T> type)ReturnsLiquibaseListeners defined in this scope and/or all its parents that are of the given type.LoggergetLog(Class clazz)MdcManagergetMdcManager()Get the current MDC manager.ScopegetParent()Returns the parent scope to this scope.ResourceAccessorgetResourceAccessor()ServiceLocatorgetServiceLocator()<T extends SingletonObject>
TgetSingleton(Class<T> type)Looks up the singleton object of the given type.UIServicegetUI()booleanhas(Enum key)Return true if the given key is defined.booleanhas(String key)Return true if the given key is defined.booleanisMdcKeyPresent(String key)Check if the provided mdc key is presentstatic voidsetScopeManager(ScopeManager scopeManager)StringtoString()
-
-
-
Field Detail
-
JAVA_PROPERTIES
public static final String JAVA_PROPERTIES
- See Also:
- Constant Field Values
-
-
Method Detail
-
getCurrentScope
public static Scope getCurrentScope()
-
setScopeManager
public static void setScopeManager(ScopeManager scopeManager)
-
getParent
public Scope 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 Exception
Creates 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 Exception
Creates a new scope that is a child of this scope.- Throws:
Exception
-
child
public static void child(LiquibaseListener listener, Scope.ScopedRunner runner) throws Exception
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:
getListeners(Class)
-
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
public static String enter(Map<String,Object> scopeValues) throws Exception
Convenience version ofenter(LiquibaseListener, Map)with noLiquibaseListener- Throws:
Exception
-
enter
public static String enter(LiquibaseListener listener, Map<String,Object> scopeValues) throws Exception
Creates 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
public static void exit(String scopeId) throws Exception
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
public boolean has(String key)
Return true if the given key is defined.
-
has
public boolean has(Enum key)
Return true if the given key is defined.
-
get
public <T> T get(Enum key, T defaultValue)
-
get
public <T> T get(String key, Class<T> type)
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
public <T> T get(String key, T defaultValue)
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
public <T extends SingletonObject> T getSingleton(Class<T> type)
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.
-
getUI
public UIService getUI()
-
getDatabase
public Database getDatabase()
-
getClassLoader
public ClassLoader getClassLoader()
-
getClassLoader
public ClassLoader getClassLoader(boolean fallbackToContextClassLoader)
-
getServiceLocator
public ServiceLocator getServiceLocator()
-
getResourceAccessor
public ResourceAccessor getResourceAccessor()
-
getChecksumVersion
public ChecksumVersion getChecksumVersion()
-
getLineSeparator
public String getLineSeparator()
-
getFileEncoding
public Charset getFileEncoding()
Deprecated.
-
getMdcManager
public MdcManager getMdcManager()
Get the current MDC manager.
-
addMdcValue
public MdcObject addMdcValue(String key, String value)
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, String value, 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.
-
addMdcValue
public MdcObject addMdcValue(String key, Map<String,Object> value)
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, Map<String,Object> value, 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.
-
addMdcValue
public MdcObject addMdcValue(String key, CustomMdcObject customMdcObject)
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
@Beta public boolean isMdcKeyPresent(String key)
Check if the provided mdc key is present- Returns:
- true if there is an existing key, false otherwise
-
getListeners
public <T extends LiquibaseListener> Collection<T> getListeners(Class<T> type)
ReturnsLiquibaseListeners defined in this scope and/or all its parents that are of the given type.
-
describe
public String describe()
-
-