1 | |
package liquibase.sqlgenerator.core; |
2 | |
|
3 | |
import liquibase.database.Database; |
4 | |
import liquibase.exception.ValidationErrors; |
5 | |
import liquibase.sql.Sql; |
6 | |
import liquibase.sql.UnparsedSql; |
7 | |
import liquibase.sqlgenerator.SqlGenerator; |
8 | |
import liquibase.sqlgenerator.SqlGeneratorChain; |
9 | |
import liquibase.statement.StoredProcedureStatement; |
10 | |
|
11 | 10 | public class StoredProcedureGenerator extends AbstractSqlGenerator<StoredProcedureStatement> { |
12 | |
|
13 | |
public ValidationErrors validate(StoredProcedureStatement storedProcedureStatement, Database database, |
14 | |
SqlGeneratorChain sqlGeneratorChain) { |
15 | 0 | ValidationErrors validationErrors = new ValidationErrors(); |
16 | 0 | validationErrors.checkRequiredField("procedureName", storedProcedureStatement.getProcedureName()); |
17 | 0 | return validationErrors; |
18 | |
} |
19 | |
|
20 | |
public Sql[] generateSql(StoredProcedureStatement statement, Database database, SqlGeneratorChain sqlGeneratorChain) { |
21 | 0 | StringBuffer string = new StringBuffer(); |
22 | 0 | string.append("exec (").append(statement.getProcedureName()); |
23 | 0 | for (String param : statement.getParameters()) { |
24 | 0 | string.append(" ").append(param).append(","); |
25 | |
} |
26 | 0 | return new Sql[] { new UnparsedSql(string.toString().replaceFirst(",$", ")")) }; |
27 | |
|
28 | |
} |
29 | |
} |