Search in sources :

Example 1 with MappingMongoConverter

use of org.springframework.data.mongodb.core.convert.MappingMongoConverter in project oc-explorer by devgateway.

the class MongoTemplateConfig method shadowMongoTemplate.

/**
 * Creates a shadow template configuration by adding "-shadow" as postfix of database name.
 * This is used to replicate the entire database structure in a shadow/temporary database location
 *
 * @return
 * @throws Exception
 */
@Bean(autowire = Autowire.BY_NAME, name = "shadowMongoTemplate")
public MongoTemplate shadowMongoTemplate() throws Exception {
    MongoTemplate template = new MongoTemplate(new SimpleMongoDbFactory(new MongoClientURI(properties.getUri() + SHADOW_POSTFIX)));
    ((MappingMongoConverter) template.getConverter()).setCustomConversions(customConversions);
    return template;
}
Also used : SimpleMongoDbFactory(org.springframework.data.mongodb.core.SimpleMongoDbFactory) MongoClientURI(com.mongodb.MongoClientURI) MappingMongoConverter(org.springframework.data.mongodb.core.convert.MappingMongoConverter) MongoTemplate(org.springframework.data.mongodb.core.MongoTemplate) Bean(org.springframework.context.annotation.Bean)

Example 2 with MappingMongoConverter

use of org.springframework.data.mongodb.core.convert.MappingMongoConverter in project oc-explorer by devgateway.

the class MongoTemplateConfig method mongoTemplate.

@Bean(autowire = Autowire.BY_NAME, name = "mongoTemplate")
public MongoTemplate mongoTemplate() throws Exception {
    MongoTemplate template = new MongoTemplate(new SimpleMongoDbFactory(new MongoClientURI(properties.getUri())));
    ((MappingMongoConverter) template.getConverter()).setCustomConversions(customConversions);
    return template;
}
Also used : SimpleMongoDbFactory(org.springframework.data.mongodb.core.SimpleMongoDbFactory) MongoClientURI(com.mongodb.MongoClientURI) MappingMongoConverter(org.springframework.data.mongodb.core.convert.MappingMongoConverter) MongoTemplate(org.springframework.data.mongodb.core.MongoTemplate) Bean(org.springframework.context.annotation.Bean)

Example 3 with MappingMongoConverter

use of org.springframework.data.mongodb.core.convert.MappingMongoConverter in project oc-explorer by devgateway.

the class MongoTemplateTestConfig method shadowMongoTemplate.

/**
 * Creates a shadow template configuration by adding "-shadow" as postfix of database name.
 * This is used to replicate the entire database structure in a shadow/temporary database location
 *
 * @return
 * @throws Exception
 */
@Bean(name = "shadowMongoTemplate")
public MongoTemplate shadowMongoTemplate(MongodProcess mongodProcess) throws Exception {
    Net net = mongodProcess.getConfig().net();
    properties.setHost(net.getServerAddress().getHostName());
    properties.setPort(net.getPort());
    properties.setDatabase(originalUri + MongoTemplateConfig.SHADOW_POSTFIX);
    properties.setUri(null);
    MongoTemplate template = new MongoTemplate(new SimpleMongoDbFactory(properties.createMongoClient(this.options, environment), properties.getDatabase()));
    ((MappingMongoConverter) template.getConverter()).setCustomConversions(customConversions);
    return template;
}
Also used : SimpleMongoDbFactory(org.springframework.data.mongodb.core.SimpleMongoDbFactory) MappingMongoConverter(org.springframework.data.mongodb.core.convert.MappingMongoConverter) Net(de.flapdoodle.embed.mongo.config.Net) MongoTemplate(org.springframework.data.mongodb.core.MongoTemplate) Bean(org.springframework.context.annotation.Bean)

Example 4 with MappingMongoConverter

use of org.springframework.data.mongodb.core.convert.MappingMongoConverter in project oc-explorer by devgateway.

the class MongoTemplateTestConfig method mongoTemplate.

@Bean(name = "mongoTemplate")
public MongoTemplate mongoTemplate(MongodProcess mongodProcess) throws Exception {
    Net net = mongodProcess.getConfig().net();
    properties.setHost(net.getServerAddress().getHostName());
    properties.setPort(net.getPort());
    properties.setDatabase(originalUri);
    properties.setUri(null);
    MongoTemplate template = new MongoTemplate(new SimpleMongoDbFactory(properties.createMongoClient(this.options, environment), properties.getDatabase()));
    ((MappingMongoConverter) template.getConverter()).setCustomConversions(customConversions);
    return template;
}
Also used : SimpleMongoDbFactory(org.springframework.data.mongodb.core.SimpleMongoDbFactory) MappingMongoConverter(org.springframework.data.mongodb.core.convert.MappingMongoConverter) Net(de.flapdoodle.embed.mongo.config.Net) MongoTemplate(org.springframework.data.mongodb.core.MongoTemplate) Bean(org.springframework.context.annotation.Bean)

Example 5 with MappingMongoConverter

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

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