diff --git a/Code/Common/otbMacro.h b/Code/Common/otbMacro.h index abb1e33b5b36e01fa97a00c47e42fc09e2c6b746..61acd04395134e4fcd7dd7227679607aa1f4136a 100644 --- a/Code/Common/otbMacro.h +++ b/Code/Common/otbMacro.h @@ -27,6 +27,7 @@ #define __otbMacro_h #include "itkMacro.h" +#include "itkObject.h" #include "otbConfigure.h" /** diff --git a/Code/GISFilters/otbPostGISCreateTableTransactor.h b/Code/GISFilters/otbPostGISCreateTableTransactor.h index 50db733db6baea565649e9db8eeb3154bc35814b..2696bb9fffe4affafae103ddcc00d700b42f14f2 100644 --- a/Code/GISFilters/otbPostGISCreateTableTransactor.h +++ b/Code/GISFilters/otbPostGISCreateTableTransactor.h @@ -22,6 +22,7 @@ #include <sstream> + namespace otb { @@ -44,17 +45,19 @@ public: typedef pqxx::result ResultType; - PostGISCreateTableTransactor(){};/* : - pqxx::transactor<pqxx::nontransaction>("CreateTable") {}*/ + typedef pqxx::transactor<pqxx::nontransaction> Superclass; + + PostGISCreateTableTransactor() : Superclass("CreateTable") {} void operator()(argument_type &T) { -/* std::stringstream createCommand; + std::stringstream createCommand; createCommand << "CREATE TABLE "<< m_TableName <<" (id serial PRIMARY KEY,genre text);"; - + + otbGenericMsgDebugMacro(<<"Create Command " << createCommand.str()); m_Result = T.exec(createCommand.str()); std::stringstream addGeometryCommand; @@ -63,7 +66,7 @@ public: "', 'geom', "<< m_SRID <<", 'GEOMETRY',"<< m_Dimension <<" );"; m_Result = T.exec(addGeometryCommand.str()); -*/ + } @@ -73,18 +76,42 @@ public: } -/* itkGetMacro(TableName, std::string); - itkSetMacro(TableName, std::string); + std::string GetTableName() const + { + return m_TableName; + } - itkGetMacro(SRID, int); - itkSetMacro(SRID, int); + void SetTableName(const std::string& aName) + { + m_TableName = aName; + } - itkGetMacro(Dimension, unsigned short); - itkSetMacro(Dimension, unsigned short); + int GetSRID() const + { + return m_SRID; + } - itkGetMacro(Result, ResultType); - */ - + void SetSRID(int aSRID) + { + m_SRID = aSRID; + } + + unsigned short GetDimension() const + { + return m_Dimension; + } + + void SetDimension(unsigned short aDim) + { + m_Dimension = aDim; + } + + ResultType GetResult() const + { + return m_Result; + } + + protected: ResultType m_Result; std::string m_TableName; diff --git a/Testing/Code/GISFilters/CMakeLists.txt b/Testing/Code/GISFilters/CMakeLists.txt index 4369f66e508eb5c0676380c332cbc43d40723569..407b0603e51c68594c6b78718c9c9cf82b1e04f2 100644 --- a/Testing/Code/GISFilters/CMakeLists.txt +++ b/Testing/Code/GISFilters/CMakeLists.txt @@ -24,11 +24,22 @@ ADD_TEST(gfTuPostGISCreateTableTransactorNew ${GISFILTERS_TESTS} otbPostGISCreateTableTransactorNew ) +ADD_TEST(gfTuPostGISCreateTableTransactorAccessors ${GISFILTERS_TESTS} + otbPostGISCreateTableTransactorAccessors + ) +ADD_TEST(gfTuPostGISCreateTableTransactorCreate ${GISFILTERS_TESTS} + otbPostGISCreateTableTransactorCreate + localhost + testgis + postgres + ) # ------- CXX source files ----------------------------------- SET(GISFilters_SRCS otbPostGISCreateTableTransactorNew.cxx +otbPostGISCreateTableTransactorAccessors.cxx +otbPostGISCreateTableTransactorCreate.cxx ) INCLUDE_DIRECTORIES("${OTBTesting_BINARY_DIR}") diff --git a/Testing/Code/GISFilters/otbGISFiltersTests.cxx b/Testing/Code/GISFilters/otbGISFiltersTests.cxx index 7b0223f2638696ca52c01fdb61940fe0833dfdea..e37d6c2c6f0abbbd7f0f44417eb466c8b902f43b 100644 --- a/Testing/Code/GISFilters/otbGISFiltersTests.cxx +++ b/Testing/Code/GISFilters/otbGISFiltersTests.cxx @@ -27,4 +27,6 @@ void RegisterTests() { REGISTER_TEST(otbPostGISCreateTableTransactorNew); + REGISTER_TEST(otbPostGISCreateTableTransactorAccessors); + REGISTER_TEST(otbPostGISCreateTableTransactorCreate); } diff --git a/Testing/Code/GISFilters/otbPostGISCreateTableTransactorAccessors.cxx b/Testing/Code/GISFilters/otbPostGISCreateTableTransactorAccessors.cxx new file mode 100644 index 0000000000000000000000000000000000000000..2a3d8fdb0205f1db2744edf39fcce35a8a46b260 --- /dev/null +++ b/Testing/Code/GISFilters/otbPostGISCreateTableTransactorAccessors.cxx @@ -0,0 +1,54 @@ +/*========================================================================= + + Program: ORFEO Toolbox + Language: C++ + Date: $Date$ + Version: $Revision$ + + + Copyright (c) Centre National d'Etudes Spatiales. All rights reserved. + See OTBCopyright.txt for details. + + + This software is distributed WITHOUT ANY WARRANTY; without even + the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + PURPOSE. See the above copyright notices for more information. + +=========================================================================*/ +#include "itkExceptionObject.h" +#include "otbMacro.h" + +#include "otbPostGISCreateTableTransactor.h" + +int otbPostGISCreateTableTransactorAccessors(int argc, char * argv[]) +{ + typedef otb::PostGISCreateTableTransactor TransactorType; + + //Instantiation + TransactorType myTransactor; + + unsigned short dimension = 2; + + myTransactor.SetDimension( dimension ); + + if( dimension != myTransactor.GetDimension() ) + return EXIT_FAILURE; + + std::string name = "mytable"; + + myTransactor.SetTableName( name ); + + if( name != myTransactor.GetTableName() ) + return EXIT_FAILURE; + + + int srid = -1; + + myTransactor.SetSRID( srid ); + + if( srid != myTransactor.GetSRID() ) + return EXIT_FAILURE; + + + return EXIT_SUCCESS; +} diff --git a/Testing/Code/GISFilters/otbPostGISCreateTableTransactorCreate.cxx b/Testing/Code/GISFilters/otbPostGISCreateTableTransactorCreate.cxx new file mode 100644 index 0000000000000000000000000000000000000000..a02d71df8265709ed352201b8c9f3db0074ce1d3 --- /dev/null +++ b/Testing/Code/GISFilters/otbPostGISCreateTableTransactorCreate.cxx @@ -0,0 +1,60 @@ +/*========================================================================= + + Program: ORFEO Toolbox + Language: C++ + Date: $Date$ + Version: $Revision$ + + + Copyright (c) Centre National d'Etudes Spatiales. All rights reserved. + See OTBCopyright.txt for details. + + + This software is distributed WITHOUT ANY WARRANTY; without even + the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + PURPOSE. See the above copyright notices for more information. + +=========================================================================*/ +#include "itkExceptionObject.h" +#include "otbMacro.h" + +#include "otbPostGISCreateTableTransactor.h" +#include "otbPostGISConnectionImplementation.h" + +int otbPostGISCreateTableTransactorCreate(int argc, char * argv[]) +{ + typedef otb::PostGISCreateTableTransactor TransactorType; + + //Instantiation + TransactorType myTransactor; + + unsigned short dimension = 2; + myTransactor.SetDimension( dimension ); + + std::string name = "mytable"; + myTransactor.SetTableName( name ); + + int srid = -1; + myTransactor.SetSRID( srid ); + + + + const std::string hostName = argv[1]; + const std::string dbName = argv[2]; + const std::string userName = argv[3]; + + typedef otb::PostGISConnectionImplementation GISConnectionType; + + //Instantiation + GISConnectionType::Pointer connection = GISConnectionType::New(); + + connection->SetHost( hostName ); + connection->SetDBName( dbName ); + connection->SetUser( userName ); + + connection->ConnectToDB(); + + connection->PerformTransaction( myTransactor ); + + return EXIT_SUCCESS; +}