Search in sources :

Example 1 with Sequence

use of liquibase.structure.core.Sequence in project liquibase by liquibase.

the class UnexpectedSequenceChangeGenerator method fixUnexpected.

@Override
public Change[] fixUnexpected(DatabaseObject unexpectedObject, DiffOutputControl control, Database referenceDatabase, Database comparisonDatabase, ChangeGeneratorChain chain) {
    Sequence sequence = (Sequence) unexpectedObject;
    DropSequenceChange change = new DropSequenceChange();
    change.setSequenceName(sequence.getName());
    if (control.getIncludeCatalog()) {
        change.setCatalogName(sequence.getSchema().getCatalogName());
    }
    if (control.getIncludeSchema()) {
        change.setSchemaName(sequence.getSchema().getName());
    }
    return new Change[] { change };
}
Also used : DropSequenceChange(liquibase.change.core.DropSequenceChange) Sequence(liquibase.structure.core.Sequence) DropSequenceChange(liquibase.change.core.DropSequenceChange) Change(liquibase.change.Change)

Example 2 with Sequence

use of liquibase.structure.core.Sequence in project liquibase by liquibase.

the class CreateSequenceChange method checkStatus.

@Override
public ChangeStatus checkStatus(Database database) {
    ChangeStatus result = new ChangeStatus();
    try {
        Sequence sequence = SnapshotGeneratorFactory.getInstance().createSnapshot(new Sequence(getCatalogName(), getSchemaName(), getSequenceName()), database);
        result.assertComplete(sequence != null, "Sequence " + getSequenceName() + " does not exist");
        if (sequence != null) {
            if (getIncrementBy() != null) {
                result.assertCorrect(getIncrementBy().equals(sequence.getIncrementBy()), "Increment by has a different value");
            }
            if (getMinValue() != null) {
                result.assertCorrect(getMinValue().equals(sequence.getMinValue()), "Min Value is different");
            }
            if (getMaxValue() != null) {
                result.assertCorrect(getMaxValue().equals(sequence.getMaxValue()), "Max Value is different");
            }
            if (isOrdered() != null) {
                result.assertCorrect(isOrdered().equals(sequence.getOrdered()), "Max Value is different");
            }
            if (getCycle() != null) {
                result.assertCorrect(getCycle().equals(sequence.getWillCycle()), "Will Cycle is different");
            }
            if (getCacheSize() != null) {
                result.assertCorrect(getCacheSize().equals(sequence.getCacheSize()), "Cache size is different");
            }
        }
    } catch (Exception e) {
        return result.unknown(e);
    }
    return result;
}
Also used : Sequence(liquibase.structure.core.Sequence)

Example 3 with Sequence

use of liquibase.structure.core.Sequence in project liquibase by liquibase.

the class SequenceExistsPrecondition method check.

@Override
public void check(Database database, DatabaseChangeLog changeLog, ChangeSet changeSet) throws PreconditionFailedException, PreconditionErrorException {
    DatabaseSnapshot snapshot;
    Schema schema = new Schema(getCatalogName(), getSchemaName());
    try {
        if (!SnapshotGeneratorFactory.getInstance().has(new Sequence().setName(getSequenceName()).setSchema(schema), database)) {
            throw new PreconditionFailedException("Sequence " + database.escapeSequenceName(getCatalogName(), getSchemaName(), getSequenceName()) + " does not exist", changeLog, this);
        }
    } catch (LiquibaseException e) {
        throw new PreconditionErrorException(e, changeLog, this);
    }
}
Also used : Schema(liquibase.structure.core.Schema) Sequence(liquibase.structure.core.Sequence) DatabaseSnapshot(liquibase.snapshot.DatabaseSnapshot)

Example 4 with Sequence

use of liquibase.structure.core.Sequence in project liquibase by liquibase.

the class SequenceSnapshotGenerator method mapToSequence.

private Sequence mapToSequence(Map<String, ?> sequenceRow, Schema schema, Database database) {
    String name = cleanNameFromDatabase((String) sequenceRow.get("SEQUENCE_NAME"), database);
    Sequence seq = new Sequence();
    seq.setName(name);
    seq.setSchema(schema);
    seq.setStartValue(toBigInteger(sequenceRow.get("START_VALUE"), database));
    seq.setMinValue(toBigInteger(sequenceRow.get("MIN_VALUE"), database));
    seq.setMaxValue(toBigInteger(sequenceRow.get("MAX_VALUE"), database));
    seq.setCacheSize(toBigInteger(sequenceRow.get("CACHE_SIZE"), database));
    seq.setIncrementBy(toBigInteger(sequenceRow.get("INCREMENT_BY"), database));
    seq.setWillCycle(toBoolean(sequenceRow.get("WILL_CYCLE"), database));
    seq.setOrdered(toBoolean(sequenceRow.get("IS_ORDERED"), database));
    seq.setAttribute("liquibase-complete", true);
    return seq;
}
Also used : Sequence(liquibase.structure.core.Sequence)

Example 5 with Sequence

use of liquibase.structure.core.Sequence in project liquibase by liquibase.

the class ChangedSequenceChangeGenerator method fixChanged.

@Override
public Change[] fixChanged(DatabaseObject changedObject, ObjectDifferences differences, DiffOutputControl control, Database referenceDatabase, Database comparisonDatabase, ChangeGeneratorChain chain) {
    Sequence sequence = (Sequence) changedObject;
    List<Change> changes = new ArrayList<Change>();
    if (differences.isDifferent("incrementBy")) {
        AlterSequenceChange change = createAlterSequenceChange(sequence, control);
        change.setIncrementBy(sequence.getIncrementBy());
        changes.add(change);
    }
    if (differences.isDifferent("maxValue")) {
        AlterSequenceChange change = createAlterSequenceChange(sequence, control);
        change.setMaxValue(sequence.getMaxValue());
        changes.add(change);
    }
    if (differences.isDifferent("ordered")) {
        AlterSequenceChange change = createAlterSequenceChange(sequence, control);
        change.setOrdered(sequence.getOrdered());
        changes.add(change);
    }
    if (differences.isDifferent("cacheSize")) {
        AlterSequenceChange change = createAlterSequenceChange(sequence, control);
        change.setCacheSize(sequence.getCacheSize());
        changes.add(change);
    }
    if (differences.isDifferent("willCycle")) {
        AlterSequenceChange change = createAlterSequenceChange(sequence, control);
        change.setCycle(sequence.getWillCycle());
        changes.add(change);
    }
    if (changes.size() == 0) {
        return null;
    } else {
        return changes.toArray(new Change[changes.size()]);
    }
}
Also used : ArrayList(java.util.ArrayList) Sequence(liquibase.structure.core.Sequence) AlterSequenceChange(liquibase.change.core.AlterSequenceChange) Change(liquibase.change.Change) AlterSequenceChange(liquibase.change.core.AlterSequenceChange)

Aggregations

Sequence (liquibase.structure.core.Sequence)6 Change (liquibase.change.Change)3 ArrayList (java.util.ArrayList)1 AlterSequenceChange (liquibase.change.core.AlterSequenceChange)1 CreateSequenceChange (liquibase.change.core.CreateSequenceChange)1 DropSequenceChange (liquibase.change.core.DropSequenceChange)1 DatabaseSnapshot (liquibase.snapshot.DatabaseSnapshot)1 Schema (liquibase.structure.core.Schema)1