View Javadoc

1   package liquibase.executor;
2   
3   import liquibase.database.Database;
4   import liquibase.exception.UnexpectedLiquibaseException;
5   import liquibase.servicelocator.ServiceLocator;
6   
7   import java.util.Map;
8   import java.util.concurrent.ConcurrentHashMap;
9   
10  public class ExecutorService {
11  
12      private static ExecutorService instance = new ExecutorService();
13  
14      private Map<Database, Executor> executors = new ConcurrentHashMap<Database, Executor>();
15  
16      private ExecutorService() {
17      }
18  
19      public static ExecutorService getInstance() {
20          return instance;
21      }
22  
23      public Executor getExecutor(Database database) {
24          if (!executors.containsKey(database)) {
25              try {
26                  Executor executor = (Executor) ServiceLocator.getInstance().newInstance(Executor.class);
27                  executor.setDatabase(database);
28                  executors.put(database, executor);
29              } catch (Exception e) {
30                  throw new UnexpectedLiquibaseException(e);
31              }
32          }
33          return executors.get(database);
34      }
35  
36      public void setExecutor(Database database, Executor executor) {
37          executors.put(database, executor);
38      }
39  
40      public void clearExecutor(Database database) {
41          executors.remove(database);
42      }
43  
44      public void reset() {
45          executors.clear();
46      }
47  }