use of org.springframework.data.mongodb.core.SimpleMongoClientDatabaseFactory in project spring-data-mongodb by spring-projects.
the class PerformanceTests method setUp.
@BeforeEach
public void setUp() throws Exception {
this.mongo = MongoClients.create();
SimpleMongoClientDatabaseFactory mongoDbFactory = new SimpleMongoClientDatabaseFactory(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 SimpleMongoClientDatabaseFactory(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();
}
use of org.springframework.data.mongodb.core.SimpleMongoClientDatabaseFactory in project kiwi by kiwiproject.
the class PagingQueryRealMongoTest method beforeAll.
@BeforeAll
static void beforeAll() {
var databaseName = "test_db_" + System.nanoTime();
LOG.info("Using database name: {}", databaseName);
var mongoUri = stripTrailingSlash(System.getProperty("realMongoDB.url"));
var connectionString = f("{}/{}?connectTimeoutMS=500&socketTimeoutMS=500&serverSelectionTimeoutMS=500", mongoUri, databaseName);
LOG.info("Mongo connection string: {}", connectionString);
var dbFactory = new SimpleMongoClientDatabaseFactory(connectionString);
mongoTemplate = new MongoTemplate(dbFactory);
}
use of org.springframework.data.mongodb.core.SimpleMongoClientDatabaseFactory in project kiwi by kiwiproject.
the class KiwiSpringMongoQueriesTest method beforeAll.
@BeforeAll
static void beforeAll() {
var connectionString = MONGO_SERVER_EXTENSION.getConnectionString();
var mongoClientDbFactory = new SimpleMongoClientDatabaseFactory(connectionString);
mongoTemplate = new MongoTemplate(mongoClientDbFactory);
}
use of org.springframework.data.mongodb.core.SimpleMongoClientDatabaseFactory in project charon by harvies.
the class MongoAutoConfiguration method postProcessBeanDefinitionRegistry.
@Override
public void postProcessBeanDefinitionRegistry(BeanDefinitionRegistry beanDefinitionRegistry) throws BeansException {
if (multipleDataSourcesProperties == null) {
return;
}
Map<String, MongoProperties> dataSources = multipleDataSourcesProperties.getDataSources();
for (Map.Entry<String, MongoProperties> stringMongoPropertiesEntry : dataSources.entrySet()) {
String dataSourceName = stringMongoPropertiesEntry.getKey();
MongoProperties mongoProperties = stringMongoPropertiesEntry.getValue();
GenericBeanDefinition genericBeanDefinition = new GenericBeanDefinition();
genericBeanDefinition.setBeanClass(MongoTemplate.class);
genericBeanDefinition.setScope(ConfigurableBeanFactory.SCOPE_SINGLETON);
ConstructorArgumentValues constructorArgumentValues = new ConstructorArgumentValues();
genericBeanDefinition.setConstructorArgumentValues(constructorArgumentValues);
constructorArgumentValues.addGenericArgumentValue(new SimpleMongoClientDatabaseFactory(mongoProperties.getUri()));
String mongoTemplateBeanName = dataSourceName + "MongoTemplate";
beanDefinitionRegistry.registerBeanDefinition(mongoTemplateBeanName, genericBeanDefinition);
}
}
use of org.springframework.data.mongodb.core.SimpleMongoClientDatabaseFactory in project spring-oxygen by isxcode.
the class FlysqlAutoConfiguration method flysql.
/**
* 初始化flysql factory
*
* @param flysqlProperties configs
* @param jdbcTemplate jdbcTemplate
* @param mongoTemplate mongoTemplate
* @since 0.0.1
*/
@Bean("flysql")
@ConditionalOnClass(FlysqlAutoConfiguration.class)
private Flysql flysql(FlysqlProperties flysqlProperties, @Nullable JdbcTemplate jdbcTemplate, @Nullable MongoTemplate mongoTemplate) {
Map<String, JdbcTemplate> jdbcTemplateMap;
Map<String, MongoTemplate> mongoTemplateMap;
// 集成oracle/mysql/h2数据库
Map<String, DataSourceProperties> dataSourcePropertiesMap = flysqlProperties.getDatasource();
if (dataSourcePropertiesMap == null) {
jdbcTemplateMap = new HashMap<>(1);
} else {
jdbcTemplateMap = new HashMap<>(dataSourcePropertiesMap.size() + 1);
dataSourcePropertiesMap.forEach((k, v) -> jdbcTemplateMap.put(k, new JdbcTemplate(v.initializeDataSourceBuilder().build())));
}
if (jdbcTemplate != null) {
jdbcTemplateMap.put(FlysqlConstants.PRIMARY_DATASOURCE_NAME, jdbcTemplate);
}
// 集成mongodb数据库
Map<String, MongoProperties> mongodbPropertiesMap = flysqlProperties.getMongodb();
if (mongodbPropertiesMap == null) {
mongoTemplateMap = new HashMap<>(1);
} else {
mongoTemplateMap = new HashMap<>(mongodbPropertiesMap.size() + 1);
mongodbPropertiesMap.forEach((k, v) -> {
String connectSetting;
if (v.getUri() == null) {
connectSetting = "mongo://" + v.getUsername() + ":" + String.valueOf(v.getPassword()) + "@" + v.getHost() + ":" + v.getPort() + "/" + v.getDatabase();
} else {
connectSetting = v.getUri();
}
mongoTemplateMap.put(k, new MongoTemplate(new SimpleMongoClientDatabaseFactory(connectSetting)));
});
}
if (mongoTemplate != null) {
mongoTemplateMap.put(FlysqlConstants.PRIMARY_DATASOURCE_NAME, mongoTemplate);
}
// 储存关系型数据库和非关系型数据库
return new Flysql(jdbcTemplateMap, mongoTemplateMap, flysqlProperties);
}
Aggregations