+ occi: added row_limit parameter (like any other database input plugin)

+ occi: added row_prefetch parameter to control how many rows the driver has to prefetch (default to 100)
This commit is contained in:
Lucio Asnaghi 2009-04-28 14:06:35 +00:00
parent 201461e8c9
commit 1fcabec480
5 changed files with 55 additions and 8 deletions

View file

@ -97,6 +97,8 @@ occi_datasource::occi_datasource(parameters const& params)
geometry_field_(*params.get<std::string>("geometry_field","GEOLOC")), geometry_field_(*params.get<std::string>("geometry_field","GEOLOC")),
type_(datasource::Vector), type_(datasource::Vector),
extent_initialized_(false), extent_initialized_(false),
row_limit_(*params_.get<int>("row_limit",0)),
row_prefetch_(*params_.get<int>("row_prefetch",100)),
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")),
pool_(0) pool_(0)
{ {
@ -421,10 +423,10 @@ 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 = table_from_sql(query);
if (use_spatial_index_) if (use_spatial_index_)
{ {
std::string table_name = table_from_sql(query);
std::ostringstream spatial_sql; std::ostringstream spatial_sql;
spatial_sql << std::setprecision(16); spatial_sql << std::setprecision(16);
spatial_sql << " where sdo_filter(" << geometry_field_ << ","; 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; s << query;
#ifdef MAPNIK_DEBUG #ifdef MAPNIK_DEBUG
clog << s.str() << endl; clog << s.str() << endl;
#endif #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(); 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()); 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; s << query;
@ -500,7 +535,12 @@ featureset_ptr occi_datasource::features_at_point(coord2d const& pt) const
clog << s.str() << endl; clog << s.str() << endl;
#endif #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(); return featureset_ptr();

View file

@ -58,6 +58,8 @@ class occi_datasource : public mapnik::datasource
int srid_; int srid_;
mutable bool extent_initialized_; mutable bool extent_initialized_;
mutable mapnik::Envelope<double> extent_; mutable mapnik::Envelope<double> extent_;
const int row_limit_;
const int row_prefetch_;
mapnik::layer_descriptor desc_; mapnik::layer_descriptor desc_;
oracle::occi::StatelessConnectionPool* pool_; oracle::occi::StatelessConnectionPool* pool_;
bool multiple_geometries_; bool multiple_geometries_;

View file

@ -62,6 +62,7 @@ occi_featureset::occi_featureset(StatelessConnectionPool * pool,
std::string const& sqlstring, std::string const& sqlstring,
std::string const& encoding, std::string const& encoding,
bool multiple_geometries, bool multiple_geometries,
unsigned prefetch_rows,
unsigned num_attrs) unsigned num_attrs)
: conn_(pool), : conn_(pool),
tr_(new transcoder(encoding)), tr_(new transcoder(encoding)),
@ -71,7 +72,7 @@ occi_featureset::occi_featureset(StatelessConnectionPool * pool,
{ {
try try
{ {
rs_ = conn_.execute_query (sqlstring); rs_ = conn_.execute_query (sqlstring, prefetch_rows);
} }
catch (SQLException &ex) catch (SQLException &ex)
{ {

View file

@ -42,6 +42,7 @@ class occi_featureset : public mapnik::Featureset
std::string const& sqlstring, std::string const& sqlstring,
std::string const& encoding, std::string const& encoding,
bool multiple_geometries, bool multiple_geometries,
unsigned prefetch_rows,
unsigned num_attrs); unsigned num_attrs);
virtual ~occi_featureset(); virtual ~occi_featureset();
mapnik::feature_ptr next(); mapnik::feature_ptr next();

View file

@ -145,14 +145,17 @@ public:
close_query (true); 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); close_query (false);
stmt_ = conn_->createStatement (s); stmt_ = conn_->createStatement (s);
stmt_->setPrefetchRowCount (100); if (prefetch > 0)
stmt_->setPrefetchMemorySize (0); {
stmt_->setPrefetchMemorySize (0);
stmt_->setPrefetchRowCount (prefetch);
}
rs_ = stmt_->executeQuery (); rs_ = stmt_->executeQuery ();