diff --git a/plugins/input/occi/occi_datasource.cpp b/plugins/input/occi/occi_datasource.cpp index f2609b13c..d2885e702 100644 --- a/plugins/input/occi/occi_datasource.cpp +++ b/plugins/input/occi/occi_datasource.cpp @@ -2,7 +2,7 @@ * * 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 * modify it under the terms of the GNU Lesser General Public @@ -63,30 +63,29 @@ using oracle::occi::SQLException; using oracle::occi::Type; 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) - occi_datasource::occi_datasource(parameters const& params, bool bind) - : datasource (params), - type_(datasource::Vector), - fields_(*params_.get("fields","*")), - geometry_field_(*params_.get("geometry_field","")), - srid_initialized_(false), - extent_initialized_(false), - desc_(*params_.get("type"), *params_.get("encoding","utf-8")), - row_limit_(*params_.get("row_limit",0)), - row_prefetch_(*params_.get("row_prefetch",100)), - pool_(0), - conn_(0) + : datasource (params), + type_(datasource::Vector), + fields_(*params_.get("fields", "*")), + geometry_field_(*params_.get("geometry_field", "")), + srid_initialized_(false), + extent_initialized_(false), + desc_(*params_.get("type"), *params_.get("encoding", "utf-8")), + row_limit_(*params_.get("row_limit", 0)), + row_prefetch_(*params_.get("row_prefetch", 100)), + pool_(0), + conn_(0) { if (! params_.get("user")) throw datasource_exception("OCCI Plugin: no specified"); if (! params_.get("password")) throw datasource_exception("OCCI Plugin: no specified"); if (! params_.get("host")) throw datasource_exception("OCCI Plugin: no string specified"); boost::optional table = params_.get("table"); - if (!table) + if (! table) { throw datasource_exception("OCCI Plugin: no parameter specified"); } @@ -124,12 +123,16 @@ occi_datasource::~occi_datasource() if (use_connection_pool_) { if (pool_ != 0) - env->terminateStatelessConnectionPool (pool_, StatelessConnectionPool::SPD_FORCE); + { + env->terminateStatelessConnectionPool(pool_, StatelessConnectionPool::SPD_FORCE); + } } else { if (conn_ != 0) + { env->terminateConnection(conn_); + } } } } @@ -149,12 +152,12 @@ void occi_datasource::bind() const *params_.get("user"), *params_.get("password"), *params_.get("host"), - *params_.get("max_size",10), - *params_.get("initial_size",1), + *params_.get("max_size", 10), + *params_.get("initial_size", 1), 1, StatelessConnectionPool::HOMOGENEOUS); } - catch (SQLException &ex) + catch (SQLException& ex) { throw datasource_exception("OCCI Plugin: " + ex.getMessage()); } @@ -170,7 +173,7 @@ void occi_datasource::bind() const *params_.get("password"), *params_.get("host")); } - catch (SQLException &ex) + catch (SQLException& ex) { throw datasource_exception("OCCI Plugin: " + ex.getMessage()); } @@ -186,7 +189,9 @@ void occi_datasource::bind() const s << " LOWER(table_name) = LOWER('" << table_name << "')"; if (geometry_field_ != "") + { s << " AND LOWER(column_name) = LOWER('" << geometry_field_ << "')"; + } #ifdef MAPNIK_DEBUG 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_); 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 (! srid_initialized_) @@ -213,7 +218,7 @@ void occi_datasource::bind() const } } } - catch (SQLException &ex) + catch (SQLException& ex) { throw datasource_exception("OCCI Plugin: " + ex.getMessage()); } @@ -234,7 +239,7 @@ void occi_datasource::bind() const if (use_connection_pool_) conn.set_pool(pool_); else conn.set_connection(conn_, false); - ResultSet* rs = conn.execute_query (s.str()); + ResultSet* rs = conn.execute_query(s.str()); if (rs) { std::vector listOfColumns = rs->getColumnListMetaData(); @@ -317,20 +322,22 @@ void occi_datasource::bind() const case oracle::occi::OCCI_SQLT_BLOB: case oracle::occi::OCCI_SQLT_RSET: #ifdef MAPNIK_DEBUG - std::clog << "OCCI Plugin: unsupported datatype " << occi_enums::resolve_datatype(type_oid) - << " (type_oid=" << type_oid << ")" << std::endl; + std::clog << "OCCI Plugin: unsupported datatype " + << occi_enums::resolve_datatype(type_oid) + << " (type_oid=" << type_oid << ")" << std::endl; #endif break; default: #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 break; } } } } - catch (SQLException &ex) + catch (SQLException& ex) { throw datasource_exception(ex.getMessage()); } @@ -352,11 +359,12 @@ int occi_datasource::type() const box2d occi_datasource::envelope() const { 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; - boost::optional estimate_extent = params_.get("estimate_extent",false); + boost::optional estimate_extent = + params_.get("estimate_extent",false); if (estimate_extent && *estimate_extent) { @@ -375,8 +383,8 @@ box2d occi_datasource::envelope() const if (use_connection_pool_) conn.set_pool(pool_); else conn.set_connection(conn_, false); - ResultSet* rs = conn.execute_query (s.str()); - if (rs && rs->next ()) + ResultSet* rs = conn.execute_query(s.str()); + if (rs && rs->next()) { try { @@ -384,16 +392,16 @@ box2d occi_datasource::envelope() const loy = lexical_cast(rs->getDouble(2)); hix = lexical_cast(rs->getDouble(3)); hiy = lexical_cast(rs->getDouble(4)); - extent_.init (lox,loy,hix,hiy); + extent_.init(lox, loy, hix, hiy); extent_initialized_ = true; } - catch (bad_lexical_cast &ex) + catch (bad_lexical_cast& ex) { std::clog << "OCCI Plugin: " << ex.what() << std::endl; } } } - catch (SQLException &ex) + catch (SQLException& ex) { throw datasource_exception("OCCI Plugin: " + ex.getMessage()); } @@ -421,63 +429,65 @@ box2d occi_datasource::envelope() const if (use_connection_pool_) conn.set_pool(pool_); else conn.set_connection(conn_, false); - ResultSet* rs = conn.execute_query (s.str()); + ResultSet* rs = conn.execute_query(s.str()); if (rs) { - if (rs->next ()) + if (rs->next()) { try { lox = lexical_cast(rs->getDouble(1)); hix = lexical_cast(rs->getDouble(2)); } - catch (bad_lexical_cast &ex) + catch (bad_lexical_cast& ex) { std::clog << "OCCI Plugin: " << ex.what() << std::endl; } } - if (rs->next ()) + if (rs->next()) { try { loy = lexical_cast(rs->getDouble(1)); hiy = lexical_cast(rs->getDouble(2)); } - catch (bad_lexical_cast &ex) + catch (bad_lexical_cast& ex) { std::clog << "OCCI Plugin: " << ex.what() << std::endl; } } - extent_.init (lox,loy,hix,hiy); + extent_.init(lox, loy, hix, hiy); extent_initialized_ = true; } } - catch (SQLException &ex) + catch (SQLException& ex) { throw datasource_exception("OCCI Plugin: " + ex.getMessage()); } } if (! extent_initialized_) + { throw datasource_exception("OCCI Plugin: unable to determine the extent of a table"); + } return extent_; } layer_descriptor occi_datasource::get_descriptor() const { - if (!is_bound_) bind(); + if (! is_bound_) bind(); return desc_; } featureset_ptr occi_datasource::features(query const& q) const { - if (!is_bound_) bind(); + if (! is_bound_) bind(); - box2d const& box=q.get_bbox(); + box2d const& box = q.get_bbox(); std::ostringstream s; s << "SELECT " << geometry_field_; @@ -492,7 +502,7 @@ featureset_ptr occi_datasource::features(query const& q) const s << " FROM "; - std::string query (table_); + std::string query(table_); std::string table_name = mapnik::table_from_sql(query); if (use_spatial_index_) @@ -549,24 +559,24 @@ featureset_ptr occi_datasource::features(query const& q) const #endif return boost::make_shared(pool_, - conn_, - s.str(), - desc_.get_encoding(), - multiple_geometries_, - use_connection_pool_, - row_prefetch_, - props.size()); + conn_, + s.str(), + desc_.get_encoding(), + multiple_geometries_, + use_connection_pool_, + row_prefetch_, + props.size()); } featureset_ptr occi_datasource::features_at_point(coord2d const& pt) const { - if (!is_bound_) bind(); + if (! is_bound_) bind(); std::ostringstream s; s << "SELECT " << geometry_field_; std::vector::const_iterator itr = desc_.get_descriptors().begin(); std::vector::const_iterator end = desc_.get_descriptors().end(); - unsigned size=0; + unsigned size = 0; while (itr != end) { s << ", " << itr->get_name(); @@ -576,7 +586,7 @@ featureset_ptr occi_datasource::features_at_point(coord2d const& pt) const s << " FROM "; - std::string query (table_); + std::string query(table_); std::string table_name = mapnik::table_from_sql(query); 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 "); } - 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()); } @@ -632,12 +642,11 @@ featureset_ptr occi_datasource::features_at_point(coord2d const& pt) const #endif return boost::make_shared(pool_, - conn_, - s.str(), - desc_.get_encoding(), - multiple_geometries_, - use_connection_pool_, - row_prefetch_, - size); + conn_, + s.str(), + desc_.get_encoding(), + multiple_geometries_, + use_connection_pool_, + row_prefetch_, + size); } - diff --git a/plugins/input/occi/occi_datasource.hpp b/plugins/input/occi/occi_datasource.hpp index 53badc22d..cc7bad223 100644 --- a/plugins/input/occi/occi_datasource.hpp +++ b/plugins/input/occi/occi_datasource.hpp @@ -2,7 +2,7 @@ * * 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 * modify it under the terms of the GNU Lesser General Public @@ -38,35 +38,35 @@ class occi_datasource : public mapnik::datasource { - public: - occi_datasource(mapnik::parameters const& params, bool bind=true); - virtual ~occi_datasource (); - int type() const; - static std::string name(); - mapnik::featureset_ptr features(mapnik::query const& q) const; - mapnik::featureset_ptr features_at_point(mapnik::coord2d const& pt) const; - mapnik::box2d envelope() const; - mapnik::layer_descriptor get_descriptor() const; - void bind() const; - private: - int type_; - mutable std::string table_; - mutable std::string fields_; - mutable std::string geometry_field_; - mutable int srid_; - mutable bool srid_initialized_; - mutable bool extent_initialized_; - mutable mapnik::box2d extent_; - mutable mapnik::layer_descriptor desc_; - int row_limit_; - int row_prefetch_; - mutable oracle::occi::StatelessConnectionPool* pool_; - mutable oracle::occi::Connection* conn_; - bool use_connection_pool_; - bool multiple_geometries_; - bool use_spatial_index_; - static const std::string METADATA_TABLE; +public: + occi_datasource(mapnik::parameters const& params, bool bind = true); + virtual ~occi_datasource (); + int type() const; + static std::string name(); + mapnik::featureset_ptr features(mapnik::query const& q) const; + mapnik::featureset_ptr features_at_point(mapnik::coord2d const& pt) const; + mapnik::box2d envelope() const; + mapnik::layer_descriptor get_descriptor() const; + void bind() const; + +private: + int type_; + mutable std::string table_; + mutable std::string fields_; + mutable std::string geometry_field_; + mutable int srid_; + mutable bool srid_initialized_; + mutable bool extent_initialized_; + mutable mapnik::box2d extent_; + mutable mapnik::layer_descriptor desc_; + int row_limit_; + int row_prefetch_; + mutable oracle::occi::StatelessConnectionPool* pool_; + mutable oracle::occi::Connection* conn_; + bool use_connection_pool_; + bool multiple_geometries_; + bool use_spatial_index_; + static const std::string METADATA_TABLE; }; - #endif // OCCI_DATASOURCE_HPP diff --git a/plugins/input/occi/occi_featureset.cpp b/plugins/input/occi/occi_featureset.cpp index 9d850b1e7..c9fe9dae9 100644 --- a/plugins/input/occi/occi_featureset.cpp +++ b/plugins/input/occi/occi_featureset.cpp @@ -2,7 +2,7 @@ * * 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 * modify it under the terms of the GNU Lesser General Public @@ -64,19 +64,23 @@ occi_featureset::occi_featureset(StatelessConnectionPool* pool, bool use_connection_pool, unsigned prefetch_rows, unsigned num_attrs) - : tr_(new transcoder(encoding)), - multiple_geometries_(multiple_geometries), - num_attrs_(num_attrs), - feature_id_(1) + : tr_(new transcoder(encoding)), + multiple_geometries_(multiple_geometries), + num_attrs_(num_attrs), + feature_id_(1) { if (use_connection_pool) + { conn_.set_pool(pool); + } else + { conn_.set_connection(conn, false); + } try { - rs_ = conn_.execute_query (sqlstring, prefetch_rows); + rs_ = conn_.execute_query(sqlstring, prefetch_rows); } catch (SQLException &ex) { @@ -95,10 +99,10 @@ feature_ptr occi_featureset::next() feature_ptr feature(feature_factory::create(feature_id_)); ++feature_id_; - boost::scoped_ptr geom (dynamic_cast (rs_->getObject(1))); + boost::scoped_ptr geom(dynamic_cast(rs_->getObject(1))); if (geom.get()) { - convert_geometry (geom.get(), feature, multiple_geometries_); + convert_geometry(geom.get(), feature, multiple_geometries_); } std::vector listOfColumns = rs_->getColumnListMetaData(); @@ -120,75 +124,77 @@ feature_ptr occi_featureset::next() switch (type_oid) { - case oracle::occi::OCCIBOOL: - case oracle::occi::OCCIINT: - case oracle::occi::OCCIUNSIGNED_INT: - case oracle::occi::OCCIROWID: - boost::put(*feature,fld_name,rs_->getInt (i + 1)); - break; - case oracle::occi::OCCIFLOAT: - case oracle::occi::OCCIBFLOAT: - case oracle::occi::OCCIDOUBLE: - case oracle::occi::OCCIBDOUBLE: - case oracle::occi::OCCINUMBER: - case oracle::occi::OCCI_SQLT_NUM: - boost::put(*feature,fld_name,rs_->getDouble (i + 1)); - break; - case oracle::occi::OCCICHAR: - case oracle::occi::OCCISTRING: - case oracle::occi::OCCI_SQLT_AFC: - case oracle::occi::OCCI_SQLT_AVC: - case oracle::occi::OCCI_SQLT_CHR: - case oracle::occi::OCCI_SQLT_LVC: - case oracle::occi::OCCI_SQLT_RDD: - case oracle::occi::OCCI_SQLT_STR: - case oracle::occi::OCCI_SQLT_VCS: - case oracle::occi::OCCI_SQLT_VNU: - case oracle::occi::OCCI_SQLT_VBI: - case oracle::occi::OCCI_SQLT_VST: - boost::put(*feature,fld_name,(UnicodeString) tr_->transcode (rs_->getString (i + 1).c_str())); - break; - case oracle::occi::OCCIDATE: - case oracle::occi::OCCITIMESTAMP: - case oracle::occi::OCCIINTERVALDS: - case oracle::occi::OCCIINTERVALYM: - case oracle::occi::OCCI_SQLT_DAT: - case oracle::occi::OCCI_SQLT_DATE: - case oracle::occi::OCCI_SQLT_TIME: - case oracle::occi::OCCI_SQLT_TIME_TZ: - case oracle::occi::OCCI_SQLT_TIMESTAMP: - case oracle::occi::OCCI_SQLT_TIMESTAMP_LTZ: - case oracle::occi::OCCI_SQLT_TIMESTAMP_TZ: - case oracle::occi::OCCI_SQLT_INTERVAL_YM: - case oracle::occi::OCCI_SQLT_INTERVAL_DS: - case oracle::occi::OCCIANYDATA: - case oracle::occi::OCCIBLOB: - case oracle::occi::OCCIBFILE: - case oracle::occi::OCCIBYTES: - case oracle::occi::OCCICLOB: - case oracle::occi::OCCIVECTOR: - case oracle::occi::OCCIMETADATA: - case oracle::occi::OCCIPOBJECT: - case oracle::occi::OCCIREF: - case oracle::occi::OCCIREFANY: - case oracle::occi::OCCISTREAM: - case oracle::occi::OCCICURSOR: - case oracle::occi::OCCI_SQLT_FILE: - case oracle::occi::OCCI_SQLT_CFILE: - case oracle::occi::OCCI_SQLT_REF: - case oracle::occi::OCCI_SQLT_CLOB: - case oracle::occi::OCCI_SQLT_BLOB: - case oracle::occi::OCCI_SQLT_RSET: + case oracle::occi::OCCIBOOL: + case oracle::occi::OCCIINT: + case oracle::occi::OCCIUNSIGNED_INT: + case oracle::occi::OCCIROWID: + boost::put(*feature,fld_name,rs_->getInt (i + 1)); + break; + case oracle::occi::OCCIFLOAT: + case oracle::occi::OCCIBFLOAT: + case oracle::occi::OCCIDOUBLE: + case oracle::occi::OCCIBDOUBLE: + case oracle::occi::OCCINUMBER: + case oracle::occi::OCCI_SQLT_NUM: + boost::put(*feature,fld_name,rs_->getDouble (i + 1)); + break; + case oracle::occi::OCCICHAR: + case oracle::occi::OCCISTRING: + case oracle::occi::OCCI_SQLT_AFC: + case oracle::occi::OCCI_SQLT_AVC: + case oracle::occi::OCCI_SQLT_CHR: + case oracle::occi::OCCI_SQLT_LVC: + case oracle::occi::OCCI_SQLT_RDD: + case oracle::occi::OCCI_SQLT_STR: + case oracle::occi::OCCI_SQLT_VCS: + case oracle::occi::OCCI_SQLT_VNU: + case oracle::occi::OCCI_SQLT_VBI: + case oracle::occi::OCCI_SQLT_VST: + boost::put(*feature,fld_name,(UnicodeString) tr_->transcode (rs_->getString (i + 1).c_str())); + break; + case oracle::occi::OCCIDATE: + case oracle::occi::OCCITIMESTAMP: + case oracle::occi::OCCIINTERVALDS: + case oracle::occi::OCCIINTERVALYM: + case oracle::occi::OCCI_SQLT_DAT: + case oracle::occi::OCCI_SQLT_DATE: + case oracle::occi::OCCI_SQLT_TIME: + case oracle::occi::OCCI_SQLT_TIME_TZ: + case oracle::occi::OCCI_SQLT_TIMESTAMP: + case oracle::occi::OCCI_SQLT_TIMESTAMP_LTZ: + case oracle::occi::OCCI_SQLT_TIMESTAMP_TZ: + case oracle::occi::OCCI_SQLT_INTERVAL_YM: + case oracle::occi::OCCI_SQLT_INTERVAL_DS: + case oracle::occi::OCCIANYDATA: + case oracle::occi::OCCIBLOB: + case oracle::occi::OCCIBFILE: + case oracle::occi::OCCIBYTES: + case oracle::occi::OCCICLOB: + case oracle::occi::OCCIVECTOR: + case oracle::occi::OCCIMETADATA: + case oracle::occi::OCCIPOBJECT: + case oracle::occi::OCCIREF: + case oracle::occi::OCCIREFANY: + case oracle::occi::OCCISTREAM: + case oracle::occi::OCCICURSOR: + case oracle::occi::OCCI_SQLT_FILE: + case oracle::occi::OCCI_SQLT_CFILE: + case oracle::occi::OCCI_SQLT_REF: + case oracle::occi::OCCI_SQLT_CLOB: + case oracle::occi::OCCI_SQLT_BLOB: + case oracle::occi::OCCI_SQLT_RSET: #ifdef MAPNIK_DEBUG - std::clog << "OCCI Plugin: unsupported datatype " << occi_enums::resolve_datatype(type_oid) - << " (type_oid=" << type_oid << ")" << std::endl; + std::clog << "OCCI Plugin: unsupported datatype " + << occi_enums::resolve_datatype(type_oid) + << " (type_oid=" << type_oid << ")" << std::endl; #endif - break; - default: // shouldn't get here + break; + default: // shouldn't get here #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 - 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 lrsvalue = (gtype - dimensions * 1000) / 100; int geomtype = (gtype - dimensions * 1000 - lrsvalue * 100); #if 0 - clog << "-----------Geometry Object ------------" << endl; - clog << "SDO GTYPE = " << gtype << endl; - clog << "SDO DIMENSIONS = " << dimensions << endl; - clog << "SDO LRS = " << lrsvalue << endl; - clog << "SDO GEOMETRY TYPE = " << geomtype << endl; + std::clog << "-----------Geometry Object ------------" << std::endl; + std::clog << "SDO GTYPE = " << gtype << std::endl; + std::clog << "SDO DIMENSIONS = " << dimensions << std::endl; + std::clog << "SDO LRS = " << lrsvalue << std::endl; + std::clog << "SDO GEOMETRY TYPE = " << geomtype << std::endl; Number sdo_srid = geom->getSdo_srid(); if (sdo_srid.isNull()) - clog << "SDO SRID = " << "Null" << endl; + std::clog << "SDO SRID = " << "Null" << std::endl; else - clog << "SDO SRID = " << (int) sdo_srid << endl; + std::clog << "SDO SRID = " << (int)sdo_srid << std::endl; #endif const std::vector& elem_info = geom->getSdo_elem_info(); const std::vector& ordinates = geom->getSdo_ordinates(); - const int ordinates_size = (int) ordinates.size(); + const int ordinates_size = (int)ordinates.size(); switch (geomtype) { @@ -232,8 +238,8 @@ void occi_featureset::convert_geometry (SDOGeometry* geom, feature_ptr feature, if (sdopoint && ! sdopoint->isNull()) { geometry_type* point = new geometry_type(mapnik::Point); - point->move_to (sdopoint->getX(), sdopoint->getY()); - feature->add_geometry (point); + point->move_to(sdopoint->getX(), sdopoint->getY()); + feature->add_geometry(point); } } break; @@ -245,14 +251,14 @@ void occi_featureset::convert_geometry (SDOGeometry* geom, feature_ptr feature, const bool is_point_type = false; const bool multiple_geoms = false; - convert_ordinates (feature, - mapnik::LineString, - elem_info, - ordinates, - dimensions, - is_single_geom, - is_point_type, - multiple_geoms); + convert_ordinates(feature, + mapnik::LineString, + elem_info, + ordinates, + dimensions, + is_single_geom, + is_point_type, + multiple_geoms); } } break; @@ -264,14 +270,14 @@ void occi_featureset::convert_geometry (SDOGeometry* geom, feature_ptr feature, const bool is_point_type = false; const bool multiple_geoms = false; - convert_ordinates (feature, - mapnik::Polygon, - elem_info, - ordinates, - dimensions, - is_single_geom, - is_point_type, - multiple_geoms); + convert_ordinates(feature, + mapnik::Polygon, + elem_info, + ordinates, + dimensions, + is_single_geom, + is_point_type, + multiple_geoms); } } break; @@ -286,14 +292,14 @@ void occi_featureset::convert_geometry (SDOGeometry* geom, feature_ptr feature, // Todo - force using true as multiple_geometries until we have proper multipoint handling // http://trac.mapnik.org/ticket/458 - convert_ordinates (feature, - mapnik::Point, - elem_info, - ordinates, - dimensions, - is_single_geom, - is_point_type, - multiple_geoms); + convert_ordinates(feature, + mapnik::Point, + elem_info, + ordinates, + dimensions, + is_single_geom, + is_point_type, + multiple_geoms); } } break; @@ -304,16 +310,15 @@ void occi_featureset::convert_geometry (SDOGeometry* geom, feature_ptr feature, const bool is_single_geom = false; const bool is_point_type = false; - convert_ordinates (feature, - mapnik::LineString, - elem_info, - ordinates, - dimensions, - is_single_geom, - is_point_type, - multiple_geometries); + convert_ordinates(feature, + mapnik::LineString, + elem_info, + ordinates, + dimensions, + is_single_geom, + is_point_type, + multiple_geometries); } - } break; case SDO_GTYPE_MULTIPOLYGON: @@ -323,14 +328,14 @@ void occi_featureset::convert_geometry (SDOGeometry* geom, feature_ptr feature, const bool is_single_geom = false; const bool is_point_type = false; - convert_ordinates (feature, - mapnik::Polygon, - elem_info, - ordinates, - dimensions, - is_single_geom, - is_point_type, - multiple_geometries); + convert_ordinates(feature, + mapnik::Polygon, + elem_info, + ordinates, + dimensions, + is_single_geom, + is_point_type, + multiple_geometries); } } @@ -342,55 +347,56 @@ void occi_featureset::convert_geometry (SDOGeometry* geom, feature_ptr feature, const bool is_single_geom = false; const bool is_point_type = false; - convert_ordinates (feature, - mapnik::Polygon, - elem_info, - ordinates, - dimensions, - is_single_geom, - is_point_type, - multiple_geometries); + convert_ordinates(feature, + mapnik::Polygon, + elem_info, + ordinates, + dimensions, + is_single_geom, + is_point_type, + multiple_geometries); } } break; case SDO_GTYPE_UNKNOWN: default: #ifdef MAPNIK_DEBUG - std::clog << "OCCI Plugin: unknown " << occi_enums::resolve_gtype(geomtype) - << "(gtype=" << gtype << ")" << std::endl; + std::clog << "OCCI Plugin: unknown " + << occi_enums::resolve_gtype(geomtype) + << "(gtype=" << gtype << ")" << std::endl; #endif break; } } -void occi_featureset::convert_ordinates (mapnik::feature_ptr feature, - const mapnik::eGeomType& geom_type, - const std::vector& elem_info, - const std::vector& ordinates, - const int dimensions, - const bool is_single_geom, - const bool is_point_geom, - const bool multiple_geometries) +void occi_featureset::convert_ordinates(mapnik::feature_ptr feature, + const mapnik::eGeomType& geom_type, + const std::vector& elem_info, + const std::vector& ordinates, + const int dimensions, + const bool is_single_geom, + const bool is_point_geom, + const bool multiple_geometries) { const int elem_size = elem_info.size(); const int ord_size = ordinates.size(); if (elem_size >= 0) { - int offset = elem_info [0]; - int etype = elem_info [1]; - int interp = elem_info [2]; + int offset = elem_info[0]; + int etype = elem_info[1]; + int interp = elem_info[2]; if (! is_single_geom && elem_size > SDO_ELEM_INFO_SIZE) { 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) { - int next_offset = elem_info [i]; - int next_etype = elem_info [i + 1]; - int next_interp = elem_info [i + 2]; + int next_offset = elem_info[i]; + int next_etype = elem_info[i + 1]; + int next_interp = elem_info[i + 2]; bool is_linear_element = true; bool is_unknown_etype = false; mapnik::eGeomType gtype = mapnik::Point; @@ -398,14 +404,14 @@ void occi_featureset::convert_ordinates (mapnik::feature_ptr feature, switch (etype) { case SDO_ETYPE_POINT: - if (interp == SDO_INTERPRETATION_POINT) {} - if (interp > SDO_INTERPRETATION_POINT) {} + if (interp == SDO_INTERPRETATION_POINT) {} + if (interp > SDO_INTERPRETATION_POINT) {} gtype = mapnik::Point; break; case SDO_ETYPE_LINESTRING: - if (interp == SDO_INTERPRETATION_STRAIGHT) {} - if (interp == SDO_INTERPRETATION_CIRCULAR) {} + if (interp == SDO_INTERPRETATION_STRAIGHT) {} + if (interp == SDO_INTERPRETATION_CIRCULAR) {} gtype = mapnik::LineString; break; @@ -433,25 +439,29 @@ void occi_featureset::convert_ordinates (mapnik::feature_ptr feature, } if (is_unknown_etype) + { break; + } if (is_linear_element) { if (multiple_geometries) { if (geom) - feature->add_geometry (geom); + { + feature->add_geometry(geom); + } geom = new geometry_type(gtype); - geom->set_capacity ((next_offset - 1) - (offset - 1 - dimensions)); + geom->set_capacity((next_offset - 1) - (offset - 1 - dimensions)); } - fill_geometry_type (geom, - offset - 1, - next_offset - 1, - ordinates, - dimensions, - is_point_geom); + fill_geometry_type(geom, + offset - 1, + next_offset - 1, + ordinates, + dimensions, + is_point_geom); } offset = next_offset; @@ -461,45 +471,48 @@ void occi_featureset::convert_ordinates (mapnik::feature_ptr feature, if (geom) { - feature->add_geometry (geom); + feature->add_geometry(geom); geom = 0; } } else { geometry_type * geom = new geometry_type(geom_type); - geom->set_capacity (ord_size); + geom->set_capacity(ord_size); - fill_geometry_type (geom, - offset - 1, - ord_size, - ordinates, - dimensions, - is_point_geom); + fill_geometry_type(geom, + offset - 1, + ord_size, + ordinates, + dimensions, + is_point_geom); - feature->add_geometry (geom); + feature->add_geometry(geom); } } } -void occi_featureset::fill_geometry_type (geometry_type * geom, - const int real_offset, - const int next_offset, - const std::vector& ordinates, - const int dimensions, - const bool is_point_geom) +void occi_featureset::fill_geometry_type(geometry_type* geom, + const int real_offset, + const int next_offset, + const std::vector& ordinates, + const int dimensions, + 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) { 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 { 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]); + } } } - diff --git a/plugins/input/occi/occi_featureset.hpp b/plugins/input/occi/occi_featureset.hpp index 6536d934e..1d5987dfa 100644 --- a/plugins/input/occi/occi_featureset.hpp +++ b/plugins/input/occi/occi_featureset.hpp @@ -2,7 +2,7 @@ * * 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 * modify it under the terms of the GNU Lesser General Public @@ -38,40 +38,42 @@ class occi_featureset : public mapnik::Featureset { - public: - occi_featureset(oracle::occi::StatelessConnectionPool* pool, - oracle::occi::Connection* conn, - std::string const& sqlstring, - std::string const& encoding, - bool multiple_geometries, - bool use_connection_pool, - unsigned prefetch_rows, - unsigned num_attrs); - virtual ~occi_featureset(); - mapnik::feature_ptr next(); - private: - void convert_geometry (SDOGeometry* geom, mapnik::feature_ptr feature, bool multiple_geometries); - void convert_ordinates (mapnik::feature_ptr feature, - const mapnik::eGeomType& geom_type, - const std::vector& elem_info, - const std::vector& ordinates, - const int dimensions, - const bool is_single_geom, - const bool is_point_geom, - const bool multiple_geometries); - void fill_geometry_type (mapnik::geometry_type * geom, - const int real_offset, - const int next_offset, - const std::vector& ordinates, - const int dimensions, - const bool is_point_geom); - occi_connection_ptr conn_; - oracle::occi::ResultSet* rs_; - boost::scoped_ptr tr_; - const char* fidcolumn_; - bool multiple_geometries_; - unsigned num_attrs_; - mutable int feature_id_; +public: + occi_featureset(oracle::occi::StatelessConnectionPool* pool, + oracle::occi::Connection* conn, + std::string const& sqlstring, + std::string const& encoding, + bool multiple_geometries, + bool use_connection_pool, + unsigned prefetch_rows, + unsigned num_attrs); + virtual ~occi_featureset(); + mapnik::feature_ptr next(); + +private: + void convert_geometry (SDOGeometry* geom, mapnik::feature_ptr feature, bool multiple_geometries); + void convert_ordinates (mapnik::feature_ptr feature, + const mapnik::eGeomType& geom_type, + const std::vector& elem_info, + const std::vector& ordinates, + const int dimensions, + const bool is_single_geom, + const bool is_point_geom, + const bool multiple_geometries); + void fill_geometry_type (mapnik::geometry_type* geom, + const int real_offset, + const int next_offset, + const std::vector& ordinates, + const int dimensions, + const bool is_point_geom); + + occi_connection_ptr conn_; + oracle::occi::ResultSet* rs_; + boost::scoped_ptr tr_; + const char* fidcolumn_; + bool multiple_geometries_; + unsigned num_attrs_; + mutable int feature_id_; }; #endif // OCCI_FEATURESET_HPP diff --git a/plugins/input/occi/occi_types.cpp b/plugins/input/occi/occi_types.cpp index 03e205eb5..18d33c467 100644 --- a/plugins/input/occi/occi_types.cpp +++ b/plugins/input/occi/occi_types.cpp @@ -2,7 +2,7 @@ * * 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 * modify it under the terms of the GNU Lesser General Public @@ -25,71 +25,69 @@ oracle::occi::Environment* occi_environment::env_ = 0; - std::string occi_enums::resolve_gtype(int gtype) { - switch(gtype) + switch (gtype) { - case SDO_GTYPE_UNKNOWN: return "SDO_GTYPE_UNKNOWN"; - case SDO_GTYPE_POINT: return "SDO_GTYPE_POINT"; - case SDO_GTYPE_LINE: return "SDO_GTYPE_LINE"; - case SDO_GTYPE_POLYGON: return "SDO_GTYPE_POLYGON"; - case SDO_GTYPE_MULTIPOINT: return "SDO_GTYPE_MULTIPOINT"; - case SDO_GTYPE_MULTILINE: return "SDO_GTYPE_MULTILINE"; - case SDO_GTYPE_MULTIPOLYGON: return "SDO_GTYPE_MULTIPOLYGON"; - case SDO_GTYPE_COLLECTION: return "SDO_GTYPE_COLLECTION"; - default: return ""; + case SDO_GTYPE_UNKNOWN: return "SDO_GTYPE_UNKNOWN"; + case SDO_GTYPE_POINT: return "SDO_GTYPE_POINT"; + case SDO_GTYPE_LINE: return "SDO_GTYPE_LINE"; + case SDO_GTYPE_POLYGON: return "SDO_GTYPE_POLYGON"; + case SDO_GTYPE_MULTIPOINT: return "SDO_GTYPE_MULTIPOINT"; + case SDO_GTYPE_MULTILINE: return "SDO_GTYPE_MULTILINE"; + case SDO_GTYPE_MULTIPOLYGON: return "SDO_GTYPE_MULTIPOLYGON"; + case SDO_GTYPE_COLLECTION: return "SDO_GTYPE_COLLECTION"; + default: return ""; } } std::string occi_enums::resolve_etype(int etype) { - switch(etype) + switch (etype) { - case SDO_ETYPE_UNKNOWN: return "SDO_ETYPE_UNKNOWN"; - case SDO_ETYPE_POINT: return "SDO_ETYPE_POINT"; - case SDO_ETYPE_LINESTRING: return "SDO_ETYPE_LINESTRING"; - case SDO_ETYPE_POLYGON: return "SDO_ETYPE_POLYGON"; - case SDO_ETYPE_POLYGON_INTERIOR: return "SDO_ETYPE_POLYGON_INTERIOR"; - case SDO_ETYPE_COMPOUND_LINESTRING: return "SDO_ETYPE_COMPOUND_LINESTRING"; - case SDO_ETYPE_COMPOUND_POLYGON: return "SDO_ETYPE_COMPOUND_POLYGON"; - case SDO_ETYPE_COMPOUND_POLYGON_INTERIOR: return "SDO_ETYPE_COMPOUND_POLYGON_INTERIOR"; - default: return ""; + case SDO_ETYPE_UNKNOWN: return "SDO_ETYPE_UNKNOWN"; + case SDO_ETYPE_POINT: return "SDO_ETYPE_POINT"; + case SDO_ETYPE_LINESTRING: return "SDO_ETYPE_LINESTRING"; + case SDO_ETYPE_POLYGON: return "SDO_ETYPE_POLYGON"; + case SDO_ETYPE_POLYGON_INTERIOR: return "SDO_ETYPE_POLYGON_INTERIOR"; + case SDO_ETYPE_COMPOUND_LINESTRING: return "SDO_ETYPE_COMPOUND_LINESTRING"; + case SDO_ETYPE_COMPOUND_POLYGON: return "SDO_ETYPE_COMPOUND_POLYGON"; + case SDO_ETYPE_COMPOUND_POLYGON_INTERIOR: return "SDO_ETYPE_COMPOUND_POLYGON_INTERIOR"; + default: return ""; } } std::string occi_enums::resolve_datatype(int type_id) { - switch(type_id) + switch (type_id) { - case oracle::occi::OCCIINT: return "OCCIINT"; - case oracle::occi::OCCIUNSIGNED_INT: return "OCCIUNSIGNED_INT"; - case oracle::occi::OCCIFLOAT: return "OCCIFLOAT"; - case oracle::occi::OCCIBFLOAT: return "OCCIBFLOAT"; - case oracle::occi::OCCIDOUBLE: return "OCCIDOUBLE"; - case oracle::occi::OCCIBDOUBLE: return "OCCIBDOUBLE"; - case oracle::occi::OCCINUMBER: return "OCCINUMBER"; - case oracle::occi::OCCI_SQLT_NUM: return "OCCI_SQLT_NUM"; - case oracle::occi::OCCICHAR: return "OCCICHAR"; - case oracle::occi::OCCISTRING: return "OCCISTRING"; - case oracle::occi::OCCI_SQLT_AFC: return "OCCI_SQLT_AFC"; - case oracle::occi::OCCI_SQLT_AVC: return "OCCI_SQLT_AVC"; - case oracle::occi::OCCI_SQLT_CHR: return "OCCI_SQLT_CHR"; - case oracle::occi::OCCI_SQLT_LVC: return "OCCI_SQLT_LVC"; - case oracle::occi::OCCI_SQLT_STR: return "OCCI_SQLT_STR"; - case oracle::occi::OCCI_SQLT_VCS: return "OCCI_SQLT_VCS"; - case oracle::occi::OCCI_SQLT_VNU: return "OCCI_SQLT_VNU"; - case oracle::occi::OCCI_SQLT_VBI: return "OCCI_SQLT_VBI"; - case oracle::occi::OCCI_SQLT_VST: return "OCCI_SQLT_VST"; - case oracle::occi::OCCI_SQLT_RDD: return "OCCI_SQLT_RDD"; - case oracle::occi::OCCIDATE: return "OCCIDATE"; - case oracle::occi::OCCITIMESTAMP: return "OCCITIMESTAMP"; - case oracle::occi::OCCI_SQLT_DAT: return "OCCI_SQLT_DAT"; - case oracle::occi::OCCI_SQLT_TIMESTAMP: return "OCCI_SQLT_TIMESTAMP"; - case oracle::occi::OCCI_SQLT_TIMESTAMP_LTZ: return "OCCI_SQLT_TIMESTAMP_LTZ"; - case oracle::occi::OCCI_SQLT_TIMESTAMP_TZ: return "OCCI_SQLT_TIMESTAMP_TZ"; - case oracle::occi::OCCIPOBJECT: return "OCCIPOBJECT"; - default: return ""; + case oracle::occi::OCCIINT: return "OCCIINT"; + case oracle::occi::OCCIUNSIGNED_INT: return "OCCIUNSIGNED_INT"; + case oracle::occi::OCCIFLOAT: return "OCCIFLOAT"; + case oracle::occi::OCCIBFLOAT: return "OCCIBFLOAT"; + case oracle::occi::OCCIDOUBLE: return "OCCIDOUBLE"; + case oracle::occi::OCCIBDOUBLE: return "OCCIBDOUBLE"; + case oracle::occi::OCCINUMBER: return "OCCINUMBER"; + case oracle::occi::OCCI_SQLT_NUM: return "OCCI_SQLT_NUM"; + case oracle::occi::OCCICHAR: return "OCCICHAR"; + case oracle::occi::OCCISTRING: return "OCCISTRING"; + case oracle::occi::OCCI_SQLT_AFC: return "OCCI_SQLT_AFC"; + case oracle::occi::OCCI_SQLT_AVC: return "OCCI_SQLT_AVC"; + case oracle::occi::OCCI_SQLT_CHR: return "OCCI_SQLT_CHR"; + case oracle::occi::OCCI_SQLT_LVC: return "OCCI_SQLT_LVC"; + case oracle::occi::OCCI_SQLT_STR: return "OCCI_SQLT_STR"; + case oracle::occi::OCCI_SQLT_VCS: return "OCCI_SQLT_VCS"; + case oracle::occi::OCCI_SQLT_VNU: return "OCCI_SQLT_VNU"; + case oracle::occi::OCCI_SQLT_VBI: return "OCCI_SQLT_VBI"; + case oracle::occi::OCCI_SQLT_VST: return "OCCI_SQLT_VST"; + case oracle::occi::OCCI_SQLT_RDD: return "OCCI_SQLT_RDD"; + case oracle::occi::OCCIDATE: return "OCCIDATE"; + case oracle::occi::OCCITIMESTAMP: return "OCCITIMESTAMP"; + case oracle::occi::OCCI_SQLT_DAT: return "OCCI_SQLT_DAT"; + case oracle::occi::OCCI_SQLT_TIMESTAMP: return "OCCI_SQLT_TIMESTAMP"; + case oracle::occi::OCCI_SQLT_TIMESTAMP_LTZ: return "OCCI_SQLT_TIMESTAMP_LTZ"; + case oracle::occi::OCCI_SQLT_TIMESTAMP_TZ: return "OCCI_SQLT_TIMESTAMP_TZ"; + case oracle::occi::OCCIPOBJECT: return "OCCIPOBJECT"; + default: return ""; } } - diff --git a/plugins/input/occi/occi_types.hpp b/plugins/input/occi/occi_types.hpp index 548c6321b..64b382ebb 100644 --- a/plugins/input/occi/occi_types.hpp +++ b/plugins/input/occi/occi_types.hpp @@ -2,7 +2,7 @@ * * 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 * 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 ! #endif - // geometry types definitions enum { @@ -79,14 +78,13 @@ enum SDO_INTERPRETATION_CIRCULAR = 2 }; - -class occi_environment : public mapnik::singleton +class occi_environment : public mapnik::singleton { friend class mapnik::CreateStatic; public: - static oracle::occi::Environment* get_environment () + static oracle::occi::Environment* get_environment() { if (env_ == 0) { @@ -94,11 +92,11 @@ public: std::clog << "OCCI Plugin: occi_environment constructor" << std::endl; #endif - int mode = oracle::occi::Environment::OBJECT - | oracle::occi::Environment::THREADED_MUTEXED; + const int mode = oracle::occi::Environment::OBJECT + | oracle::occi::Environment::THREADED_MUTEXED; - env_ = oracle::occi::Environment::createEnvironment ((oracle::occi::Environment::Mode) mode); - RegisterClasses (env_); + env_ = oracle::occi::Environment::createEnvironment((oracle::occi::Environment::Mode) mode); + RegisterClasses(env_); } return env_; @@ -118,7 +116,7 @@ private: std::clog << "OCCI Plugin: occi_environment destructor" << std::endl; #endif - oracle::occi::Environment::terminateEnvironment (env_); + oracle::occi::Environment::terminateEnvironment(env_); env_ = 0; } } @@ -126,28 +124,27 @@ private: static oracle::occi::Environment* env_; }; - class occi_connection_ptr { public: - explicit occi_connection_ptr () - : env_ (occi_environment::get_environment()), - pool_ (0), - conn_ (0), - stmt_ (0), - rs_ (0), - owns_connection_ (false) + explicit occi_connection_ptr() + : env_(occi_environment::get_environment()), + pool_(0), + conn_(0), + stmt_(0), + rs_(0), + owns_connection_(false) { } - ~occi_connection_ptr () + ~occi_connection_ptr() { - close_query (true); + close_query(true); } void set_pool(oracle::occi::StatelessConnectionPool* pool) { - close_query (true); + close_query(true); pool_ = pool; conn_ = pool_->getConnection(); @@ -156,26 +153,26 @@ public: void set_connection(oracle::occi::Connection* conn, bool owns_connection) { - close_query (true); + close_query(true); pool_ = 0; conn_ = conn; 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) { - stmt_->setPrefetchMemorySize (0); - stmt_->setPrefetchRowCount (prefetch); + stmt_->setPrefetchMemorySize(0); + stmt_->setPrefetchRowCount(prefetch); } - rs_ = stmt_->executeQuery (); + rs_ = stmt_->executeQuery(); return rs_; } @@ -186,8 +183,7 @@ public: } private: - - void close_query (const bool release_connection) + void close_query(const bool release_connection) { if (conn_) { @@ -195,11 +191,11 @@ private: { if (rs_) { - stmt_->closeResultSet (rs_); + stmt_->closeResultSet(rs_); rs_ = 0; } - conn_->terminateStatement (stmt_); + conn_->terminateStatement(stmt_); stmt_ = 0; } @@ -207,7 +203,7 @@ private: { if (pool_) { - pool_->releaseConnection (conn_); + pool_->releaseConnection(conn_); } else { @@ -230,7 +226,6 @@ private: bool owns_connection_; }; - class occi_enums { public: @@ -240,5 +235,4 @@ public: static std::string resolve_datatype(int type_id); }; - #endif // OCCI_TYPES_HPP