liquibase.sqlgenerator.ext.AlterSequenceGeneratorHanaDB 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.AlterSequenceGenerator;
import liquibase.statement.core.AlterSequenceStatement;
public class AlterSequenceGeneratorHanaDB extends AlterSequenceGenerator {
@Override
public int getPriority() {
return PRIORITY_DATABASE;
}
@Override
public boolean supports(AlterSequenceStatement statement, Database database) {
return database instanceof HanaDBDatabase;
}
@Override
public ValidationErrors validate(AlterSequenceStatement alterSequenceStatement, Database database, SqlGeneratorChain sqlGeneratorChain) {
ValidationErrors validationErrors = new ValidationErrors();
validationErrors.checkDisallowedField("ordered", alterSequenceStatement.getOrdered(), database, HanaDBDatabase.class);
validationErrors.checkRequiredField("sequenceName", alterSequenceStatement.getSequenceName());
return validationErrors;
}
@Override
public Sql[] generateSql(AlterSequenceStatement statement, Database database, SqlGeneratorChain sqlGeneratorChain) {
if (!supports(statement, database)) {
return sqlGeneratorChain.generateSql(statement, database);
}
StringBuffer buffer = new StringBuffer();
buffer.append("ALTER SEQUENCE ");
buffer.append(database.escapeSequenceName(statement.getCatalogName(), statement.getSchemaName(), statement.getSequenceName()));
if (statement.getIncrementBy() != null) {
buffer.append(" INCREMENT BY ").append(statement.getIncrementBy());
}
if (statement.getMinValue() != null) {
// buffer.append(" RESTART WITH ").append(statement.getMinValue());
buffer.append(" MINVALUE ").append(statement.getMinValue());
}
if (statement.getMaxValue() != null) {
buffer.append(" MAXVALUE ").append(statement.getMaxValue());
}
// return new Sql[]{
// new UnparsedSql(buffer.toString())
// };
return new Sql[]{
new UnparsedSql(buffer.toString(), getAffectedSequence(statement))
};
}
}