![]() |
TerraLib 4.1
|
00001 /************************************************************************************ 00002 TerraLib - a library for developing GIS applications. 00003 Copyright � 2001-2007 INPE and Tecgraf/PUC-Rio. 00004 00005 This code is part of the TerraLib library. 00006 This library is free software; you can redistribute it and/or 00007 modify it under the terms of the GNU Lesser General Public 00008 License as published by the Free Software Foundation; either 00009 version 2.1 of the License, or (at your option) any later version. 00010 00011 You should have received a copy of the GNU Lesser General Public 00012 License along with this library. 00013 00014 The authors reassure the license terms regarding the warranties. 00015 They specifically disclaim any warranties, including, but not limited to, 00016 the implied warranties of merchantability and fitness for a particular purpose. 00017 The library provided hereunder is on an "as is" basis, and the authors have no 00018 obligation to provide maintenance, support, updates, enhancements, or modifications. 00019 In no event shall INPE and Tecgraf / PUC-Rio be held liable to any party for direct, 00020 indirect, special, incidental, or consequential damages arising out of the use 00021 of this library and its documentation. 00022 *************************************************************************************/ 00026 #ifndef __TERRALIB_INTERNAL_DATABASE_H 00027 #define __TERRALIB_INTERNAL_DATABASE_H 00028 00029 #if defined(_MSC_VER) /* MSVC Compiler */ 00030 #pragma warning(disable: 4786) 00031 #endif 00032 00033 00034 #include "TeDefines.h" 00035 #include "TeDataTypes.h" 00036 #include "TeTable.h" 00037 #include "TeGeometry.h" 00038 #include "TeStatistics.h" 00039 #include "TeProject.h" 00040 #include "TeRaster.h" 00041 #include "TeView.h" 00042 #include "TeVisual.h" 00043 #include "TeMetaModelCache.h" 00044 #include "TeSharedPtr.h" 00045 #include "TeDatabaseIndex.h" 00046 #include "TeConnection.h" 00047 00048 class TeLayer; 00049 class TeDatabaseFactoryParams; 00050 class TeRasterParams; 00051 class TeTheme; 00052 class TeTime; 00053 class TeTimeInterval; 00054 00055 #include <set> 00056 #include <string> 00057 //using namespace std; 00058 00059 00063 enum TeCursorLocation { TeCLIENTESIDE, TeSERVERSIDE }; 00064 00068 enum TeCursorType { TeUNIDIRECTIONAL, TeBIDIRECTIONAL, TeRANDOMACCESS }; 00069 00073 enum TeCursorEditType { TeREADONLY, TeREADWRITE }; 00074 00078 enum TeCursorDataType { TeBINARYCURSOR, TeTEXTCURSOR }; 00079 00080 00084 enum TeSpatialIndexType {TeRTREE, TeQUADTREE}; 00085 00087 typedef vector<string> TeKeys; 00088 00090 typedef map<string, double> TeKeysToDist; 00091 00093 typedef vector<TeGeometry*> TeGeometryVect; 00094 00096 typedef map<string, TeStatisticsDimensionVect> TeObjectStatistics; 00097 00098 00099 class TeDatabasePortal; 00100 00101 00103 00118 class TL_DLL TeDatabase 00119 { 00120 public: 00122 TeDatabase(); 00123 00125 virtual ~TeDatabase(); 00126 00128 virtual TeDatabase& operator=(const TeDatabase& other); 00129 00131 virtual bool operator== (const TeDatabase& other) const 00132 { 00133 if (dbmsName_ != other.dbmsName_ || 00134 database_ != other.database_ || 00135 host_ != other.host_ || 00136 user_ != other.user_ ) 00137 return false; 00138 return true; 00139 } 00140 00141 00146 00148 virtual void setConnection(TeConnection* c); 00149 00153 virtual TeConnection* getConnection(); 00154 00156 00161 00162 virtual string errorMessage () 00163 { return errorMessage_; } 00164 00166 virtual int errorNum () 00167 { return errorNumber_; } 00168 00170 string user () 00171 { return user_; } 00172 00174 void user(string value) { user_=value;} 00175 00177 string host () 00178 { return host_; } 00179 00181 string password () 00182 { return password_; } 00183 00185 string databaseName () 00186 { return database_; } 00187 00189 string dbmsName () 00190 { return dbmsName_; } 00191 00193 int portNumber () 00194 { return portNumber_; } 00195 00197 TeLayerMap& layerMap () 00198 { return metaModel_->layerMap(); } 00199 00201 TeViewMap& viewMap () 00202 { return metaModel_->viewMap(); } 00203 00205 TeThemeMap& themeMap () 00206 { return metaModel_->themeMap(); } 00207 00209 TeThemeMap& invalidThemeMap() 00210 { return metaModel_->invalidThemeMap(); } 00211 00213 TeProjectMap& projectMap () 00214 { return metaModel_->projectMap(); } 00215 00217 TeLegendEntryMap& legendMap () 00218 { return metaModel_->legendMap(); } 00219 00221 multiset<int>& relationMSet () 00222 { return metaModel_->relationMSet(); } 00223 00225 virtual void clear(); 00226 00228 00235 00236 virtual bool newDatabase(const string& database, const string& user, const string& password, const string& host, const int &port=-1, bool terralibModel=true, const std::string& characterSet = "") = 0; 00237 00239 virtual bool connect (const string& host, const string& user, const string& password, const string& database, int port = -1) = 0; 00240 00242 virtual bool showDatabases (const string& /* host */, const string& /* user */, const string& /* password */, vector<string>& /* dbNames */ , int /* port */ = -1) 00243 { return true; } 00244 00246 virtual bool connect (const string& = "") { return false; }; 00247 00249 bool isConnected () 00250 { return isConnected_; } 00251 00253 virtual void close() = 0; 00254 00256 /* 00257 The expected return value is similar to: dbms_server;hostname;portnumber;databasename;user;password 00258 */ 00259 virtual string getDatabaseDescription(); 00260 00261 00266 static TeDatabase* DefaultObject( const TeDatabaseFactoryParams& ) 00267 { 00268 std::cout << std::endl << "TeDatabase::DefaultObject - " << 00269 " - Trying to create an invalid TeDatabase default object." << 00270 std::endl; 00271 throw; 00272 00273 return 0; 00274 }; 00275 00277 00284 00286 virtual bool listTables(vector<string>& /* tableList */) { return false; } 00287 00289 virtual bool listDatabases(std::vector<std::string> & /*databaseList*/) { return false; } 00290 00292 virtual bool dropDatabase(const std::string & /*databaseName*/) { return false;} 00293 00295 virtual bool tableExist(const string& table) = 0; 00296 00298 virtual bool columnExist(const string& table, const string& column, TeAttribute& attr) = 0; 00299 00301 virtual bool allowEmptyString(const string& /* tableName */, const string& /* column */) { return false; } 00302 00304 virtual bool validTable (TeTable& table); 00305 00307 string getTableName(int tableId); 00308 00310 string getNewTableName(const string& n); 00311 00313 00316 virtual string getConcatFieldsExpression(const vector<string>& fNamesVec); 00317 00319 00323 virtual bool createTable(const string& table, TeAttributeList &attr) = 0; 00324 00326 virtual bool deleteTable (const string& table); 00327 00329 00333 virtual bool addColumn (const string& table, TeAttributeRep &rep) = 0; 00334 00336 00340 virtual bool deleteColumn (const string& table, const string& colName); 00341 00343 00351 virtual bool createRelation (const string& relName, const string& table, const string& fieldName, 00352 const string& relatedTable, const string& relatedField, bool cascadeDeletion) = 0; 00353 00355 00359 virtual TeDBRelationType existRelation(const string& tableName, const string& relName) = 0; 00360 00362 00367 virtual bool deleteRelation(const string& name, const string& table); 00368 00370 00375 00376 virtual bool execute ( const string &sql) = 0; 00377 00379 00383 virtual TeDatabasePortal* getPortal () = 0; 00384 00386 virtual bool inClauseValues(const string& query , const string& attribute, vector<string>& inClauseVector); 00387 00389 00395 00396 /* 00397 \param withIntegrity flag that indicates that the referencial integrity should be implemented. 00398 \param createIndex flag that indicate that the indexes should be created 00399 */ 00400 virtual bool createConceptualModel(bool withIntegrity = true, bool newDatabase = true, bool createIndex = true); 00401 00403 virtual bool defineIntegrity(void); 00404 00406 virtual bool createIndex(const string& tableName, const string& indexName, const string& columnsName); 00407 00409 virtual bool deleteIndex(const string& tableName, const string& indexName); 00410 00412 virtual bool getIndexesFromTable(const string& tableName, std::vector<TeDatabaseIndex>& vecIndexes); 00413 00415 virtual bool createDatabaseTable(); 00416 00418 virtual bool createDatumTable(); 00419 00421 virtual bool createProjectionTable(); 00422 00424 virtual bool createSRSTable(); 00425 00427 virtual bool createLayerTable (); 00428 00430 virtual bool createRepresentationTable (); 00431 00433 virtual bool createViewTable (); 00434 00436 virtual bool createThemeTable (); 00437 00439 virtual bool createGroupingTable(); 00440 00442 virtual bool createThemeTablesTable(); 00443 00445 virtual bool createLegendTable (); 00446 00448 virtual bool createVisualTable(); 00449 00451 virtual bool createVisualRasterTable(); 00452 00454 virtual bool createLayerTableTable(); 00455 00457 virtual bool createTablesRelationTable(); 00458 00460 virtual bool createProjectTable(); 00461 00463 virtual bool createProjectViewTable(); 00465 00470 00471 virtual bool loadProjectSet(); 00472 00474 virtual bool loadProject(TeProject* project); 00475 00477 virtual bool insertProject(TeProject *project) = 0; 00478 00480 virtual bool updateProject(TeProject *project); 00481 00483 virtual bool deleteProject(int projectId); 00484 00486 virtual bool insertProjectViewRel(int projectId, int viewId); 00487 00489 virtual bool deleteProjectViewRel(int projectId, int viewId); 00490 00492 virtual bool projectExist(const string& projectName); 00494 00499 00501 virtual bool createPolygonGeometry (const string& tableName, const int& epsgCode = -1); 00502 00504 virtual bool createLineGeometry (const string& tableName, const int& epsgCode = -1); 00505 00507 virtual bool createPointGeometry (const string& tableName, const int& epsgCode = -1); 00508 00510 virtual bool createCellGeometry (const string& tableName, const int& epsgCode = -1); 00511 00513 virtual bool createTextGeometry (const string& tableName, const int& epsgCode = -1); 00514 00516 virtual bool createArcGeometry (const string& tableName, const int& epsgCode = -1); 00517 00519 virtual bool createNodeGeometry (const string& tableName, const int& epsgCode = -1); 00520 00522 virtual bool createRasterGeometry(const string& tableName); 00523 00525 virtual bool createRasterMetadataTable(const string& tableName); 00526 00528 virtual bool createRasterTable (const string& tableName); 00529 00531 virtual bool createCollectionTable(const string& tableName); 00533 00538 00539 /* 00540 \param atts returning vector of tables information 00541 \param attType type of the tables that are being looked for (optional) 00542 \return TRUE if any table was found and FALSE otherwise 00543 */ 00544 virtual bool getAttrTables(TeAttrTableVector& atts, TeAttrTableType attType = TeAllAttrTypes); 00545 00547 /* 00548 \param tableId table identification (from te_layer_table) 00549 \param tField link column name of the static table 00550 \param eTable name of the external table 00551 \param eField name of the link column of the related table 00552 \param relId returns the identification of the relation 00553 */ 00554 virtual bool insertRelationInfo(const int tableId, const string& tField, 00555 const string& rTable, const string& rField, int& relId) = 0; 00556 00558 virtual bool insertTableInfo (int layerId, TeTable &table, const string& user="") = 0; 00559 00561 virtual bool updateTableInfo (int layerId, TeTable &table, const string user=""); 00562 00564 virtual bool loadTableInfo(TeTable& table); 00565 00567 virtual bool insertTable(TeTable &table); 00568 00570 virtual bool alterTable(const string& tableName, TeAttributeRep& rep, const string& oldColName=""); 00571 00573 virtual bool alterTable(const string& oldTableName, const string& newTablename); 00574 00576 virtual bool insertBlob (const string& tableName, const string& columnBlob, TeAttributeRep& columnId, const string& valueId, unsigned char* data, int size); 00577 00579 virtual bool insertBlob (const string& tableName, const string& columnBlob, TeAttributeRep& columnId, const string& valueId, const string& fileName); 00580 00582 virtual bool insertBlob (const string& tableName, const string& columnBlob, const string& whereClause, unsigned char* data, int size) = 0; 00583 00585 virtual bool insertBlob (const string& tableName, const string& columnBlob, const string& whereClause, const string& fileName); 00586 00588 virtual bool updateTable (TeTable &table); 00589 00591 virtual bool loadTable (const string& tableName, TeTable &table); 00592 00594 virtual bool selectTable (const string& tableName, const string& criteria, TeTable &table); 00595 00597 virtual bool deleteLayerTable (int layerId, TeAttrTableType ttype = TeAttrStatic); 00599 00604 00606 virtual bool insertDatum(const TeDatum& datum); 00607 00609 virtual bool updateDatum(const TeDatum& datum); 00610 00612 virtual bool loadDatum(TeDatum& datum); 00613 00615 virtual void populateDatumTable(); 00616 00618 virtual bool loadDatumSet(); 00619 00621 00626 00628 virtual bool insertProjection(TeProjection* proj) = 0; 00629 00631 virtual bool insertSRSId(TeProjection* proj, int srsId); 00632 00634 virtual bool updateProjection(TeProjection *proj); 00635 00637 virtual bool updateSRSId(TeProjection* proj, int srsId); 00638 00640 virtual TeProjection* loadProjection(int id); 00641 00643 virtual TeProjection* loadProjectionFromSRSId(int srsid); 00644 00646 virtual bool deleteProjection(const unsigned int& projId); 00647 00649 00654 00655 virtual bool insertLayer (TeLayer *layer) = 0; 00656 00658 virtual bool updateLayer (TeLayer *layer); 00659 00661 /* 00662 \param loadAttrList indicates if the attribute list of each attribute table should be loaded 00663 */ 00664 virtual bool loadLayerSet (const bool& loadAttrList = true); 00665 00667 /* 00668 \param layer a pointer to a layer that will be loaded from database 00669 \param loadAttrList indicates if the attribute list of each attribute table should be loaded 00670 */ 00671 virtual bool loadLayer (TeLayer* layer, const bool& loadAttrList = true); 00672 00674 /* 00675 \param layer a pointer to a layer whose attribute table will be loaded from database 00676 \param loadAttrList indicates if the attribute list of each attribute table should be loaded 00677 */ 00678 virtual bool loadLayerTable (TeLayer* layer, const bool& loadAttrList = true); 00679 00681 virtual bool deleteLayer (int layerId); 00682 00684 virtual bool layerExist (int id); 00685 00687 virtual bool layerExist (string layerName); 00688 00690 00694 virtual string getNewLayerName(const string& n); 00696 00701 00702 virtual bool insertRepresentation (int layerId, TeRepresentation& rep) = 0; 00703 00705 virtual bool updateRepresentation (int layerId, TeRepresentation& rep); 00706 00708 virtual bool updateLayerBox(TeLayer* layer); 00709 00711 00716 00717 00722 virtual bool insertRasterGeometry(const string& tableName, TeRasterParams& par, const string& objectId = ""); 00723 00725 00730 virtual bool updateRasterRepresentation(int layerId, TeRasterParams& par, const string& objectId=""); 00731 00733 00737 virtual string getRasterTable(int layerId, const string& objectId); 00738 00740 00745 virtual bool insertRasterMetadata (const string& tableName, int geomId, TeRasterParams& par); 00746 00748 00754 virtual bool updateRasterMetadata (const string& tableName, int geomId, TeRasterParams& par); 00756 00760 00761 virtual bool insertView (TeView *view) = 0; 00762 00764 virtual bool updateView (TeView *view); 00765 00767 /* 00768 \param user the user name 00769 \param loadAttrList indicates if the attribute list of each attribute table should be loaded 00770 \param visualClass identifies which concrete class od visual should be instantiated. 00771 The default is TerraLib basic visual. 00772 */ 00773 virtual bool loadViewSet (const string& user, const bool& loadAttrList = true, const string& visualClass="tevisual"); 00774 00776 /* 00777 \param view a pointer to a view that will be loaded from database 00778 \param loadAttrList indicates if the attribute list of each attribute table should be loaded 00779 \param visualClass identifies which concrete class od visual should be instantiated. 00780 The default is TerraLib basic visual. 00781 */ 00782 virtual bool loadView (TeView* view, const bool& loadAttrList = true, const string& visualClass="tevisual"); 00783 00785 virtual bool deleteView (int viewId); 00786 00788 virtual bool insertViewTree (TeViewTree *tree) = 0; 00789 00791 /* 00792 \param view a pointer to a view that will be loaded from database 00793 \param id a specific theme or viewtree id of this view that will be loaded from database 00794 \param loadAttrList indicates if the attribute list of each attribute table should be loaded 00795 \param visualClass identifies which concrete class od visual should be instantiated. 00796 The default is TerraLib basic visual. 00797 */ 00798 virtual TeViewTree* loadViewTree(TeView* view, int id, const bool& loadAttrList = true, const string& visualClass = "tevisual"); 00799 00801 virtual bool updateViewTree (TeViewTree *tree); 00802 00804 virtual bool viewExist(string viewName); 00805 00807 00812 00813 virtual bool insertThemeGroup (TeViewTree* tree) = 0; 00814 00816 virtual bool insertTheme (TeAbstractTheme *theme) = 0; 00817 00819 virtual bool updateTheme (TeAbstractTheme *theme); 00820 00822 virtual bool loadTheme (TeAbstractTheme *theme, const bool& loadAttrList = true, const string& visualClass = "tevisual"); 00823 00825 virtual bool loadThemes (std::vector<TeAbstractTheme*>& vecThemes, const bool& loadAttrList, const std::string& userName, const bool& loadMetadata = true, const string& visualType = "tevisual"); 00826 00828 virtual bool loadExternalThemes (std::vector<TeAbstractTheme*>& vecExternalThemes); 00829 00831 virtual bool loadThemeTable (TeTheme* theme, const bool& loadAttrList = true); 00832 00834 virtual bool deleteThemeGroup (int themeId); 00835 00837 virtual bool deleteTheme (int themeId); 00838 00840 virtual bool deleteLegend (int themeId); 00841 00843 bool insertThemeTable(TeTheme *theme, TeTable& inputTable); 00844 00846 virtual bool insertThemeTable (int themeId, int tableId, int relationId, int tableOrder) = 0; 00847 00849 virtual bool updateThemeTable (TeTheme *theme); 00850 00852 bool removeThemeTable(TeTheme *theme, int tableOrder); 00853 00855 virtual bool insertGrouping (int themeId, const TeGrouping& grouping); 00856 00858 virtual bool updateGrouping (int themeId, const TeGrouping& grouping); 00859 00861 virtual bool generateLabelPositions(TeTheme *theme, const std::string& objectId = ""); 00862 00864 virtual bool themeExist(string themeName); 00865 00867 virtual bool themeExist(const std::string &viewName, const std::string &userName, const std::string &themeName); 00868 00870 00874 virtual string getNewThemeName(const string& n); 00875 00877 00882 00883 virtual bool insertLegend (TeLegendEntry *legend) = 0; 00885 virtual bool updateLegend (TeLegendEntry *legend); 00886 00887 virtual bool updateLegend (vector<TeLegendEntry>& legVec); 00888 virtual bool loadLegend (TeAbstractTheme *theme, const string& visualClass = "tevisual"); 00889 virtual bool updateVisual (TeLegendEntry *legend); 00890 virtual bool updateVisual (vector<TeLegendEntry>& legVec); 00892 00897 00898 virtual bool insertPolygonSet (const string& table, TePolygonSet &ps); 00899 00901 virtual bool updatePolygonSet (const string& table, TePolygonSet &ps); 00902 00904 virtual bool selectPolygonSet (const string& table, const string& criteria, TePolygonSet &ps); 00905 00907 virtual bool loadPolygonSet (TeTheme* theme, TePolygonSet &ps); 00908 00910 virtual bool loadPolygonSet (const string& table, const string& geoid, TePolygonSet &ps); 00911 00913 virtual bool loadPolygonSet (const string& table, TeBox &box, TePolygonSet &ps); 00914 00916 /* 00917 \return A database portal pointer if there is any polygons inside the box 00918 \return A null pointer if there isn't polygons to iterate 00919 \note The database portal pointer should be deleted by the application 00920 */ 00921 virtual TeDatabasePortal* loadPolygonSet(const string& table, TeBox &box); 00922 00924 virtual bool locatePolygon (const string& table, TeCoord2D &pt, TePolygon &polygon, const double& tol = 0.0); 00925 00927 virtual bool locatePolygonSet (const string& table, TeCoord2D &pt, double tol, TePolygonSet &polygons); 00928 00930 virtual bool insertPolygon (const string& table, TePolygon &p) = 0; 00931 00933 virtual bool updatePolygon (const string& table, TePolygon &p) = 0; 00935 00940 // Accessing/Inserting line geometries into the database 00941 virtual bool insertLineSet (const string& table, TeLineSet &ls); 00942 virtual bool updateLineSet (const string& table,TeLineSet &ls); 00943 virtual bool loadLineSet (const string& table, const string& geoid, TeLineSet &ls); 00944 virtual bool loadLineSet (TeTheme* theme, TeLineSet &ls); 00945 virtual bool loadLineSet (const string& table, TeBox &box, TeLineSet &linSet); 00946 virtual TeDatabasePortal* loadLineSet (const string& table, TeBox &box); 00947 virtual bool selectLineSet (const string& table, const string& criteria, TeLineSet &ls); 00948 00949 virtual bool insertLine (const string& table, TeLine2D &l) = 0; 00950 virtual bool updateLine (const string& table, TeLine2D &l) = 0; 00951 virtual bool locateLine (const string& table, TeCoord2D &pt, TeLine2D &line, const double& tol = 0.0); 00952 virtual bool locateLineSet (const string& table, TeCoord2D &pt, TeLineSet & ls, const double& tol = 0.0); 00953 00955 00960 // Accessing/Inserting point geometries into the database 00961 virtual bool insertPointSet (const string& table, TePointSet &ps); 00962 virtual bool updatePointSet (const string& table, TePointSet &ps); 00963 virtual bool loadPointSet (const string& table, TeBox &box, TePointSet &ps); 00964 virtual TeDatabasePortal* loadPointSet (const string& table, TeBox &box); 00965 virtual bool loadPointSet (const string& table, const string& geoid, TePointSet &ps); 00966 virtual bool loadPointSet (TeTheme* theme, TePointSet &ps); 00967 virtual bool selectPointSet (const string& table, const string& criteria, TePointSet &ps); 00968 00969 virtual bool insertPoint (const string& table, TePoint &p) = 0; 00970 virtual bool updatePoint (const string& table, TePoint &p); 00971 virtual bool locatePoint (const string& table, TeCoord2D &pt, TePoint &point, const double& tol = 0.0); 00972 virtual bool locatePointSet (const string& table, TeCoord2D &pt, TePointSet &pointSet, const double& tol=0.0); 00974 00979 // Accessing/Inserting text geometries into the database 00980 virtual bool insertTextSet (const string& table, TeTextSet &ts); 00981 virtual bool updateTextSet (const string& table, TeTextSet &ts); 00982 virtual bool loadTextSet (const string& table, const string& geoid, TeTextSet &ts); 00983 virtual bool selectTextSet (const string& table, const string& criteria, TeTextSet &ts); 00984 00985 virtual bool insertText (const string& table, TeText &t) = 0; 00986 virtual bool updateText (const string& table, TeText &t); 00987 virtual bool locateText (const string& table, TeCoord2D &pt, TeText &text, const double& tol = 0.0); 00988 virtual bool locateTextSet (const string& table, TeCoord2D &pt, TeTextSet &textSet, const double& tol = 0.0); 00990 00995 00996 virtual bool insertArcSet (const string& table, TeArcSet &as); 00997 00999 virtual bool updateArcSet (const string& table, TeArcSet &as); 01000 01002 virtual bool loadArcSet (const string& table, const string& geoid, TeArcSet &as); 01003 01005 virtual bool insertArc (const string& table,TeArc &arc) = 0; 01006 01008 virtual bool updateArc (const string& table,TeArc &arc); 01010 01015 // Accessing/Inserting node geometries into the database 01016 virtual bool insertNodeSet (const string& table, TeNodeSet &ns); 01017 virtual bool updateNodeSet (const string& table, TeNodeSet &ns); 01018 virtual bool loadNodeSet (const string& table, const string& geoid, TeNodeSet &ps); 01019 01020 virtual bool insertNode (const string& table, TeNode &node) = 0; 01021 virtual bool updateNode (const string& table, TeNode &node); 01023 01028 // Accessing/Inserting cell geometries into the database 01029 virtual bool insertCellSet (const string& table, TeCellSet &cs); 01030 virtual bool updateCellSet (const string& table, TeCellSet &cs); 01031 virtual bool loadCellSet (const int& layerId, const string& table, const string& geoid, TeCellSet &cs); 01032 virtual bool selectCellSet (const int& layerId, const string& table, const string& criteria, TeCellSet &cs); 01033 01034 virtual bool insertCell (const string& table, TeCell &c) = 0; 01035 virtual bool updateCell (const string& table, TeCell &c); 01036 virtual bool locateCell (const string& table, TeCoord2D &pt, TeCell &c, const double& tol = 0.0); 01038 01040 virtual bool removeGeometry(const string& tableName, const TeGeomRep& rep, const int& geomId); 01041 01043 01054 virtual bool insertRasterBlock(const string& table, const string& blockId, const TeCoord2D& ll, const TeCoord2D& ur, unsigned char *buf,unsigned long size, int band=0, unsigned int res=1, unsigned int subband=0) = 0; 01055 01057 virtual bool insertVisual (TeLegendEntry *legend); 01058 01060 virtual bool insertRasterVisual (int themeId , TeRasterVisual* rasterVisual); 01061 01063 virtual TeRaster* loadLayerRaster(int layerId, const string& objectId="", const char& mode = 'r'); 01064 01066 virtual bool createLUTTable(const string& name); 01067 01069 virtual bool loadRasterLUT(TeRasterParams* par); 01070 01072 virtual bool createSpatialIndex(const string& table, const string& columns, TeSpatialIndexType /*type*/ = TeRTREE,short /* level */ =0,short /* tile */ =0); 01073 01075 virtual bool insertMetadata(const string& /* table */, const string& /* column */, double /* tolx */, double /* toly */,TeBox &/* box */,short /* srid */ =0) { return true; }; 01076 01078 virtual string getSpatialIdxColumn(TeGeomRep rep); 01079 01081 /* 01082 This method gives to the drivers the ability to update box columns, considering precision issues 01083 that are particular to the driver. The box should be stored in 4 columns (lower_x, lower_y, upper_x, upper_y) 01084 \param tableName table name 01085 \param keyColumnName name of the column that is primary key 01086 \param idValue key value of the row that should be updated 01087 \param box new box value 01088 */ 01089 virtual bool updateBBox(const string& tableName, const string& keyColumnName, int keyValue, const TeBox& box); 01090 01091 01096 01110 virtual bool spatialRelation(const string& actGeomTable, TeGeomRep actRep, TeKeys& actIdsIn, 01111 TeDatabasePortal *portal, int relate, const string& actCollTable=""); 01112 01124 virtual bool spatialRelation(const string& actGeomTable, TeGeomRep actRep, TeKeys& actIdsIn, 01125 const string& visGeomTable, TeGeomRep visRep, TeDatabasePortal *portal, 01126 int relate, const string& visCollTable=""); 01127 01137 virtual bool spatialRelation(const string& actGeomTable, TeGeomRep actRep, TeGeometry* geom, 01138 TeDatabasePortal *portal, int relate, const string& actCollTable=""); 01139 01149 virtual bool spatialRelation(const string& actGeomTable, TeGeomRep actRep, TeKeys& actIdsIn, 01150 TeKeys& actIdsOut, int relate, const string& actCollTable=""); 01151 01163 virtual bool spatialRelation(const string& actGeomTable, TeGeomRep actRep, TeKeys& actIdsIn, 01164 const string& visGeomTable, TeGeomRep visRep, TeKeys& visIdsOut, int relate, 01165 const string& visCollTable="", TeDatabase* = 0); 01166 01176 virtual bool spatialRelation(const string& actGeomTable, TeGeomRep actRep, TeGeometry* geom, 01177 TeKeys& actIdsOut, int relate, const string& actCollTable=""); 01179 01191 virtual bool calculateArea(const string& actGeomTable, TeGeomRep actRep, TeKeys& actIdsIn, double &area); 01192 01200 virtual bool calculateLength(const string& actGeomTable, TeGeomRep actRep, TeKeys& actIdsIn, double &length); 01201 01209 virtual bool calculateDistance(const string& actGeomTable, TeGeomRep actRep, TeKeys& Ids, double& distance); 01210 01221 virtual bool calculateDistance(const string& actGeomTable, TeGeomRep actRep, const string& objId1, 01222 const string& visGeomTable, TeGeomRep visRep, const string& objId2, double& distance); 01223 01233 virtual bool withinDistance(const string& actGeomTable, TeGeomRep actRep, const TeCoord2D& point, 01234 TeKeysToDist& IdsDistOut, const double& max_distance, const string& actCollTable=""); 01236 01237 01250 virtual bool buffer(const string& actGeomTable, TeGeomRep actRep, TeKeys& actIds, TePolygonSet& bufferSet, double dist); 01251 01260 virtual bool centroid(const string& actGeomTable, TeGeomRep actRep, TePointSet& centroidSet, TeKeys actIds = vector<string>(), const string& actCollTable = ""); 01261 01269 virtual bool convexHull(const string& actGeomTable, TeGeomRep actRep, TeKeys& actIds, TePolygonSet& convexHullSet); 01271 01281 virtual bool nearestNeighbors(const string& actGeomTable, const string& actCollTable, 01282 TeGeomRep actRep, const string& objId1, TeKeys& actIdsOut, int numRes=1); 01283 01295 virtual bool nearestNeighbors(const string& actGeomTable, TeGeomRep actRep, const string& objId1, 01296 const string& visGeomTable, const string& visCollTable, 01297 TeGeomRep visRep, TeKeys& visIdsOut, int numRes=1); 01298 01308 virtual bool nearestNeighbors(const string& actGeomTable, const string& actCollTable, 01309 TeGeomRep actRep, const string& objId1, TeDatabasePortal* portal, int numRes=1); 01310 01322 virtual bool nearestNeighbors(const string& actGeomTable, TeGeomRep actRep, 01323 const string& objId1, const string& visGeomTable, const string& visCollTable, 01324 TeGeomRep visRep, TeDatabasePortal* portal, int numRes=1); 01325 01330 01338 virtual bool geomIntersection(const string& actGeomTable, TeGeomRep actRep, TeKeys& actIds, TeGeometryVect& geomVect); 01339 01350 virtual bool geomIntersection(const string& actGeomTable, TeGeomRep actRep, const string& objId1, 01351 const string& visGeomTable, TeGeomRep visRep, const string& objId2, TeGeometryVect& geomVect); 01352 01361 virtual bool geomDifference(const string& actGeomTable, TeGeomRep actRep, const string& objId1, 01362 const string& objId2, TeGeometryVect& geomVect); 01363 01374 virtual bool geomDifference(const string& actGeomTable, TeGeomRep actRep, const string& objId1, 01375 const string& visGeomTable, TeGeomRep visRep, const string& objId2, TeGeometryVect& geomVect); 01376 01384 virtual bool geomUnion(const string& actGeomTable, TeGeomRep actRep, TeKeys& actIds, TeGeometryVect& geomVect); 01385 01396 virtual bool geomUnion(const string& actGeomTable, TeGeomRep actRep, const string& objId1, 01397 const string& visGeomTable, TeGeomRep visRep, const string& objId2, TeGeometryVect& geomVect); 01398 01407 virtual bool geomXOr(const string& actGeomTable, TeGeomRep actRep, const string& objId1, 01408 const string& objId2, TeGeometryVect& geomVect); 01409 01420 virtual bool geomXOr(const string& actGeomTable, TeGeomRep actRep, const string& objId1, 01421 const string& visGeomTable, TeGeomRep visRep, const string& objId2, TeGeometryVect& geomVect); 01423 01435 virtual bool zonal(const string& rasterTable, const string& actGeomTable, TeKeys& Ids, TeObjectStatistics& result, const bool &useDummy=true); 01436 01444 virtual bool zonal(const string& rasterTable, const string& actGeomTable, const string& actCollTable, TeObjectStatistics& result, const bool &useDummy=true); 01445 01452 virtual bool zonal(const string& rasterTable, TePolygon& poly, TeStatisticsDimensionVect& result,const bool &useDummy=true); 01453 01462 virtual bool mask(const string& rasterTable, const string& actGeomTable, const string& objId, const string& nameLayerOut, TeStrategicIterator st); 01463 01471 virtual bool mask(const string& rasterTable, TePolygon& poly, const string& nameLayerOut, TeStrategicIterator st); 01473 01478 01479 virtual string getSQLBoxWhere (const TeBox& box, const TeGeomRep rep, const std::string& tableName); 01480 01482 virtual string getSQLBoxWhere(const TeBox& box, const TeGeomRep rep, const std::string& tableName, const std::string& columnName); 01483 01486 virtual string getSQLBoxWhere (const string& table1, const string& table2, TeGeomRep rep2, TeGeomRep rep1 = TePOLYGONS); 01487 01489 virtual string getSQLBoxSelect (const string& tableName, TeGeomRep rep); 01490 01492 virtual std::string getSQLOrderBy(const TeGeomRep& rep) const; 01493 01495 virtual string getSQLStatistics (TeGroupingAttr& attrs); 01496 01498 virtual string getSQLAutoNumber(const string& table); 01499 01501 virtual string getSQLTemporalWhere (TeTimeInterval& /* timeInterval */, TeTemporalRelation /* timeOperator */, const string& /* initialTime */, const string& /* finalTime */ ); 01502 01504 virtual string getSQLTemporalWhere (const string& temporalRest); 01505 01507 virtual string getSQLTemporalWhere(int /* time1 */, int /* time2 */, TeChronon /* chr */, TeTemporalRelation /* rel */, const string& /* initialTime */, const string& /* finalTime */); 01508 01510 virtual string getSQLTime(const TeTime& /* time */) const { return ""; }; 01511 01513 virtual string getSQLTemporalFunction (TeChronon chr, const string& colName); 01515 01517 virtual bool getMBRGeom(string tableGeom, string object_id, TeBox& box, string colGeom); 01518 01520 virtual bool getMBRSelectedObjects(string geomTable,string colGeom, string fromClause, 01521 string whereClause, string afterWhereClause, TeGeomRep repType,TeBox &bout, const double& tol = 0.0); 01522 01524 virtual bool getAttributeList(const string& tableName,TeAttributeList& attList); 01525 01527 virtual string escapeSequence(const string& from) = 0; 01528 01530 virtual TeBox getThemeBox(TeTheme* theme); 01531 01533 map<int, map<string, string> >& mapThemeAlias() {return metaModel_->mapThemeAlias();} 01534 01536 virtual string concatValues(vector<string>& values, const string& unionString) = 0; 01537 01539 virtual string toUpper(const string& value) = 0; 01540 01542 virtual string leftString(const string& /*name*/, const int& /*length*/){return "";} 01543 01545 virtual bool updateVersionStamp(const string& version ); 01546 01548 virtual bool loadVersionStamp( string& version ); 01549 01555 01556 virtual bool beginTransaction(); 01557 01559 virtual bool commitTransaction(); 01560 01562 virtual bool rollbackTransaction(); 01564 01566 virtual bool dropDBView(const string& dbViewName); 01567 01569 virtual std::string getClientEncoding() 01570 { return ""; } 01571 01573 virtual bool setClientEncoding(const std::string& /*characterSet*/) 01574 { return true; } 01575 01577 virtual bool getEncodingList(std::vector<std::string>& /*vecEncodingList*/) 01578 { return true; } 01579 01581 virtual bool getEncodingList(const std::string& /*host*/, const std::string& /*user*/, const std::string& /*password*/, const int& /*port*/, std::vector<std::string>& /*vecEncodingList*/) 01582 { return true; } 01583 01584 01585 protected : 01586 01587 bool isConnected_; 01588 std::string host_; 01589 std::string user_; 01590 std::string password_; 01591 std::string database_; 01592 int portNumber_; 01593 int errorNumber_; 01594 std::string errorMessage_; 01595 std::string dbmsName_; 01596 TeSharedPtr<TeMetaModelCache> metaModel_; 01597 01599 void alterTableInfoInMemory(const string& updatedTableName, string oldTableName=""); 01600 01601 int transactionCounter_; 01602 01603 private: 01604 01605 TeDatabase(const TeDatabase& other); 01606 }; 01607 01609 01614 class TL_DLL TeDatabasePortal { 01615 protected: 01616 01617 01618 TeDatabase* db_; 01619 TeAttributeList attList_; 01620 int numRows_; 01621 int numFields_; 01622 string errorMessage_; 01623 int errorNumber_; 01624 01625 public : 01626 01628 TeDatabasePortal (); 01629 01631 virtual ~TeDatabasePortal (); 01632 01634 TeDatabase* getDatabase() 01635 { return db_; } 01636 01638 virtual bool query ( const string &qry, TeCursorLocation l = TeSERVERSIDE, TeCursorType t = TeUNIDIRECTIONAL, TeCursorEditType e = TeREADONLY, TeCursorDataType dt = TeTEXTCURSOR ) = 0; 01639 01641 virtual bool fetchRow () = 0; 01642 01644 virtual bool fetchRow (int i) = 0; 01645 01647 virtual void freeResult () = 0; 01648 01650 virtual string errorMessage () 01651 { return errorMessage_; } 01652 01654 virtual int errorNum () 01655 { return errorNumber_; } 01656 01657 // virtual bool loadNetwork (TeLayer *layer) = 0; 01658 01659 // specific SQL SELECT command methods 01660 01666 int numRows () 01667 { return numRows_;} 01668 01670 int numFields () 01671 { return numFields_; } 01672 01674 TeAttributeList& getAttributeList() 01675 { return attList_; } 01676 01678 TeAttribute getAttribute (int i); 01679 01681 TeAttribute getAttribute (const string& s); 01682 01684 virtual char* getData (int i) = 0; 01685 01687 virtual char* getData (const string& s) = 0; 01688 01690 virtual double getDouble (int i); 01691 01693 virtual double getDouble (const string& s); 01694 01696 virtual int getInt (int i); 01697 01699 virtual int getInt (const string& s); 01700 01702 virtual bool getBool (const string& s) = 0; 01703 01705 virtual bool getBool (int i) = 0; 01706 01708 virtual TeTime getDate (int i) = 0; 01709 01711 virtual TeTime getDate (const string& s) = 0; 01712 01714 virtual string getDateAsString(int i) = 0; 01715 01717 virtual string getDateAsString(const string& s) = 0; 01718 01720 virtual bool getBlob(const string& s, unsigned char* &data, long& size) = 0; 01721 01723 int getColumnIndex (const string& s); 01724 01726 string getColumnName (int i); 01727 01733 virtual TeViewTree* getViewTree (); 01734 virtual TeLegendEntry getLegend(); 01735 virtual void getVisual(TeVisual*); 01736 virtual bool getVisual(TeVisual* vis, TeGeomRep& rep, const unsigned int& initIndex); 01737 virtual bool getRasterVisual(TeRasterVisual& vis, const unsigned int& initIndex=0); 01738 virtual TeColor getColor(); 01739 virtual bool getRasterBlock(unsigned long& size, unsigned char* ptData)=0; 01740 virtual bool getView(TeView& view, const unsigned int& initIndex=0); 01741 virtual void getDatum(TeDatum& datum, const unsigned int& initIndex=0); 01742 virtual bool getProjection(TeProjection** proj, const unsigned int& initIndex=0); 01743 virtual void getViewNodeParams (TeViewNodeParams& params, const unsigned int& initIndex=0); 01744 virtual bool getTheme(TeAbstractTheme& theme, const unsigned int& initIndex=0); 01745 virtual bool getGrouping(TeGrouping& group, const unsigned int& initIndex=0); 01746 virtual bool getLegend(TeLegendEntry& leg, const unsigned int& initIndex=0); 01747 virtual bool getAttrTable(TeTable& table, const unsigned int& initIndex=0); 01748 virtual bool getLayer(TeLayer& layer, const unsigned int& initIndex=0); 01749 virtual bool getRepresentation(TeRepresentation& rep, const unsigned int& initIndex=0); 01750 01752 01762 virtual bool fetchGeometry (TePolygon& geom) = 0; 01763 virtual bool fetchGeometry (TePolygon& geom, const unsigned int& initIndex); 01764 virtual bool fetchGeometry (TeLine2D& geom) = 0; 01765 virtual bool fetchGeometry (TeLine2D& geom, const unsigned int& initIndex); 01766 virtual bool fetchGeometry (TeNode& geom) = 0; 01767 virtual bool fetchGeometry (TeNode& geom, const unsigned int& initIndex); 01768 virtual bool fetchGeometry (TePoint& geom) = 0; 01769 virtual bool fetchGeometry (TePoint& geom, const unsigned int& initIndex); 01770 virtual bool fetchGeometry (TeCell& geom); 01771 virtual bool fetchGeometry (TeCell& geom, const unsigned int& initIndex); 01772 virtual bool fetchGeometry (TeArc& geom); 01773 virtual bool fetchGeometry (TeArc& geom, const unsigned int& initIndex); 01774 virtual bool fetchGeometry (TeText& geom); 01775 virtual bool fetchGeometry (TeText& geom, const unsigned int& initIndex); 01777 }; 01778 01779 01781 /* 01782 \params begin Iterator that p oints to the beginning of the collection 01783 \params end Iterator that points to the end of the collection 01784 \param db pointer to the database where the query expression will be applied 01785 \param addPlicae flat to indicate that the character ' should enclose each string 01786 */ 01787 template <typename Iterator> 01788 vector<string> 01789 generateInClauses(const Iterator& begin, const Iterator& end, TeDatabase* db, bool addPlicae=true) 01790 { 01791 int i, chunkSize = 200; 01792 string inClause; 01793 vector<string> inClauseVector; 01794 01795 Iterator temp = begin; 01796 i = 0; 01797 while (temp != end) 01798 { 01799 if (i%chunkSize == 0) 01800 { 01801 if (!inClause.empty()) 01802 { 01803 inClause[inClause.size() - 1] = ')'; 01804 inClauseVector.push_back(inClause); 01805 inClause.clear(); 01806 } 01807 inClause = "("; 01808 } 01809 01810 if (addPlicae) 01811 inClause += "'" + db->escapeSequence(*temp) + "',"; 01812 else 01813 inClause += db->escapeSequence(*temp) + ","; 01814 i++; 01815 ++temp; 01816 } 01817 if (!inClause.empty()) 01818 { 01819 inClause[inClause.size() - 1] = ')'; 01820 inClauseVector.push_back(inClause); 01821 } 01822 return inClauseVector; 01823 } 01824 01825 01848 #endif 01849