1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package org.apache.ibatis.migration.hook;
17
18 import java.io.Reader;
19 import java.io.StringReader;
20 import java.sql.Connection;
21 import java.sql.SQLException;
22
23 import org.apache.ibatis.migration.Change;
24 import org.apache.ibatis.migration.ConnectionProvider;
25 import org.apache.ibatis.migration.operations.ScriptRunner;
26
27 public class HookContext {
28 private ConnectionProvider connectionProvider;
29 private ScriptRunner scriptRunner;
30 private Change change;
31
32 public HookContext(ConnectionProvider connectionProvider, ScriptRunner scriptRunner, Change change) {
33 this.connectionProvider = connectionProvider;
34 this.scriptRunner = scriptRunner;
35 this.change = change;
36 }
37
38
39
40
41
42
43
44 public Connection getConnection() throws SQLException {
45 return connectionProvider.getConnection();
46 }
47
48
49
50
51
52 public void executeSql(Reader reader) {
53 scriptRunner.runScript(reader);
54 }
55
56
57
58
59
60 public void executeSql(String sql) {
61 try (StringReader reader = new StringReader(sql)) {
62 executeSql(reader);
63 }
64 }
65
66
67
68
69 public Change getChange() {
70 return change;
71 }
72 }