diff --git a/plugins/input/occi/occi_datasource.cpp b/plugins/input/occi/occi_datasource.cpp index 523dadc4e..82ca1f040 100644 --- a/plugins/input/occi/occi_datasource.cpp +++ b/plugins/input/occi/occi_datasource.cpp @@ -97,6 +97,8 @@ occi_datasource::occi_datasource(parameters const& params) geometry_field_(*params.get("geometry_field","GEOLOC")), type_(datasource::Vector), extent_initialized_(false), + row_limit_(*params_.get("row_limit",0)), + row_prefetch_(*params_.get("row_prefetch",100)), desc_(*params.get("type"), *params.get("encoding","utf-8")), pool_(0) { @@ -421,10 +423,10 @@ featureset_ptr occi_datasource::features(query const& q) const s << " from "; std::string query (table_); - + std::string table_name = table_from_sql(query); + if (use_spatial_index_) { - std::string table_name = table_from_sql(query); std::ostringstream spatial_sql; spatial_sql << std::setprecision(16); spatial_sql << " where sdo_filter(" << geometry_field_ << ","; @@ -444,13 +446,32 @@ featureset_ptr occi_datasource::features(query const& q) const } } + if (row_limit_ > 0) + { + std::string row_limit_string = "rownum < " + row_limit_; + + if (boost::algorithm::ifind_first(query,"where")) + { + boost::algorithm::ireplace_first(query, "where", row_limit_string + " and"); + } + else if (boost::algorithm::find_first(query,table_name)) + { + boost::algorithm::ireplace_first(query, table_name , table_name + " " + row_limit_string); + } + } + s << query; #ifdef MAPNIK_DEBUG clog << s.str() << endl; #endif - return featureset_ptr(new occi_featureset(pool_,s.str(),desc_.get_encoding(),multiple_geometries_,props.size())); + return featureset_ptr (new occi_featureset (pool_, + s.str(), + desc_.get_encoding(), + multiple_geometries_, + row_prefetch_, + props.size())); } return featureset_ptr(); @@ -493,6 +514,20 @@ featureset_ptr occi_datasource::features_at_point(coord2d const& pt) const { boost::algorithm::ireplace_first(query, table_name , table_name + " " + spatial_sql.str()); } + + if (row_limit_ > 0) + { + std::string row_limit_string = "rownum < " + row_limit_; + + if (boost::algorithm::ifind_first(query,"where")) + { + boost::algorithm::ireplace_first(query, "where", row_limit_string + " and"); + } + else if (boost::algorithm::find_first(query,table_name)) + { + boost::algorithm::ireplace_first(query, table_name , table_name + " " + row_limit_string); + } + } s << query; @@ -500,7 +535,12 @@ featureset_ptr occi_datasource::features_at_point(coord2d const& pt) const clog << s.str() << endl; #endif - return featureset_ptr(new occi_featureset(pool_,s.str(),desc_.get_encoding(),multiple_geometries_,size)); + return featureset_ptr (new occi_featureset (pool_, + s.str(), + desc_.get_encoding(), + multiple_geometries_, + row_prefetch_, + size)); } return featureset_ptr(); diff --git a/plugins/input/occi/occi_datasource.hpp b/plugins/input/occi/occi_datasource.hpp index ee7ad5b54..1c0472827 100644 --- a/plugins/input/occi/occi_datasource.hpp +++ b/plugins/input/occi/occi_datasource.hpp @@ -58,6 +58,8 @@ class occi_datasource : public mapnik::datasource int srid_; mutable bool extent_initialized_; mutable mapnik::Envelope extent_; + const int row_limit_; + const int row_prefetch_; mapnik::layer_descriptor desc_; oracle::occi::StatelessConnectionPool* pool_; bool multiple_geometries_; diff --git a/plugins/input/occi/occi_featureset.cpp b/plugins/input/occi/occi_featureset.cpp index 32b9256c8..f4d02fd9d 100644 --- a/plugins/input/occi/occi_featureset.cpp +++ b/plugins/input/occi/occi_featureset.cpp @@ -62,6 +62,7 @@ occi_featureset::occi_featureset(StatelessConnectionPool * pool, std::string const& sqlstring, std::string const& encoding, bool multiple_geometries, + unsigned prefetch_rows, unsigned num_attrs) : conn_(pool), tr_(new transcoder(encoding)), @@ -71,7 +72,7 @@ occi_featureset::occi_featureset(StatelessConnectionPool * pool, { try { - rs_ = conn_.execute_query (sqlstring); + rs_ = conn_.execute_query (sqlstring, prefetch_rows); } catch (SQLException &ex) { diff --git a/plugins/input/occi/occi_featureset.hpp b/plugins/input/occi/occi_featureset.hpp index 99d5887cb..b64e806c2 100644 --- a/plugins/input/occi/occi_featureset.hpp +++ b/plugins/input/occi/occi_featureset.hpp @@ -42,6 +42,7 @@ class occi_featureset : public mapnik::Featureset std::string const& sqlstring, std::string const& encoding, bool multiple_geometries, + unsigned prefetch_rows, unsigned num_attrs); virtual ~occi_featureset(); mapnik::feature_ptr next(); diff --git a/plugins/input/occi/occi_types.hpp b/plugins/input/occi/occi_types.hpp index 76aa73075..c5b9a3643 100644 --- a/plugins/input/occi/occi_types.hpp +++ b/plugins/input/occi/occi_types.hpp @@ -145,14 +145,17 @@ public: close_query (true); } - oracle::occi::ResultSet* execute_query (const std::string& s) + oracle::occi::ResultSet* execute_query (const std::string& s, const unsigned prefetch = 0) { close_query (false); stmt_ = conn_->createStatement (s); - stmt_->setPrefetchRowCount (100); - stmt_->setPrefetchMemorySize (0); + if (prefetch > 0) + { + stmt_->setPrefetchMemorySize (0); + stmt_->setPrefetchRowCount (prefetch); + } rs_ = stmt_->executeQuery ();