+ apply occi-input-plugin-2.patch (kunitoki) (#212)

This commit is contained in:
Dane Springmeyer 2009-02-03 22:23:33 +00:00
parent e7adc3b8ba
commit 1fb229d035
4 changed files with 81 additions and 33 deletions

View file

@ -133,7 +133,7 @@ occi_datasource::occi_datasource(parameters const& params)
// get SRID from geometry metadata
{
Connection* conn = pool_->getConnection ();
occi_connection_ptr conn (pool_);
std::ostringstream s;
s << "select srid from " << SDO_GEOMETRY_METADATA_TABLE << " where";
@ -142,28 +142,21 @@ occi_datasource::occi_datasource(parameters const& params)
try
{
Statement* stmt = conn->createStatement (s.str());
ResultSet* rs = stmt->executeQuery();
if (rs->next ())
ResultSet* rs = conn.execute_query (s.str());
if (rs && rs->next ())
{
srid_ = rs->getInt(1);
}
stmt->closeResultSet (rs);
conn->terminateStatement (stmt);
}
catch (SQLException &ex)
{
throw datasource_exception(ex.getMessage());
}
pool_->releaseConnection (conn);
}
// get table metadata
Connection* conn = pool_->getConnection ();
MetaData metadata = conn->getMetaData(table_.c_str(), MetaData::PTYPE_TABLE);
occi_connection_ptr conn (pool_);
MetaData metadata = (*conn)->getMetaData(table_.c_str(), MetaData::PTYPE_TABLE);
vector<MetaData> listOfColumns = metadata.getVector(MetaData::ATTR_LIST_COLUMNS);
for (unsigned int i=0;i<listOfColumns.size();++i)
@ -228,8 +221,6 @@ occi_datasource::occi_datasource(parameters const& params)
break;
}
}
pool_->releaseConnection (conn);
}
occi_datasource::~occi_datasource()

View file

@ -64,7 +64,7 @@ occi_featureset::occi_featureset(StatelessConnectionPool * pool,
std::string const& encoding,
bool multiple_geometries,
unsigned num_attrs)
: pool_(pool),
: conn_(pool),
tr_(new transcoder(encoding)),
multiple_geometries_(multiple_geometries),
num_attrs_(num_attrs),
@ -72,9 +72,7 @@ occi_featureset::occi_featureset(StatelessConnectionPool * pool,
{
try
{
conn_ = pool_->getConnection();
stmt_ = conn_->createStatement (sqlstring);
rs_ = stmt_->executeQuery();
rs_ = conn_.execute_query (sqlstring);
}
catch (SQLException &ex)
{
@ -84,22 +82,18 @@ occi_featureset::occi_featureset(StatelessConnectionPool * pool,
occi_featureset::~occi_featureset()
{
stmt_->closeResultSet (rs_);
conn_->terminateStatement (stmt_);
pool_->releaseConnection (conn_);
}
feature_ptr occi_featureset::next()
{
if (rs_->next())
if (rs_ && rs_->next())
{
feature_ptr feature(new Feature(count_));
SDOGeometry* geom = (SDOGeometry*) rs_->getObject(1);
if (geom)
boost::shared_ptr<SDOGeometry> geom (dynamic_cast<SDOGeometry*> (rs_->getObject(1)));
if (geom.get())
{
convert_geometry (geom, feature);
delete geom;
convert_geometry (geom.get(), feature);
}
vector<MetaData> listOfColumns = rs_->getColumnListMetaData();

View file

@ -30,6 +30,7 @@
// boost
#include <boost/scoped_ptr.hpp>
#include <boost/shared_ptr.hpp>
// oci
#include "occi_types.hpp"
@ -50,20 +51,18 @@ class occi_featureset : public mapnik::Featureset
void convert_linestring (SDOGeometry* geom, mapnik::feature_ptr feature, int dims);
void convert_polygon (SDOGeometry* geom, mapnik::feature_ptr feature, int dims);
void convert_multipoint (SDOGeometry* geom, mapnik::feature_ptr feature, int dims);
// void convert_multipoint_2 (SDOGeometry* geom, mapnik::feature_ptr feature, int dims);
//void convert_multipoint_2 (SDOGeometry* geom, mapnik::feature_ptr feature, int dims);
void convert_multilinestring (SDOGeometry* geom, mapnik::feature_ptr feature, int dims);
// void convert_multilinestring_2 (SDOGeometry* geom, mapnik::feature_ptr feature, int dims);
//void convert_multilinestring_2 (SDOGeometry* geom, mapnik::feature_ptr feature, int dims);
void convert_multipolygon (SDOGeometry* geom, mapnik::feature_ptr feature, int dims);
// void convert_multipolygon_2 (SDOGeometry* geom, mapnik::feature_ptr feature, int dims);
// void convert_collection (SDOGeometry* geom, mapnik::feature_ptr feature, int dims);
//void convert_multipolygon_2 (SDOGeometry* geom, mapnik::feature_ptr feature, int dims);
//void convert_collection (SDOGeometry* geom, mapnik::feature_ptr feature, int dims);
void fill_geometry2d (mapnik::geometry2d * geom,
const int dimensions,
const std::vector<oracle::occi::Number>& elem_info,
const std::vector<oracle::occi::Number>& ordinates,
const bool is_point_geom);
oracle::occi::StatelessConnectionPool* pool_;
oracle::occi::Connection* conn_;
oracle::occi::Statement* stmt_;
occi_connection_ptr conn_;
oracle::occi::ResultSet* rs_;
boost::scoped_ptr<mapnik::transcoder> tr_;
const char* fidcolumn_;

View file

@ -75,4 +75,68 @@ enum
SDO_INTERPRETATION_CIRCULAR = 2
};
class occi_connection_ptr
{
public:
occi_connection_ptr (oracle::occi::StatelessConnectionPool* pool)
: pool_ (pool),
conn_ (pool->getConnection ()),
stmt_ (0),
rs_ (0)
{
}
~occi_connection_ptr ()
{
close_query (true);
}
oracle::occi::ResultSet* execute_query (const std::string& s)
{
close_query (false);
stmt_ = conn_->createStatement (s);
rs_ = stmt_->executeQuery ();
return rs_;
}
oracle::occi::Connection* operator*()
{
return conn_;
}
private:
void close_query (const bool release_connection)
{
if (conn_)
{
if (stmt_)
{
if (rs_)
{
stmt_->closeResultSet (rs_);
rs_ = 0;
}
conn_->terminateStatement (stmt_);
stmt_ = 0;
}
if (release_connection)
{
pool_->releaseConnection (conn_);
conn_ = 0;
}
}
}
oracle::occi::StatelessConnectionPool* pool_;
oracle::occi::Connection* conn_;
oracle::occi::Statement* stmt_;
oracle::occi::ResultSet* rs_;
};
#endif // OCCI_TYPES_HPP