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);
}
}
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);
}
}
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;
}
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();
}
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);
}
Aggregations