1 | |
package liquibase.executor; |
2 | |
|
3 | |
import liquibase.database.Database; |
4 | |
import liquibase.exception.DatabaseException; |
5 | |
import liquibase.exception.StatementNotSupportedOnDatabaseException; |
6 | |
import liquibase.sql.Sql; |
7 | |
import liquibase.sql.visitor.SqlVisitor; |
8 | |
import liquibase.sqlgenerator.SqlGeneratorFactory; |
9 | |
import liquibase.statement.SqlStatement; |
10 | |
|
11 | |
import java.util.List; |
12 | |
import java.util.Set; |
13 | |
|
14 | 6 | public abstract class AbstractExecutor { |
15 | |
protected Database database; |
16 | |
|
17 | |
public void setDatabase(Database database) { |
18 | 6 | this.database = database; |
19 | 6 | } |
20 | |
|
21 | |
protected String[] applyVisitors(SqlStatement statement, List<SqlVisitor> sqlVisitors) throws DatabaseException { |
22 | 0 | Sql[] sql = SqlGeneratorFactory.getInstance().generateSql(statement, database); |
23 | 0 | if (sql == null) { |
24 | 0 | return new String[0]; |
25 | |
} |
26 | 0 | String[] returnSql = new String[sql.length]; |
27 | |
|
28 | 0 | for (int i = 0; i < sql.length; i++) { |
29 | 0 | if (sql[i] == null) { |
30 | 0 | continue; |
31 | |
} |
32 | 0 | returnSql[i] = sql[i].toSql(); |
33 | 0 | for (SqlVisitor visitor : sqlVisitors) { |
34 | 0 | returnSql[i] = visitor.modifySql(returnSql[i], database); |
35 | |
} |
36 | |
|
37 | |
} |
38 | 0 | return returnSql; |
39 | |
} |
40 | |
|
41 | |
} |