Package liquibase

Class 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 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.
    • Constructor Detail

      • Scope

        protected Scope​(Scope parent,
                        Map<String,​Object> scopeValues)
        Parameters:
        parent - The new Scopes parent in the hierarchy of Scopes, not null.
        scopeValues - The values for the new Scope.
    • 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.
      • 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, call exit(String)
        Returns:
        Returns the scopeId to pass to to exit(String)
        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,
                         Class<T> type)
      • 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 using ObjectUtil.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 using ObjectUtil.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.
      • getDatabase

        public Database getDatabase()
      • getClassLoader

        public ClassLoader getClassLoader​(boolean fallbackToContextClassLoader)
      • getLineSeparator

        public String getLineSeparator()
      • 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
      • describe

        public String describe()