liquibase.change.core.CreateSequenceChange Maven / Gradle / Ivy
package liquibase.change.core;
import liquibase.change.*;
import liquibase.database.Database;
import liquibase.statement.SqlStatement;
import liquibase.statement.core.CreateSequenceStatement;
import java.math.BigInteger;
/**
* Creates a new sequence.
*/
@DatabaseChange(name="createSequence", description = "Creates a new database sequence", priority = ChangeMetaData.PRIORITY_DEFAULT)
public class CreateSequenceChange extends AbstractChange {
private String catalogName;
private String schemaName;
private String sequenceName;
private BigInteger startValue;
private BigInteger incrementBy;
private BigInteger maxValue;
private BigInteger minValue;
private Boolean ordered;
private Boolean cycle;
@DatabaseChangeProperty(since = "3.0")
public String getCatalogName() {
return catalogName;
}
public void setCatalogName(String catalogName) {
this.catalogName = catalogName;
}
public String getSchemaName() {
return schemaName;
}
public void setSchemaName(String schemaName) {
this.schemaName = schemaName;
}
@DatabaseChangeProperty(description = "Name of the sequence to create")
public String getSequenceName() {
return sequenceName;
}
public void setSequenceName(String sequenceName) {
this.sequenceName = sequenceName;
}
@DatabaseChangeProperty(description = "The first sequence number to be generated.", exampleValue = "5")
public BigInteger getStartValue() {
return startValue;
}
public void setStartValue(BigInteger startValue) {
this.startValue = startValue;
}
@DatabaseChangeProperty(description = "Interval between sequence numbers", exampleValue = "2")
public BigInteger getIncrementBy() {
return incrementBy;
}
public void setIncrementBy(BigInteger incrementBy) {
this.incrementBy = incrementBy;
}
@DatabaseChangeProperty(description = "The maximum value of the sequence", exampleValue = "1000")
public BigInteger getMaxValue() {
return maxValue;
}
public void setMaxValue(BigInteger maxValue) {
this.maxValue = maxValue;
}
@DatabaseChangeProperty(description = "The minimum value of the sequence", exampleValue = "10")
public BigInteger getMinValue() {
return minValue;
}
public void setMinValue(BigInteger minValue) {
this.minValue = minValue;
}
@DatabaseChangeProperty(description = "Does the sequence need to be guaranteed to be genererated inm the order of request?")
public Boolean isOrdered() {
return ordered;
}
public void setOrdered(Boolean ordered) {
this.ordered = ordered;
}
@DatabaseChangeProperty(description = "Can the sequence cycle when it hits the max value?")
public Boolean getCycle() {
return cycle;
}
public void setCycle(Boolean cycle) {
this.cycle = cycle;
}
@Override
public SqlStatement[] generateStatements(Database database) {
return new SqlStatement[] {
new CreateSequenceStatement(getCatalogName(), getSchemaName(), getSequenceName())
.setIncrementBy(getIncrementBy())
.setMaxValue(getMaxValue())
.setMinValue(getMinValue())
.setOrdered(isOrdered())
.setStartValue(getStartValue())
.setCycle(getCycle())
};
}
@Override
protected Change[] createInverses() {
DropSequenceChange inverse = new DropSequenceChange();
inverse.setSequenceName(getSequenceName());
inverse.setSchemaName(getSchemaName());
return new Change[]{
inverse
};
}
@Override
public String getConfirmationMessage() {
return "Sequence " + getSequenceName() + " created";
}
@Override
public String getSerializedObjectNamespace() {
return STANDARD_CHANGELOG_NAMESPACE;
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy