+ 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")),
type_(datasource::Vector),
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")),
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();
@ -494,13 +515,32 @@ 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;
#ifdef MAPNIK_DEBUG
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();

View file

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

View file

@ -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)
{

View file

@ -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();

View file

@ -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 ();