Search in sources :

Example 1 with MongoRepositoryFactoryBean

use of org.springframework.data.mongodb.repository.support.MongoRepositoryFactoryBean 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)

Aggregations

MongoClient (com.mongodb.MongoClient)1 ObjectId (org.bson.types.ObjectId)1 Before (org.junit.Before)1 MongoTemplate (org.springframework.data.mongodb.core.MongoTemplate)1 SimpleMongoDbFactory (org.springframework.data.mongodb.core.SimpleMongoDbFactory)1 DefaultDbRefResolver (org.springframework.data.mongodb.core.convert.DefaultDbRefResolver)1 MappingMongoConverter (org.springframework.data.mongodb.core.convert.MappingMongoConverter)1 MongoMappingContext (org.springframework.data.mongodb.core.mapping.MongoMappingContext)1 MongoRepositoryFactoryBean (org.springframework.data.mongodb.repository.support.MongoRepositoryFactoryBean)1