Fire Core  8.0.0.alpha
GIS framework per tutti gli usi
 Tutto Classi Namespace Funzioni Variabili Ridefinizioni di tipo (typedef) Tipi enumerati (enum) Valori del tipo enumerato Friend
ConnectionQtSql.hpp
1 // Copyright 2015 GEOSYSTEMS SRL
2 // All Rights Reserved.
3 
4 #ifndef FIRE_CONNECTION_QT_CONNECTIONQTSQL_HPP_INCLUDED
5 #define FIRE_CONNECTION_QT_CONNECTIONQTSQL_HPP_INCLUDED
6 
7 #include <QtSql/QSqlError>
8 #include <QtSql/QSqlQuery>
9 #include <boost/thread.hpp>
10 #include <QtCore/QByteArray>
11 #include <QtSql/QSqlDatabase>
12 #include <fire/logging/Logger.hpp>
13 #include <boost/thread/mutex.hpp>
14 #include <fire/source/vector/Metadata.hpp>
15 #include <boost/thread/condition_variable.hpp>
16 #include <fire/gear/geom/shared/EnvelopeSh.hpp>
17 #include <fire/source/vector/shared/MetadataSh.hpp>
18 
19 #include <string>
20 #include <exception>
21 
22 #include "fire/source/vector/ConnectionSpatialDb.hpp"
23 
24 namespace fire {
25 namespace connection {
26 namespace qt {
27 
28 namespace shared {
29 class ConnectionQtSqlSh;
30 } // namespace shared
31 
36  public:
38 
45  static void qtToVal(source::vector::DataValue::DataValueShp& data, QVariant const & val, const std::string& poolName);
46 
52  static QVariant valToQt(const source::vector::DataValue::DataValueShp& val);
53 
59 
63  virtual ~ConnectionQtSql();
64 
65  virtual void beginTransaction();
66  virtual void commitTransaction();
67  virtual void rollbackTransaction();
68 
69  virtual bool isValid() const;
70  virtual source::Features const getFeatures() const;
71  virtual LayerList getLayers() const;
72  virtual source::vector::VectorLayerInfo::VectorLayerInfoShp getLayerInfo(std::string const & name) const;
73  virtual source::vector::DataSet::DataSetShp const getData(const std::string &schema, std::string const & tbl) const;
74  virtual source::vector::DataSet::DataSetShp getData(const std::string &schema, std::string const & tbl);
75  virtual source::vector::DataSet::DataSetShp const getData(const std::string &schema, std::string const & tbl, gear::geom::Envelope::EnvelopeShp const & rect) const;
76  virtual source::vector::DataSet::DataSetShp getData(const std::string &schema, std::string const & tbl, const gear::geom::Envelope::EnvelopeShp &rect);
79  virtual void execUpdate(std::string const & sql, const source::vector::DataRow::MapSqlParam &params);
81  virtual source::vector::VectorLayerInfo::VectorLayerInfoShp createTable(const source::vector::Metadata::MetadataShp & mtd, const source::vector::VectorLayerInfo::VctEnvelope& extents);
82 
83  virtual gear::geom::Geometry* buff2Geom(const QByteArray& buff) const;
84  size_t getCount(const std::string & name, const std::string & schema) const;
85  int getSrid(const std::string & name, const std::string & schema, const std::string & geom) const;
86  virtual source::vector::Metadata::MetadataShp buildMetadata(const std::string & tblName, const std::string & schemaName) const;
87  source::vector::Metadata::MetadataShp buildMetadata(const std::string & sql, const source::vector::DataRow::MapSqlParam &prams) const;
88  gear::geom::Envelope::EnvelopeShp getExtent(const std::string & tblName, const std::string & schemaName, const std::string & geomFld) const;
89 
90  protected:
91  virtual void _openNoWait();
92  virtual void _closeNoWait();
93  virtual bool _isOpenNoWait() const;
94 
95  virtual std::string const _getTestSql() const = 0;
96  virtual std::string const _getQtDriverName() const = 0;
97  virtual bool _isGeometryNativeType(const int &id) const = 0;
98  virtual bool _isGeographyNativeType(const int &id) const = 0;
99  virtual void _configureDb(ConnectionParams const & pramas);
100  virtual void _configureDbNoWait(ConnectionParams const & pramas);
101  virtual std::string const _getBuff2GeomSql(const bool& useWkb) const = 0;
102  virtual std::string const _getLayersSql(const std::string & schema, const std::string & tbl) const = 0;
103  virtual std::string _getSridSql(const std::string & tblName, const std::string & schemaName, const std::string & geomFld) const = 0;
104  virtual std::string const _getLayerExtentSql(const std::string & tblName, const std::string & schemaName, const std::string & geomFld) const = 0;
105 
106  // sezione da spostare sul QueryBuilder
107  virtual const std::string _getCreationFieldSql(const source::vector::Field::FieldShp& fld) const = 0;
108  virtual const std::string _getSpatialIndexCreationSql(const std::string& schema, const std::string& tbl, const source::vector::Field::FieldShp& fld) const = 0;
109  virtual const std::string _getCatalogInsertSql(const std::string &schema, const std::string& tbl, const source::vector::Field::FieldShp& fld, const gear::geom::Envelope::EnvelopeShp& extent) const = 0;
110  virtual const std::string _getPkSql(const std::string& tbl, const source::vector::Metadata::MetadataShp& mtd) const = 0;
111  // end
112 
113  QVariant _valToQt(const source::vector::DataValue::DataValueShp& val) const;
114  std::string const _getConnectionIdNoWait(ConnectionParams const & cnnParams) const;
115  source::vector::Metadata::MetadataShp _buildMetadata(const std::string & sql, const source::vector::DataRow::MapSqlParam &prams) const;
116  QSqlDatabase _getQtDbNoWait(std::string const & name, const bool &verify = true) const;
117  source::vector::Metadata::MetadataShp _recordToMetadataNoWait(QSqlRecord const & rec) const;
118  int _getSridNoWait(const std::string & name, const std::string & schema, const std::string &geom) const;
119  QSqlQuery _execQueryNoWait(std::string const & sql, const std::string & dbName, const source::vector::DataRow::MapSqlParam& params = source::vector::DataRow::MapSqlParam()) const;
120  source::vector::DataSet::DataSetShp _execQueryNoWait(std::string const & sql, const std::string & tbl, const std::string & schema, const std::string & dbName, const source::vector::DataRow::MapSqlParam& params = source::vector::DataRow::MapSqlParam()) const;
121 
122  std::string _dbName;
123  std::string _defaultSchema;
124 };
125 
126 } // namespace qt
127 } // namespace connection
128 } // namespace fire
129 
130 #endif
Definition: DataSetSh.hpp:21
virtual void rollbackTransaction()
Effettua il rollback della transazione corrente.
Specializzazione per connessioni vettoriali su db con supporto spaziale.
Definition: ConnectionSpatialDb.hpp:27
Definition: EnvelopeSh.hpp:18
Oggetto che consente di verificare la presenza di specifiche funzionalità sull'implementazione di una...
Definition: Features.hpp:21
virtual source::Features const getFeatures() const
Restituisce un oggetto indicante le caratteristiche supportate da questa connessione.
ConnectionQtSql()
Costruttore ConnectionQtSql.
static void qtToVal(source::vector::DataValue::DataValueShp &data, QVariant const &val, const std::string &poolName)
Metodo statico che valorizza un DataValue.
Definition: ConnectionQtSqlSh.hpp:21
Definition: FieldSh.hpp:21
virtual void execUpdate(std::string const &sql, const source::vector::DataRow::MapSqlParam &params)
Esegue una interrogazione di modifica (INSERIMENTO, MODIFICA O CANCELLAZIONE) sul contenitore dei dat...
std::map< std::string, DataValue::DataValueShp > MapSqlParam
Mappa di parametri usata per query SQL parametriche.
Definition: DataRow.hpp:47
virtual void commitTransaction()
Persiste sul DB la transazione corrente.
Implementazione Connection per l'accesso a banche dati spaziali basato su QtSql.
Definition: ConnectionQtSql.hpp:35
Definition: MetadataSh.hpp:22
virtual source::vector::VectorLayerInfo::VectorLayerInfoShp getLayerInfo(std::string const &name) const
Estrae le informazioni relative ad un contenitore di dati vettoriali.
Definition: Geometry.hpp:69
virtual source::vector::DataSet::DataSetShp const execQuery(std::string const &sql, const source::vector::DataRow::MapSqlParam &params=source::vector::DataRow::MapSqlParam()) const
Esegue una interrogazione restituendo un cursore sui dati.
static QVariant valToQt(const source::vector::DataValue::DataValueShp &val)
Trasforma il valore in un Variant.
virtual source::vector::VectorLayerInfo::VectorLayerInfoShp createTable(const source::vector::Metadata::MetadataShp &mtd, const source::vector::VectorLayerInfo::VctEnvelope &extents)
crea una nuova tabella geografica sulla sorgente dati allineando il catalogo spaziale ...
virtual ~ConnectionQtSql()
Distruttore connessione.
virtual source::vector::DataSet::DataSetShp const getData(const std::string &schema, std::string const &tbl) const
Interroga il livello tematico restituendo un cursore sui dati in sola lettura.
virtual void execUpdate(std::string const &query)
Esegue una interrogazione di modifica (INSERIMENTO, MODIFICA O CANCELLAZIONE) sul contenitore dei dat...
virtual LayerList getLayers() const
Restituisce la lista degli identificativi testuali dei livelli tematici presenti nella connessione...
virtual void beginTransaction()
Avvia una transazione sul DB.
Definition: DataValueSh.hpp:24
virtual bool isValid() const
Indica se la connessione risulta operativa.
Definition: VectorLayerInfoSh.hpp:23