@SuppressWarnings({ "unchecked", "rawtypes" }) ChangeStreamTask(MongoTemplate template, ChangeStreamRequest<?> request, Class<?> targetType, ErrorHandler errorHandler) { super(template, (ChangeStreamRequest) request, (Class) targetType, errorHandler); queryMapper = new QueryMapper(template.getConverter()); mongoConverter = template.getConverter(); }
@SuppressWarnings({ "unchecked", "rawtypes" }) public TailableCursorTask(MongoTemplate template, TailableCursorRequest<?> request, Class<?> targetType, ErrorHandler errorHandler) { super(template, (TailableCursorRequest) request, (Class) targetType, errorHandler); queryMapper = new QueryMapper(template.getConverter()); }
public Object doInCollection(MongoCollection<Document> collection) throws MongoException, DataAccessException { for (Document dbo : collection.find(dbk)) { String key = (String) dbo.get(ENTITY_FIELD_NAME); if (log.isDebugEnabled()) { log.debug("Processing key: {}", key); } if (!changeSet.getValues().containsKey(key)) { String className = (String) dbo.get(ENTITY_FIELD_CLASS); if (className == null) { throw new DataIntegrityViolationException( "Unble to convert property " + key + ": Invalid metadata, " + ENTITY_FIELD_CLASS + " not available"); } Class<?> clazz = ClassUtils.resolveClassName(className, ClassUtils.getDefaultClassLoader()); Object value = mongoTemplate.getConverter().read(clazz, dbo); if (log.isDebugEnabled()) { log.debug("Adding to ChangeSet: {}", key); } changeSet.set(key, value); } } return null; } });
@SuppressWarnings("unchecked") List<Document> prepareFilter(MongoTemplate template, ChangeStreamOptions options) { if (!options.getFilter().isPresent()) { return Collections.emptyList(); } Object filter = options.getFilter().orElse(null); if (filter instanceof Aggregation) { Aggregation agg = (Aggregation) filter; AggregationOperationContext context = agg instanceof TypedAggregation ? new TypeBasedAggregationOperationContext(((TypedAggregation<?>) agg).getInputType(), template.getConverter().getMappingContext(), queryMapper) : Aggregation.DEFAULT_CONTEXT; return agg.toPipeline(new PrefixingDelegatingAggregationOperationContext(context, "fullDocument", blacklist)); } if (filter instanceof List) { return (List<Document>) filter; } throw new IllegalArgumentException( "ChangeStreamRequestOptions.filter mut be either an Aggregation or a plain list of Documents"); }
MongoConverter converter = getConverter(); DefaultDbRefResolver dbRefResolver = new DefaultDbRefResolver(mongoDbFactory);
@Override public List<MongoEndpointNotification> findNotificationsByKeyHash(final byte[] keyHash) { LOG.debug("Find unicast notifications by endpoint key hash [{}] ", keyHash); DBObject dbObject = query(where(EP_ENDPOINT_KEY_HASH).is(keyHash)).getQueryObject(); DBCursor cursor = mongoTemplate.getDb().getCollection(getCollectionName()).find(dbObject); List<MongoEndpointNotification> endpointNotifications = new ArrayList<>(); while (cursor.hasNext()) { endpointNotifications.add(mongoTemplate.getConverter() .read(MongoEndpointNotification.class, cursor.next())); } return endpointNotifications; }
log.debug("Flush: saving: {}", dbQuery); mongoTemplate.getConverter().write(value, dbDoc); dbDoc.put(ENTITY_FIELD_CLASS, value.getClass().getName()); if (dbId != null) {
filter.putAll(queryMapper.getMappedObject(query.getQueryObject(), template.getConverter().getMappingContext() .getPersistentEntity(targetType.equals(Document.class) ? Object.class : targetType)));
@Override public MongoEndpointProfile findByKeyHash(byte[] endpointKeyHash) { LOG.debug("Find endpoint profile by endpoint key hash [{}] ", endpointKeyHash); DBObject dbObject = query(where(EP_ENDPOINT_KEY_HASH) .is(endpointKeyHash)) .getQueryObject(); DBObject result = mongoTemplate.getDb() .getCollection(getCollectionName()) .findOne(dbObject); return mongoTemplate.getConverter().read(getDocumentClass(), result); }
@Override public MongoEndpointConfiguration findByHash(final byte[] hash) { LOG.debug("Find endpoint configuration by hash [{}] ", hash); DBObject dbObject = query(where(ID).is(hash)).getQueryObject(); DBObject result = mongoTemplate.getDb() .getCollection(getCollectionName()) .findOne(dbObject); return mongoTemplate.getConverter().read(getDocumentClass(), result); }
@Override public MongoEndpointProfile findByAccessToken(String endpointAccessToken) { LOG.debug("Find endpoint profile by access token [{}] ", endpointAccessToken); DBObject dbObject = query(where(EP_ACCESS_TOKEN).is(endpointAccessToken)) .getQueryObject(); DBObject result = mongoTemplate.getDb() .getCollection(getCollectionName()) .findOne(dbObject); return mongoTemplate.getConverter().read(getDocumentClass(), result); }
@Override public MongoTopicListEntry findByHash(byte[] hash) { LOG.debug("Find topic list entry by hash [{}] ", hash); DBObject dbObject = query(where(ID).is(hash)).getQueryObject(); DBObject result = mongoTemplate.getDb() .getCollection(getCollectionName()) .findOne(dbObject); return mongoTemplate.getConverter().read(getDocumentClass(), result); }
protected Message<T, R> createMessage(T source, Class<R> targetType, RequestOptions options) { SimpleMessage<T, T> message = new SimpleMessage<>(source, source, MessageProperties.builder() .databaseName(template.getDb().getName()).collectionName(options.getCollectionName()).build()); return new LazyMappingDelegatingMessage<>(message, targetType, template.getConverter()); }
@SuppressWarnings({ "unchecked", "rawtypes" }) ChangeStreamTask(MongoTemplate template, ChangeStreamRequest<?> request, Class<?> targetType, ErrorHandler errorHandler) { super(template, (ChangeStreamRequest) request, (Class) targetType, errorHandler); queryMapper = new QueryMapper(template.getConverter()); mongoConverter = template.getConverter(); }
@SuppressWarnings({ "unchecked", "rawtypes" }) public TailableCursorTask(MongoTemplate template, TailableCursorRequest<?> request, Class<?> targetType, ErrorHandler errorHandler) { super(template, (TailableCursorRequest) request, (Class) targetType, errorHandler); queryMapper = new QueryMapper(template.getConverter()); }
@SuppressWarnings("unchecked") List<Document> prepareFilter(MongoTemplate template, ChangeStreamOptions options) { if (!options.getFilter().isPresent()) { return Collections.emptyList(); } Object filter = options.getFilter().orElse(null); if (filter instanceof Aggregation) { Aggregation agg = (Aggregation) filter; AggregationOperationContext context = agg instanceof TypedAggregation ? new TypeBasedAggregationOperationContext(((TypedAggregation<?>) agg).getInputType(), template.getConverter().getMappingContext(), queryMapper) : Aggregation.DEFAULT_CONTEXT; return agg.toPipeline(new PrefixingDelegatingAggregationOperationContext(context, "fullDocument", blacklist)); } if (filter instanceof List) { return (List<Document>) filter; } throw new IllegalArgumentException( "ChangeStreamRequestOptions.filter mut be either an Aggregation or a plain list of Documents"); }
MongoConverter converter = getConverter(); DefaultDbRefResolver dbRefResolver = new DefaultDbRefResolver(mongoDbFactory);
filter.putAll(queryMapper.getMappedObject(query.getQueryObject(), template.getConverter().getMappingContext() .getPersistentEntity(targetType.equals(Document.class) ? Object.class : targetType)));
protected Message<T, R> createMessage(T source, Class<R> targetType, RequestOptions options) { SimpleMessage<T, T> message = new SimpleMessage<>(source, source, MessageProperties.builder() .databaseName(template.getDb().getName()).collectionName(options.getCollectionName()).build()); return new LazyMappingDelegatingMessage<>(message, targetType, template.getConverter()); }
public Object toObject(Class clazz, DBObject dbObject) { if (clazz.equals(ValueWrapper.class)) { return dbObject.get("value"); } return mongoTemplate.getConverter().read(clazz, dbObject); }