- move occi object creation in the environment
This commit is contained in:
parent
1bcb9784ab
commit
40c01fd0ed
2 changed files with 64 additions and 29 deletions
|
@ -120,16 +120,13 @@ occi_datasource::occi_datasource(parameters const& params)
|
|||
{
|
||||
try
|
||||
{
|
||||
Environment* env = occi_environment::get_environment();
|
||||
|
||||
pool_ = env->createStatelessConnectionPool(
|
||||
pool_ = occi_environment::create_pool(
|
||||
*params.get<std::string>("user"),
|
||||
*params.get<std::string>("password"),
|
||||
*params.get<std::string>("host"),
|
||||
*params.get<int>("max_size", 5),
|
||||
*params.get<int>("initial_size", 1),
|
||||
1,
|
||||
StatelessConnectionPool::HOMOGENEOUS);
|
||||
1);
|
||||
}
|
||||
catch (SQLException& ex)
|
||||
{
|
||||
|
@ -140,9 +137,7 @@ occi_datasource::occi_datasource(parameters const& params)
|
|||
{
|
||||
try
|
||||
{
|
||||
Environment* env = occi_environment::get_environment();
|
||||
|
||||
conn_ = env->createConnection(
|
||||
conn_ = occi_environment::create_connection(
|
||||
*params.get<std::string>("user"),
|
||||
*params.get<std::string>("password"),
|
||||
*params.get<std::string>("host"));
|
||||
|
@ -325,22 +320,18 @@ occi_datasource::occi_datasource(parameters const& params)
|
|||
|
||||
occi_datasource::~occi_datasource()
|
||||
{
|
||||
if (use_connection_pool_)
|
||||
{
|
||||
Environment* env = occi_environment::get_environment();
|
||||
|
||||
if (use_connection_pool_)
|
||||
if (pool_ != 0)
|
||||
{
|
||||
if (pool_ != 0)
|
||||
{
|
||||
env->terminateStatelessConnectionPool(pool_, StatelessConnectionPool::SPD_FORCE);
|
||||
}
|
||||
occi_environment::destroy_pool(pool_);
|
||||
}
|
||||
else
|
||||
}
|
||||
else
|
||||
{
|
||||
if (conn_ != 0)
|
||||
{
|
||||
if (conn_ != 0)
|
||||
{
|
||||
env->terminateConnection(conn_);
|
||||
}
|
||||
occi_environment::destroy_connection(conn_);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -100,6 +100,56 @@ public:
|
|||
return env_;
|
||||
}
|
||||
|
||||
static oracle::occi::Connection* create_connection(
|
||||
const std::string& user,
|
||||
const std::string& password,
|
||||
const std::string& host)
|
||||
{
|
||||
oracle::occi::Environment* env = get_environment();
|
||||
|
||||
MAPNIK_LOG_DEBUG(occi) << "occi_environment: create_connection";
|
||||
|
||||
return env->createConnection(user, password, host);
|
||||
}
|
||||
|
||||
static void destroy_connection(oracle::occi::Connection* conn)
|
||||
{
|
||||
oracle::occi::Environment* env = get_environment();
|
||||
|
||||
env->terminateConnection(conn);
|
||||
}
|
||||
|
||||
static oracle::occi::StatelessConnectionPool* create_pool(
|
||||
const std::string& user,
|
||||
const std::string& password,
|
||||
const std::string& host,
|
||||
int max_size,
|
||||
int initial_size,
|
||||
int incr_size)
|
||||
{
|
||||
oracle::occi::Environment* env = get_environment();
|
||||
|
||||
MAPNIK_LOG_DEBUG(occi) << "occi_environment: create_pool";
|
||||
|
||||
return env->createStatelessConnectionPool(
|
||||
user,
|
||||
password,
|
||||
host,
|
||||
max_size,
|
||||
initial_size,
|
||||
incr_size,
|
||||
oracle::occi::StatelessConnectionPool::HOMOGENEOUS);
|
||||
}
|
||||
|
||||
static void destroy_pool(oracle::occi::StatelessConnectionPool* pool)
|
||||
{
|
||||
oracle::occi::Environment* env = get_environment();
|
||||
|
||||
env->terminateStatelessConnectionPool(
|
||||
pool,
|
||||
oracle::occi::StatelessConnectionPool::SPD_FORCE);
|
||||
}
|
||||
|
||||
private:
|
||||
|
||||
occi_environment()
|
||||
|
@ -120,12 +170,12 @@ private:
|
|||
static oracle::occi::Environment* env_;
|
||||
};
|
||||
|
||||
|
||||
class occi_connection_ptr
|
||||
{
|
||||
public:
|
||||
explicit occi_connection_ptr()
|
||||
: env_(occi_environment::get_environment()),
|
||||
pool_(0),
|
||||
: pool_(0),
|
||||
conn_(0),
|
||||
stmt_(0),
|
||||
rs_(0),
|
||||
|
@ -175,11 +225,6 @@ public:
|
|||
return rs_;
|
||||
}
|
||||
|
||||
oracle::occi::Connection* operator*()
|
||||
{
|
||||
return conn_;
|
||||
}
|
||||
|
||||
private:
|
||||
void close_query(const bool release_connection)
|
||||
{
|
||||
|
@ -207,7 +252,7 @@ private:
|
|||
{
|
||||
if (owns_connection_)
|
||||
{
|
||||
env_->terminateConnection(conn_);
|
||||
occi_environment::destroy_connection(conn_);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -216,7 +261,6 @@ private:
|
|||
}
|
||||
}
|
||||
|
||||
oracle::occi::Environment* env_;
|
||||
oracle::occi::StatelessConnectionPool* pool_;
|
||||
oracle::occi::Connection* conn_;
|
||||
oracle::occi::Statement* stmt_;
|
||||
|
|
Loading…
Add table
Reference in a new issue