Search in sources :

Example 6 with DbRefResolver

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

the class ReactivePerformanceTests method setUp.

@Before
public void setUp() throws Exception {
    mongo = MongoClients.create();
    SimpleReactiveMongoDatabaseFactory mongoDbFactory = new SimpleReactiveMongoDatabaseFactory(this.mongo, DATABASE_NAME);
    MongoMappingContext context = new MongoMappingContext();
    context.setInitialEntitySet(Collections.singleton(Person.class));
    context.afterPropertiesSet();
    converter = new MappingMongoConverter(new DbRefResolver() {

        @Override
        public Object resolveDbRef(MongoPersistentProperty property, DBRef dbref, DbRefResolverCallback callback, DbRefProxyHandler proxyHandler) {
            return null;
        }

        @Override
        public DBRef createDbRef(org.springframework.data.mongodb.core.mapping.DBRef annotation, MongoPersistentEntity<?> entity, Object id) {
            return null;
        }

        @Override
        public Document fetch(DBRef dbRef) {
            return null;
        }

        @Override
        public List<Document> bulkFetch(List<DBRef> dbRefs) {
            return null;
        }
    }, context);
    operations = new ReactiveMongoTemplate(mongoDbFactory, converter);
    ReactiveMongoRepositoryFactory factory = new ReactiveMongoRepositoryFactory(operations);
    repository = factory.getRepository(ReactivePersonRepository.class);
}
Also used : MongoPersistentProperty(org.springframework.data.mongodb.core.mapping.MongoPersistentProperty) DbRefResolverCallback(org.springframework.data.mongodb.core.convert.DbRefResolverCallback) DBRef(com.mongodb.DBRef) DbRefResolver(org.springframework.data.mongodb.core.convert.DbRefResolver) Document(org.bson.Document) SimpleReactiveMongoDatabaseFactory(org.springframework.data.mongodb.core.SimpleReactiveMongoDatabaseFactory) ReactiveMongoTemplate(org.springframework.data.mongodb.core.ReactiveMongoTemplate) MongoPersistentEntity(org.springframework.data.mongodb.core.mapping.MongoPersistentEntity) ReactiveMongoRepositoryFactory(org.springframework.data.mongodb.repository.support.ReactiveMongoRepositoryFactory) MongoMappingContext(org.springframework.data.mongodb.core.mapping.MongoMappingContext) MappingMongoConverter(org.springframework.data.mongodb.core.convert.MappingMongoConverter) BasicDBObject(com.mongodb.BasicDBObject) BasicDBList(com.mongodb.BasicDBList) DbRefProxyHandler(org.springframework.data.mongodb.core.convert.DbRefProxyHandler) Before(org.junit.Before)

Example 7 with DbRefResolver

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

the class AbstractMongoQueryUnitTests method setUp.

@Before
public void setUp() {
    doReturn("persons").when(persitentEntityMock).getCollection();
    doReturn(persitentEntityMock).when(mappingContextMock).getPersistentEntity(Mockito.any(Class.class));
    doReturn(persitentEntityMock).when(mappingContextMock).getRequiredPersistentEntity(Mockito.any(Class.class));
    doReturn(Person.class).when(persitentEntityMock).getType();
    DbRefResolver dbRefResolver = new DefaultDbRefResolver(mock(MongoDbFactory.class));
    MappingMongoConverter converter = new MappingMongoConverter(dbRefResolver, mappingContextMock);
    converter.afterPropertiesSet();
    doReturn(converter).when(mongoOperationsMock).getConverter();
    doReturn(executableFind).when(mongoOperationsMock).query(any());
    doReturn(withQueryMock).when(executableFind).as(any());
    doReturn(withQueryMock).when(withQueryMock).matching(any());
}
Also used : MongoDbFactory(org.springframework.data.mongodb.MongoDbFactory) 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 8 with DbRefResolver

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

the class AbstractMongoConfiguration method mappingMongoConverter.

/**
 * Creates a {@link MappingMongoConverter} using the configured {@link #mongoDbFactory()} and
 * {@link #mongoMappingContext()}. Will get {@link #customConversions()} applied.
 *
 * @see #customConversions()
 * @see #mongoMappingContext()
 * @see #mongoDbFactory()
 * @return
 * @throws Exception
 */
@Bean
public MappingMongoConverter mappingMongoConverter() throws Exception {
    DbRefResolver dbRefResolver = new DefaultDbRefResolver(mongoDbFactory());
    MappingMongoConverter converter = new MappingMongoConverter(dbRefResolver, mongoMappingContext());
    converter.setCustomConversions(customConversions());
    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) Bean(org.springframework.context.annotation.Bean)

Example 9 with DbRefResolver

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

the class SessionBoundMongoTemplateTests method getDefaultMongoConverter.

private 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 : DefaultDbRefResolver(org.springframework.data.mongodb.core.convert.DefaultDbRefResolver) MongoCustomConversions(org.springframework.data.mongodb.core.convert.MongoCustomConversions) MongoMappingContext(org.springframework.data.mongodb.core.mapping.MongoMappingContext) MappingMongoConverter(org.springframework.data.mongodb.core.convert.MappingMongoConverter) DbRefResolver(org.springframework.data.mongodb.core.convert.DbRefResolver) DefaultDbRefResolver(org.springframework.data.mongodb.core.convert.DefaultDbRefResolver)

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