Search in sources :

Example 31 with SimpleMongoDbFactory

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

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

use of org.springframework.data.mongodb.core.SimpleMongoDbFactory in project cas by apereo.

the class MongoDbConnectionFactory method mongoDbFactory.

private MongoDbFactory mongoDbFactory(final Mongo mongo, final BaseMongoDbProperties props) {
    final String dbName;
    final String authDbName;
    if (StringUtils.isNotBlank(props.getClientUri())) {
        final MongoClientURI uri = buildMongoClientURI(props.getClientUri(), buildMongoDbClientOptions(props));
        authDbName = uri.getCredentials().getSource();
        dbName = uri.getDatabase();
        LOGGER.debug("Using database [{}] from the connection client URI", dbName);
    } else {
        authDbName = props.getAuthenticationDatabaseName();
        dbName = props.getDatabaseName();
        LOGGER.debug("Using database [{}] from individual settings", dbName);
    }
    if (StringUtils.isBlank(dbName)) {
        LOGGER.error("Database name cannot be undefined. It must be specified as part of the client URI connection string if used, or " + "as an individual setting for the MongoDb connection");
    }
    return new SimpleMongoDbFactory(mongo, dbName, null, authDbName);
}
Also used : SimpleMongoDbFactory(org.springframework.data.mongodb.core.SimpleMongoDbFactory) MongoClientURI(com.mongodb.MongoClientURI)

Example 34 with SimpleMongoDbFactory

use of org.springframework.data.mongodb.core.SimpleMongoDbFactory in project commons-dao by reportportal.

the class MongodbConfiguration method mongoDbFactory.

@Bean
@Profile("!unittest")
MongoDbFactory mongoDbFactory() throws UnknownHostException {
    SimpleMongoDbFactory mongoDbFactory = new SimpleMongoDbFactory(mongo(), mongoProperties.getDatabase());
    mongoDbFactory.setWriteConcern(WriteConcern.ACKNOWLEDGED);
    return mongoDbFactory;
}
Also used : SimpleMongoDbFactory(org.springframework.data.mongodb.core.SimpleMongoDbFactory) Profile(org.springframework.context.annotation.Profile) ReportPortalRepositoryFactoryBean(com.epam.ta.reportportal.database.dao.ReportPortalRepositoryFactoryBean) RepositoriesFactoryBean(com.epam.ta.reportportal.database.support.RepositoriesFactoryBean) Bean(org.springframework.context.annotation.Bean)

Example 35 with SimpleMongoDbFactory

use of org.springframework.data.mongodb.core.SimpleMongoDbFactory in project ocvn 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)

Aggregations

SimpleMongoDbFactory (org.springframework.data.mongodb.core.SimpleMongoDbFactory)51 MongoClient (com.mongodb.MongoClient)38 Test (org.junit.Test)28 MongoDbAvailable (org.springframework.integration.mongodb.rules.MongoDbAvailable)28 AbstractBatchingMessageGroupStore (org.springframework.integration.store.AbstractBatchingMessageGroupStore)16 MessageGroupStore (org.springframework.integration.store.MessageGroupStore)16 GenericMessage (org.springframework.messaging.support.GenericMessage)14 MessageGroup (org.springframework.integration.store.MessageGroup)12 MongoTemplate (org.springframework.data.mongodb.core.MongoTemplate)10 Bean (org.springframework.context.annotation.Bean)9 MongoDbFactory (org.springframework.data.mongodb.MongoDbFactory)8 MappingMongoConverter (org.springframework.data.mongodb.core.convert.MappingMongoConverter)8 MessageStore (org.springframework.integration.store.MessageStore)8 MongoClientURI (com.mongodb.MongoClientURI)6 Net (de.flapdoodle.embed.mongo.config.Net)4 Matchers.containsString (org.hamcrest.Matchers.containsString)4 GenericApplicationContext (org.springframework.context.support.GenericApplicationContext)4 ClaimCheckInTransformer (org.springframework.integration.transformer.ClaimCheckInTransformer)4 ClaimCheckOutTransformer (org.springframework.integration.transformer.ClaimCheckOutTransformer)4 ClassPathXmlApplicationContext (org.springframework.context.support.ClassPathXmlApplicationContext)3