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 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.
  • Field Details

  • Constructor Details

    • 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 Details

    • 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 given LiquibaseListener. 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

      public static String enter(Map<String,Object> scopeValues) throws Exception
      Convenience version of enter(LiquibaseListener, Map) with no LiquibaseListener
      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, call exit(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 with enter(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, 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.
    • getLog

      public Logger getLog(Class clazz)
    • 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

      @Deprecated public Charset getFileEncoding()
    • 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)
      Returns LiquibaseListeners defined in this scope and/or all its parents that are of the given type.
    • getAnalyticsEvent

      public Event getAnalyticsEvent()
      Get the current analytics event. This can return null if analytics is not enabled.
      Returns:
    • toString

      public String toString()
      Overrides:
      toString in class Object
    • describe

      public String describe()