libmysqlxx: enabled empty password. refactoring [#METR-8598]

This commit is contained in:
Pavel Kartavyy 2013-10-29 09:27:10 +00:00
parent ff61e2cbc8
commit 2fab08ae10
2 changed files with 27 additions and 29 deletions

View File

@ -121,6 +121,13 @@ public:
incrementRefCount();
}
std::string getDescription() const
{
if (pool)
return pool->getDescription();
else
return "pool is null";
}
friend class Pool;
private:
@ -182,6 +189,7 @@ public:
}
};
/**
* @param config_name Имя параметра в конфигурационном файле
* @param default_connections_ Количество подключений по-умолчанию
@ -190,8 +198,7 @@ public:
Pool(const std::string & config_name,
unsigned default_connections_ = MYSQLXX_POOL_DEFAULT_START_CONNECTIONS,
unsigned max_connections_ = MYSQLXX_POOL_DEFAULT_MAX_CONNECTIONS,
const std::string & user_default = "", const std::string & password_default = "",
const std::string & db_default = "", int port_default = 0)
const char * parent_config_name_ = NULL)
: default_connections(default_connections_), max_connections(max_connections_),
initialized(false), was_successful(false)
{
@ -199,19 +206,24 @@ public:
server = cfg.getString(config_name + ".host");
db = cfg.getString(config_name + ".db", db_default);
if (!user_default.empty())
user = cfg.getString(config_name + ".user", user_default);
if (parent_config_name_)
{
const std::string parent_config_name(parent_config_name_);
db = cfg.getString(config_name + ".db", cfg.getString(parent_config_name + ".db", ""));
user = cfg.has(config_name + ".user") ?
cfg.getString(config_name + ".user") : cfg.getString(parent_config_name + ".user");
password = cfg.has(config_name + ".password") ?
cfg.getString(config_name + ".password") : cfg.getString(parent_config_name + ".password");
port = cfg.has(config_name + ".port") ? cfg.getInt(config_name + ".port") :
cfg.getInt(parent_config_name + ".port");
}
else
user = cfg.getString(config_name + ".user");
if (!password_default.empty())
password = cfg.getString(config_name + ".password", password_default);
else
password = cfg.getString(config_name + ".password");
if (port_default)
port = cfg.getInt(config_name + ".port", port_default);
else
port = cfg.getInt(config_name + ".port");
{
db = cfg.getString(config_name + ".db", "");
user = cfg.getString(config_name + ".user");
password = cfg.getString(config_name + ".password");
port = cfg.getInt(config_name + ".port");
}
connect_timeout = cfg.getInt(config_name + ".connect_timeout",
cfg.getInt("mysql_connect_timeout",

View File

@ -11,20 +11,6 @@ PoolWithFailover::PoolWithFailover(const std::string & config_name, unsigned def
if (cfg.has(config_name + ".replica"))
{
int port_g = 0;
std::string user_g;
std::string password_g;
std::string db_g;
if (cfg.has(config_name + ".user"))
user_g = cfg.getString(config_name + ".user");
if (cfg.has(config_name + ".password"))
password_g = cfg.getString(config_name + ".password");
if (cfg.has(config_name + ".db"))
db_g= cfg.getString(config_name + ".db");
if (cfg.has(config_name + ".port"))
port_g = cfg.getInt(config_name + ".port");
Poco::Util::AbstractConfiguration::Keys replica_keys;
cfg.keys(config_name, replica_keys);
for (Poco::Util::AbstractConfiguration::Keys::const_iterator it = replica_keys.begin(); it != replica_keys.end(); ++it)
@ -34,7 +20,7 @@ PoolWithFailover::PoolWithFailover(const std::string & config_name, unsigned def
if (it->size() < std::string("replica").size() || it->substr(0, std::string("replica").size()) != "replica")
throw Poco::Exception("Unknown element in config: " + *it + ", expected replica");
std::string replica_name = config_name + "." + *it;
Replica replica(new Pool(replica_name, default_connections, max_connections, user_g, password_g, db_g, port_g),
Replica replica(new Pool(replica_name, default_connections, max_connections, config_name.c_str()),
cfg.getInt(replica_name + ".priority", 0));
replicas_by_priority[replica.priority].push_back(replica);
}