Example usage for org.springframework.integration.mongodb.store MessageDocumentFields SEQUENCE

List of usage examples for org.springframework.integration.mongodb.store MessageDocumentFields SEQUENCE

Introduction

In this page you can find the example usage for org.springframework.integration.mongodb.store MessageDocumentFields SEQUENCE.

Prototype

String SEQUENCE

To view the source code for org.springframework.integration.mongodb.store MessageDocumentFields SEQUENCE.

Click Source Link

Usage

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

@Override
public void afterPropertiesSet() throws Exception {
    if (this.mongoTemplate == null) {
        if (this.mappingMongoConverter == null) {
            this.mappingMongoConverter = new MappingMongoConverter(
                    new DefaultDbRefResolver(this.mongoDbFactory), new MongoMappingContext());
            this.mappingMongoConverter.setApplicationContext(this.applicationContext);
            List<Object> customConverters = new ArrayList<Object>();
            customConverters.add(new MessageToBinaryConverter());
            customConverters.add(new BinaryToMessageConverter());
            this.mappingMongoConverter.setCustomConversions(new CustomConversions(customConverters));
            this.mappingMongoConverter.afterPropertiesSet();
        }//w w w  .  java2  s. c  o  m
        this.mongoTemplate = new MongoTemplate(this.mongoDbFactory, this.mappingMongoConverter);
    }

    this.messageBuilderFactory = IntegrationUtils.getMessageBuilderFactory(this.applicationContext);

    IndexOperations indexOperations = this.mongoTemplate.indexOps(this.collectionName);

    indexOperations.ensureIndex(new Index(MessageDocumentFields.MESSAGE_ID, Sort.Direction.ASC));

    indexOperations.ensureIndex(new Index(MessageDocumentFields.GROUP_ID, Sort.Direction.ASC)
            .on(MessageDocumentFields.MESSAGE_ID, Sort.Direction.ASC).unique());

    indexOperations.ensureIndex(new Index(MessageDocumentFields.GROUP_ID, Sort.Direction.ASC)
            .on(MessageDocumentFields.LAST_MODIFIED_TIME, Sort.Direction.DESC)
            .on(MessageDocumentFields.SEQUENCE, Sort.Direction.DESC));
}

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  . ja  v a2  s . c  o  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);
}