Search in sources :

Example 1 with DefaultDbRefResolver

use of org.springframework.data.mongodb.core.convert.DefaultDbRefResolver in project commons-dao by reportportal.

the class MongodbConfiguration method mappingMongoConverter.

@Bean
public MappingMongoConverter mappingMongoConverter() throws UnknownHostException {
    MappingMongoConverter converter = new MappingMongoConverter(new DefaultDbRefResolver(mongoDbFactory()), mongoMappingContext());
    converter.setCustomConversions(customConversions());
    return converter;
}
Also used : DefaultDbRefResolver(org.springframework.data.mongodb.core.convert.DefaultDbRefResolver) MappingMongoConverter(org.springframework.data.mongodb.core.convert.MappingMongoConverter) ReportPortalRepositoryFactoryBean(com.epam.ta.reportportal.database.dao.ReportPortalRepositoryFactoryBean) RepositoriesFactoryBean(com.epam.ta.reportportal.database.support.RepositoriesFactoryBean) Bean(org.springframework.context.annotation.Bean)

Example 2 with DefaultDbRefResolver

use of org.springframework.data.mongodb.core.convert.DefaultDbRefResolver 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 3 with DefaultDbRefResolver

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

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

the class AbstractConfigurableMongoDbMessageStore method afterPropertiesSet.

@Override
public void afterPropertiesSet() throws Exception {
    if (this.mongoTemplate == null) {
        if (this.mappingMongoConverter == null) {
            this.mappingMongoConverter = new MappingMongoConverter(new DefaultDbRefResolver(this.mongoDbFactory), new MongoMappingContext());
            this.mappingMongoConverter.setApplicationContext(this.applicationContext);
            List<Object> customConverters = new ArrayList<Object>();
            customConverters.add(new MessageToBinaryConverter());
            customConverters.add(new BinaryToMessageConverter());
            this.mappingMongoConverter.setCustomConversions(new MongoCustomConversions(customConverters));
            this.mappingMongoConverter.afterPropertiesSet();
        }
        this.mongoTemplate = new MongoTemplate(this.mongoDbFactory, this.mappingMongoConverter);
    }
    this.messageBuilderFactory = IntegrationUtils.getMessageBuilderFactory(this.applicationContext);
    IndexOperations indexOperations = this.mongoTemplate.indexOps(this.collectionName);
    indexOperations.ensureIndex(new Index(MessageDocumentFields.MESSAGE_ID, Sort.Direction.ASC));
    indexOperations.ensureIndex(new Index(MessageDocumentFields.GROUP_ID, Sort.Direction.ASC).on(MessageDocumentFields.MESSAGE_ID, Sort.Direction.ASC).unique());
    indexOperations.ensureIndex(new Index(MessageDocumentFields.GROUP_ID, Sort.Direction.ASC).on(MessageDocumentFields.LAST_MODIFIED_TIME, Sort.Direction.DESC).on(MessageDocumentFields.SEQUENCE, Sort.Direction.DESC));
}
Also used : MessageToBinaryConverter(org.springframework.integration.mongodb.support.MessageToBinaryConverter) IndexOperations(org.springframework.data.mongodb.core.index.IndexOperations) DefaultDbRefResolver(org.springframework.data.mongodb.core.convert.DefaultDbRefResolver) MongoMappingContext(org.springframework.data.mongodb.core.mapping.MongoMappingContext) MongoCustomConversions(org.springframework.data.mongodb.core.convert.MongoCustomConversions) ArrayList(java.util.ArrayList) MappingMongoConverter(org.springframework.data.mongodb.core.convert.MappingMongoConverter) Index(org.springframework.data.mongodb.core.index.Index) BinaryToMessageConverter(org.springframework.integration.mongodb.support.BinaryToMessageConverter) MongoTemplate(org.springframework.data.mongodb.core.MongoTemplate)

Example 5 with DefaultDbRefResolver

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

the class MongoDatabaseFactoryDependentConfiguration method mappingMongoConverter.

@Bean
@ConditionalOnMissingBean(MongoConverter.class)
MappingMongoConverter mappingMongoConverter(MongoDatabaseFactory factory, MongoMappingContext context, MongoCustomConversions 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) ConditionalOnBean(org.springframework.boot.autoconfigure.condition.ConditionalOnBean) ConditionalOnMissingBean(org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean) Bean(org.springframework.context.annotation.Bean)

Aggregations

DefaultDbRefResolver (org.springframework.data.mongodb.core.convert.DefaultDbRefResolver)25 MappingMongoConverter (org.springframework.data.mongodb.core.convert.MappingMongoConverter)24 MongoMappingContext (org.springframework.data.mongodb.core.mapping.MongoMappingContext)14 DbRefResolver (org.springframework.data.mongodb.core.convert.DbRefResolver)12 MongoCustomConversions (org.springframework.data.mongodb.core.convert.MongoCustomConversions)7 Bean (org.springframework.context.annotation.Bean)6 Before (org.junit.Before)5 BeforeEach (org.junit.jupiter.api.BeforeEach)5 Document (org.bson.Document)3 Bson (org.bson.conversions.Bson)3 MongoTemplate (org.springframework.data.mongodb.core.MongoTemplate)3 ClientSession (com.mongodb.client.ClientSession)2 CountOptions (com.mongodb.client.model.CountOptions)2 List (java.util.List)2 MongoDatabaseFactory (org.springframework.data.mongodb.MongoDatabaseFactory)2 MongoExceptionTranslator (org.springframework.data.mongodb.core.MongoExceptionTranslator)2 BasicQuery (org.springframework.data.mongodb.core.query.BasicQuery)2 Query (org.springframework.data.mongodb.core.query.Query)2 UpdateDefinition (org.springframework.data.mongodb.core.query.UpdateDefinition)2 ReportPortalRepositoryFactoryBean (com.epam.ta.reportportal.database.dao.ReportPortalRepositoryFactoryBean)1