Example usage for org.springframework.data.mongodb.core FindAndModifyOptions options

List of usage examples for org.springframework.data.mongodb.core FindAndModifyOptions options

Introduction

In this page you can find the example usage for org.springframework.data.mongodb.core FindAndModifyOptions options.

Prototype

public static FindAndModifyOptions options() 

Source Link

Document

Static factory method to create a FindAndModifyOptions instance

Usage

From source file:com.vladmihalcea.mongo.dao.impl.ProductRepositoryImpl.java

@Override
public Product findAndInsert(Long id) {
    return mongoTemplate.findAndModify(new Query(where(Properties.ID).is(id)), Update.update(Properties.ID, id),
            FindAndModifyOptions.options().upsert(true).returnNew(true), Product.class);
}

From source file:com.pubkit.platform.persistence.impl.SequenceImpl.java

private long increaseCounter(String className) {
    Query query = new Query(Criteria.where("_id").is(className));
    Update update = new Update().inc("sequence", 1);

    FindAndModifyOptions options = FindAndModifyOptions.options();
    Sequence sequence = mongoTemplate.findAndModify(query, update, options.returnNew(true), Sequence.class);
    if (sequence == null) {
        sequence = new Sequence();
        sequence.setId(className);//www . j  a  va2  s . co m
        sequence.setSequence(1000l);

        mongoTemplate.save(sequence);
    }
    return sequence.getSequence();
}

From source file:org.springframework.integration.mongodb.store.AbstractConfigurableMongoDbMessageStore.java

/**
 * Perform MongoDB {@code INC} operation for the document, which contains the {@link MessageDocument}
 * {@code sequence}, and return the new incremented value for the new {@link MessageDocument}.
 * The {@link #SEQUENCE_NAME} document is created on demand.
 * @return the next sequence value./*from  w  w  w .  j  a  v a  2s.  co m*/
 */
protected int getNextId() {
    Query query = Query.query(Criteria.where("_id").is(SEQUENCE_NAME));
    query.fields().include(MessageDocumentFields.SEQUENCE);
    return (Integer) this.mongoTemplate
            .findAndModify(query, new Update().inc(MessageDocumentFields.SEQUENCE, 1),
                    FindAndModifyOptions.options().returnNew(true).upsert(true), Map.class, this.collectionName)
            .get(MessageDocumentFields.SEQUENCE);
}