- fix indentation and trailing spaces (generally coding style) in occi plugin partially related to #911

This commit is contained in:
kunitoki 2011-10-22 03:33:03 +02:00
parent 35739ae917
commit 26fbcb51ef
6 changed files with 414 additions and 398 deletions

View file

@ -2,7 +2,7 @@
* *
* This file is part of Mapnik (c++ mapping toolkit) * This file is part of Mapnik (c++ mapping toolkit)
* *
* Copyright (C) 2007 Artem Pavlenko * Copyright (C) 2011 Artem Pavlenko
* *
* This library is free software; you can redistribute it and/or * This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public * modify it under the terms of the GNU Lesser General Public
@ -63,21 +63,20 @@ using oracle::occi::SQLException;
using oracle::occi::Type; using oracle::occi::Type;
using oracle::occi::StatelessConnectionPool; using oracle::occi::StatelessConnectionPool;
const std::string occi_datasource::METADATA_TABLE="USER_SDO_GEOM_METADATA"; const std::string occi_datasource::METADATA_TABLE = "USER_SDO_GEOM_METADATA";
DATASOURCE_PLUGIN(occi_datasource) DATASOURCE_PLUGIN(occi_datasource)
occi_datasource::occi_datasource(parameters const& params, bool bind) occi_datasource::occi_datasource(parameters const& params, bool bind)
: datasource (params), : datasource (params),
type_(datasource::Vector), type_(datasource::Vector),
fields_(*params_.get<std::string>("fields","*")), fields_(*params_.get<std::string>("fields", "*")),
geometry_field_(*params_.get<std::string>("geometry_field","")), geometry_field_(*params_.get<std::string>("geometry_field", "")),
srid_initialized_(false), srid_initialized_(false),
extent_initialized_(false), extent_initialized_(false),
desc_(*params_.get<std::string>("type"), *params_.get<std::string>("encoding","utf-8")), desc_(*params_.get<std::string>("type"), *params_.get<std::string>("encoding", "utf-8")),
row_limit_(*params_.get<int>("row_limit",0)), row_limit_(*params_.get<int>("row_limit", 0)),
row_prefetch_(*params_.get<int>("row_prefetch",100)), row_prefetch_(*params_.get<int>("row_prefetch", 100)),
pool_(0), pool_(0),
conn_(0) conn_(0)
{ {
@ -86,7 +85,7 @@ occi_datasource::occi_datasource(parameters const& params, bool bind)
if (! params_.get<std::string>("host")) throw datasource_exception("OCCI Plugin: no <host> string specified"); if (! params_.get<std::string>("host")) throw datasource_exception("OCCI Plugin: no <host> string specified");
boost::optional<std::string> table = params_.get<std::string>("table"); boost::optional<std::string> table = params_.get<std::string>("table");
if (!table) if (! table)
{ {
throw datasource_exception("OCCI Plugin: no <table> parameter specified"); throw datasource_exception("OCCI Plugin: no <table> parameter specified");
} }
@ -124,14 +123,18 @@ occi_datasource::~occi_datasource()
if (use_connection_pool_) if (use_connection_pool_)
{ {
if (pool_ != 0) if (pool_ != 0)
env->terminateStatelessConnectionPool (pool_, StatelessConnectionPool::SPD_FORCE); {
env->terminateStatelessConnectionPool(pool_, StatelessConnectionPool::SPD_FORCE);
}
} }
else else
{ {
if (conn_ != 0) if (conn_ != 0)
{
env->terminateConnection(conn_); env->terminateConnection(conn_);
} }
} }
}
} }
void occi_datasource::bind() const void occi_datasource::bind() const
@ -149,12 +152,12 @@ void occi_datasource::bind() const
*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"),
*params_.get<int>("max_size",10), *params_.get<int>("max_size", 10),
*params_.get<int>("initial_size",1), *params_.get<int>("initial_size", 1),
1, 1,
StatelessConnectionPool::HOMOGENEOUS); StatelessConnectionPool::HOMOGENEOUS);
} }
catch (SQLException &ex) catch (SQLException& ex)
{ {
throw datasource_exception("OCCI Plugin: " + ex.getMessage()); throw datasource_exception("OCCI Plugin: " + ex.getMessage());
} }
@ -170,7 +173,7 @@ void occi_datasource::bind() const
*params_.get<std::string>("password"), *params_.get<std::string>("password"),
*params_.get<std::string>("host")); *params_.get<std::string>("host"));
} }
catch (SQLException &ex) catch (SQLException& ex)
{ {
throw datasource_exception("OCCI Plugin: " + ex.getMessage()); throw datasource_exception("OCCI Plugin: " + ex.getMessage());
} }
@ -186,7 +189,9 @@ void occi_datasource::bind() const
s << " LOWER(table_name) = LOWER('" << table_name << "')"; s << " LOWER(table_name) = LOWER('" << table_name << "')";
if (geometry_field_ != "") if (geometry_field_ != "")
{
s << " AND LOWER(column_name) = LOWER('" << geometry_field_ << "')"; s << " AND LOWER(column_name) = LOWER('" << geometry_field_ << "')";
}
#ifdef MAPNIK_DEBUG #ifdef MAPNIK_DEBUG
std::clog << "OCCI Plugin: " << s.str() << std::endl; std::clog << "OCCI Plugin: " << s.str() << std::endl;
@ -198,7 +203,7 @@ void occi_datasource::bind() const
if (use_connection_pool_) conn.set_pool(pool_); if (use_connection_pool_) conn.set_pool(pool_);
else conn.set_connection(conn_, false); else conn.set_connection(conn_, false);
ResultSet* rs = conn.execute_query (s.str()); ResultSet* rs = conn.execute_query(s.str());
if (rs && rs->next ()) if (rs && rs->next ())
{ {
if (! srid_initialized_) if (! srid_initialized_)
@ -213,7 +218,7 @@ void occi_datasource::bind() const
} }
} }
} }
catch (SQLException &ex) catch (SQLException& ex)
{ {
throw datasource_exception("OCCI Plugin: " + ex.getMessage()); throw datasource_exception("OCCI Plugin: " + ex.getMessage());
} }
@ -234,7 +239,7 @@ void occi_datasource::bind() const
if (use_connection_pool_) conn.set_pool(pool_); if (use_connection_pool_) conn.set_pool(pool_);
else conn.set_connection(conn_, false); else conn.set_connection(conn_, false);
ResultSet* rs = conn.execute_query (s.str()); ResultSet* rs = conn.execute_query(s.str());
if (rs) if (rs)
{ {
std::vector<MetaData> listOfColumns = rs->getColumnListMetaData(); std::vector<MetaData> listOfColumns = rs->getColumnListMetaData();
@ -317,20 +322,22 @@ void occi_datasource::bind() const
case oracle::occi::OCCI_SQLT_BLOB: case oracle::occi::OCCI_SQLT_BLOB:
case oracle::occi::OCCI_SQLT_RSET: case oracle::occi::OCCI_SQLT_RSET:
#ifdef MAPNIK_DEBUG #ifdef MAPNIK_DEBUG
std::clog << "OCCI Plugin: unsupported datatype " << occi_enums::resolve_datatype(type_oid) std::clog << "OCCI Plugin: unsupported datatype "
<< occi_enums::resolve_datatype(type_oid)
<< " (type_oid=" << type_oid << ")" << std::endl; << " (type_oid=" << type_oid << ")" << std::endl;
#endif #endif
break; break;
default: default:
#ifdef MAPNIK_DEBUG #ifdef MAPNIK_DEBUG
std::clog << "OCCI Plugin: unknown datatype (type_oid=" << type_oid << ")" << std::endl; std::clog << "OCCI Plugin: unknown datatype "
<< "(type_oid=" << type_oid << ")" << std::endl;
#endif #endif
break; break;
} }
} }
} }
} }
catch (SQLException &ex) catch (SQLException& ex)
{ {
throw datasource_exception(ex.getMessage()); throw datasource_exception(ex.getMessage());
} }
@ -352,11 +359,12 @@ int occi_datasource::type() const
box2d<double> occi_datasource::envelope() const box2d<double> occi_datasource::envelope() const
{ {
if (extent_initialized_) return extent_; if (extent_initialized_) return extent_;
if (!is_bound_) bind(); if (! is_bound_) bind();
double lox = 0.0, loy = 0.0, hix = 0.0, hiy = 0.0; double lox = 0.0, loy = 0.0, hix = 0.0, hiy = 0.0;
boost::optional<mapnik::boolean> estimate_extent = params_.get<mapnik::boolean>("estimate_extent",false); boost::optional<mapnik::boolean> estimate_extent =
params_.get<mapnik::boolean>("estimate_extent",false);
if (estimate_extent && *estimate_extent) if (estimate_extent && *estimate_extent)
{ {
@ -375,8 +383,8 @@ box2d<double> occi_datasource::envelope() const
if (use_connection_pool_) conn.set_pool(pool_); if (use_connection_pool_) conn.set_pool(pool_);
else conn.set_connection(conn_, false); else conn.set_connection(conn_, false);
ResultSet* rs = conn.execute_query (s.str()); ResultSet* rs = conn.execute_query(s.str());
if (rs && rs->next ()) if (rs && rs->next())
{ {
try try
{ {
@ -384,16 +392,16 @@ box2d<double> occi_datasource::envelope() const
loy = lexical_cast<double>(rs->getDouble(2)); loy = lexical_cast<double>(rs->getDouble(2));
hix = lexical_cast<double>(rs->getDouble(3)); hix = lexical_cast<double>(rs->getDouble(3));
hiy = lexical_cast<double>(rs->getDouble(4)); hiy = lexical_cast<double>(rs->getDouble(4));
extent_.init (lox,loy,hix,hiy); extent_.init(lox, loy, hix, hiy);
extent_initialized_ = true; extent_initialized_ = true;
} }
catch (bad_lexical_cast &ex) catch (bad_lexical_cast& ex)
{ {
std::clog << "OCCI Plugin: " << ex.what() << std::endl; std::clog << "OCCI Plugin: " << ex.what() << std::endl;
} }
} }
} }
catch (SQLException &ex) catch (SQLException& ex)
{ {
throw datasource_exception("OCCI Plugin: " + ex.getMessage()); throw datasource_exception("OCCI Plugin: " + ex.getMessage());
} }
@ -421,63 +429,65 @@ box2d<double> occi_datasource::envelope() const
if (use_connection_pool_) conn.set_pool(pool_); if (use_connection_pool_) conn.set_pool(pool_);
else conn.set_connection(conn_, false); else conn.set_connection(conn_, false);
ResultSet* rs = conn.execute_query (s.str()); ResultSet* rs = conn.execute_query(s.str());
if (rs) if (rs)
{ {
if (rs->next ()) if (rs->next())
{ {
try try
{ {
lox = lexical_cast<double>(rs->getDouble(1)); lox = lexical_cast<double>(rs->getDouble(1));
hix = lexical_cast<double>(rs->getDouble(2)); hix = lexical_cast<double>(rs->getDouble(2));
} }
catch (bad_lexical_cast &ex) catch (bad_lexical_cast& ex)
{ {
std::clog << "OCCI Plugin: " << ex.what() << std::endl; std::clog << "OCCI Plugin: " << ex.what() << std::endl;
} }
} }
if (rs->next ()) if (rs->next())
{ {
try try
{ {
loy = lexical_cast<double>(rs->getDouble(1)); loy = lexical_cast<double>(rs->getDouble(1));
hiy = lexical_cast<double>(rs->getDouble(2)); hiy = lexical_cast<double>(rs->getDouble(2));
} }
catch (bad_lexical_cast &ex) catch (bad_lexical_cast& ex)
{ {
std::clog << "OCCI Plugin: " << ex.what() << std::endl; std::clog << "OCCI Plugin: " << ex.what() << std::endl;
} }
} }
extent_.init (lox,loy,hix,hiy); extent_.init(lox, loy, hix, hiy);
extent_initialized_ = true; extent_initialized_ = true;
} }
} }
catch (SQLException &ex) catch (SQLException& ex)
{ {
throw datasource_exception("OCCI Plugin: " + ex.getMessage()); throw datasource_exception("OCCI Plugin: " + ex.getMessage());
} }
} }
if (! extent_initialized_) if (! extent_initialized_)
{
throw datasource_exception("OCCI Plugin: unable to determine the extent of a <occi> table"); throw datasource_exception("OCCI Plugin: unable to determine the extent of a <occi> table");
}
return extent_; return extent_;
} }
layer_descriptor occi_datasource::get_descriptor() const layer_descriptor occi_datasource::get_descriptor() const
{ {
if (!is_bound_) bind(); if (! is_bound_) bind();
return desc_; return desc_;
} }
featureset_ptr occi_datasource::features(query const& q) const featureset_ptr occi_datasource::features(query const& q) const
{ {
if (!is_bound_) bind(); if (! is_bound_) bind();
box2d<double> const& box=q.get_bbox(); box2d<double> const& box = q.get_bbox();
std::ostringstream s; std::ostringstream s;
s << "SELECT " << geometry_field_; s << "SELECT " << geometry_field_;
@ -492,7 +502,7 @@ featureset_ptr occi_datasource::features(query const& q) const
s << " FROM "; s << " FROM ";
std::string query (table_); std::string query(table_);
std::string table_name = mapnik::table_from_sql(query); std::string table_name = mapnik::table_from_sql(query);
if (use_spatial_index_) if (use_spatial_index_)
@ -560,13 +570,13 @@ featureset_ptr occi_datasource::features(query const& q) const
featureset_ptr occi_datasource::features_at_point(coord2d const& pt) const featureset_ptr occi_datasource::features_at_point(coord2d const& pt) const
{ {
if (!is_bound_) bind(); if (! is_bound_) bind();
std::ostringstream s; std::ostringstream s;
s << "SELECT " << geometry_field_; s << "SELECT " << geometry_field_;
std::vector<attribute_descriptor>::const_iterator itr = desc_.get_descriptors().begin(); std::vector<attribute_descriptor>::const_iterator itr = desc_.get_descriptors().begin();
std::vector<attribute_descriptor>::const_iterator end = desc_.get_descriptors().end(); std::vector<attribute_descriptor>::const_iterator end = desc_.get_descriptors().end();
unsigned size=0; unsigned size = 0;
while (itr != end) while (itr != end)
{ {
s << ", " << itr->get_name(); s << ", " << itr->get_name();
@ -576,7 +586,7 @@ featureset_ptr occi_datasource::features_at_point(coord2d const& pt) const
s << " FROM "; s << " FROM ";
std::string query (table_); std::string query(table_);
std::string table_name = mapnik::table_from_sql(query); std::string table_name = mapnik::table_from_sql(query);
if (use_spatial_index_) if (use_spatial_index_)
@ -593,7 +603,7 @@ featureset_ptr occi_datasource::features_at_point(coord2d const& pt) const
{ {
boost::algorithm::ireplace_first(query, "WHERE", spatial_sql.str() + " AND "); boost::algorithm::ireplace_first(query, "WHERE", spatial_sql.str() + " AND ");
} }
else if (boost::algorithm::ifind_first(query,table_name)) else if (boost::algorithm::ifind_first(query, table_name))
{ {
boost::algorithm::ireplace_first(query, table_name, table_name + " " + spatial_sql.str()); boost::algorithm::ireplace_first(query, table_name, table_name + " " + spatial_sql.str());
} }
@ -640,4 +650,3 @@ featureset_ptr occi_datasource::features_at_point(coord2d const& pt) const
row_prefetch_, row_prefetch_,
size); size);
} }

View file

@ -2,7 +2,7 @@
* *
* This file is part of Mapnik (c++ mapping toolkit) * This file is part of Mapnik (c++ mapping toolkit)
* *
* Copyright (C) 2007 Artem Pavlenko * Copyright (C) 2011 Artem Pavlenko
* *
* This library is free software; you can redistribute it and/or * This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public * modify it under the terms of the GNU Lesser General Public
@ -38,8 +38,8 @@
class occi_datasource : public mapnik::datasource class occi_datasource : public mapnik::datasource
{ {
public: public:
occi_datasource(mapnik::parameters const& params, bool bind=true); occi_datasource(mapnik::parameters const& params, bool bind = true);
virtual ~occi_datasource (); virtual ~occi_datasource ();
int type() const; int type() const;
static std::string name(); static std::string name();
@ -48,7 +48,8 @@ class occi_datasource : public mapnik::datasource
mapnik::box2d<double> envelope() const; mapnik::box2d<double> envelope() const;
mapnik::layer_descriptor get_descriptor() const; mapnik::layer_descriptor get_descriptor() const;
void bind() const; void bind() const;
private:
private:
int type_; int type_;
mutable std::string table_; mutable std::string table_;
mutable std::string fields_; mutable std::string fields_;
@ -68,5 +69,4 @@ class occi_datasource : public mapnik::datasource
static const std::string METADATA_TABLE; static const std::string METADATA_TABLE;
}; };
#endif // OCCI_DATASOURCE_HPP #endif // OCCI_DATASOURCE_HPP

View file

@ -2,7 +2,7 @@
* *
* This file is part of Mapnik (c++ mapping toolkit) * This file is part of Mapnik (c++ mapping toolkit)
* *
* Copyright (C) 2007 Artem Pavlenko * Copyright (C) 2011 Artem Pavlenko
* *
* This library is free software; you can redistribute it and/or * This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public * modify it under the terms of the GNU Lesser General Public
@ -70,13 +70,17 @@ occi_featureset::occi_featureset(StatelessConnectionPool* pool,
feature_id_(1) feature_id_(1)
{ {
if (use_connection_pool) if (use_connection_pool)
{
conn_.set_pool(pool); conn_.set_pool(pool);
}
else else
{
conn_.set_connection(conn, false); conn_.set_connection(conn, false);
}
try try
{ {
rs_ = conn_.execute_query (sqlstring, prefetch_rows); rs_ = conn_.execute_query(sqlstring, prefetch_rows);
} }
catch (SQLException &ex) catch (SQLException &ex)
{ {
@ -95,10 +99,10 @@ feature_ptr occi_featureset::next()
feature_ptr feature(feature_factory::create(feature_id_)); feature_ptr feature(feature_factory::create(feature_id_));
++feature_id_; ++feature_id_;
boost::scoped_ptr<SDOGeometry> geom (dynamic_cast<SDOGeometry*> (rs_->getObject(1))); boost::scoped_ptr<SDOGeometry> geom(dynamic_cast<SDOGeometry*>(rs_->getObject(1)));
if (geom.get()) if (geom.get())
{ {
convert_geometry (geom.get(), feature, multiple_geometries_); convert_geometry(geom.get(), feature, multiple_geometries_);
} }
std::vector<MetaData> listOfColumns = rs_->getColumnListMetaData(); std::vector<MetaData> listOfColumns = rs_->getColumnListMetaData();
@ -180,13 +184,15 @@ feature_ptr occi_featureset::next()
case oracle::occi::OCCI_SQLT_BLOB: case oracle::occi::OCCI_SQLT_BLOB:
case oracle::occi::OCCI_SQLT_RSET: case oracle::occi::OCCI_SQLT_RSET:
#ifdef MAPNIK_DEBUG #ifdef MAPNIK_DEBUG
std::clog << "OCCI Plugin: unsupported datatype " << occi_enums::resolve_datatype(type_oid) std::clog << "OCCI Plugin: unsupported datatype "
<< occi_enums::resolve_datatype(type_oid)
<< " (type_oid=" << type_oid << ")" << std::endl; << " (type_oid=" << type_oid << ")" << std::endl;
#endif #endif
break; break;
default: // shouldn't get here default: // shouldn't get here
#ifdef MAPNIK_DEBUG #ifdef MAPNIK_DEBUG
std::clog << "OCCI Plugin: unknown datatype (type_oid=" << type_oid << ")" << std::endl; std::clog << "OCCI Plugin: unknown datatype "
<< "(type_oid=" << type_oid << ")" << std::endl;
#endif #endif
break; break;
} }
@ -199,30 +205,30 @@ feature_ptr occi_featureset::next()
} }
void occi_featureset::convert_geometry (SDOGeometry* geom, feature_ptr feature, bool multiple_geometries) void occi_featureset::convert_geometry(SDOGeometry* geom, feature_ptr feature, bool multiple_geometries)
{ {
int gtype = (int) geom->getSdo_gtype(); int gtype = (int)geom->getSdo_gtype();
int dimensions = gtype / 1000; int dimensions = gtype / 1000;
int lrsvalue = (gtype - dimensions * 1000) / 100; int lrsvalue = (gtype - dimensions * 1000) / 100;
int geomtype = (gtype - dimensions * 1000 - lrsvalue * 100); int geomtype = (gtype - dimensions * 1000 - lrsvalue * 100);
#if 0 #if 0
clog << "-----------Geometry Object ------------" << endl; std::clog << "-----------Geometry Object ------------" << std::endl;
clog << "SDO GTYPE = " << gtype << endl; std::clog << "SDO GTYPE = " << gtype << std::endl;
clog << "SDO DIMENSIONS = " << dimensions << endl; std::clog << "SDO DIMENSIONS = " << dimensions << std::endl;
clog << "SDO LRS = " << lrsvalue << endl; std::clog << "SDO LRS = " << lrsvalue << std::endl;
clog << "SDO GEOMETRY TYPE = " << geomtype << endl; std::clog << "SDO GEOMETRY TYPE = " << geomtype << std::endl;
Number sdo_srid = geom->getSdo_srid(); Number sdo_srid = geom->getSdo_srid();
if (sdo_srid.isNull()) if (sdo_srid.isNull())
clog << "SDO SRID = " << "Null" << endl; std::clog << "SDO SRID = " << "Null" << std::endl;
else else
clog << "SDO SRID = " << (int) sdo_srid << endl; std::clog << "SDO SRID = " << (int)sdo_srid << std::endl;
#endif #endif
const std::vector<Number>& elem_info = geom->getSdo_elem_info(); const std::vector<Number>& elem_info = geom->getSdo_elem_info();
const std::vector<Number>& ordinates = geom->getSdo_ordinates(); const std::vector<Number>& ordinates = geom->getSdo_ordinates();
const int ordinates_size = (int) ordinates.size(); const int ordinates_size = (int)ordinates.size();
switch (geomtype) switch (geomtype)
{ {
@ -232,8 +238,8 @@ void occi_featureset::convert_geometry (SDOGeometry* geom, feature_ptr feature,
if (sdopoint && ! sdopoint->isNull()) if (sdopoint && ! sdopoint->isNull())
{ {
geometry_type* point = new geometry_type(mapnik::Point); geometry_type* point = new geometry_type(mapnik::Point);
point->move_to (sdopoint->getX(), sdopoint->getY()); point->move_to(sdopoint->getX(), sdopoint->getY());
feature->add_geometry (point); feature->add_geometry(point);
} }
} }
break; break;
@ -245,7 +251,7 @@ void occi_featureset::convert_geometry (SDOGeometry* geom, feature_ptr feature,
const bool is_point_type = false; const bool is_point_type = false;
const bool multiple_geoms = false; const bool multiple_geoms = false;
convert_ordinates (feature, convert_ordinates(feature,
mapnik::LineString, mapnik::LineString,
elem_info, elem_info,
ordinates, ordinates,
@ -264,7 +270,7 @@ void occi_featureset::convert_geometry (SDOGeometry* geom, feature_ptr feature,
const bool is_point_type = false; const bool is_point_type = false;
const bool multiple_geoms = false; const bool multiple_geoms = false;
convert_ordinates (feature, convert_ordinates(feature,
mapnik::Polygon, mapnik::Polygon,
elem_info, elem_info,
ordinates, ordinates,
@ -286,7 +292,7 @@ void occi_featureset::convert_geometry (SDOGeometry* geom, feature_ptr feature,
// Todo - force using true as multiple_geometries until we have proper multipoint handling // Todo - force using true as multiple_geometries until we have proper multipoint handling
// http://trac.mapnik.org/ticket/458 // http://trac.mapnik.org/ticket/458
convert_ordinates (feature, convert_ordinates(feature,
mapnik::Point, mapnik::Point,
elem_info, elem_info,
ordinates, ordinates,
@ -304,7 +310,7 @@ void occi_featureset::convert_geometry (SDOGeometry* geom, feature_ptr feature,
const bool is_single_geom = false; const bool is_single_geom = false;
const bool is_point_type = false; const bool is_point_type = false;
convert_ordinates (feature, convert_ordinates(feature,
mapnik::LineString, mapnik::LineString,
elem_info, elem_info,
ordinates, ordinates,
@ -313,7 +319,6 @@ void occi_featureset::convert_geometry (SDOGeometry* geom, feature_ptr feature,
is_point_type, is_point_type,
multiple_geometries); multiple_geometries);
} }
} }
break; break;
case SDO_GTYPE_MULTIPOLYGON: case SDO_GTYPE_MULTIPOLYGON:
@ -323,7 +328,7 @@ void occi_featureset::convert_geometry (SDOGeometry* geom, feature_ptr feature,
const bool is_single_geom = false; const bool is_single_geom = false;
const bool is_point_type = false; const bool is_point_type = false;
convert_ordinates (feature, convert_ordinates(feature,
mapnik::Polygon, mapnik::Polygon,
elem_info, elem_info,
ordinates, ordinates,
@ -342,7 +347,7 @@ void occi_featureset::convert_geometry (SDOGeometry* geom, feature_ptr feature,
const bool is_single_geom = false; const bool is_single_geom = false;
const bool is_point_type = false; const bool is_point_type = false;
convert_ordinates (feature, convert_ordinates(feature,
mapnik::Polygon, mapnik::Polygon,
elem_info, elem_info,
ordinates, ordinates,
@ -356,14 +361,15 @@ void occi_featureset::convert_geometry (SDOGeometry* geom, feature_ptr feature,
case SDO_GTYPE_UNKNOWN: case SDO_GTYPE_UNKNOWN:
default: default:
#ifdef MAPNIK_DEBUG #ifdef MAPNIK_DEBUG
std::clog << "OCCI Plugin: unknown <occi> " << occi_enums::resolve_gtype(geomtype) std::clog << "OCCI Plugin: unknown <occi> "
<< occi_enums::resolve_gtype(geomtype)
<< "(gtype=" << gtype << ")" << std::endl; << "(gtype=" << gtype << ")" << std::endl;
#endif #endif
break; break;
} }
} }
void occi_featureset::convert_ordinates (mapnik::feature_ptr feature, void occi_featureset::convert_ordinates(mapnik::feature_ptr feature,
const mapnik::eGeomType& geom_type, const mapnik::eGeomType& geom_type,
const std::vector<Number>& elem_info, const std::vector<Number>& elem_info,
const std::vector<Number>& ordinates, const std::vector<Number>& ordinates,
@ -377,20 +383,20 @@ void occi_featureset::convert_ordinates (mapnik::feature_ptr feature,
if (elem_size >= 0) if (elem_size >= 0)
{ {
int offset = elem_info [0]; int offset = elem_info[0];
int etype = elem_info [1]; int etype = elem_info[1];
int interp = elem_info [2]; int interp = elem_info[2];
if (! is_single_geom && elem_size > SDO_ELEM_INFO_SIZE) if (! is_single_geom && elem_size > SDO_ELEM_INFO_SIZE)
{ {
geometry_type* geom = multiple_geometries ? 0 : new geometry_type(geom_type); geometry_type* geom = multiple_geometries ? 0 : new geometry_type(geom_type);
if (geom) geom->set_capacity (ord_size); if (geom) geom->set_capacity(ord_size);
for (int i = SDO_ELEM_INFO_SIZE; i < elem_size; i+=3) for (int i = SDO_ELEM_INFO_SIZE; i < elem_size; i+=3)
{ {
int next_offset = elem_info [i]; int next_offset = elem_info[i];
int next_etype = elem_info [i + 1]; int next_etype = elem_info[i + 1];
int next_interp = elem_info [i + 2]; int next_interp = elem_info[i + 2];
bool is_linear_element = true; bool is_linear_element = true;
bool is_unknown_etype = false; bool is_unknown_etype = false;
mapnik::eGeomType gtype = mapnik::Point; mapnik::eGeomType gtype = mapnik::Point;
@ -433,20 +439,24 @@ void occi_featureset::convert_ordinates (mapnik::feature_ptr feature,
} }
if (is_unknown_etype) if (is_unknown_etype)
{
break; break;
}
if (is_linear_element) if (is_linear_element)
{ {
if (multiple_geometries) if (multiple_geometries)
{ {
if (geom) if (geom)
feature->add_geometry (geom); {
feature->add_geometry(geom);
geom = new geometry_type(gtype);
geom->set_capacity ((next_offset - 1) - (offset - 1 - dimensions));
} }
fill_geometry_type (geom, geom = new geometry_type(gtype);
geom->set_capacity((next_offset - 1) - (offset - 1 - dimensions));
}
fill_geometry_type(geom,
offset - 1, offset - 1,
next_offset - 1, next_offset - 1,
ordinates, ordinates,
@ -461,45 +471,48 @@ void occi_featureset::convert_ordinates (mapnik::feature_ptr feature,
if (geom) if (geom)
{ {
feature->add_geometry (geom); feature->add_geometry(geom);
geom = 0; geom = 0;
} }
} }
else else
{ {
geometry_type * geom = new geometry_type(geom_type); geometry_type * geom = new geometry_type(geom_type);
geom->set_capacity (ord_size); geom->set_capacity(ord_size);
fill_geometry_type (geom, fill_geometry_type(geom,
offset - 1, offset - 1,
ord_size, ord_size,
ordinates, ordinates,
dimensions, dimensions,
is_point_geom); is_point_geom);
feature->add_geometry (geom); feature->add_geometry(geom);
} }
} }
} }
void occi_featureset::fill_geometry_type (geometry_type * geom, void occi_featureset::fill_geometry_type(geometry_type* geom,
const int real_offset, const int real_offset,
const int next_offset, const int next_offset,
const std::vector<Number>& ordinates, const std::vector<Number>& ordinates,
const int dimensions, const int dimensions,
const bool is_point_geom) const bool is_point_geom)
{ {
geom->move_to ((double) ordinates[real_offset], (double) ordinates[real_offset + 1]); geom->move_to((double) ordinates[real_offset], (double) ordinates[real_offset + 1]);
if (is_point_geom) if (is_point_geom)
{ {
for (int p = real_offset + dimensions; p < next_offset; p += dimensions) for (int p = real_offset + dimensions; p < next_offset; p += dimensions)
geom->move_to ((double) ordinates[p], (double) ordinates[p + 1]); {
geom->move_to((double) ordinates[p], (double) ordinates[p + 1]);
}
} }
else else
{ {
for (int p = real_offset + dimensions; p < next_offset; p += dimensions) for (int p = real_offset + dimensions; p < next_offset; p += dimensions)
geom->line_to ((double) ordinates[p], (double) ordinates[p + 1]); {
geom->line_to((double) ordinates[p], (double) ordinates[p + 1]);
}
} }
} }

View file

@ -2,7 +2,7 @@
* *
* This file is part of Mapnik (c++ mapping toolkit) * This file is part of Mapnik (c++ mapping toolkit)
* *
* Copyright (C) 2007 Artem Pavlenko * Copyright (C) 2011 Artem Pavlenko
* *
* This library is free software; you can redistribute it and/or * This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public * modify it under the terms of the GNU Lesser General Public
@ -38,7 +38,7 @@
class occi_featureset : public mapnik::Featureset class occi_featureset : public mapnik::Featureset
{ {
public: public:
occi_featureset(oracle::occi::StatelessConnectionPool* pool, occi_featureset(oracle::occi::StatelessConnectionPool* pool,
oracle::occi::Connection* conn, oracle::occi::Connection* conn,
std::string const& sqlstring, std::string const& sqlstring,
@ -49,7 +49,8 @@ class occi_featureset : public mapnik::Featureset
unsigned num_attrs); unsigned num_attrs);
virtual ~occi_featureset(); virtual ~occi_featureset();
mapnik::feature_ptr next(); mapnik::feature_ptr next();
private:
private:
void convert_geometry (SDOGeometry* geom, mapnik::feature_ptr feature, bool multiple_geometries); void convert_geometry (SDOGeometry* geom, mapnik::feature_ptr feature, bool multiple_geometries);
void convert_ordinates (mapnik::feature_ptr feature, void convert_ordinates (mapnik::feature_ptr feature,
const mapnik::eGeomType& geom_type, const mapnik::eGeomType& geom_type,
@ -59,12 +60,13 @@ class occi_featureset : public mapnik::Featureset
const bool is_single_geom, const bool is_single_geom,
const bool is_point_geom, const bool is_point_geom,
const bool multiple_geometries); const bool multiple_geometries);
void fill_geometry_type (mapnik::geometry_type * geom, void fill_geometry_type (mapnik::geometry_type* geom,
const int real_offset, const int real_offset,
const int next_offset, const int next_offset,
const std::vector<oracle::occi::Number>& ordinates, const std::vector<oracle::occi::Number>& ordinates,
const int dimensions, const int dimensions,
const bool is_point_geom); const bool is_point_geom);
occi_connection_ptr conn_; occi_connection_ptr conn_;
oracle::occi::ResultSet* rs_; oracle::occi::ResultSet* rs_;
boost::scoped_ptr<mapnik::transcoder> tr_; boost::scoped_ptr<mapnik::transcoder> tr_;

View file

@ -2,7 +2,7 @@
* *
* This file is part of Mapnik (c++ mapping toolkit) * This file is part of Mapnik (c++ mapping toolkit)
* *
* Copyright (C) 2007 Artem Pavlenko * Copyright (C) 2011 Artem Pavlenko
* *
* This library is free software, you can redistribute it and/or * This library is free software, you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public * modify it under the terms of the GNU Lesser General Public
@ -25,10 +25,9 @@
oracle::occi::Environment* occi_environment::env_ = 0; 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)
{ {
case SDO_GTYPE_UNKNOWN: return "SDO_GTYPE_UNKNOWN"; case SDO_GTYPE_UNKNOWN: return "SDO_GTYPE_UNKNOWN";
case SDO_GTYPE_POINT: return "SDO_GTYPE_POINT"; case SDO_GTYPE_POINT: return "SDO_GTYPE_POINT";
@ -44,7 +43,7 @@ std::string occi_enums::resolve_gtype(int gtype)
std::string occi_enums::resolve_etype(int etype) std::string occi_enums::resolve_etype(int etype)
{ {
switch(etype) switch (etype)
{ {
case SDO_ETYPE_UNKNOWN: return "SDO_ETYPE_UNKNOWN"; case SDO_ETYPE_UNKNOWN: return "SDO_ETYPE_UNKNOWN";
case SDO_ETYPE_POINT: return "SDO_ETYPE_POINT"; case SDO_ETYPE_POINT: return "SDO_ETYPE_POINT";
@ -60,7 +59,7 @@ std::string occi_enums::resolve_etype(int etype)
std::string occi_enums::resolve_datatype(int type_id) std::string occi_enums::resolve_datatype(int type_id)
{ {
switch(type_id) switch (type_id)
{ {
case oracle::occi::OCCIINT: return "OCCIINT"; case oracle::occi::OCCIINT: return "OCCIINT";
case oracle::occi::OCCIUNSIGNED_INT: return "OCCIUNSIGNED_INT"; case oracle::occi::OCCIUNSIGNED_INT: return "OCCIUNSIGNED_INT";
@ -92,4 +91,3 @@ std::string occi_enums::resolve_datatype(int type_id)
default: return "<unknown ATTR_DATA_TYPE>"; default: return "<unknown ATTR_DATA_TYPE>";
} }
} }

View file

@ -2,7 +2,7 @@
* *
* This file is part of Mapnik (c++ mapping toolkit) * This file is part of Mapnik (c++ mapping toolkit)
* *
* Copyright (C) 2007 Artem Pavlenko * Copyright (C) 2011 Artem Pavlenko
* *
* This library is free software, you can redistribute it and/or * This library is free software, you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public * modify it under the terms of the GNU Lesser General Public
@ -41,7 +41,6 @@
#error Only ORACLE 10g >= 10.2.0.X is supported ! #error Only ORACLE 10g >= 10.2.0.X is supported !
#endif #endif
// geometry types definitions // geometry types definitions
enum enum
{ {
@ -79,14 +78,13 @@ enum
SDO_INTERPRETATION_CIRCULAR = 2 SDO_INTERPRETATION_CIRCULAR = 2
}; };
class occi_environment : public mapnik::singleton<occi_environment, mapnik::CreateStatic>
class occi_environment : public mapnik::singleton<occi_environment,mapnik::CreateStatic>
{ {
friend class mapnik::CreateStatic<occi_environment>; friend class mapnik::CreateStatic<occi_environment>;
public: public:
static oracle::occi::Environment* get_environment () static oracle::occi::Environment* get_environment()
{ {
if (env_ == 0) if (env_ == 0)
{ {
@ -94,11 +92,11 @@ public:
std::clog << "OCCI Plugin: occi_environment constructor" << std::endl; std::clog << "OCCI Plugin: occi_environment constructor" << std::endl;
#endif #endif
int mode = oracle::occi::Environment::OBJECT const int mode = oracle::occi::Environment::OBJECT
| oracle::occi::Environment::THREADED_MUTEXED; | oracle::occi::Environment::THREADED_MUTEXED;
env_ = oracle::occi::Environment::createEnvironment ((oracle::occi::Environment::Mode) mode); env_ = oracle::occi::Environment::createEnvironment((oracle::occi::Environment::Mode) mode);
RegisterClasses (env_); RegisterClasses(env_);
} }
return env_; return env_;
@ -118,7 +116,7 @@ private:
std::clog << "OCCI Plugin: occi_environment destructor" << std::endl; std::clog << "OCCI Plugin: occi_environment destructor" << std::endl;
#endif #endif
oracle::occi::Environment::terminateEnvironment (env_); oracle::occi::Environment::terminateEnvironment(env_);
env_ = 0; env_ = 0;
} }
} }
@ -126,28 +124,27 @@ private:
static oracle::occi::Environment* env_; static oracle::occi::Environment* env_;
}; };
class occi_connection_ptr class occi_connection_ptr
{ {
public: public:
explicit occi_connection_ptr () explicit occi_connection_ptr()
: env_ (occi_environment::get_environment()), : env_(occi_environment::get_environment()),
pool_ (0), pool_(0),
conn_ (0), conn_(0),
stmt_ (0), stmt_(0),
rs_ (0), rs_(0),
owns_connection_ (false) owns_connection_(false)
{ {
} }
~occi_connection_ptr () ~occi_connection_ptr()
{ {
close_query (true); close_query(true);
} }
void set_pool(oracle::occi::StatelessConnectionPool* pool) void set_pool(oracle::occi::StatelessConnectionPool* pool)
{ {
close_query (true); close_query(true);
pool_ = pool; pool_ = pool;
conn_ = pool_->getConnection(); conn_ = pool_->getConnection();
@ -156,26 +153,26 @@ public:
void set_connection(oracle::occi::Connection* conn, bool owns_connection) void set_connection(oracle::occi::Connection* conn, bool owns_connection)
{ {
close_query (true); close_query(true);
pool_ = 0; pool_ = 0;
conn_ = conn; conn_ = conn;
owns_connection_ = owns_connection; owns_connection_ = owns_connection;
} }
oracle::occi::ResultSet* execute_query (const std::string& s, const unsigned prefetch = 0) oracle::occi::ResultSet* execute_query(const std::string& s, const unsigned prefetch = 0)
{ {
close_query (false); close_query(false);
stmt_ = conn_->createStatement (s); stmt_ = conn_->createStatement(s);
if (prefetch > 0) if (prefetch > 0)
{ {
stmt_->setPrefetchMemorySize (0); stmt_->setPrefetchMemorySize(0);
stmt_->setPrefetchRowCount (prefetch); stmt_->setPrefetchRowCount(prefetch);
} }
rs_ = stmt_->executeQuery (); rs_ = stmt_->executeQuery();
return rs_; return rs_;
} }
@ -186,8 +183,7 @@ public:
} }
private: private:
void close_query(const bool release_connection)
void close_query (const bool release_connection)
{ {
if (conn_) if (conn_)
{ {
@ -195,11 +191,11 @@ private:
{ {
if (rs_) if (rs_)
{ {
stmt_->closeResultSet (rs_); stmt_->closeResultSet(rs_);
rs_ = 0; rs_ = 0;
} }
conn_->terminateStatement (stmt_); conn_->terminateStatement(stmt_);
stmt_ = 0; stmt_ = 0;
} }
@ -207,7 +203,7 @@ private:
{ {
if (pool_) if (pool_)
{ {
pool_->releaseConnection (conn_); pool_->releaseConnection(conn_);
} }
else else
{ {
@ -230,7 +226,6 @@ private:
bool owns_connection_; bool owns_connection_;
}; };
class occi_enums class occi_enums
{ {
public: public:
@ -240,5 +235,4 @@ public:
static std::string resolve_datatype(int type_id); static std::string resolve_datatype(int type_id);
}; };
#endif // OCCI_TYPES_HPP #endif // OCCI_TYPES_HPP