2015-01-07 01:26:14 +08:00
|
|
|
|
/*
|
|
|
|
|
* DatabaseDriverFactory.cpp
|
|
|
|
|
*
|
|
|
|
|
* Created on: 2012-8-14
|
|
|
|
|
* Author: fasiondog
|
|
|
|
|
*/
|
|
|
|
|
|
2020-04-05 02:02:05 +08:00
|
|
|
|
#include "../GlobalInitializer.h"
|
2017-10-09 02:25:02 +08:00
|
|
|
|
#include <boost/algorithm/string.hpp>
|
2019-08-16 01:17:24 +08:00
|
|
|
|
#include "base_info/sqlite/SQLiteBaseInfoDriver.h"
|
2020-04-05 02:02:05 +08:00
|
|
|
|
#include "base_info/mysql/MySQLBaseInfoDriver.h"
|
2016-04-03 00:08:31 +08:00
|
|
|
|
#include "block_info/qianlong/QLBlockInfoDriver.h"
|
2017-10-20 02:11:57 +08:00
|
|
|
|
#include "kdata/hdf5/H5KDataDriver.h"
|
2020-04-05 02:02:05 +08:00
|
|
|
|
#include "kdata/mysql/MySQLKDataDriver.h"
|
|
|
|
|
#include "kdata/tdx/TdxKDataDriver.h"
|
2021-01-20 00:32:01 +08:00
|
|
|
|
#include "kdata/cvs/KDataTempCsvDriver.h"
|
2015-01-07 01:26:14 +08:00
|
|
|
|
#include "DataDriverFactory.h"
|
|
|
|
|
#include "KDataDriver.h"
|
|
|
|
|
|
|
|
|
|
namespace hku {
|
|
|
|
|
|
2020-04-06 01:56:04 +08:00
|
|
|
|
map<string, BaseInfoDriverPtr>* DataDriverFactory::m_baseInfoDrivers{nullptr};
|
|
|
|
|
map<string, BlockInfoDriverPtr>* DataDriverFactory::m_blockDrivers{nullptr};
|
2021-01-22 23:50:46 +08:00
|
|
|
|
map<string, KDataDriverPtr>* DataDriverFactory::m_kdataPrototypeDrivers{nullptr};
|
2015-01-07 01:26:14 +08:00
|
|
|
|
|
2021-01-24 20:47:38 +08:00
|
|
|
|
map<string, KDataDriverConnectPoolPtr>* DataDriverFactory::m_kdataDriverPools{nullptr};
|
2021-01-20 00:32:01 +08:00
|
|
|
|
|
2020-04-05 02:02:05 +08:00
|
|
|
|
void DataDriverFactory::init() {
|
|
|
|
|
m_baseInfoDrivers = new map<string, BaseInfoDriverPtr>();
|
|
|
|
|
DataDriverFactory::regBaseInfoDriver(make_shared<SQLiteBaseInfoDriver>());
|
|
|
|
|
DataDriverFactory::regBaseInfoDriver(make_shared<MySQLBaseInfoDriver>());
|
2015-01-07 01:26:14 +08:00
|
|
|
|
|
2020-04-05 02:02:05 +08:00
|
|
|
|
m_blockDrivers = new map<string, BlockInfoDriverPtr>();
|
|
|
|
|
DataDriverFactory::regBlockDriver(make_shared<QLBlockInfoDriver>());
|
2017-10-20 02:11:57 +08:00
|
|
|
|
|
2021-01-22 23:50:46 +08:00
|
|
|
|
m_kdataPrototypeDrivers = new map<string, KDataDriverPtr>();
|
2021-01-24 20:47:38 +08:00
|
|
|
|
m_kdataDriverPools = new map<string, KDataDriverConnectPoolPtr>();
|
2021-01-20 00:32:01 +08:00
|
|
|
|
|
2020-04-05 02:02:05 +08:00
|
|
|
|
DataDriverFactory::regKDataDriver(make_shared<TdxKDataDriver>());
|
|
|
|
|
DataDriverFactory::regKDataDriver(make_shared<H5KDataDriver>());
|
|
|
|
|
DataDriverFactory::regKDataDriver(make_shared<MySQLKDataDriver>());
|
2021-01-20 00:32:01 +08:00
|
|
|
|
DataDriverFactory::regKDataDriver(make_shared<KDataTempCsvDriver>());
|
2020-04-05 02:02:05 +08:00
|
|
|
|
}
|
2015-01-07 01:26:14 +08:00
|
|
|
|
|
2020-04-04 01:39:19 +08:00
|
|
|
|
void DataDriverFactory::release() {
|
2020-04-05 02:02:05 +08:00
|
|
|
|
m_baseInfoDrivers->clear();
|
|
|
|
|
delete m_baseInfoDrivers;
|
|
|
|
|
|
|
|
|
|
m_blockDrivers->clear();
|
|
|
|
|
delete m_blockDrivers;
|
|
|
|
|
|
2021-01-22 23:50:46 +08:00
|
|
|
|
m_kdataPrototypeDrivers->clear();
|
|
|
|
|
delete m_kdataPrototypeDrivers;
|
2021-01-20 00:32:01 +08:00
|
|
|
|
|
|
|
|
|
m_kdataDriverPools->clear();
|
|
|
|
|
delete m_kdataDriverPools;
|
2020-04-04 01:39:19 +08:00
|
|
|
|
}
|
|
|
|
|
|
2020-04-05 02:02:05 +08:00
|
|
|
|
void DataDriverFactory::regBaseInfoDriver(const BaseInfoDriverPtr& driver) {
|
|
|
|
|
HKU_CHECK(driver, "driver is nullptr!");
|
2017-10-09 02:25:02 +08:00
|
|
|
|
string new_type(driver->name());
|
2019-08-03 01:44:57 +08:00
|
|
|
|
to_upper(new_type);
|
2020-04-05 02:02:05 +08:00
|
|
|
|
(*m_baseInfoDrivers)[new_type] = driver;
|
2016-04-03 00:08:31 +08:00
|
|
|
|
}
|
2015-01-07 01:26:14 +08:00
|
|
|
|
|
2017-10-09 02:25:02 +08:00
|
|
|
|
void DataDriverFactory::removeBaseInfoDriver(const string& name) {
|
|
|
|
|
string new_type(name);
|
2019-08-03 01:44:57 +08:00
|
|
|
|
to_upper(new_type);
|
2020-04-05 02:02:05 +08:00
|
|
|
|
m_baseInfoDrivers->erase(new_type);
|
2017-10-09 02:25:02 +08:00
|
|
|
|
}
|
|
|
|
|
|
2019-11-10 23:31:41 +08:00
|
|
|
|
BaseInfoDriverPtr DataDriverFactory ::getBaseInfoDriver(const Parameter& params) {
|
2017-10-09 02:25:02 +08:00
|
|
|
|
map<string, BaseInfoDriverPtr>::const_iterator iter;
|
|
|
|
|
string type = params.get<string>("type");
|
2019-08-03 01:44:57 +08:00
|
|
|
|
to_upper(type);
|
2020-04-05 02:02:05 +08:00
|
|
|
|
iter = m_baseInfoDrivers->find(type);
|
2017-10-09 02:25:02 +08:00
|
|
|
|
BaseInfoDriverPtr result;
|
2020-04-05 02:02:05 +08:00
|
|
|
|
if (iter != m_baseInfoDrivers->end()) {
|
2017-10-09 02:25:02 +08:00
|
|
|
|
result = iter->second;
|
2017-10-20 02:11:57 +08:00
|
|
|
|
result->init(params);
|
2017-10-09 02:25:02 +08:00
|
|
|
|
}
|
|
|
|
|
return result;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void DataDriverFactory::regBlockDriver(const BlockInfoDriverPtr& driver) {
|
2020-04-05 02:02:05 +08:00
|
|
|
|
HKU_CHECK(driver, "driver is nullptr!");
|
2017-10-09 02:25:02 +08:00
|
|
|
|
string name(driver->name());
|
2019-08-03 01:44:57 +08:00
|
|
|
|
to_upper(name);
|
2020-04-05 02:02:05 +08:00
|
|
|
|
(*m_blockDrivers)[name] = driver;
|
2017-10-09 02:25:02 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void DataDriverFactory::removeBlockDriver(const string& name) {
|
|
|
|
|
string new_name(name);
|
2019-08-03 01:44:57 +08:00
|
|
|
|
to_upper(new_name);
|
2020-04-05 02:02:05 +08:00
|
|
|
|
m_blockDrivers->erase(new_name);
|
2017-10-09 02:25:02 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
BlockInfoDriverPtr DataDriverFactory::getBlockDriver(const Parameter& params) {
|
|
|
|
|
BlockInfoDriverPtr result;
|
|
|
|
|
map<string, BlockInfoDriverPtr>::const_iterator iter;
|
|
|
|
|
string name = params.get<string>("type");
|
2019-08-03 01:44:57 +08:00
|
|
|
|
to_upper(name);
|
2020-04-05 02:02:05 +08:00
|
|
|
|
iter = m_blockDrivers->find(name);
|
|
|
|
|
if (iter != m_blockDrivers->end()) {
|
2017-10-09 02:25:02 +08:00
|
|
|
|
result = iter->second;
|
2017-10-20 02:11:57 +08:00
|
|
|
|
result->init(params);
|
2017-10-09 02:25:02 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return result;
|
|
|
|
|
}
|
|
|
|
|
|
2017-10-12 01:58:08 +08:00
|
|
|
|
void DataDriverFactory::regKDataDriver(const KDataDriverPtr& driver) {
|
|
|
|
|
string new_type(driver->name());
|
2019-08-03 01:44:57 +08:00
|
|
|
|
to_upper(new_type);
|
2021-01-20 00:32:01 +08:00
|
|
|
|
HKU_CHECK(m_kdataDriverPools->find(new_type) == m_kdataDriverPools->end(),
|
|
|
|
|
"Repeat regKDataDriver!");
|
2021-01-22 23:50:46 +08:00
|
|
|
|
(*m_kdataPrototypeDrivers)[new_type] = driver;
|
|
|
|
|
// 不在此创建连接池
|
2021-01-22 00:39:37 +08:00
|
|
|
|
//(*m_kdataDriverPools)[new_type] = make_shared<KDataDriverPool>();
|
2017-10-12 01:58:08 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void DataDriverFactory::removeKDataDriver(const string& name) {
|
|
|
|
|
string new_name(name);
|
2019-08-03 01:44:57 +08:00
|
|
|
|
to_upper(new_name);
|
2021-01-22 23:50:46 +08:00
|
|
|
|
m_kdataPrototypeDrivers->erase(new_name);
|
2021-01-20 00:32:01 +08:00
|
|
|
|
auto iter = m_kdataDriverPools->find(new_name);
|
|
|
|
|
if (iter != m_kdataDriverPools->end()) {
|
|
|
|
|
m_kdataDriverPools->erase(iter);
|
|
|
|
|
}
|
2017-10-12 01:58:08 +08:00
|
|
|
|
}
|
|
|
|
|
|
2021-01-24 20:47:38 +08:00
|
|
|
|
KDataDriverConnectPoolPtr DataDriverFactory::getKDataDriverPool(const Parameter& params) {
|
|
|
|
|
KDataDriverConnectPoolPtr result;
|
2021-01-20 00:32:01 +08:00
|
|
|
|
string name = params.get<string>("type");
|
|
|
|
|
to_upper(name);
|
|
|
|
|
auto iter = m_kdataDriverPools->find(name);
|
|
|
|
|
if (iter != m_kdataDriverPools->end()) {
|
|
|
|
|
result = iter->second;
|
2021-01-22 00:39:37 +08:00
|
|
|
|
} else {
|
2021-01-22 23:50:46 +08:00
|
|
|
|
auto prototype_iter = m_kdataPrototypeDrivers->find(name);
|
|
|
|
|
HKU_CHECK(prototype_iter != m_kdataPrototypeDrivers->end(), "Unregistered driver:{}",
|
|
|
|
|
name);
|
2021-01-24 20:47:38 +08:00
|
|
|
|
HKU_CHECK(prototype_iter->second->init(params), "Failed init driver: {}", name);
|
|
|
|
|
(*m_kdataDriverPools)[name] = make_shared<KDataDriverConnectPool>(prototype_iter->second);
|
2021-01-22 00:39:37 +08:00
|
|
|
|
result = (*m_kdataDriverPools)[name];
|
2021-01-20 00:32:01 +08:00
|
|
|
|
}
|
|
|
|
|
return result;
|
|
|
|
|
}
|
|
|
|
|
|
2015-01-07 01:26:14 +08:00
|
|
|
|
} /* namespace hku */
|