liquibase.change.core.CreateSequenceChange Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of liquibase-core Show documentation
Show all versions of liquibase-core Show documentation
Liquibase is a tool for managing and executing database changes.
package liquibase.change.core;
import liquibase.change.AbstractChange;
import liquibase.change.Change;
import liquibase.change.ChangeMetaData;
import liquibase.database.Database;
import liquibase.statement.SqlStatement;
import liquibase.statement.core.CreateSequenceStatement;
import liquibase.util.StringUtils;
import java.math.BigInteger;
/**
* Creates a new sequence.
*/
public class CreateSequenceChange extends AbstractChange {
private String schemaName;
private String sequenceName;
private BigInteger startValue;
private BigInteger incrementBy;
private BigInteger maxValue;
private BigInteger minValue;
private Boolean ordered;
private Boolean cycle;
public CreateSequenceChange() {
super("createSequence", "Create Sequence", ChangeMetaData.PRIORITY_DEFAULT);
}
public String getSchemaName() {
return schemaName;
}
public void setSchemaName(String schemaName) {
this.schemaName = StringUtils.trimToNull(schemaName);
}
public String getSequenceName() {
return sequenceName;
}
public void setSequenceName(String sequenceName) {
this.sequenceName = sequenceName;
}
public BigInteger getStartValue() {
return startValue;
}
public void setStartValue(BigInteger startValue) {
this.startValue = startValue;
}
public BigInteger getIncrementBy() {
return incrementBy;
}
public void setIncrementBy(BigInteger incrementBy) {
this.incrementBy = incrementBy;
}
public BigInteger getMaxValue() {
return maxValue;
}
public void setMaxValue(BigInteger maxValue) {
this.maxValue = maxValue;
}
public BigInteger getMinValue() {
return minValue;
}
public void setMinValue(BigInteger minValue) {
this.minValue = minValue;
}
public Boolean isOrdered() {
return ordered;
}
public void setOrdered(Boolean ordered) {
this.ordered = ordered;
}
public Boolean getCycle() {
return cycle;
}
public void setCycle(Boolean cycle) {
this.cycle = cycle;
}
public SqlStatement[] generateStatements(Database database) {
return new SqlStatement[] {
new CreateSequenceStatement(getSchemaName() == null?database.getDefaultSchemaName():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
};
}
public String getConfirmationMessage() {
return "Sequence " + getSequenceName() + " created";
}
}