- better usage of mapnik::singleton instance in occi datasource

- occi small cosmetics
This commit is contained in:
kunitoki 2013-04-08 15:18:48 +02:00
parent 40c01fd0ed
commit 206a563e0c
4 changed files with 32 additions and 44 deletions

View file

@ -120,7 +120,7 @@ occi_datasource::occi_datasource(parameters const& params)
{ {
try try
{ {
pool_ = occi_environment::create_pool( pool_ = occi_environment::instance().create_pool(
*params.get<std::string>("user"), *params.get<std::string>("user"),
*params.get<std::string>("password"), *params.get<std::string>("password"),
*params.get<std::string>("host"), *params.get<std::string>("host"),
@ -137,7 +137,7 @@ occi_datasource::occi_datasource(parameters const& params)
{ {
try try
{ {
conn_ = occi_environment::create_connection( conn_ = occi_environment::instance().create_connection(
*params.get<std::string>("user"), *params.get<std::string>("user"),
*params.get<std::string>("password"), *params.get<std::string>("password"),
*params.get<std::string>("host")); *params.get<std::string>("host"));
@ -324,14 +324,14 @@ occi_datasource::~occi_datasource()
{ {
if (pool_ != 0) if (pool_ != 0)
{ {
occi_environment::destroy_pool(pool_); occi_environment::instance().destroy_pool(pool_);
} }
} }
else else
{ {
if (conn_ != 0) if (conn_ != 0)
{ {
occi_environment::destroy_connection(conn_); occi_environment::instance().destroy_connection(conn_);
} }
} }
} }

View file

@ -132,8 +132,6 @@ feature_ptr occi_featureset::next()
} }
} }
++feature_id_;
std::vector<MetaData> listOfColumns = rs_->getColumnListMetaData(); std::vector<MetaData> listOfColumns = rs_->getColumnListMetaData();
for (unsigned int i = 1; i < listOfColumns.size(); ++i) for (unsigned int i = 1; i < listOfColumns.size(); ++i)
@ -233,6 +231,8 @@ feature_ptr occi_featureset::next()
} }
} }
++feature_id_;
return feature; return feature;
} }

View file

@ -22,8 +22,6 @@
#include "occi_types.hpp" #include "occi_types.hpp"
oracle::occi::Environment* occi_environment::env_ = 0;
std::string occi_enums::resolve_gtype(int gtype) std::string occi_enums::resolve_gtype(int gtype)
{ {
switch (gtype) switch (gtype)

View file

@ -27,6 +27,11 @@
#include <mapnik/debug.hpp> #include <mapnik/debug.hpp>
#include <mapnik/utils.hpp> #include <mapnik/utils.hpp>
// boost
#ifdef MAPNIK_THREADSAFE
#include <boost/thread/mutex.hpp>
#endif
// occi // occi
#include <occi.h> #include <occi.h>
@ -84,42 +89,27 @@ class occi_environment : public mapnik::singleton<occi_environment, mapnik::Crea
public: public:
static oracle::occi::Environment* get_environment() oracle::occi::Environment* get_environment()
{ {
if (env_ == 0)
{
MAPNIK_LOG_DEBUG(occi) << "occi_environment: constructor";
const int mode = oracle::occi::Environment::OBJECT
| oracle::occi::Environment::THREADED_MUTEXED;
env_ = oracle::occi::Environment::createEnvironment((oracle::occi::Environment::Mode) mode);
RegisterClasses(env_);
}
return env_; return env_;
} }
static oracle::occi::Connection* create_connection( oracle::occi::Connection* create_connection(
const std::string& user, const std::string& user,
const std::string& password, const std::string& password,
const std::string& host) const std::string& host)
{ {
oracle::occi::Environment* env = get_environment();
MAPNIK_LOG_DEBUG(occi) << "occi_environment: create_connection"; MAPNIK_LOG_DEBUG(occi) << "occi_environment: create_connection";
return env->createConnection(user, password, host); return env_->createConnection(user, password, host);
} }
static void destroy_connection(oracle::occi::Connection* conn) void destroy_connection(oracle::occi::Connection* conn)
{ {
oracle::occi::Environment* env = get_environment(); env_->terminateConnection(conn);
env->terminateConnection(conn);
} }
static oracle::occi::StatelessConnectionPool* create_pool( oracle::occi::StatelessConnectionPool* create_pool(
const std::string& user, const std::string& user,
const std::string& password, const std::string& password,
const std::string& host, const std::string& host,
@ -127,11 +117,9 @@ public:
int initial_size, int initial_size,
int incr_size) int incr_size)
{ {
oracle::occi::Environment* env = get_environment();
MAPNIK_LOG_DEBUG(occi) << "occi_environment: create_pool"; MAPNIK_LOG_DEBUG(occi) << "occi_environment: create_pool";
return env->createStatelessConnectionPool( return env_->createStatelessConnectionPool(
user, user,
password, password,
host, host,
@ -141,11 +129,9 @@ public:
oracle::occi::StatelessConnectionPool::HOMOGENEOUS); oracle::occi::StatelessConnectionPool::HOMOGENEOUS);
} }
static void destroy_pool(oracle::occi::StatelessConnectionPool* pool) void destroy_pool(oracle::occi::StatelessConnectionPool* pool)
{ {
oracle::occi::Environment* env = get_environment(); env_->terminateStatelessConnectionPool(
env->terminateStatelessConnectionPool(
pool, pool,
oracle::occi::StatelessConnectionPool::SPD_FORCE); oracle::occi::StatelessConnectionPool::SPD_FORCE);
} }
@ -153,21 +139,25 @@ public:
private: private:
occi_environment() occi_environment()
: env_(0)
{ {
MAPNIK_LOG_DEBUG(occi) << "occi_environment: constructor";
env_ = oracle::occi::Environment::createEnvironment(
(oracle::occi::Environment::Mode)(oracle::occi::Environment::OBJECT
| oracle::occi::Environment::THREADED_MUTEXED));
RegisterClasses(env_);
} }
~occi_environment() ~occi_environment()
{
if (env_)
{ {
MAPNIK_LOG_DEBUG(occi) << "occi_environment: destructor"; MAPNIK_LOG_DEBUG(occi) << "occi_environment: destructor";
oracle::occi::Environment::terminateEnvironment(env_); oracle::occi::Environment::terminateEnvironment(env_);
env_ = 0; env_ = 0;
} }
}
static oracle::occi::Environment* env_; oracle::occi::Environment* env_;
}; };
@ -252,7 +242,7 @@ private:
{ {
if (owns_connection_) if (owns_connection_)
{ {
occi_environment::destroy_connection(conn_); occi_environment::instance().destroy_connection(conn_);
} }
} }