View Javadoc

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  public class StoredProcedureGenerator extends AbstractSqlGenerator<StoredProcedureStatement> {
12  
13      public ValidationErrors validate(StoredProcedureStatement storedProcedureStatement, Database database,
14              SqlGeneratorChain sqlGeneratorChain) {
15          ValidationErrors validationErrors = new ValidationErrors();
16          validationErrors.checkRequiredField("procedureName", storedProcedureStatement.getProcedureName());
17          return validationErrors;
18      }
19  
20      public Sql[] generateSql(StoredProcedureStatement statement, Database database, SqlGeneratorChain sqlGeneratorChain) {
21          StringBuffer string = new StringBuffer();
22          string.append("exec (").append(statement.getProcedureName());
23          for (String param : statement.getParameters()) {
24              string.append(" ").append(param).append(",");
25          }
26          return new Sql[] { new UnparsedSql(string.toString().replaceFirst(",$", ")")) };
27  
28      }
29  }