Search in sources :

Example 6 with DefaultDbRefResolver

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

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

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

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

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

the class ConvertingParameterAccessorUnitTests method setUp.

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

Aggregations

DefaultDbRefResolver (org.springframework.data.mongodb.core.convert.DefaultDbRefResolver)15 MappingMongoConverter (org.springframework.data.mongodb.core.convert.MappingMongoConverter)14 Before (org.junit.Before)10 MongoMappingContext (org.springframework.data.mongodb.core.mapping.MongoMappingContext)10 DbRefResolver (org.springframework.data.mongodb.core.convert.DbRefResolver)8 MongoDbFactory (org.springframework.data.mongodb.MongoDbFactory)3 Bean (org.springframework.context.annotation.Bean)2 MongoCustomConversions (org.springframework.data.mongodb.core.convert.MongoCustomConversions)2 MongoClient (com.mongodb.MongoClient)1 CountOptions (com.mongodb.client.model.CountOptions)1 ClientSession (com.mongodb.session.ClientSession)1 List (java.util.List)1 Document (org.bson.Document)1 BsonValueCodec (org.bson.codecs.BsonValueCodec)1 Bson (org.bson.conversions.Bson)1 ObjectId (org.bson.types.ObjectId)1 Autowired (org.springframework.beans.factory.annotation.Autowired)1 ConditionalOnMissingBean (org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean)1 CustomConversions (org.springframework.data.convert.CustomConversions)1 MongoTemplate (org.springframework.data.mongodb.core.MongoTemplate)1