View Javadoc
1   /*
2    *    Copyright 2010-2022 the original author or authors.
3    *
4    *    Licensed under the Apache License, Version 2.0 (the "License");
5    *    you may not use this file except in compliance with the License.
6    *    You may obtain a copy of the License at
7    *
8    *       https://www.apache.org/licenses/LICENSE-2.0
9    *
10   *    Unless required by applicable law or agreed to in writing, software
11   *    distributed under the License is distributed on an "AS IS" BASIS,
12   *    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13   *    See the License for the specific language governing permissions and
14   *    limitations under the License.
15   */
16  package org.apache.ibatis.migration.hook;
17  
18  import java.util.Map;
19  
20  public class FileMigrationHook implements MigrationHook {
21  
22    protected final HookScript beforeScript;
23    protected final HookScript beforeEachScript;
24    protected final HookScript afterEachScript;
25    protected final HookScript afterScript;
26  
27    public FileMigrationHook(HookScript beforeScript, HookScript beforeEachScript, HookScript afterEachScript,
28        HookScript afterScript) {
29      this.beforeScript = beforeScript;
30      this.beforeEachScript = beforeEachScript;
31      this.afterEachScript = afterEachScript;
32      this.afterScript = afterScript;
33    }
34  
35    @Override
36    public void before(Map<String, Object> bindingMap) {
37      if (beforeScript != null) {
38        beforeScript.execute(bindingMap);
39      }
40    }
41  
42    @Override
43    public void beforeEach(Map<String, Object> bindingMap) {
44      if (beforeEachScript != null) {
45        beforeEachScript.execute(bindingMap);
46      }
47    }
48  
49    @Override
50    public void afterEach(Map<String, Object> bindingMap) {
51      if (afterEachScript != null) {
52        afterEachScript.execute(bindingMap);
53      }
54    }
55  
56    @Override
57    public void after(Map<String, Object> bindingMap) {
58      if (afterScript != null) {
59        afterScript.execute(bindingMap);
60      }
61    }
62  }