use of liquibase.statement.core.CreateProcedureStatement in project liquibase by liquibase.
the class CreateProcedureChange method generateStatements.
protected SqlStatement[] generateStatements(String logicText, String endDelimiter, Database database) {
CreateProcedureStatement statement = new CreateProcedureStatement(getCatalogName(), getSchemaName(), getProcedureName(), logicText, endDelimiter);
statement.setReplaceIfExists(getReplaceIfExists());
return new SqlStatement[] { statement };
}
use of liquibase.statement.core.CreateProcedureStatement in project liquibase by liquibase.
the class LoggingExecutor method outputStatement.
private void outputStatement(SqlStatement sql, List<SqlVisitor> sqlVisitors) throws DatabaseException {
try {
if (SqlGeneratorFactory.getInstance().generateStatementsVolatile(sql, database)) {
throw new DatabaseException(sql.getClass().getSimpleName() + " requires access to up to date database metadata which is not available in SQL output mode");
}
if (sql instanceof ExecutablePreparedStatement) {
output.write("WARNING: This statement uses a prepared statement which cannot be execute directly by this script. Only works in 'update' mode\n\n");
}
for (String statement : applyVisitors(sql, sqlVisitors)) {
if (statement == null) {
continue;
}
if (database instanceof OracleDatabase) {
//remove trailing /
while (statement.matches("(?s).*[\\s\\r\\n]*/[\\s\\r\\n]*$")) {
//all trailing /'s
statement = statement.replaceFirst("[\\s\\r\\n]*/[\\s\\r\\n]*$", "");
}
}
output.write(statement);
if (database instanceof MSSQLDatabase || database instanceof SybaseDatabase || database instanceof SybaseASADatabase) {
output.write(StreamUtil.getLineSeparator());
output.write("GO");
// } else if (database instanceof OracleDatabase) {
// output.write(StreamUtil.getLineSeparator());
// output.write("/");
} else {
String endDelimiter = ";";
String potentialDelimiter = null;
if (sql instanceof RawSqlStatement) {
potentialDelimiter = ((RawSqlStatement) sql).getEndDelimiter();
} else if (sql instanceof CreateProcedureStatement) {
potentialDelimiter = ((CreateProcedureStatement) sql).getEndDelimiter();
}
if (potentialDelimiter != null) {
//ignore trailing $ as a regexp to determine if it should be output
potentialDelimiter = potentialDelimiter.replaceFirst("\\$$", "");
if (potentialDelimiter.replaceAll("\\n", "\n").replace("\\r", "\r").matches("[;/\r\n\\w@\\-]+")) {
endDelimiter = potentialDelimiter;
}
}
endDelimiter = endDelimiter.replace("\\n", "\n");
endDelimiter = endDelimiter.replace("\\r", "\r");
if (!statement.endsWith(endDelimiter)) {
output.write(endDelimiter);
}
}
output.write(StreamUtil.getLineSeparator());
output.write(StreamUtil.getLineSeparator());
}
} catch (IOException e) {
throw new DatabaseException(e);
}
}
Aggregations