src/terralib/terralib4/Transactor.cpp
Go to the documentation of this file.
1 /* Copyright (C) 2008 National Institute For Space Research (INPE) - Brazil.
2 
3  This file is part of the TerraLib - a Framework for building GIS enabled applications.
4 
5  TerraLib is free software: you can redistribute it and/or modify
6  it under the terms of the GNU Lesser General Public License as published by
7  the Free Software Foundation, either version 3 of the License,
8  or (at your option) any later version.
9 
10  TerraLib is distributed in the hope that it will be useful,
11  but WITHOUT ANY WARRANTY; without even the implied warranty of
12  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13  GNU Lesser General Public License for more details.
14 
15  You should have received a copy of the GNU Lesser General Public License
16  along with TerraLib. See COPYING. If not, write to
17  TerraLib Team at <terralib-team@terralib.org>.
18  */
19 
20 /*!
21  \file terralib/terralib4/Transactor.cpp
22 
23  \brief DataSourceTransactor implementation for TerraLib 4.x API.
24 */
25 
26 // TerraLib
27 #include "../common/StringUtils.h"
28 #include "../core/translator/Translator.h"
29 #include "../dataaccess/dataset/CheckConstraint.h"
30 #include "../dataaccess/dataset/DataSet.h"
31 #include "../dataaccess/dataset/ForeignKey.h"
32 #include "../dataaccess/dataset/Index.h"
33 #include "../dataaccess/dataset/ObjectIdSet.h"
34 #include "../dataaccess/dataset/PrimaryKey.h"
35 #include "../dataaccess/dataset/Sequence.h"
36 #include "../dataaccess/dataset/UniqueKey.h"
37 #include "../dataaccess/datasource/DataSourceCatalog.h"
38 #include "../dataaccess/datasource/ScopedTransaction.h"
39 #include "../dataaccess/query/Select.h"
40 #include "../dataaccess/query/SQLDialect.h"
41 #include "../dataaccess/utils/Utils.h"
42 #include "../datatype/Array.h"
43 #include "../datatype/Date.h"
44 #include "../datatype/DateTimeProperty.h"
45 #include "../datatype/Property.h"
46 #include "../datatype/SimpleData.h"
47 #include "../datatype/StringProperty.h"
48 #include "../geometry/Envelope.h"
49 #include "../geometry/GeometryProperty.h"
50 #include "../geometry/Utils.h"
51 #include "../geometry/Geometry.h"
52 #include "../memory/DataSet.h"
53 #include "../raster/RasterProperty.h"
54 #include "VectorDataSet.h"
55 #include "DataSource.h"
56 #include "Exception.h"
57 #include "Globals.h"
58 #include "RasterDataSet.h"
59 #include "TableDataSet.h"
60 #include "ThemeInfo.h"
61 #include "Transactor.h"
62 #include "Utils.h"
63 
64 // Terralib 4.x
65 #include <terralib4/kernel/TeDatabase.h>
66 #include <terralib4/kernel/TeLayer.h>
67 #include <terralib4/kernel/TeTable.h>
68 #include <terralib4/kernel/TeTheme.h>
69 #include <terralib4/kernel/TeRasterTransform.h>
70 #include <terralib4/kernel/TeVisual.h>
71 
72 // STL
73 #include <cassert>
74 //#include <cstring>
75 #include <memory>
76 #include <iostream>
77 
78 // Boost
79 //#include <boost/algorithm/string/case_conv.hpp>
80 #include <boost/format.hpp>
81 #include <boost/lexical_cast.hpp>
82 //#include <boost/thread.hpp>
83 
84 int getViewId(const std::string& viewName, TeViewMap& viewMap)
85 {
86  std::map<int, TeView*>::iterator it = viewMap.begin();
87 
88  while(it != viewMap.end())
89  {
90  std::string viewNameUtf8 = terralib4::Convert2Utf8(it->second->name());
91 
92  if (viewNameUtf8 == viewName)
93  return it->second->id();
94 
95  ++it;
96  }
97 
98  return -1;
99 }
100 
102  : m_ds(ds),
103  m_db(db),
104  m_isInTransaction(false),
105  m_layerMap(m_db->layerMap()),
106  m_viewMap(m_db->viewMap()),
107  m_themeMap(m_db->themeMap())
108 {
109 }
110 
112 {
113 }
114 
116 {
117  return m_ds;
118 }
119 
121 {
122  m_db->beginTransaction();
123  m_isInTransaction = true;
124 }
125 
127 {
128  m_db->commitTransaction();
129  m_isInTransaction = false;
130 }
131 
133 {
134  m_db->rollbackTransaction();
135  m_isInTransaction = false;
136 }
137 
139 {
140  return m_isInTransaction;
141 }
142 
143 std::unique_ptr<te::da::DataSet> terralib4::Transactor::getDataSet(const std::string& name,
144  te::common::TraverseType /*travType*/,
145  bool /*connected*/,
146  const te::common::AccessPolicy /*accessPolicy*/)
147 {
148  TeLayer* layer = 0;
149 
150  std::string nameLatin1 = terralib4::Convert2Latin1(name);
151 
152  if (m_db->layerExist(nameLatin1))
153  {
154  std::map<int, TeLayer*>::iterator it = m_layerMap.begin();
155 
156  while(it != m_layerMap.end())
157  {
158  if (it->second->name() == nameLatin1)
159  {
160  layer = it->second;
161  break;
162  }
163  ++it;
164  }
165 
166  if(layer->hasGeometry(TeRASTER))
167  {
168  return std::unique_ptr<te::da::DataSet>(new RasterDataSet(layer->raster()));
169  }
170  else
171  return std::unique_ptr<te::da::DataSet>(new VectorDataSet(layer));
172  }
173  else
174  {
175  TeAttrTableVector tables;
176  m_db->getAttrTables(tables);
177 
178  TeTable table;
179 
180  for(std::size_t i = 0; i < tables.size(); ++i)
181  {
182  if(tables[i].tableType() == TeAttrExternal && tables[i].name() == nameLatin1)
183  {
184  table = tables[i];
185  break;
186  }
187  }
188 
189 
190  return std::unique_ptr<te::da::DataSet>(new TableDataSet(m_db, table));
191  }
192 }
193 
194 std::unique_ptr<te::da::DataSet> terralib4::Transactor::getDataSet(const std::string&,
195  const std::string&,
196  const te::gm::Envelope*,
199  bool,
201 {
202  throw Exception(TE_TR("This method is not supported by TerraLib 4.x driver!"));
203 }
204 
205 std::unique_ptr<te::da::DataSet> terralib4::Transactor::getDataSet(const std::string&,
206  const std::string&,
207  const te::gm::Geometry*,
210  bool,
212 {
213  throw Exception(TE_TR("This method is not supported by TerraLib 4.x driver!"));
214 }
215 
216 std::unique_ptr<te::da::DataSet> terralib4::Transactor::getDataSet(const std::string&,
217  const ObjectIdSet*,
219  bool,
221 {
222  throw Exception(TE_TR("This method is not supported by TerraLib 4.x driver!"));
223 }
224 
225 
226 
227 std::unique_ptr<te::da::DataSet> terralib4::Transactor::query(const te::da::Select& /*q*/,
228  te::common::TraverseType /*travType*/,
229  bool /*connected*/,
230  const te::common::AccessPolicy /*accessPolicy*/)
231 {
232  throw Exception(TE_TR("TerraLib 4.x driver doesn't support queries!"));
233 }
234 
235 std::unique_ptr<te::da::DataSet> terralib4::Transactor::query(const std::string& /*query*/,
236  te::common::TraverseType /*travType*/,
237  bool /*connected*/,
238  const te::common::AccessPolicy /*accessPolicy*/)
239 {
240  throw Exception(TE_TR("TerraLib 4.x driver doesn't support queries!"));
241 }
242 
244 {
245  throw Exception(TE_TR("TerraLib 4.x driver doesn't support command execution!"));
246 }
247 
248 void terralib4::Transactor::execute(const std::string& /*command*/)
249 {
250  throw Exception(TE_TR("TerraLib 4.x driver doesn't support command execution!"));
251 }
252 
253 std::unique_ptr<te::da::PreparedQuery> terralib4::Transactor::getPrepared(const std::string&)
254 {
255  throw Exception(TE_TR("TerraLib 4.x driver doesn't support prepared queries!"));
256 }
257 
258 std::unique_ptr<te::da::BatchExecutor> terralib4::Transactor::getBatchExecutor()
259 {
260  throw Exception(TE_TR("TerraLib 4.x driver doesn't support prepared batch executors!"));
261 }
262 
264 {
265 }
266 
268 {
269  throw Exception(TE_TR("TerraLib 4.x driver is read-only!"));
270 }
271 
272 std::string terralib4::Transactor::escape(const std::string&)
273 {
274  throw Exception(TE_TR("This method is not supported by TerraLib 4.x driver!"));
275 }
276 
277 bool terralib4::Transactor::isDataSetNameValid(const std::string& /*datasetName*/)
278 {
279  throw Exception(TE_TR("TerraLib 4.x driver is read-only!"));
280 }
281 
282 bool terralib4::Transactor::isPropertyNameValid(const std::string& /*propertyName*/)
283 {
284  throw Exception(TE_TR("TerraLib 4.x driver is read-only!"));
285 }
286 
287 std::vector<std::string> terralib4::Transactor::getDataSetNames()
288 {
289  std::map<int, TeLayer*>::iterator it = m_layerMap.begin();
290 
291  std::vector<std::string> dataSets;
292 
293  while(it != m_layerMap.end())
294  {
295  std::string layerNameUtf8 = terralib4::Convert2Utf8(it->second->name());
296 
297  dataSets.push_back(layerNameUtf8);
298 
299  ++it;
300  }
301 
302  TeAttrTableVector tableVector;
303  m_db->getAttrTables(tableVector);
304 
305  for(std::size_t i = 0; i < tableVector.size(); ++i)
306  {
307  if (tableVector[i].tableType() == TeAttrExternal)
308  {
309  std::string tableNameUtf8 = terralib4::Convert2Utf8(tableVector[i].name());
310 
311  dataSets.push_back(tableNameUtf8);
312  }
313  }
314 
315  return dataSets;
316 }
317 
319 {
320  return getDataSetNames().size();
321 }
322 
323 std::unique_ptr<te::da::DataSetType> terralib4::Transactor::getDataSetType(const std::string& name)
324 {
325  TeLayer* layer = 0;
326 
327  std::string nameLatin1 = terralib4::Convert2Latin1(name);
328 
329  if (m_db->layerExist(nameLatin1))
330  {
331  std::map<int, TeLayer*>::iterator it = m_layerMap.begin();
332 
333  while(it != m_layerMap.end())
334  {
335  if (it->second->name() == nameLatin1)
336  {
337  layer = it->second;
338  break;
339  }
340  ++it;
341  }
342  }
343 
344  TeTable table;
345 
346  if(!layer)
347  {
348  TeAttrTableVector tables;
349  m_db->getAttrTables(tables);
350 
351  for(std::size_t i = 0; i < tables.size(); i++)
352  {
353  if (tables[i].tableType() == TeAttrExternal && nameLatin1 == tables[i].name())
354  {
355  table = tables[i];
356  break;
357  }
358  }
359  }
360  else
361  {
362 
363 // Is a layer
364 
365  if(layer->hasGeometry(TeRASTER))
366  {
367  std::string layerNameUtf8 = terralib4::Convert2Utf8(layer->name());
368 
369  std::unique_ptr<te::da::DataSetType> dst(new te::da::DataSetType(layerNameUtf8, 0));
370 
371  // TODO: handle rasters with multiple objectid!
372  te::rst::RasterProperty* prop = Convert2T5(layer->raster()->params());
373  dst->add(prop);
374  return dst;
375  }
376 
377  TeAttrTableVector tables;
378  layer->getAttrTables(tables);
379 
380  if (!tables.empty())
381  table = tables[0];
382  }
383 
384  std::unique_ptr<te::da::DataSetType> mainDst(terralib4::Convert2T5(table));
385 
386  std::string tableNameUtf8 = terralib4::Convert2Utf8(table.name());
387 
388  mainDst->setTitle(tableNameUtf8);
389 
390  std::vector<std::string> pkey;
391  table.primaryKeys(pkey);
392 
393  te::da::PrimaryKey* pk = 0;
394 
395  if(!pkey.empty())
396  {
397  pk = new te::da::PrimaryKey(tableNameUtf8 + "_pk", mainDst.get());
398 
399  std::vector<te::dt::Property*> pkProps;
400  for(std::size_t i = 0; i < pkey.size(); ++i)
401  {
402  te::dt::Property* p = mainDst->getProperty(pkey[i]);
403  pkProps.push_back(p);
404  }
405 
406  pk->setProperties(pkProps);
407  }
408  else
409  {
410  TeAttribute attLink;
411  table.attrLink(attLink);
412 
413  std::string attLinkNameUtf8 = terralib4::Convert2Utf8(attLink.rep_.name_);
414 
415  if (!attLinkNameUtf8.empty())
416  {
417  pk = new te::da::PrimaryKey(table.name() + "_pk", mainDst.get());
418 
419  te::dt::Property* p = mainDst->getProperty(attLinkNameUtf8);
420 
421  std::vector<te::dt::Property*> pkProps;
422  pkProps.push_back(p);
423 
424  pk->setProperties(pkProps);
425  }
426  }
427 
428  if(layer)
429  {
430  TeAttrTableVector tables;
431  layer->getAttrTables(tables);
432 
433  if(tables.size() > 1)
434  {
435  for(std::size_t i = 1; i < tables.size(); ++i)
436  {
437  TeTable table = tables[i];
438 
439  std::unique_ptr<te::da::DataSetType> dst(terralib4::Convert2T5(table));
440 
441  std::vector<te::dt::Property*> props = dst->getProperties();
442 
443  for(std::size_t j = 0; j < props.size(); ++j)
444  {
445  te::dt::Property* prop = props[j]->clone();
446  prop->setName(dst->getName() + "_" + prop->getName());
447 
448  mainDst->add(prop);
449  }
450  }
451  }
452 
453  TeRepresPointerVector vec = layer->vectRepres();
454 
455  if(!vec.empty())
456  {
457  int srid = layer->projection()->epsgCode();
458 
459  if(srid == 4979)
460  srid = 4326;
461 
462 
463  te::gm::GeometryProperty* geomProp = 0;
464 
465  if (vec.size() > 1)
466  {
467 
468  TeGeomRep geomRep;
469  for (std::size_t i = 0; i < vec.size(); ++i)
470  {
471  if (i == 0)
472  {
473  geomRep = vec[i]->geomRep_;
474  }
475  else
476  {
477  if (vec[i]->geomRep_ < geomRep)
478  geomRep = vec[i]->geomRep_;
479  }
480  }
481 
482  te::gm::GeomType geomType = GetCollection(geomRep);
483 
484  geomProp = new te::gm::GeometryProperty("spatial_data", srid, geomType);
485 
486  //geomProp = new te::gm::GeometryProperty("spatial_data", srid, te::gm::GeometryCollectionType);
487  }
488  else
489  {
490  TeGeomRep geomRep = vec[0]->geomRep_;
491 
492  te::gm::GeomType geomType = GetCollection(geomRep);
493 
494  geomProp = new te::gm::GeometryProperty("spatial_data", srid, geomType);
495  }
496 
497  mainDst->add(geomProp);
498  }
499  }
500 
501  return mainDst;
502 }
503 
504 boost::ptr_vector<te::dt::Property> terralib4::Transactor::getProperties(const std::string& datasetName)
505 {
506  std::unique_ptr<te::da::DataSetType> dt = getDataSetType(datasetName);
507 
508  std::vector<te::dt::Property*> dtProperties = dt->getProperties();
509 
510  boost::ptr_vector<te::dt::Property> properties;
511 
512  for(std::size_t i = 0; i < dtProperties.size(); ++i)
513  properties.push_back(dtProperties[i]->clone());
514 
515  return properties;
516 }
517 
518 std::unique_ptr<te::dt::Property> terralib4::Transactor::getProperty(const std::string& datasetName, const std::string& name)
519 {
520  if(!propertyExists(datasetName, name))
521  throw Exception((boost::format(TE_TR("The dataset \"%1%\" has no property with this name \"%2%\"!")) % datasetName % name).str());
522 
523  std::unique_ptr<te::da::DataSetType> dt(getDataSetType(datasetName));
524 
525  return std::unique_ptr<te::dt::Property>(dt->getProperty(name)->clone());
526 }
527 
528 std::unique_ptr<te::dt::Property> terralib4::Transactor::getProperty(const std::string& datasetName, std::size_t propertyPos)
529 {
530  std::unique_ptr<te::da::DataSetType> dt(getDataSetType(datasetName));
531 
532  assert(propertyPos < dt->size());
533 
534  return std::unique_ptr<te::dt::Property>(dt->getProperty(propertyPos)->clone());
535 }
536 
537 std::vector<std::string> terralib4::Transactor::getPropertyNames(const std::string& datasetName)
538 {
539  std::unique_ptr<te::da::DataSetType> dt(getDataSetType(datasetName));
540 
541  std::vector<std::string> pNames;
542 
543  std::size_t numProperties = dt->size();
544 
545  for(std::size_t i = 0; i < numProperties; ++i)
546  pNames.push_back(dt->getProperty(i)->getName());
547 
548  return pNames;
549 }
550 
551 std::size_t terralib4::Transactor::getNumberOfProperties(const std::string& datasetName)
552 {
553  std::unique_ptr<te::da::DataSetType> dt(getDataSetType(datasetName));
554 
555  return dt->size();
556 }
557 
558 bool terralib4::Transactor::propertyExists(const std::string& datasetName, const std::string& name)
559 {
560  std::unique_ptr<te::da::DataSetType> dt(getDataSetType(datasetName));
561 
562  std::vector<std::string> pNames = getPropertyNames(datasetName);
563 
564  if(std::find(pNames.begin(), pNames.end(), name) != pNames.end())
565  return true;
566 
567  return false;
568 }
569 
570 void terralib4::Transactor::addProperty(const std::string& datasetName, te::dt::Property* p)
571 {
572  std::string name = p->getName();
573  if(propertyExists(datasetName, name))
574  throw Exception((boost::format(TE_TR("The dataset already \"%1%\" has a property with this name \"%2%\"!")) % datasetName % name).str());
575 
576  std::string propertyNameLatin1 = terralib4::Convert2Latin1(name);
577 
578  TeAttributeRep newProperty;
579 
580  newProperty.name_ = propertyNameLatin1;
581 
582  if(p->getType() != te::dt::GEOMETRY_TYPE)
583  newProperty.type_ = terralib4::Convert2T4(p->getType());
584  else
585  {
586  te::gm::Geometry* geom = dynamic_cast<te::gm::Geometry*>(p);
587  newProperty.type_ = terralib4::Convert2T4GeomType(geom->getGeomTypeId());
588  }
589 
590  std::map<int, TeLayer*>::iterator it = m_layerMap.begin();
591 
592  TeLayer* layer = 0;
593 
594  while(it != m_layerMap.end())
595  {
596  std::string layerNameUtf8 = terralib4::Convert2Utf8(it->second->name());
597 
598  if (layerNameUtf8 == datasetName)
599  {
600  layer = it->second;
601  break;
602  }
603  ++it;
604  }
605 
606  TeAttrTableVector tables;
607  layer->getAttrTables(tables);
608  std::string tableNameUtf8 = terralib4::Convert2Utf8(tables[0].name());
609 
610  m_db->addColumn(tableNameUtf8, newProperty);
611 }
612 
613 void terralib4::Transactor::dropProperty(const std::string&, const std::string&)
614 {
615  throw;
616 }
617 
619  const std::string&,
620  const std::string&)
621 {
622  throw Exception(TE_TR("This method is not supported by TerraLib 4.x driver!"));
623 }
624 
625 std::unique_ptr<te::da::PrimaryKey> terralib4::Transactor::getPrimaryKey(const std::string& datasetName)
626 {
627  std::unique_ptr<te::da::DataSetType> dt(getDataSetType(datasetName));
628 
629  return std::unique_ptr<te::da::PrimaryKey>(static_cast<te::da::PrimaryKey*>(dt->getPrimaryKey()->clone()));
630 }
631 
632 bool terralib4::Transactor::primaryKeyExists(const std::string& datasetName, const std::string& name)
633 {
634  std::unique_ptr<te::da::DataSetType> dt(getDataSetType(datasetName));
635 
636  if(dt->getPrimaryKey()->getName() == name)
637  return true;
638 
639  return false;
640 }
641 
643 {
644  throw Exception(TE_TR("This method is not supported by TerraLib 4.x driver!"));
645 }
646 
648 {
649  throw Exception(TE_TR("This method is not supported by TerraLib 4.x driver!"));
650 }
651 
652 std::unique_ptr<te::da::ForeignKey> terralib4::Transactor::getForeignKey(const std::string&, const std::string&)
653 {
654  throw Exception(TE_TR("This method is not supported by TerraLib 4.x driver!"));
655 }
656 
657 std::vector<std::string> terralib4::Transactor::getForeignKeyNames(const std::string&)
658 {
659  throw Exception(TE_TR("This method is not supported by TerraLib 4.x driver!"));
660 }
661 
662 bool terralib4::Transactor::foreignKeyExists(const std::string&, const std::string&)
663 {
664  throw Exception(TE_TR("This method is not supported by TerraLib 4.x driver!"));
665 }
666 
668 {
669  throw Exception(TE_TR("This method is not supported by TerraLib 4.x driver!"));
670 }
671 
672 void terralib4::Transactor::dropForeignKey(const std::string&, const std::string&)
673 {
674  throw Exception(TE_TR("This method is not supported by TerraLib 4.x driver!"));
675 }
676 
677 std::unique_ptr<te::da::UniqueKey> terralib4::Transactor::getUniqueKey(const std::string&, const std::string&)
678 {
679  throw Exception(TE_TR("This method is not supported by TerraLib 4.x driver!"));
680 }
681 
682 std::vector<std::string> terralib4::Transactor::getUniqueKeyNames(const std::string&)
683 {
684  throw Exception(TE_TR("This method is not supported by TerraLib 4.x driver!"));
685 }
686 
687 bool terralib4::Transactor::uniqueKeyExists(const std::string&, const std::string&)
688 {
689  throw Exception(TE_TR("This method is not supported by TerraLib 4.x driver!"));
690 }
691 
693 {
694  throw Exception(TE_TR("This method is not supported by TerraLib 4.x driver!"));
695 }
696 
697 void terralib4::Transactor::dropUniqueKey(const std::string&, const std::string&)
698 {
699  throw Exception(TE_TR("This method is not supported by TerraLib 4.x driver!"));
700 }
701 
702 std::unique_ptr<te::da::CheckConstraint> terralib4::Transactor::getCheckConstraint(const std::string&, const std::string&)
703 {
704  throw Exception(TE_TR("This method is not supported by TerraLib 4.x driver!"));
705 }
706 
707 std::vector<std::string> terralib4::Transactor::getCheckConstraintNames(const std::string&)
708 {
709  throw Exception(TE_TR("This method is not supported by TerraLib 4.x driver!"));
710 }
711 
712 bool terralib4::Transactor::checkConstraintExists(const std::string&, const std::string&)
713 {
714  throw Exception(TE_TR("This method is not supported by TerraLib 4.x driver!"));
715 }
716 
718 {
719  throw Exception(TE_TR("This method is not supported by TerraLib 4.x driver!"));
720 }
721 
722 void terralib4::Transactor::dropCheckConstraint(const std::string&, const std::string&)
723 {
724  throw Exception(TE_TR("This method is not supported by TerraLib 4.x driver!"));
725 }
726 
727 std::unique_ptr<te::da::Index> terralib4::Transactor::getIndex(const std::string&, const std::string&)
728 {
729  throw Exception(TE_TR("This method is not supported by TerraLib 4.x driver!"));
730 }
731 
732 std::vector<std::string> terralib4::Transactor::getIndexNames(const std::string&)
733 {
734  throw Exception(TE_TR("This method is not supported by TerraLib 4.x driver!"));
735 }
736 
737 bool terralib4::Transactor::indexExists(const std::string&, const std::string&)
738 {
739  throw Exception(TE_TR("This method is not supported by TerraLib 4.x driver!"));
740 }
741 
743  const std::map<std::string, std::string>&)
744 {
745  throw Exception(TE_TR("This method is not supported by TerraLib 4.x driver!"));
746 }
747 
748 void terralib4::Transactor::dropIndex(const std::string&, const std::string&)
749 {
750  throw Exception(TE_TR("This method is not supported by TerraLib 4.x driver!"));
751 }
752 
753 std::unique_ptr<te::da::Sequence> terralib4::Transactor::getSequence(const std::string&)
754 {
755  throw Exception(TE_TR("This method is not supported by TerraLib 4.x driver!"));
756 }
757 
758 std::vector<std::string> terralib4::Transactor::getSequenceNames()
759 {
760  throw Exception(TE_TR("This method is not supported by TerraLib 4.x driver!"));
761 }
762 
764 {
765  throw Exception(TE_TR("This method is not supported by TerraLib 4.x driver!"));
766 }
767 
769 {
770  throw Exception(TE_TR("This method is not supported by TerraLib 4.x driver!"));
771 }
772 
773 void terralib4::Transactor::dropSequence(const std::string&)
774 {
775  throw Exception(TE_TR("This method is not supported by TerraLib 4.x driver!"));
776 }
777 
778 std::unique_ptr<te::gm::Envelope> terralib4::Transactor::getExtent(const std::string&,
779  const std::string&)
780 {
781  throw Exception(TE_TR("This method is not supported by TerraLib 4.x driver!"));
782 }
783 
784 std::unique_ptr<te::gm::Envelope> terralib4::Transactor::getExtent(const std::string&,
785  std::size_t)
786 {
787  throw Exception(TE_TR("This method is not supported by TerraLib 4.x driver!"));
788 }
789 
790 std::size_t terralib4::Transactor::getNumberOfItems(const std::string&)
791 {
792  throw Exception(TE_TR("This method is not supported by TerraLib 4.x driver!"));
793 }
794 
796 {
797  throw Exception(TE_TR("This method is not supported by TerraLib 4.x driver!"));
798 }
799 
800 bool terralib4::Transactor::dataSetExists(const std::string& name)
801 {
802  std::vector<std::string> names = getDataSetNames();
803 
804  for(std::size_t i = 0; i < names.size(); ++i)
805  if(names[i] == name)
806  return true;
807 
808  return false;
809 }
810 
811 void terralib4::Transactor::createDataSet(te::da::DataSetType*, const std::map<std::string, std::string>&)
812 {
813  throw Exception(TE_TR("This method is not supported by TerraLib 4.x driver!"));
814 }
815 
816 void terralib4::Transactor::cloneDataSet(const std::string&,
817  const std::string&,
818  const std::map<std::string, std::string>&)
819 {
820  throw Exception(TE_TR("This method is not supported by TerraLib 4.x driver!"));
821 }
822 
823 void terralib4::Transactor::dropDataSet(const std::string&)
824 {
825  throw Exception(TE_TR("This method is not supported by TerraLib 4.x driver!"));
826 }
827 
828 void terralib4::Transactor::renameDataSet(const std::string&, const std::string&)
829 {
830  throw Exception(TE_TR("This method is not supported by TerraLib 4.x driver!"));
831 }
832 
833 void terralib4::Transactor::add(const std::string&,
835  const std::map<std::string, std::string>&,
836  std::size_t,
837  bool)
838 {
839  throw Exception(TE_TR("This method is not supported by TerraLib 4.x driver!"));
840 }
841 
842 void terralib4::Transactor::remove(const std::string&, const te::da::ObjectIdSet*)
843 {
844  throw Exception(TE_TR("This method is not supported by TerraLib 4.x driver!"));
845 }
846 
847 void terralib4::Transactor::update(const std::string&,
849  const std::vector<std::size_t>&,
850  const te::da::ObjectIdSet*,
851  const std::map<std::string, std::string>&,
852  std::size_t)
853 {
854  throw Exception(TE_TR("This method is not supported by TerraLib 4.x driver!"));
855 }
856 
857 void terralib4::Transactor::optimize(const std::map<std::string, std::string>&)
858 {
859  throw Exception(TE_TR("This method is not supported by TerraLib 4.x driver!"));
860 }
861 
862 std::vector<std::string> terralib4::Transactor::getTL4Layers()
863 {
864  std::vector<std::string> layers;
865 
866  std::map<int, TeLayer*>::iterator it = m_layerMap.begin();
867 
868  while(it != m_layerMap.end())
869  {
870  if (!it->second->hasGeometry(TeRASTER) && !it->second->hasGeometry(TeRASTERFILE))
871  {
872  std::string strConverted = terralib4::Convert2Utf8(it->second->name());
873 
874  layers.push_back(strConverted);
875  }
876 
877  ++it;
878  }
879 
880  return layers;
881 }
882 
883 std::vector<std::string> terralib4::Transactor::getTL4Tables()
884 {
885  std::vector<std::string> tablesVec;
886 
887  TeAttrTableVector tables;
888  m_db->getAttrTables(tables, TeAttrExternal);
889 
890  for (std::size_t i = 0; i < tables.size(); i++)
891  {
892  std::string strConverted = terralib4::Convert2Utf8(tables[i].name());
893 
894  tablesVec.push_back(strConverted);
895  }
896 
897  return tablesVec;
898 }
899 
900 std::vector<std::string> terralib4::Transactor::getTL4Rasters()
901 {
902  std::vector<std::string> rasters;
903 
904  std::map<int, TeLayer*>::iterator it = m_layerMap.begin();
905 
906  while(it != m_layerMap.end())
907  {
908  if(it->second->hasGeometry(TeRASTER))
909  {
910  std::string strConverted = terralib4::Convert2Utf8(it->second->name());
911 
912  rasters.push_back(strConverted);
913  }
914  ++it;
915  }
916 
917  return rasters;
918 }
919 
920 std::vector<std::pair<std::string, std::string> > terralib4::Transactor::getTL4RasterFiles()
921 {
922  std::vector<std::pair<std::string, std::string> > rasters;
923 
924  std::map<int, TeLayer*>::iterator it = m_layerMap.begin();
925 
926  while (it != m_layerMap.end())
927  {
928  if (it->second->hasGeometry(TeRASTERFILE))
929  {
930  std::pair<std::string, std::string> pair;
931  pair.first = terralib4::Convert2Utf8(it->second->name());
932  pair.second = terralib4::Convert2Utf8(it->second->raster()->params().fileName_);
933  rasters.push_back(pair);
934  }
935  ++it;
936  }
937 
938  return rasters;
939 }
940 
941 std::vector<::terralib4::ThemeInfo> terralib4::Transactor::getTL4Themes()
942 {
943  std::vector<::terralib4::ThemeInfo> themes;
944 
945  TeViewMap& vMap = m_db->viewMap();
946  TeThemeMap& tMap = m_db->themeMap();
947 
948  std::map<int, TeView*>::iterator it = vMap.begin();
949 
950  while(it != vMap.end())
951  {
952  TeView* view = it->second;
953 
954  std::map<int, TeAbstractTheme*>::iterator itT = tMap.begin();
955 
956  while(itT != tMap.end())
957  {
958  TeAbstractTheme* abTheme = itT->second;
959 
960  if(abTheme->type() == TeTHEME)
961  {
962  TeTheme* theme = dynamic_cast<TeTheme*>(abTheme);
963 
964  if(theme->view() == view->id())
965  {
966  ::terralib4::ThemeInfo themeInfo;
967  themeInfo.m_name = terralib4::Convert2Utf8(theme->name());
968  themeInfo.m_viewName = terralib4::Convert2Utf8(view->name());
969  themeInfo.m_layerName = terralib4::Convert2Utf8(theme->layer()->name());
970 
971  themes.push_back(themeInfo);
972  }
973  }
974  ++itT;
975  }
976  ++it;
977  }
978 
979  return themes;
980 }
981 
982 TeTheme* terralib4::Transactor::getTL4Theme(const ::terralib4::ThemeInfo& theme)
983 {
984  std::map<int, TeAbstractTheme*>::iterator it = m_themeMap.begin();
985 
986  while(it != m_themeMap.end())
987  {
988  if(it->second->view() == getViewId(theme.m_viewName, m_viewMap))
989  {
990  TeAbstractTheme* abTheme = it->second;
991 
992  if(abTheme->type() == TeTHEME)
993  {
994  TeTheme* tl4Theme = dynamic_cast<TeTheme*>(abTheme);
995 
996  std::string themeNameUtf8 = terralib4::Convert2Utf8(tl4Theme->layer()->name());
997 
998  if(themeNameUtf8 == theme.m_layerName)
999  {
1000  return tl4Theme;
1001  }
1002  }
1003  }
1004 
1005  ++it;
1006  }
1007 
1008  return 0;
1009 }
1010 
1011 int terralib4::Transactor::getLayerSRID(const std::string & layerName)
1012 {
1013  std::map<int, TeLayer*>::iterator it = m_layerMap.begin();
1014 
1015  while(it != m_layerMap.end())
1016  {
1017  std::string nameUtf8 = terralib4::Convert2Utf8(it->second->name());
1018 
1019  if (nameUtf8 == layerName)
1020  {
1021  int srid = it->second->projection()->epsgCode();
1022  if(srid == 4979)
1023  srid = 4326;
1024 
1025  return srid;
1026  }
1027 
1028  ++it;
1029  }
1030 
1031  return 0;
1032 }
TeAttrDataType Convert2T4GeomType(te::gm::GeomType type)
std::vector< std::string > getTL4Rasters()
std::unique_ptr< te::da::DataSetType > getDataSetType(const std::string &name)
It gets information about the given dataset.
void push_back(Curve *ring)
It adds the curve to the curve polygon.
bool isInTransaction() const
It returns true if a transaction is in progress, otherwise, it returns false.
Geometric property.
bool indexExists(const std::string &datasetName, const std::string &name)
It checks if an index with the given name exists in the dataset.
GeomType
Each enumerated type is compatible with a Well-known Binary (WKB) type code.
void addProperty(const std::string &datasetName, te::dt::Property *p)
It adds a new property to the dataset schema.
std::string m_layerName
Definition: ThemeInfo.h:41
boost::int64_t getLastGeneratedId()
It returns the last id generated by an insertion command.
std::vector< std::pair< std::string, std::string > > getTL4RasterFiles()
void cloneDataSet(const std::string &name, const std::string &cloneName, const std::map< std::string, std::string > &options)
It clones the dataset in the data source.
TETERRALIB4EXPORT std::string Convert2Utf8(const std::string &str)
bool primaryKeyExists(const std::string &datasetName, const std::string &name)
It checks if a primary key exists in the dataset.
std::map< int, TeLayer * > & m_layerMap
int getViewId(const std::string &viewName, TeViewMap &viewMap)
std::unique_ptr< te::da::PrimaryKey > getPrimaryKey(const std::string &datasetName)
It retrieves the primary key of the dataset.
std::vector< std::string > getDataSetNames()
It It gets the dataset names available in the data source.
std::map< int, TeView * > & m_viewMap
A class that models the description of a dataset.
Definition: DataSetType.h:72
std::unique_ptr< te::da::UniqueKey > getUniqueKey(const std::string &datasetName, const std::string &name)
It gets the unique key in the dataset with the given name.
bool propertyExists(const std::string &datasetName, const std::string &name)
It checks if a property with the given name exists in the dataset.
std::vector< std::string > getForeignKeyNames(const std::string &datasetName)
It gets the foreign key names of the given dataset.
GeomType getGeomTypeId() const _NOEXCEPT_OP(true)
It returns the geometry subclass type identifier.
void createDataSet(te::da::DataSetType *dt, const std::map< std::string, std::string > &options)
It creates the dataset schema definition in the target data source.
std::unique_ptr< te::da::CheckConstraint > getCheckConstraint(const std::string &datasetName, const std::string &name)
It gets the check constraint of the dataset with the given name.
bool uniqueKeyExists(const std::string &datasetName, const std::string &name)
It checks if a unique key with the given name exists in the dataset.
void dropIndex(const std::string &datasetName, const std::string &idxName)
It removes the index from the dataset schema.
std::unique_ptr< te::da::PreparedQuery > getPrepared(const std::string &qName=std::string(""))
It creates a prepared query object that may be used for query commands (select, insert, update and delete) that are used repeatedly.
SpatialRelation
Spatial relations between geometric objects.
std::unique_ptr< te::da::Sequence > getSequence(const std::string &name)
It gets the sequence with the given name in the data source.
te::gm::GeomType GetCollection(TeGeomRep rep)
It describes a sequence (a number generator).
void renameProperty(const std::string &datasetName, const std::string &propertyName, const std::string &newPropertyName)
It renames a property of the given dataset.
bool dataSetExists(const std::string &name)
It checks if a dataset with the given name exists in the data source.
static te::dt::Date ds(2010, 01, 01)
bool hasDataSets()
It checks if the data source has any dataset.
void optimize(const std::map< std::string, std::string > &opInfo)
For some data access drivers, this method will perform some operations to optimize the data storage...
A class that describes a check constraint.
std::string escape(const std::string &value)
It escapes a string for using in commands and queries.
An abstract class for data providers like a DBMS, Web Services or a regular file. ...
#define TE_TR(message)
It marks a string in order to get translated.
Definition: Translator.h:242
std::vector< std::string > getTL4Tables()
Transactor(DataSource *ds, TeDatabase *db)
virtual Property * clone() const =0
It returns a clone of the object.
void cancel()
It requests that the data source stop the processing of the current command.
It models a property definition.
Definition: Property.h:59
Raster property.
boost::ptr_vector< te::dt::Property > getProperties(const std::string &datasetName)
It retrieves the properties of the dataset.
void dropForeignKey(const std::string &datasetName, const std::string &fkName)
It removes the foreign key constraint from the dataset schema.
std::unique_ptr< te::dt::Property > Convert2T5(const TeAttributeRep &attRep)
It creates a valid TerraLib 5 property given a valid TerraLib 4.x attribute representation.
std::vector< std::string > getPropertyNames(const std::string &datasetName)
It gets the property names of the given dataset.
The basic information about a Terralib 4.x Theme.
void rollBack()
It aborts the transaction. Any changes will be rolled-back.
std::unique_ptr< te::da::DataSet > query(const te::da::Select &q, te::common::TraverseType travType=te::common::FORWARDONLY, bool connected=false, const te::common::AccessPolicy accessPolicy=te::common::RAccess)
It executes a query that may return some data using a generic query. A dataset can be connected or di...
AccessPolicy
Supported data access policies (can be used as bitfield).
TraverseType
A dataset can be traversed in two ways:
void remove(const std::string &datasetName, const te::da::ObjectIdSet *oids=0)
It removes all the informed items from the dataset.
void update(const std::string &datasetName, te::da::DataSet *dataset, const std::vector< std::size_t > &properties, const te::da::ObjectIdSet *oids, const std::map< std::string, std::string > &options, std::size_t limit=0)
It updates the contents of a dataset for the set of data items.
void renameDataSet(const std::string &name, const std::string &newName)
It renames a dataset.
void setName(const std::string &name)
It sets the property name.
Definition: Property.h:137
std::vector< std::string > getCheckConstraintNames(const std::string &datasetName)
It gets the check constraint names of the given dataset.
std::unique_ptr< te::da::Index > getIndex(const std::string &datasetName, const std::string &name)
It gets the index with the given name from the dataset.
An Envelope defines a 2D rectangular region.
This class represents a set of unique ids created in the same context. i.e. from the same data set...
Definition: ObjectIdSet.h:55
bool foreignKeyExists(const std::string &datasetName, const std::string &name)
It checks if a foreign key with the given name exists in the data source.
Implements the DataSource class for the TerraLib 4.x Data Access Driver.
bool sequenceExists(const std::string &name)
It checks if a sequence with the given name exists in the data source.
TeTheme * getTL4Theme(const ::terralib4::ThemeInfo &theme)
static te::dt::TimeDuration dt(20, 30, 50, 11)
Implementation of a dataset for the TerraLib 4 driver.
Definition: TableDataSet.h:61
void addPrimaryKey(const std::string &datasetName, te::da::PrimaryKey *pk)
It adds a primary key constraint to the dataset schema.
std::size_t getNumberOfProperties(const std::string &datasetName)
It gets the number of properties of the given dataset.
void setProperties(const std::vector< te::dt::Property * > &properties)
It sets the properties that form the primary key.
Definition: PrimaryKey.h:116
void dropPrimaryKey(const std::string &datasetName)
It removes the primary key constraint from the dataset schema.
std::vector< std::string > getIndexNames(const std::string &datasetName)
It gets the index names of the given dataset.
void addIndex(const std::string &datasetName, te::da::Index *idx, const std::map< std::string, std::string > &options)
It adds an index to the dataset.
std::string m_name
Definition: ThemeInfo.h:39
void execute(const te::da::Query &command)
It executes the specified command using a generic query representation.
te::gm::Polygon * p
It models a foreign key constraint for a DataSetType.
Definition: ForeignKey.h:50
std::unique_ptr< te::da::ForeignKey > getForeignKey(const std::string &datasetName, const std::string &name)
It retrieves the foreign key from the given dataset.
std::vector< std::string > getUniqueKeyNames(const std::string &datasetName)
It gets the unique key names of the given dataset.
It describes a unique key (uk) constraint.
Definition: UniqueKey.h:53
std::size_t getNumberOfItems(const std::string &datasetName)
It retrieves the number of items of the given dataset.
bool isPropertyNameValid(const std::string &propertyName)
It checks if the given property name is valid.
void add(const std::string &datasetName, te::da::DataSet *d, const std::map< std::string, std::string > &options, std::size_t limit=0, bool enableProgress=true)
It adds data items to the dataset in the data source.
Utility functions for the data access module.
std::unique_ptr< te::da::BatchExecutor > getBatchExecutor()
It creates a batch command executor.
Geometry is the root class of the geometries hierarchy, it follows OGC and ISO standards.
A Select models a query to be used when retrieving data from a DataSource.
Definition: Select.h:65
void addForeignKey(const std::string &datasetName, te::da::ForeignKey *fk)
It adds a foreign key constraint to a dataset.
TETERRALIB4EXPORT std::string Convert2Latin1(const std::string &str)
int getType() const
It returns the property data type.
Definition: Property.h:161
A dataset is the unit of information manipulated by the data access module of TerraLib.
An static class with global definitions.
std::unique_ptr< te::dt::Property > getProperty(const std::string &datasetName, const std::string &name)
It retrieves the property with the given name from the dataset.
void addSequence(te::da::Sequence *sequence)
It creates a new sequence in the data source.
int getLayerSRID(const std::string &layerName)
Implementation of a dataset for the TerraLib 4 driver.
Definition: VectorDataSet.h:61
DataSourceTransactor implementation for TerraLib 4.x API.
It describes a primary key (pk) constraint.
Definition: PrimaryKey.h:52
std::unique_ptr< te::gm::Envelope > getExtent(const std::string &datasetName, const std::string &propertyName)
It retrieves the bounding rectangle of the spatial property for the given dataset.
void dropCheckConstraint(const std::string &datasetName, const std::string &name)
It removes the check constraint from the dataset.
void dropUniqueKey(const std::string &datasetName, const std::string &name)
It removes the unique key constraint from the dataset.
void addCheckConstraint(const std::string &datasetName, te::da::CheckConstraint *cc)
It adds a check constraint to the dataset.
void commit()
It commits the transaction.
std::size_t getNumberOfDataSets()
It retrieves the number of data sets available in the data source.
std::map< int, TeAbstractTheme * > & m_themeMap
void begin()
It starts a new transaction.
TeAttrDataType Convert2T4(int type)
It converts a Terralib 5 data type to Terralib 4.x data type.
list rasters
Definition: compose.py:3
std::vector< std::string > getTL4Layers()
bool isDataSetNameValid(const std::string &datasetName)
It returns true if the given string is a valid dataset name.
std::vector< std::string > getSequenceNames()
It gets the sequence names available in the data source.
std::string m_viewName
Definition: ThemeInfo.h:40
void dropDataSet(const std::string &name)
It removes the dataset schema from the data source.
void dropSequence(const std::string &name)
It removes the sequence from the data source.
A Query is independent from the data source language/dialect.
Definition: Query.h:46
It describes an index associated to a DataSetType.
te::da::DataSource * getDataSource() const
It returns the parent data source of the transactor.
std::unique_ptr< te::da::DataSet > getDataSet(const std::string &name, te::common::TraverseType travType=te::common::FORWARDONLY, bool connected=false, const te::common::AccessPolicy accessPolicy=te::common::RAccess)
It gets the dataset identified by the given name. A dataset can be connected or disconnected. A connected dataset, after its creation through the data source transactor, continues to depend on the connection given by its associated data source. Differently, a disconnected dataset, after its creation, no more depends of the connection given by the data source, and it continues to live after the connection has been released to the data source.
void addUniqueKey(const std::string &datasetName, te::da::UniqueKey *uk)
It adds a unique key constraint to the dataset.
std::vector<::terralib4::ThemeInfo > getTL4Themes()
void dropProperty(const std::string &datasetName, const std::string &name)
It removes a property from the given dataset.
bool checkConstraintExists(const std::string &datasetName, const std::string &name)
It checks if a check-constraint with the given name exists in the data source.
const std::string & getName() const
It returns the property name.
Definition: Property.h:127