All Downloads are FREE. Search and download functionalities are using the official Maven repository.

liquibase.ThreadLocalScopeManager Maven / Gradle / Ivy

There is a newer version: 4.29.1
Show newest version
package liquibase;

/**
 * An alternative to {@link SingletonScopeManager} which manages a separate Scope per thread.

* Integrations that would prefer to use this scope manager can call
Scope.setScopeManager(new ThreadLocalScopeManager())
. *

* The value of Scope.getCurrentScope() at the time of the ThreadLocalScopeManger's creation will be the basis of all scopes created after setScopeManager() is changed, * so you will generally want to setScopeManager as soon as possible. */ @SuppressWarnings("java:S5164") public class ThreadLocalScopeManager extends ScopeManager { private final Scope rootScope; private final ThreadLocal threadLocalScopes = new ThreadLocal<>(); public ThreadLocalScopeManager() { this.rootScope = Scope.getCurrentScope(); } @Override public synchronized Scope getCurrentScope() { Scope current = threadLocalScopes.get(); if (current == null) { threadLocalScopes.set(rootScope); current = rootScope; } return current; } @Override protected synchronized void setCurrentScope(Scope scope) { this.threadLocalScopes.set(scope); } @Override protected Scope init(Scope scope) throws Exception { return rootScope; } }




© 2015 - 2024 Weber Informatics LLC | Privacy Policy