use of io.lumeer.api.model.Sequence in project engine by Lumeer.
the class MongoSequenceDao method updateSequence.
private Sequence updateSequence(final Sequence sequence, final Bson filter) {
FindOneAndUpdateOptions options = new FindOneAndUpdateOptions().returnDocument(ReturnDocument.AFTER);
try {
Bson update = new Document("$set", sequence);
final Sequence returnedSequence = databaseCollection().findOneAndUpdate(filter, update, options);
if (returnedSequence == null) {
throw new StorageException("Sequence '" + sequence.getId() + "' has not been updated.");
}
if (createOrUpdateSequenceEvent != null) {
createOrUpdateSequenceEvent.fire(new CreateOrUpdateSequence(returnedSequence));
}
return returnedSequence;
} catch (MongoException ex) {
throw new StorageException("Cannot update sequence " + sequence, ex);
}
}
use of io.lumeer.api.model.Sequence in project engine by Lumeer.
the class MongoSequenceDao method getNextSequenceNo.
@Override
public synchronized int getNextSequenceNo(final String indexName) {
final FindOneAndUpdateOptions options = new FindOneAndUpdateOptions();
options.returnDocument(ReturnDocument.AFTER);
final Sequence seq = databaseCollection().findOneAndUpdate(eq(SequenceCodec.NAME, indexName), inc(SequenceCodec.SEQ, 1), options);
if (seq == null) {
// the sequence did not exist
resetSequence(indexName);
return 0;
} else {
return seq.getSeq();
}
}
Aggregations