@Override public Flux<T> findAllById(Iterable<ID> ids) { Assert.notNull(ids, "The given Iterable of Id's must not be null!"); return findAll(new Query(new Criteria(entityInformation.getIdAttribute()) .in(Streamable.of(ids).stream().collect(StreamUtils.toUnmodifiableList())))); }
private boolean doUpdate(Object id, DBObject data, String... fieldsToDelete) { Assert.notNull(id); data.removeField("_id"); Update update = new Update(); setField("", data, update); for (String field : fieldsToDelete) { update.unset(field); } WriteResult result = mongoOperations.updateFirst(Query.query(Criteria.where("_id").is(id)), update, metadata.getCollectionName()); return result.getN() != 0; }
/** * Creates a criterion ({@code $jsonSchema}) matching documents against a given structure defined by the * {@link MongoJsonSchema}. <br /> * <strong>NOTE:</strong> {@code $jsonSchema} cannot be used on field/property level but defines the whole document * structure. Please use * {@link org.springframework.data.mongodb.core.schema.MongoJsonSchema.MongoJsonSchemaBuilder#properties(JsonSchemaProperty...)} * to specify nested fields or query them using the {@link #type(Type...) $type} operator. * * @param schema must not be {@literal null}. * @return this * @since 2.1 * @see <a href="https://docs.mongodb.com/manual/reference/operator/query/jsonSchema/">MongoDB Query operator: * $jsonSchema</a> */ public Criteria andDocumentStructureMatches(MongoJsonSchema schema) { Assert.notNull(schema, "Schema must not be null!"); Criteria schemaCriteria = new Criteria(); schemaCriteria.criteria.putAll(schema.toDocument()); return registerCriteriaChainElement(schemaCriteria); }
@Override @ManagedAttribute public int getMessageCountForAllMessageGroups() { Query query = Query.query(Criteria.where(MessageDocumentFields.MESSAGE_ID).exists(true) .and(MessageDocumentFields.GROUP_ID).exists(true)); long count = this.mongoTemplate.count(query, this.collectionName); Assert.isTrue(count <= Integer.MAX_VALUE, "Message count is out of Integer's range"); return (int) count; }
@Override public void removeByEndpointKeyHashAndConfigurationVersion(byte[] endpointKeyHash, Integer confSchemaVersion) { LOG.debug("Remove endpoint specific configuration by endpoint key hash [{}] ", endpointKeyHash); mongoTemplate.remove( query(where(EP_SPECIFIC_CONFIGURATION_KEY_HASH).is(endpointKeyHash) .and(EP_CONFIGURATION_VERSION).is(confSchemaVersion)), getCollectionName()); }
@Override public List<HmilyTransaction> listAllByDelay(final Date date) { Query query = new Query(); query.addCriteria(Criteria.where("lastTime").lt(date)); final List<MongoAdapter> mongoBeans = template.find(query, MongoAdapter.class, collectionName); if (CollectionUtils.isNotEmpty(mongoBeans)) { return mongoBeans.stream().map(this::buildByCache).collect(Collectors.toList()); } return Collections.emptyList(); }
final PageParameter pageParameter = query.getPageParameter(); final int pageSize = pageParameter.getPageSize(); Query baseQuery = new Query(); if (StringUtils.isNoneBlank(query.getTransId())) { baseQuery.addCriteria(new Criteria("transId").is(query.getTransId())); baseQuery.addCriteria(new Criteria("retriedCount").lt(query.getRetry())); final long totalCount = mongoTemplate.count(baseQuery, mongoTableName); if (totalCount <= 0) { return voCommonPager; baseQuery.skip(start).limit(pageSize); final List<MongoAdapter> mongoAdapters = mongoTemplate.find(baseQuery, MongoAdapter.class, mongoTableName); if (CollectionUtils.isNotEmpty(mongoAdapters)) { final List<HmilyCompensationVO> recoverVOS =
public void updateById(RoncooUser roncooUser) { Criteria criteria = Criteria.where("id").in(roncooUser.getId()); Query query = new Query(criteria); Update update = new Update(); update.set("name", roncooUser.getName()); update.set("createTime", roncooUser.getCreateTime()); mongoTemplate.updateMulti(query, update, RoncooUser.class); }
@Override public int remove(final String id) { AssertUtils.notNull(id); Query query = new Query(); query.addCriteria(new Criteria("transId").is(id)); template.remove(query, collectionName); return ROWS; }
@Override public List<TransactionRecover> listAllByDelay(final Date date) { Query query = new Query(); query.addCriteria(new Criteria("status") .in(TransactionStatusEnum.BEGIN.getCode(), TransactionStatusEnum.FAILURE.getCode(), TransactionStatusEnum.ROLLBACK.getCode())) .addCriteria(Criteria.where("lastTime").lt(date)); final List<MongoAdapter> mongoBeans = template.find(query, MongoAdapter.class, collectionName); if (CollectionUtils.isNotEmpty(mongoBeans)) { return mongoBeans.stream().map(this::buildByCache).collect(Collectors.toList()); } return null; }
@Override public Query getQueryForVersion() { MongoPersistentProperty idProperty = entity.getRequiredIdProperty(); MongoPersistentProperty property = entity.getRequiredVersionProperty(); return new Query(Criteria.where(idProperty.getName()).is(getId())// .and(property.getName()).is(getVersion())); }
@Override public HmilyTransaction findById(final String id) { Query query = new Query(); query.addCriteria(new Criteria("transId").is(id)); MongoAdapter cache = template.findOne(query, MongoAdapter.class, collectionName); return buildByCache(Objects.requireNonNull(cache)); }
@Override public int updateStatus(final String id, final Integer status) { Query query = new Query(); query.addCriteria(new Criteria("transId").is(id)); Update update = new Update(); update.set("status", status); final UpdateResult updateResult = template.updateFirst(query, update, MongoAdapter.class, collectionName); if (updateResult.getModifiedCount() <= 0) { throw new HmilyRuntimeException("update data exception!"); } return ROWS; }
@Override public List<MongoNotification> findNotificationsByTopicIdAndVersionAndStartSecNum( String topicId, int seqNumber, int sysNfVersion, int userNfVersion ) { LOG.debug("Find notifications by topic id [{}], sequence number start [{}], " + "system schema version [{}], user schema version [{}]", topicId, seqNumber, sysNfVersion, userNfVersion); return find(query(where(NF_TOPIC_ID) .is(topicId) .and(NF_SEQ_NUM) .gt(seqNumber) .orOperator(where(NF_VERSION) .is(sysNfVersion) .and(NF_TYPE) .is(SYSTEM), where(NF_VERSION) .is(userNfVersion) .and(NF_TYPE) .is(USER)))); }