liquibase.sqlgenerator.ext.CreateSequenceGeneratorHanaDB Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of liquibase-hana Show documentation
Show all versions of liquibase-hana Show documentation
Liquibase support for SAP Hana DB
The newest version!
package liquibase.sqlgenerator.ext;
import liquibase.database.Database;
import liquibase.database.ext.HanaDBDatabase;
import liquibase.exception.ValidationErrors;
import liquibase.sql.Sql;
import liquibase.sql.UnparsedSql;
import liquibase.sqlgenerator.SqlGeneratorChain;
import liquibase.sqlgenerator.core.CreateSequenceGenerator;
import liquibase.statement.core.CreateSequenceStatement;
public class CreateSequenceGeneratorHanaDB extends CreateSequenceGenerator {
@Override
public int getPriority() {
return PRIORITY_DATABASE;
}
@Override
public boolean supports(CreateSequenceStatement statement, Database database) {
return database instanceof HanaDBDatabase;
}
@Override
public ValidationErrors validate(CreateSequenceStatement statement, Database database, SqlGeneratorChain sqlGeneratorChain) {
ValidationErrors validationErrors = new ValidationErrors();
validationErrors.checkRequiredField("sequenceName", statement.getSequenceName());
validationErrors.checkDisallowedField("ordered", statement.getOrdered(), database, HanaDBDatabase.class);
return validationErrors;
}
@Override
public Sql[] generateSql(CreateSequenceStatement statement, Database database, SqlGeneratorChain sqlGeneratorChain) {
if (!supports(statement, database)) {
return sqlGeneratorChain.generateSql(statement, database);
}
StringBuffer buffer = new StringBuffer();
buffer.append("CREATE SEQUENCE ");
buffer.append(database.escapeSequenceName(statement.getCatalogName(), statement.getSchemaName(), statement.getSequenceName()));
if (statement.getStartValue() != null) {
buffer.append(" START WITH ").append(statement.getStartValue());
}
if (statement.getIncrementBy() != null) {
buffer.append(" INCREMENT BY ").append(statement.getIncrementBy());
}
if (statement.getMinValue() != null) {
buffer.append(" MINVALUE ").append(statement.getMinValue());
}
if (statement.getMaxValue() != null) {
buffer.append(" MAXVALUE ").append(statement.getMaxValue());
}
if (statement.getCycle() != null) {
if (statement.getCycle()) {
buffer.append(" CYCLE");
}
else {
buffer.append(" NO CYCLE");
}
}
// return new Sql[]{new UnparsedSql(buffer.toString())};
return new Sql[]{new UnparsedSql(buffer.toString(), getAffectedSequence(statement))};
}
}