Search in sources :

Example 1 with DbRefResolver

use of org.springframework.data.mongodb.core.convert.DbRefResolver in project spring-data-mongodb by spring-projects.

the class MongoQueryCreatorUnitTests method setUp.

@Before
public void setUp() throws SecurityException, NoSuchMethodException {
    context = new MongoMappingContext();
    DbRefResolver resolver = new DefaultDbRefResolver(mock(MongoDbFactory.class));
    converter = new MappingMongoConverter(resolver, context);
}
Also used : MongoDbFactory(org.springframework.data.mongodb.MongoDbFactory) MongoMappingContext(org.springframework.data.mongodb.core.mapping.MongoMappingContext) DefaultDbRefResolver(org.springframework.data.mongodb.core.convert.DefaultDbRefResolver) MappingMongoConverter(org.springframework.data.mongodb.core.convert.MappingMongoConverter) DbRefResolver(org.springframework.data.mongodb.core.convert.DbRefResolver) DefaultDbRefResolver(org.springframework.data.mongodb.core.convert.DefaultDbRefResolver) Before(org.junit.Before)

Example 2 with DbRefResolver

use of org.springframework.data.mongodb.core.convert.DbRefResolver in project spring-data-mongodb by spring-projects.

the class PartTreeMongoQueryUnitTests method setUp.

@Before
public void setUp() {
    mappingContext = new MongoMappingContext();
    DbRefResolver dbRefResolver = new DefaultDbRefResolver(mock(MongoDbFactory.class));
    MongoConverter converter = new MappingMongoConverter(dbRefResolver, mappingContext);
    doReturn(converter).when(mongoOperationsMock).getConverter();
    doReturn(findOperationMock).when(mongoOperationsMock).query(any());
}
Also used : MongoDbFactory(org.springframework.data.mongodb.MongoDbFactory) MongoMappingContext(org.springframework.data.mongodb.core.mapping.MongoMappingContext) DefaultDbRefResolver(org.springframework.data.mongodb.core.convert.DefaultDbRefResolver) MappingMongoConverter(org.springframework.data.mongodb.core.convert.MappingMongoConverter) DbRefResolver(org.springframework.data.mongodb.core.convert.DbRefResolver) DefaultDbRefResolver(org.springframework.data.mongodb.core.convert.DefaultDbRefResolver) MongoConverter(org.springframework.data.mongodb.core.convert.MongoConverter) MappingMongoConverter(org.springframework.data.mongodb.core.convert.MappingMongoConverter) Before(org.junit.Before)

Example 3 with DbRefResolver

use of org.springframework.data.mongodb.core.convert.DbRefResolver in project spring-boot by spring-projects.

the class MongoDataAutoConfiguration method mappingMongoConverter.

@Bean
@ConditionalOnMissingBean(MongoConverter.class)
public MappingMongoConverter mappingMongoConverter(MongoDbFactory factory, MongoMappingContext context, BeanFactory beanFactory, CustomConversions conversions) {
    DbRefResolver dbRefResolver = new DefaultDbRefResolver(factory);
    MappingMongoConverter mappingConverter = new MappingMongoConverter(dbRefResolver, context);
    mappingConverter.setCustomConversions(conversions);
    return mappingConverter;
}
Also used : DefaultDbRefResolver(org.springframework.data.mongodb.core.convert.DefaultDbRefResolver) MappingMongoConverter(org.springframework.data.mongodb.core.convert.MappingMongoConverter) DbRefResolver(org.springframework.data.mongodb.core.convert.DbRefResolver) DefaultDbRefResolver(org.springframework.data.mongodb.core.convert.DefaultDbRefResolver) ConditionalOnMissingBean(org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean) ConditionalOnMissingBean(org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean) Bean(org.springframework.context.annotation.Bean)

Example 4 with DbRefResolver

use of org.springframework.data.mongodb.core.convert.DbRefResolver in project cas by apereo.

the class MongoDbConnectionFactory method mappingMongoConverter.

private MappingMongoConverter mappingMongoConverter(final MongoDbFactory mongoDbFactory) {
    final DbRefResolver dbRefResolver = new DefaultDbRefResolver(mongoDbFactory);
    final MappingMongoConverter converter = new MappingMongoConverter(dbRefResolver, this.mongoMappingContext());
    converter.setCustomConversions(customConversions);
    converter.afterPropertiesSet();
    return converter;
}
Also used : DefaultDbRefResolver(org.springframework.data.mongodb.core.convert.DefaultDbRefResolver) MappingMongoConverter(org.springframework.data.mongodb.core.convert.MappingMongoConverter) DbRefResolver(org.springframework.data.mongodb.core.convert.DbRefResolver) DefaultDbRefResolver(org.springframework.data.mongodb.core.convert.DefaultDbRefResolver)

Example 5 with DbRefResolver

use of org.springframework.data.mongodb.core.convert.DbRefResolver in project spring-data-mongodb by spring-projects.

the class MongoTemplateTests method setMongo.

@Autowired
public void setMongo(Mongo mongo) throws Exception {
    CustomConversions conversions = new MongoCustomConversions(Arrays.asList(DateToDateTimeConverter.INSTANCE, DateTimeToDateConverter.INSTANCE));
    MongoMappingContext mappingContext = new MongoMappingContext();
    mappingContext.setInitialEntitySet(new HashSet<Class<?>>(Arrays.asList(PersonWith_idPropertyOfTypeObjectId.class, PersonWith_idPropertyOfTypeString.class, PersonWithIdPropertyOfTypeObjectId.class, PersonWithIdPropertyOfTypeString.class, PersonWithIdPropertyOfTypeInteger.class, PersonWithIdPropertyOfTypeBigInteger.class, PersonWithIdPropertyOfPrimitiveInt.class, PersonWithIdPropertyOfTypeLong.class, PersonWithIdPropertyOfPrimitiveLong.class, PersonWithIdPropertyOfTypeUUID.class)));
    mappingContext.setSimpleTypeHolder(conversions.getSimpleTypeHolder());
    mappingContext.initialize();
    DbRefResolver dbRefResolver = new DefaultDbRefResolver(factory);
    MappingMongoConverter mappingConverter = new MappingMongoConverter(dbRefResolver, mappingContext);
    mappingConverter.setCustomConversions(conversions);
    mappingConverter.afterPropertiesSet();
    this.mappingTemplate = new MongoTemplate(factory, mappingConverter);
}
Also used : CustomConversions(org.springframework.data.convert.CustomConversions) MongoCustomConversions(org.springframework.data.mongodb.core.convert.MongoCustomConversions) MongoCustomConversions(org.springframework.data.mongodb.core.convert.MongoCustomConversions) MongoMappingContext(org.springframework.data.mongodb.core.mapping.MongoMappingContext) DefaultDbRefResolver(org.springframework.data.mongodb.core.convert.DefaultDbRefResolver) MappingMongoConverter(org.springframework.data.mongodb.core.convert.MappingMongoConverter) DbRefResolver(org.springframework.data.mongodb.core.convert.DbRefResolver) DefaultDbRefResolver(org.springframework.data.mongodb.core.convert.DefaultDbRefResolver) Autowired(org.springframework.beans.factory.annotation.Autowired)

Aggregations

DbRefResolver (org.springframework.data.mongodb.core.convert.DbRefResolver)9 MappingMongoConverter (org.springframework.data.mongodb.core.convert.MappingMongoConverter)9 DefaultDbRefResolver (org.springframework.data.mongodb.core.convert.DefaultDbRefResolver)8 MongoMappingContext (org.springframework.data.mongodb.core.mapping.MongoMappingContext)5 Before (org.junit.Before)4 MongoDbFactory (org.springframework.data.mongodb.MongoDbFactory)3 Bean (org.springframework.context.annotation.Bean)2 MongoCustomConversions (org.springframework.data.mongodb.core.convert.MongoCustomConversions)2 BasicDBList (com.mongodb.BasicDBList)1 BasicDBObject (com.mongodb.BasicDBObject)1 DBRef (com.mongodb.DBRef)1 Document (org.bson.Document)1 Autowired (org.springframework.beans.factory.annotation.Autowired)1 ConditionalOnMissingBean (org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean)1 CustomConversions (org.springframework.data.convert.CustomConversions)1 ReactiveMongoTemplate (org.springframework.data.mongodb.core.ReactiveMongoTemplate)1 SimpleReactiveMongoDatabaseFactory (org.springframework.data.mongodb.core.SimpleReactiveMongoDatabaseFactory)1 DbRefProxyHandler (org.springframework.data.mongodb.core.convert.DbRefProxyHandler)1 DbRefResolverCallback (org.springframework.data.mongodb.core.convert.DbRefResolverCallback)1 MongoConverter (org.springframework.data.mongodb.core.convert.MongoConverter)1