org.springframework.data.mongodb.core.MongoTemplate.getConverter()方法的使用及代码示例

x33g5p2x  于2022-01-24 转载在 其他  
字(9.1k)|赞(0)|评价(0)|浏览(116)

本文整理了Java中org.springframework.data.mongodb.core.MongoTemplate.getConverter()方法的一些代码示例,展示了MongoTemplate.getConverter()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。MongoTemplate.getConverter()方法的具体详情如下:
包路径:org.springframework.data.mongodb.core.MongoTemplate
类名称:MongoTemplate
方法名:getConverter

MongoTemplate.getConverter介绍

[英]Returns the default org.springframework.data.mongodb.core.convert.MongoConverter.
[中]返回默认组织。springframework。数据mongodb。果心转换MongoConverter。

代码示例

代码示例来源:origin: spring-projects/spring-data-mongodb

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

代码示例来源:origin: spring-projects/spring-data-mongodb

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

代码示例来源:origin: spring-projects/spring-data-mongodb

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

代码示例来源:origin: spring-projects/spring-data-mongodb

@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");
}

代码示例来源:origin: spring-projects/spring-data-mongodb

MongoConverter converter = getConverter();
DefaultDbRefResolver dbRefResolver = new DefaultDbRefResolver(mongoDbFactory);

代码示例来源:origin: kaaproject/kaa

@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;
}

代码示例来源:origin: spring-projects/spring-data-mongodb

log.debug("Flush: saving: {}", dbQuery);
mongoTemplate.getConverter().write(value, dbDoc);
dbDoc.put(ENTITY_FIELD_CLASS, value.getClass().getName());
if (dbId != null) {

代码示例来源:origin: spring-projects/spring-data-mongodb

filter.putAll(queryMapper.getMappedObject(query.getQueryObject(), template.getConverter().getMappingContext()
    .getPersistentEntity(targetType.equals(Document.class) ? Object.class : targetType)));

代码示例来源:origin: kaaproject/kaa

@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);
}

代码示例来源:origin: kaaproject/kaa

@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);
}

代码示例来源:origin: kaaproject/kaa

@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);
}

代码示例来源:origin: kaaproject/kaa

@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);
}

代码示例来源:origin: spring-projects/spring-data-mongodb

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

代码示例来源:origin: org.springframework.data/spring-data-mongodb

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

代码示例来源:origin: org.springframework.data/spring-data-mongodb

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

代码示例来源:origin: org.springframework.data/spring-data-mongodb

@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");
}

代码示例来源:origin: org.springframework.data/spring-data-mongodb

MongoConverter converter = getConverter();
DefaultDbRefResolver dbRefResolver = new DefaultDbRefResolver(mongoDbFactory);

代码示例来源:origin: org.springframework.data/spring-data-mongodb

filter.putAll(queryMapper.getMappedObject(query.getQueryObject(), template.getConverter().getMappingContext()
    .getPersistentEntity(targetType.equals(Document.class) ? Object.class : targetType)));

代码示例来源:origin: org.springframework.data/spring-data-mongodb

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

代码示例来源:origin: hazelcast/hazelcast-code-samples

public Object toObject(Class clazz, DBObject dbObject) {
  if (clazz.equals(ValueWrapper.class)) {
    return dbObject.get("value");
  }
  return mongoTemplate.getConverter().read(clazz, dbObject);
}

相关文章