Search in sources :

Example 21 with MappingMongoConverter

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

the class MappingMongoConverterParserIntegrationTests method hasCustomTypeMapper.

// DATAMONGO-725
@Test
public void hasCustomTypeMapper() {
    loadValidConfiguration();
    MappingMongoConverter converter = factory.getBean("converter", MappingMongoConverter.class);
    MongoTypeMapper customMongoTypeMapper = factory.getBean(CustomMongoTypeMapper.class);
    assertThat(converter.getTypeMapper(), is(customMongoTypeMapper));
}
Also used : MappingMongoConverter(org.springframework.data.mongodb.core.convert.MappingMongoConverter) MongoTypeMapper(org.springframework.data.mongodb.core.convert.MongoTypeMapper) Test(org.junit.Test)

Example 22 with MappingMongoConverter

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

the class DefaultBulkOperationsUnitTests method setUp.

@Before
public void setUp() {
    mappingContext = new MongoMappingContext();
    mappingContext.afterPropertiesSet();
    converter = new MappingMongoConverter(dbRefResolver, mappingContext);
    template = new MongoTemplate(factory, converter);
    when(factory.getDb()).thenReturn(database);
    when(database.getCollection(anyString(), eq(Document.class))).thenReturn(collection);
    ops = new DefaultBulkOperations(template, "collection-1", new BulkOperationContext(BulkMode.ORDERED, Optional.of(mappingContext.getPersistentEntity(SomeDomainType.class)), new QueryMapper(converter), new UpdateMapper(converter)));
}
Also used : BulkOperationContext(org.springframework.data.mongodb.core.DefaultBulkOperations.BulkOperationContext) MongoMappingContext(org.springframework.data.mongodb.core.mapping.MongoMappingContext) MappingMongoConverter(org.springframework.data.mongodb.core.convert.MappingMongoConverter) Document(org.bson.Document) QueryMapper(org.springframework.data.mongodb.core.convert.QueryMapper) UpdateMapper(org.springframework.data.mongodb.core.convert.UpdateMapper) Before(org.junit.Before)

Example 23 with MappingMongoConverter

use of org.springframework.data.mongodb.core.convert.MappingMongoConverter 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)

Example 24 with MappingMongoConverter

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

the class PerformanceTests method setUp.

@Before
public void setUp() throws Exception {
    this.mongo = new MongoClient();
    SimpleMongoDbFactory mongoDbFactory = new SimpleMongoDbFactory(this.mongo, DATABASE_NAME);
    MongoMappingContext context = new MongoMappingContext();
    context.setInitialEntitySet(Collections.singleton(Person.class));
    context.afterPropertiesSet();
    this.converter = new MappingMongoConverter(new DefaultDbRefResolver(mongoDbFactory), context);
    this.operations = new MongoTemplate(new SimpleMongoDbFactory(this.mongo, DATABASE_NAME), converter);
    MongoRepositoryFactoryBean<PersonRepository, Person, ObjectId> factory = new MongoRepositoryFactoryBean<PersonRepository, Person, ObjectId>(PersonRepository.class);
    factory.setMongoOperations(operations);
    factory.afterPropertiesSet();
    this.repository = factory.getObject();
}
Also used : MongoClient(com.mongodb.MongoClient) SimpleMongoDbFactory(org.springframework.data.mongodb.core.SimpleMongoDbFactory) ObjectId(org.bson.types.ObjectId) MongoRepositoryFactoryBean(org.springframework.data.mongodb.repository.support.MongoRepositoryFactoryBean) MongoMappingContext(org.springframework.data.mongodb.core.mapping.MongoMappingContext) DefaultDbRefResolver(org.springframework.data.mongodb.core.convert.DefaultDbRefResolver) MappingMongoConverter(org.springframework.data.mongodb.core.convert.MappingMongoConverter) MongoTemplate(org.springframework.data.mongodb.core.MongoTemplate) Before(org.junit.Before)

Example 25 with MappingMongoConverter

use of org.springframework.data.mongodb.core.convert.MappingMongoConverter 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)

Aggregations

MappingMongoConverter (org.springframework.data.mongodb.core.convert.MappingMongoConverter)35 MongoMappingContext (org.springframework.data.mongodb.core.mapping.MongoMappingContext)21 Before (org.junit.Before)19 DefaultDbRefResolver (org.springframework.data.mongodb.core.convert.DefaultDbRefResolver)14 DbRefResolver (org.springframework.data.mongodb.core.convert.DbRefResolver)9 Bean (org.springframework.context.annotation.Bean)7 Test (org.junit.Test)6 Document (org.bson.Document)5 MongoTemplate (org.springframework.data.mongodb.core.MongoTemplate)5 SimpleMongoDbFactory (org.springframework.data.mongodb.core.SimpleMongoDbFactory)5 QueryMapper (org.springframework.data.mongodb.core.convert.QueryMapper)5 MongoDbFactory (org.springframework.data.mongodb.MongoDbFactory)3 MongoCustomConversions (org.springframework.data.mongodb.core.convert.MongoCustomConversions)3 MongoTypeMapper (org.springframework.data.mongodb.core.convert.MongoTypeMapper)3 BasicDBObject (com.mongodb.BasicDBObject)2 MongoClientURI (com.mongodb.MongoClientURI)2 CountOptions (com.mongodb.client.model.CountOptions)2 ClientSession (com.mongodb.session.ClientSession)2 Net (de.flapdoodle.embed.mongo.config.Net)2 BsonValueCodec (org.bson.codecs.BsonValueCodec)2