Search in sources :

Example 51 with Query

use of org.springframework.data.mongodb.core.query.Query in project spring-integration by spring-projects.

the class MongoDbMessageStore method getMessageGroup.

@Override
public MessageGroup getMessageGroup(Object groupId) {
    Assert.notNull(groupId, "'groupId' must not be null");
    Query query = whereGroupIdOrder(groupId);
    MessageWrapper messageWrapper = this.template.findOne(query, MessageWrapper.class, this.collectionName);
    if (messageWrapper != null) {
        long createdTime = messageWrapper.get_Group_timestamp();
        long lastModifiedTime = messageWrapper.get_Group_update_timestamp();
        boolean complete = messageWrapper.get_Group_complete();
        int lastReleasedSequence = messageWrapper.get_LastReleasedSequenceNumber();
        MessageGroup messageGroup = getMessageGroupFactory().create(this, groupId, createdTime, complete);
        messageGroup.setLastModified(lastModifiedTime);
        messageGroup.setLastReleasedMessageSequenceNumber(lastReleasedSequence);
        return messageGroup;
    } else {
        return new SimpleMessageGroup(groupId);
    }
}
Also used : Query(org.springframework.data.mongodb.core.query.Query) MessageGroup(org.springframework.integration.store.MessageGroup) SimpleMessageGroup(org.springframework.integration.store.SimpleMessageGroup) SimpleMessageGroup(org.springframework.integration.store.SimpleMessageGroup)

Example 52 with Query

use of org.springframework.data.mongodb.core.query.Query in project spring-integration by spring-projects.

the class MongoDbMessageStore method addMessageDocument.

private void addMessageDocument(MessageWrapper document) {
    UUID messageId = (UUID) document.headers.get(MessageHeaders.ID);
    Query query = whereMessageIdIsAndGroupIdIs(messageId, document.get_GroupId());
    if (!this.template.exists(query, MessageWrapper.class, this.collectionName)) {
        if (document.get_Group_timestamp() == 0) {
            document.set_Group_timestamp(System.currentTimeMillis());
        }
        document.set_message_timestamp(System.currentTimeMillis());
        this.template.insert(document, this.collectionName);
    }
}
Also used : Query(org.springframework.data.mongodb.core.query.Query) UUID(java.util.UUID)

Example 53 with Query

use of org.springframework.data.mongodb.core.query.Query in project spring-integration by spring-projects.

the class MongoDbMessageStore method messageGroupSize.

@Override
public int messageGroupSize(Object groupId) {
    long lCount = this.template.count(new Query(Criteria.where(GROUP_ID_KEY).is(groupId)), this.collectionName);
    Assert.isTrue(lCount <= Integer.MAX_VALUE, "Message count is out of Integer's range");
    return (int) lCount;
}
Also used : Query(org.springframework.data.mongodb.core.query.Query)

Example 54 with Query

use of org.springframework.data.mongodb.core.query.Query in project spring-integration by spring-projects.

the class MongoDbMessageStore method iterator.

@Override
public Iterator<MessageGroup> iterator() {
    List<MessageGroup> messageGroups = new ArrayList<>();
    Query query = Query.query(Criteria.where(GROUP_ID_KEY).exists(true));
    @SuppressWarnings("rawtypes") Iterable<String> groupIds = this.template.getCollection(this.collectionName).distinct(GROUP_ID_KEY, query.getQueryObject(), String.class);
    for (Object groupId : groupIds) {
        messageGroups.add(getMessageGroup(groupId));
    }
    return messageGroups.iterator();
}
Also used : Query(org.springframework.data.mongodb.core.query.Query) MessageGroup(org.springframework.integration.store.MessageGroup) SimpleMessageGroup(org.springframework.integration.store.SimpleMessageGroup) ArrayList(java.util.ArrayList) DBObject(com.mongodb.DBObject)

Example 55 with Query

use of org.springframework.data.mongodb.core.query.Query in project spring-integration by spring-projects.

the class MongoDbMessageStore method updateGroup.

private void updateGroup(Object groupId, Update update) {
    Query query = whereGroupIdIs(groupId).with(new Sort(Sort.Direction.DESC, GROUP_UPDATE_TIMESTAMP_KEY, SEQUENCE));
    this.template.updateFirst(query, update, this.collectionName);
}
Also used : Query(org.springframework.data.mongodb.core.query.Query) Sort(org.springframework.data.domain.Sort)

Aggregations

Query (org.springframework.data.mongodb.core.query.Query)690 Test (org.junit.jupiter.api.Test)391 BasicQuery (org.springframework.data.mongodb.core.query.BasicQuery)259 NearQuery (org.springframework.data.mongodb.core.query.NearQuery)109 TextQuery (org.springframework.data.mongodb.core.query.TextQuery)91 Document (org.bson.Document)90 Update (org.springframework.data.mongodb.core.query.Update)83 Criteria (org.springframework.data.mongodb.core.query.Criteria)74 Test (org.junit.Test)72 lombok.val (lombok.val)50 ObjectId (org.bson.types.ObjectId)47 PartTree (org.springframework.data.repository.query.parser.PartTree)44 Sort (org.springframework.data.domain.Sort)41 StepVerifier (reactor.test.StepVerifier)39 Assertions (org.assertj.core.api.Assertions)30 Bson (org.bson.conversions.Bson)29 Mono (reactor.core.publisher.Mono)29 Point (org.springframework.data.geo.Point)28 Collation (org.springframework.data.mongodb.core.query.Collation)27 List (java.util.List)26