From cee97667cf5beca7dd1ad74d4d35bb676ff56e98 Mon Sep 17 00:00:00 2001 From: Howard Butler Date: Mon, 1 Oct 2012 15:44:34 -0500 Subject: [PATCH] more soci cleanups --- include/pdal/drivers/soci/Reader.hpp | 4 +- include/pdal/drivers/soci/Writer.hpp | 54 +---------------- include/pdal/drivers/soci/common.hpp | 86 ++++++++++++++++++++++++++++ src/CMakeLists.txt | 1 + src/drivers/soci/Writer.cpp | 42 +++++++------- 5 files changed, 113 insertions(+), 74 deletions(-) create mode 100644 include/pdal/drivers/soci/common.hpp diff --git a/include/pdal/drivers/soci/Reader.hpp b/include/pdal/drivers/soci/Reader.hpp index a13a406fe9..7458c49233 100644 --- a/include/pdal/drivers/soci/Reader.hpp +++ b/include/pdal/drivers/soci/Reader.hpp @@ -39,6 +39,7 @@ #include #include +#include #include #include @@ -93,7 +94,8 @@ class PDAL_DLL Reader : public pdal::Reader Reader(const Reader&); // not implemented // - + Database_Type m_database_type; + // Connection m_connection; // Statement m_initialQueryStatement; // QueryType m_querytype; diff --git a/include/pdal/drivers/soci/Writer.hpp b/include/pdal/drivers/soci/Writer.hpp index 8542daba4d..fb181888ef 100644 --- a/include/pdal/drivers/soci/Writer.hpp +++ b/include/pdal/drivers/soci/Writer.hpp @@ -35,16 +35,9 @@ #ifndef INCLUDED_DRIVERS_SOCI_WRITER_HPP #define INCLUDED_DRIVERS_SOCI_WRITER_HPP -#include -#ifdef PDAL_HAVE_SOCI -#include -#include -#include -#include -#include -#include -#endif +#include +#include pdal::Writer* createSociWriter(pdal::Stage& prevStage, const pdal::Options& options); @@ -64,50 +57,7 @@ PDAL_DLL void PDALRegister_writer_soci(void* factory); PDAL_C_END #endif -enum Database_Type -{ - Database_Postgresql, - Database_Oracle, - Database_Unknown = 128 -}; -// class PDAL_DLL Table -// { -// public: -// -// -// Table( std::string const& name, -// ::soci::session* session); -// -// inline std::string const getName() const { return m_name; } -// -// virtual void create() = 0; -// virtual void destroy() = 0; -// virtual bool exists() = 0; -// -// private: -// std::string m_name; -// ::soci::session* m_session; -// }; -// -// class PDAL_DLL Postgresql : public Table -// { -// public: -// Postgresql( std::string const& name, -// ::soci::session* session); -// -// virtual void create() {}; -// virtual void destroy() {}; -// virtual bool exists() { return true; } -// }; - -class soci_driver_error : public pdal_error -{ -public: - soci_driver_error(std::string const& msg) - : pdal_error(msg) - {} -}; class PDAL_DLL Writer : public pdal::Writer { diff --git a/include/pdal/drivers/soci/common.hpp b/include/pdal/drivers/soci/common.hpp new file mode 100644 index 0000000000..9662e90c4e --- /dev/null +++ b/include/pdal/drivers/soci/common.hpp @@ -0,0 +1,86 @@ +/****************************************************************************** +* Copyright (c) 2012, Howard Butler, hobu.inc@gmail.com +* +* All rights reserved. +* +* Redistribution and use in source and binary forms, with or without +* modification, are permitted provided that the following +* conditions are met: +* +* * Redistributions of source code must retain the above copyright +* notice, this list of conditions and the following disclaimer. +* * Redistributions in binary form must reproduce the above copyright +* notice, this list of conditions and the following disclaimer in +* the documentation and/or other materials provided +* with the distribution. +* * Neither the name of Hobu, Inc. or Flaxen Geo Consulting nor the +* names of its contributors may be used to endorse or promote +* products derived from this software without specific prior +* written permission. +* +* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS +* FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE +* COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, +* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, +* BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS +* OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED +* AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, +* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT +* OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY +* OF SUCH DAMAGE. +****************************************************************************/ + +#ifndef INCLUDED_DRIVER_SOCI_COMMON_HPP +#define INCLUDED_DRIVER_SOCI_COMMON_HPP + +#ifdef PDAL_HAVE_SOCI +#include +#include +#include +#include +#include +#include +#endif + +#include + +namespace pdal +{ +namespace drivers +{ +namespace soci +{ + + class soci_driver_error : public pdal_error + { + public: + soci_driver_error(std::string const& msg) + : pdal_error(msg) + {} + }; + + + enum Database_Type + { + DATABASE_POSTGRESQL, + DATABASE_ORACLE, + Database_Unknown = 128 + }; + + enum QueryType + { + QUERY_SDO_PC = 0, + QUERY_SDO_PC_BLK_TYPE, + QUERY_SDO_BLK_PC_VIEW, + QUERY_UNKNOWN = 512 + }; + + +} +} +} // namespace pdal::driver::soci + + +#endif diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index abb90c3dbe..43391c718a 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -399,6 +399,7 @@ set(PDAL_SOCI_HEADERS ${PDAL_HEADERS_DIR}/${PDAL_SOCI_PATH}) set(PDAL_SOCI_SRC ${PROJECT_SOURCE_DIR}/src/${PDAL_SOCI_PATH}) set(PDAL_DRIVERS_SOCI_HPP + ${PDAL_SOCI_HEADERS}/common.hpp ${PDAL_SOCI_HEADERS}/Reader.hpp ${PDAL_SOCI_HEADERS}/Writer.hpp ) diff --git a/src/drivers/soci/Writer.cpp b/src/drivers/soci/Writer.cpp index 6296e3123d..0c22a586ca 100644 --- a/src/drivers/soci/Writer.cpp +++ b/src/drivers/soci/Writer.cpp @@ -76,7 +76,7 @@ namespace soci Writer::Writer(Stage& prevStage, const Options& options) : pdal::Writer(prevStage, options) , m_session(0) - , m_type(Database_Postgresql) + , m_type(DATABASE_POSTGRESQL) , m_doCreateIndex(false) , m_bounds(Bounds()) , m_sdo_pc_is_initialized(false) @@ -105,9 +105,9 @@ void Writer::initialize() std::string connection_type = getOptions().getValueOrDefault("type", "postgresql"); if (boost::iequals(connection_type, "oracle")) - m_type = Database_Oracle; + m_type = DATABASE_ORACLE; else if (boost::iequals(connection_type, "postgresql")) - m_type = Database_Postgresql; + m_type = DATABASE_POSTGRESQL; else m_type = Database_Unknown; @@ -120,7 +120,7 @@ void Writer::initialize() try { - if (m_type == Database_Postgresql) + if (m_type == DATABASE_POSTGRESQL) m_session = new ::soci::session(::soci::postgresql, connection); log()->get(logDEBUG) << "Connected to database" << std::endl; @@ -206,9 +206,9 @@ bool Writer::CheckTableExists(std::string const& name) std::ostringstream oss; - if (m_type == Database_Oracle) + if (m_type == DATABASE_ORACLE) oss << "select table_name from user_tables"; - else if (m_type == Database_Postgresql) + else if (m_type == DATABASE_POSTGRESQL) oss << "SELECT tablename FROM pg_tables"; log()->get(logDEBUG) << "checking for " << name << " existence ... " << std::endl; @@ -236,7 +236,7 @@ void Writer::CreateBlockTable(std::string const& name, boost::uint32_t srid) { std::ostringstream oss; - if (m_type == Database_Oracle) + if (m_type == DATABASE_ORACLE) { // We just create a new block table as a copy of // the SDO_PC_BLK_TYPE @@ -244,7 +244,7 @@ void Writer::CreateBlockTable(std::string const& name, boost::uint32_t srid) m_session->once << oss.str(); oss.str(""); } - else if (m_type == Database_Postgresql) + else if (m_type == DATABASE_POSTGRESQL) { std::string cloud_column = getOptions().getValueOrDefault("cloud_column", "id"); std::string cloud_table = getOptions().getValueOrThrow("cloud_table"); @@ -285,7 +285,7 @@ void Writer::DeleteBlockTable(std::string const& cloud_table_name, oss.str(""); // Drop the table's dependencies - if (m_type == Database_Oracle) + if (m_type == DATABASE_ORACLE) { // These need to be uppercase to satisfy the PLSQL function oss << "declare\n" @@ -300,7 +300,7 @@ void Writer::DeleteBlockTable(std::string const& cloud_table_name, } // Go drop the table - if (m_type == Database_Oracle) + if (m_type == DATABASE_ORACLE) { // We need to clean up the geometry column before dropping the table // Oracle upper cases the table name when inserting it in the @@ -313,7 +313,7 @@ void Writer::DeleteBlockTable(std::string const& cloud_table_name, m_session->once << oss.str(); oss.str(""); - } else if (m_type == Database_Postgresql) + } else if (m_type == DATABASE_POSTGRESQL) { // We need to clean up the geometry column before dropping the table oss << "SELECT DropGeometryColumn('" << boost::to_lower_copy(block_table_name) << "', 'extent')"; @@ -333,7 +333,7 @@ void Writer::CreateCloudTable(std::string const& name, boost::uint32_t srid) std::ostringstream oss; - if (m_type == Database_Postgresql) + if (m_type == DATABASE_POSTGRESQL) { oss << "CREATE SEQUENCE " << boost::to_lower_copy(name)<<"_id_seq"; m_session->once << oss.str(); @@ -373,7 +373,7 @@ void Writer::DeleteCloudTable(std::string const& cloud_table_name, oss.str(""); // Go drop the table - if (m_type == Database_Oracle) + if (m_type == DATABASE_ORACLE) { try @@ -402,7 +402,7 @@ void Writer::DeleteCloudTable(std::string const& cloud_table_name, } oss.str(""); - } else if (m_type == Database_Postgresql) + } else if (m_type == DATABASE_POSTGRESQL) { // We need to clean up the geometry column before dropping the table @@ -455,7 +455,7 @@ void Writer::CreateIndexes( std::string const& table_name, std::string index_name = index_name_ss.str().substr(0,29); // Spatial indexes - if (m_type == Database_Oracle) + if (m_type == DATABASE_ORACLE) { oss << "CREATE INDEX "<< index_name << " on " << table_name << "(" << spatial_column_name @@ -466,7 +466,7 @@ void Writer::CreateIndexes( std::string const& table_name, } m_session->once << oss.str(); oss.str(""); - } else if (m_type == Database_Postgresql) + } else if (m_type == DATABASE_POSTGRESQL) { oss << "CREATE INDEX "<< index_name << " on " << boost::to_lower_copy(table_name) << " USING GIST ("<< boost::to_lower_copy(spatial_column_name) << ")"; @@ -486,7 +486,7 @@ void Writer::CreateIndexes( std::string const& table_name, oss << "ALTER TABLE "<< table_name << " ADD CONSTRAINT "<< index_name << " PRIMARY KEY ("<("is3d", false); CreateIndexes(block_table_name, "extent", is3d); - if (m_type == Database_Postgresql) + if (m_type == DATABASE_POSTGRESQL) CreateIndexes(cloud_table_name, "extent", is3d, false); } - if (m_type == Database_Oracle) + if (m_type == DATABASE_ORACLE) { std::string block_table_name = getOptions().getValueOrThrow("block_table"); boost::uint32_t srid = getOptions().getValueOrThrow("srid"); @@ -706,7 +706,7 @@ void Writer::CreateCloud(Schema const& buffer_schema) } - if (m_type == Database_Postgresql) + if (m_type == DATABASE_POSTGRESQL) { // strk: create table tabref( ref regclass ); // [11:32am] strk: insert into tabref values ('geometry_columns'); @@ -802,7 +802,7 @@ bool Writer::WriteBlock(PointBuffer const& buffer) boost::int32_t blk_id = buffer.getField(blockDim, 0); boost::int32_t obj_id = getOptions().getValueOrThrow("pc_id"); boost::int64_t num_points = static_cast(buffer.getNumPoints()); - if (m_type == Database_Postgresql) + if (m_type == DATABASE_POSTGRESQL) { std::string cloud_column = getOptions().getValueOrDefault("cloud_column", "id"); bool is3d = getOptions().getValueOrDefault("is3d", false);