Search in sources :

Example 1 with MongoMappingContext

use of org.springframework.data.mongodb.core.mapping.MongoMappingContext in project spring-boot by spring-projects.

the class MongoDataAutoConfiguration method mongoMappingContext.

@Bean
@ConditionalOnMissingBean
public MongoMappingContext mongoMappingContext(BeanFactory beanFactory, CustomConversions conversions) throws ClassNotFoundException {
    MongoMappingContext context = new MongoMappingContext();
    context.setInitialEntitySet(new EntityScanner(this.applicationContext).scan(Document.class, Persistent.class));
    Class<?> strategyClass = this.properties.getFieldNamingStrategy();
    if (strategyClass != null) {
        context.setFieldNamingStrategy((FieldNamingStrategy) BeanUtils.instantiateClass(strategyClass));
    }
    context.setSimpleTypeHolder(conversions.getSimpleTypeHolder());
    return context;
}
Also used : MongoMappingContext(org.springframework.data.mongodb.core.mapping.MongoMappingContext) Persistent(org.springframework.data.annotation.Persistent) Document(org.springframework.data.mongodb.core.mapping.Document) EntityScanner(org.springframework.boot.autoconfigure.domain.EntityScanner) ConditionalOnMissingBean(org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean) ConditionalOnMissingBean(org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean) Bean(org.springframework.context.annotation.Bean)

Example 2 with MongoMappingContext

use of org.springframework.data.mongodb.core.mapping.MongoMappingContext in project spring-data-mongodb by spring-projects.

the class MongoTemplate method getDefaultMongoConverter.

private static MongoConverter getDefaultMongoConverter(MongoDbFactory factory) {
    DbRefResolver dbRefResolver = new DefaultDbRefResolver(factory);
    MongoCustomConversions conversions = new MongoCustomConversions(Collections.emptyList());
    MongoMappingContext mappingContext = new MongoMappingContext();
    mappingContext.setSimpleTypeHolder(conversions.getSimpleTypeHolder());
    mappingContext.afterPropertiesSet();
    MappingMongoConverter converter = new MappingMongoConverter(dbRefResolver, mappingContext);
    converter.setCustomConversions(conversions);
    converter.afterPropertiesSet();
    return converter;
}
Also used : MongoMappingContext(org.springframework.data.mongodb.core.mapping.MongoMappingContext)

Example 3 with MongoMappingContext

use of org.springframework.data.mongodb.core.mapping.MongoMappingContext 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 4 with MongoMappingContext

use of org.springframework.data.mongodb.core.mapping.MongoMappingContext in project spring-data-mongodb by spring-projects.

the class UnwrapAndReadDocumentCallbackUnitTests method setUp.

@Before
public void setUp() {
    when(factory.getExceptionTranslator()).thenReturn(exceptionTranslatorMock);
    MongoTemplate template = new MongoTemplate(factory);
    MappingMongoConverter converter = new MappingMongoConverter(new DefaultDbRefResolver(factory), new MongoMappingContext());
    this.callback = template.new UnwrapAndReadDocumentCallback(converter, Target.class, "collection-1");
}
Also used : DefaultDbRefResolver(org.springframework.data.mongodb.core.convert.DefaultDbRefResolver) MongoMappingContext(org.springframework.data.mongodb.core.mapping.MongoMappingContext) MappingMongoConverter(org.springframework.data.mongodb.core.convert.MappingMongoConverter) UnwrapAndReadDocumentCallback(org.springframework.data.mongodb.core.MongoTemplate.UnwrapAndReadDocumentCallback) Before(org.junit.Before)

Example 5 with MongoMappingContext

use of org.springframework.data.mongodb.core.mapping.MongoMappingContext in project spring-data-mongodb by spring-projects.

the class QueryMapperUnitTests method setUp.

@Before
public void setUp() {
    this.context = new MongoMappingContext();
    this.converter = new MappingMongoConverter(new DefaultDbRefResolver(factory), context);
    this.converter.afterPropertiesSet();
    this.mapper = new QueryMapper(converter);
}
Also used : MongoMappingContext(org.springframework.data.mongodb.core.mapping.MongoMappingContext) Before(org.junit.Before)

Aggregations

MongoMappingContext (org.springframework.data.mongodb.core.mapping.MongoMappingContext)118 MappingMongoConverter (org.springframework.data.mongodb.core.convert.MappingMongoConverter)56 Test (org.junit.jupiter.api.Test)41 BeforeEach (org.junit.jupiter.api.BeforeEach)31 Document (org.bson.Document)19 QueryMapper (org.springframework.data.mongodb.core.convert.QueryMapper)19 DefaultDbRefResolver (org.springframework.data.mongodb.core.convert.DefaultDbRefResolver)13 MongoCustomConversions (org.springframework.data.mongodb.core.convert.MongoCustomConversions)10 Bson (org.bson.conversions.Bson)8 Before (org.junit.Before)8 Test (org.junit.Test)8 MongoTemplate (org.springframework.data.mongodb.core.MongoTemplate)8 IndexOptions (com.mongodb.client.model.IndexOptions)7 CustomConversions (org.springframework.data.convert.CustomConversions)6 DbRefResolver (org.springframework.data.mongodb.core.convert.DbRefResolver)6 Document (org.springframework.data.mongodb.core.mapping.Document)6 Set (java.util.Set)5 MongoDbFactory (org.springframework.data.mongodb.MongoDbFactory)5 CountOptions (com.mongodb.client.model.CountOptions)4 List (java.util.List)4