All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
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 "../common/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  if(it->second->name() == viewName)
91  return it->second->id();
92 
93  ++it;
94  }
95 
96  return -1;
97 }
98 
100  : m_ds(ds),
101  m_db(db),
102  m_isInTransaction(false),
103  m_layerMap(m_db->layerMap()),
104  m_viewMap(m_db->viewMap()),
105  m_themeMap(m_db->themeMap())
106 {
107 }
108 
110 {
111 }
112 
114 {
115  return m_ds;
116 }
117 
119 {
120  m_db->beginTransaction();
121  m_isInTransaction = true;
122 }
123 
125 {
126  m_db->commitTransaction();
127  m_isInTransaction = false;
128 }
129 
131 {
132  m_db->rollbackTransaction();
133  m_isInTransaction = false;
134 }
135 
137 {
138  return m_isInTransaction;
139 }
140 
141 std::auto_ptr<te::da::DataSet> terralib4::Transactor::getDataSet(const std::string& name,
142  te::common::TraverseType /*travType*/,
143  bool /*connected*/,
144  const te::common::AccessPolicy /*accessPolicy*/)
145 {
146  TeLayer* layer = 0;
147 
148  if(m_db->layerExist(name))
149  {
150  std::map<int, TeLayer*>::iterator it = m_layerMap.begin();
151 
152  while(it != m_layerMap.end())
153  {
154  if(it->second->name() == name)
155  {
156  layer = it->second;
157  break;
158  }
159  ++it;
160  }
161 
162  if(layer->hasGeometry(TeRASTER))
163  {
164  return std::auto_ptr<te::da::DataSet>(new RasterDataSet(layer->raster()));
165  }
166  else
167  return std::auto_ptr<te::da::DataSet>(new VectorDataSet(layer));
168  }
169  else
170  {
171  TeAttrTableVector tables;
172  m_db->getAttrTables(tables);
173 
174  TeTable table;
175 
176  for(std::size_t i = 0; i < tables.size(); ++i)
177  {
178  if(tables[i].tableType() == TeAttrExternal && tables[i].name() == name)
179  {
180  table = tables[i];
181  break;
182  }
183  }
184 
185 
186  return std::auto_ptr<te::da::DataSet>(new TableDataSet(m_db, table));
187  }
188 }
189 
190 std::auto_ptr<te::da::DataSet> terralib4::Transactor::getDataSet(const std::string& name,
191  const std::string& propertyName,
192  const te::gm::Envelope* e,
194  te::common::TraverseType travType,
195  bool /*connected*/,
196  const te::common::AccessPolicy /*accessPolicy*/)
197 {
198  throw Exception(TE_TR("This method is not supported by TerraLib 4.x driver!"));
199 }
200 
201 std::auto_ptr<te::da::DataSet> terralib4::Transactor::getDataSet(const std::string& name,
202  const std::string& propertyName,
203  const te::gm::Geometry* g,
205  te::common::TraverseType travType,
206  bool /*connected*/,
207  const te::common::AccessPolicy /*accessPolicy*/)
208 {
209  throw Exception(TE_TR("This method is not supported by TerraLib 4.x driver!"));
210 }
211 
212 std::auto_ptr<te::da::DataSet> terralib4::Transactor::getDataSet(const std::string& name,
213  const ObjectIdSet* oids,
214  te::common::TraverseType travType,
215  bool /*connected*/,
216  const te::common::AccessPolicy /*accessPolicy*/)
217 {
218  throw Exception(TE_TR("This method is not supported by TerraLib 4.x driver!"));
219 }
220 
221 
222 
223 std::auto_ptr<te::da::DataSet> terralib4::Transactor::query(const te::da::Select& /*q*/,
224  te::common::TraverseType /*travType*/,
225  bool /*connected*/,
226  const te::common::AccessPolicy /*accessPolicy*/)
227 {
228  throw Exception(TE_TR("TerraLib 4.x driver doesn't support queries!"));
229 }
230 
231 std::auto_ptr<te::da::DataSet> terralib4::Transactor::query(const std::string& /*query*/,
232  te::common::TraverseType /*travType*/,
233  bool /*connected*/,
234  const te::common::AccessPolicy /*accessPolicy*/)
235 {
236  throw Exception(TE_TR("TerraLib 4.x driver doesn't support queries!"));
237 }
238 
240 {
241  throw Exception(TE_TR("TerraLib 4.x driver doesn't support command execution!"));
242 }
243 
244 void terralib4::Transactor::execute(const std::string& /*command*/)
245 {
246  throw Exception(TE_TR("TerraLib 4.x driver doesn't support command execution!"));
247 }
248 
249 std::auto_ptr<te::da::PreparedQuery> terralib4::Transactor::getPrepared(const std::string& qName)
250 {
251  throw Exception(TE_TR("TerraLib 4.x driver doesn't support prepared queries!"));
252 }
253 
254 std::auto_ptr<te::da::BatchExecutor> terralib4::Transactor::getBatchExecutor()
255 {
256  throw Exception(TE_TR("TerraLib 4.x driver doesn't support prepared batch executors!"));
257 }
258 
260 {
261 }
262 
264 {
265  throw Exception(TE_TR("TerraLib 4.x driver is read-only!"));
266 }
267 
268 std::string terralib4::Transactor::escape(const std::string& value)
269 {
270  throw Exception(TE_TR("This method is not supported by TerraLib 4.x driver!"));
271 }
272 
273 bool terralib4::Transactor::isDataSetNameValid(const std::string& /*datasetName*/)
274 {
275  throw Exception(TE_TR("TerraLib 4.x driver is read-only!"));
276 }
277 
278 bool terralib4::Transactor::isPropertyNameValid(const std::string& /*propertyName*/)
279 {
280  throw Exception(TE_TR("TerraLib 4.x driver is read-only!"));
281 }
282 
283 std::vector<std::string> terralib4::Transactor::getDataSetNames()
284 {
285  std::map<int, TeLayer*>::iterator it = m_layerMap.begin();
286 
287  std::vector<std::string> dataSets;
288 
289  while(it != m_layerMap.end())
290  {
291  dataSets.push_back(it->second->name());
292 
293  ++it;
294  }
295 
296  TeAttrTableVector tableVector;
297  m_db->getAttrTables(tableVector);
298 
299  for(std::size_t i = 0; i < tableVector.size(); ++i)
300  {
301  if(tableVector[i].tableType() == TeAttrExternal)
302  dataSets.push_back(tableVector[i].name());
303  }
304 
305  return dataSets;
306 }
307 
309 {
310  return getDataSetNames().size();
311 }
312 
313 std::auto_ptr<te::da::DataSetType> terralib4::Transactor::getDataSetType(const std::string& name)
314 {
315  TeLayer* layer = 0;
316 
317  if(m_db->layerExist(name))
318  {
319  std::map<int, TeLayer*>::iterator it = m_layerMap.begin();
320 
321  while(it != m_layerMap.end())
322  {
323  if(it->second->name() == name)
324  {
325  layer = it->second;
326  break;
327  }
328  ++it;
329  }
330  }
331 
332  TeTable table;
333 
334  if(!layer)
335  {
336  TeAttrTableVector tables;
337  m_db->getAttrTables(tables);
338 
339  for(std::size_t i = 0; i < tables.size(); i++)
340  {
341  if(tables[i].tableType() == TeAttrExternal && name == tables[i].name())
342  {
343  table = tables[i];
344  break;
345  }
346  }
347  }
348  else
349  {
350 
351 // Is a layer
352 
353  if(layer->hasGeometry(TeRASTER))
354  {
355  std::auto_ptr<te::da::DataSetType> dst(new te::da::DataSetType(layer->name(), 0));
356 
357  // TODO: handle rasters with multiple objectid!
358  te::rst::RasterProperty* prop = Convert2T5(layer->raster()->params());
359  dst->add(prop);
360  return dst;
361  }
362 
363  TeAttrTableVector tables;
364  layer->getAttrTables(tables);
365 
366  table = tables[0];
367  }
368 
369  std::auto_ptr<te::da::DataSetType> mainDst(terralib4::Convert2T5(table));
370  mainDst->setTitle(table.name());
371 
372  std::vector<std::string> pkey;
373  table.primaryKeys(pkey);
374 
375  te::da::PrimaryKey* pk = 0;
376 
377  if(!pkey.empty())
378  {
379  pk = new te::da::PrimaryKey(table.name() + "_pk", mainDst.get());
380 
381  std::vector<te::dt::Property*> pkProps;
382  for(std::size_t i = 0; i < pkey.size(); ++i)
383  {
384  te::dt::Property* p = mainDst->getProperty(pkey[i]);
385  pkProps.push_back(p);
386  }
387 
388  pk->setProperties(pkProps);
389  }
390  else
391  {
392  TeAttribute attLink;
393  table.attrLink(attLink);
394 
395  std::string attLinkName = attLink.rep_.name_;
396 
397  if(!attLinkName.empty())
398  {
399  pk = new te::da::PrimaryKey(table.name() + "_pk", mainDst.get());
400 
401  te::dt::Property* p = mainDst->getProperty(attLinkName);
402 
403  std::vector<te::dt::Property*> pkProps;
404  pkProps.push_back(p);
405 
406  pk->setProperties(pkProps);
407  }
408  }
409 
410  if(layer)
411  {
412  TeAttrTableVector tables;
413  layer->getAttrTables(tables);
414 
415  if(tables.size() > 1)
416  {
417  for(std::size_t i = 1; i < tables.size(); ++i)
418  {
419  TeTable table = tables[i];
420 
421  std::auto_ptr<te::da::DataSetType> dst(terralib4::Convert2T5(table));
422 
423  std::vector<te::dt::Property*> props = dst->getProperties();
424 
425  for(std::size_t j = 0; j < props.size(); ++j)
426  {
427  te::dt::Property* prop = props[j]->clone();
428  prop->setName(dst->getName() + "_" + prop->getName());
429 
430  mainDst->add(prop);
431  }
432  }
433  }
434 
435  TeRepresPointerVector vec = layer->vectRepres();
436 
437  if(!vec.empty())
438  {
439  TeGeomRep geomRep = vec[0]->geomRep_;
440 
441  int srid = layer->projection()->epsgCode();
442 
443  if(srid == 4979)
444  srid = 4326;
445 
446  te::gm::GeometryProperty* geomProp = new te::gm::GeometryProperty("spatial_data",
447  srid, terralib4::Convert2T5GeomType(geomRep));
448  mainDst->add(geomProp);
449  }
450  }
451 
452  return mainDst;
453 }
454 
455 boost::ptr_vector<te::dt::Property> terralib4::Transactor::getProperties(const std::string& datasetName)
456 {
457  std::auto_ptr<te::da::DataSetType> dt = getDataSetType(datasetName);
458 
459  std::vector<te::dt::Property*> dtProperties = dt->getProperties();
460 
461  boost::ptr_vector<te::dt::Property> properties;
462 
463  for(std::size_t i = 0; i < dtProperties.size(); ++i)
464  properties.push_back(dtProperties[i]->clone());
465 
466  return properties;
467 }
468 
469 std::auto_ptr<te::dt::Property> terralib4::Transactor::getProperty(const std::string& datasetName, const std::string& name)
470 {
471  if(!propertyExists(datasetName, name))
472  throw Exception((boost::format(TE_TR("The dataset \"%1%\" has no property with this name \"%2%\"!")) % datasetName % name).str());
473 
474  std::auto_ptr<te::da::DataSetType> dt(getDataSetType(datasetName));
475 
476  return std::auto_ptr<te::dt::Property>(dt->getProperty(name)->clone());
477 }
478 
479 std::auto_ptr<te::dt::Property> terralib4::Transactor::getProperty(const std::string& datasetName, std::size_t propertyPos)
480 {
481  std::auto_ptr<te::da::DataSetType> dt(getDataSetType(datasetName));
482 
483  assert(propertyPos < dt->size());
484 
485  return std::auto_ptr<te::dt::Property>(dt->getProperty(propertyPos)->clone());
486 }
487 
488 std::vector<std::string> terralib4::Transactor::getPropertyNames(const std::string& datasetName)
489 {
490  std::auto_ptr<te::da::DataSetType> dt(getDataSetType(datasetName));
491 
492  std::vector<std::string> pNames;
493 
494  std::size_t numProperties = dt->size();
495 
496  for(std::size_t i = 0; i < numProperties; ++i)
497  pNames.push_back(dt->getProperty(i)->getName());
498 
499  return pNames;
500 }
501 
502 std::size_t terralib4::Transactor::getNumberOfProperties(const std::string& datasetName)
503 {
504  std::auto_ptr<te::da::DataSetType> dt(getDataSetType(datasetName));
505 
506  return dt->size();
507 }
508 
509 bool terralib4::Transactor::propertyExists(const std::string& datasetName, const std::string& name)
510 {
511  std::auto_ptr<te::da::DataSetType> dt(getDataSetType(datasetName));
512 
513  std::vector<std::string> pNames = getPropertyNames(datasetName);
514 
515  if(std::find(pNames.begin(), pNames.end(), name) != pNames.end())
516  return true;
517 
518  return false;
519 }
520 
521 void terralib4::Transactor::addProperty(const std::string& datasetName, te::dt::Property* p)
522 {
523  std::string name = p->getName();
524  if(propertyExists(datasetName, name))
525  throw Exception((boost::format(TE_TR("The dataset already \"%1%\" has a property with this name \"%2%\"!")) % datasetName % name).str());
526 
527  int pType = p->getType();
528 
529  TeAttributeRep newProperty;
530 
531  newProperty.name_ = name;
532 
533  if(p->getType() != te::dt::GEOMETRY_TYPE)
534  newProperty.type_ = terralib4::Convert2T4(p->getType());
535  else
536  {
537  te::gm::Geometry* geom = dynamic_cast<te::gm::Geometry*>(p);
538  newProperty.type_ = terralib4::Convert2T4GeomType(geom->getGeomTypeId());
539  }
540 
541  std::map<int, TeLayer*>::iterator it = m_layerMap.begin();
542 
543  TeLayer* layer = 0;
544 
545  while(it != m_layerMap.end())
546  {
547  if(it->second->name() == datasetName)
548  {
549  layer = it->second;
550  break;
551  }
552  ++it;
553  }
554 
555  TeAttrTableVector tables;
556  layer->getAttrTables(tables);
557  std::string tableName = tables[0].name();
558 
559  m_db->addColumn(tableName, newProperty);
560 }
561 
562 void terralib4::Transactor::dropProperty(const std::string& datasetName, const std::string& name)
563 {
564  throw;
565 }
566 
567 void terralib4::Transactor::renameProperty(const std::string& datasetName,
568  const std::string& propertyName,
569  const std::string& newPropertyName)
570 {
571  throw Exception(TE_TR("This method is not supported by TerraLib 4.x driver!"));
572 }
573 
574 std::auto_ptr<te::da::PrimaryKey> terralib4::Transactor::getPrimaryKey(const std::string& datasetName)
575 {
576  std::auto_ptr<te::da::DataSetType> dt(getDataSetType(datasetName));
577 
578  return std::auto_ptr<te::da::PrimaryKey>(static_cast<te::da::PrimaryKey*>(dt->getPrimaryKey()->clone()));
579 }
580 
581 bool terralib4::Transactor::primaryKeyExists(const std::string& datasetName, const std::string& name)
582 {
583  std::auto_ptr<te::da::DataSetType> dt(getDataSetType(datasetName));
584 
585  if(dt->getPrimaryKey()->getName() == name)
586  return true;
587 
588  return false;
589 }
590 
591 void terralib4::Transactor::addPrimaryKey(const std::string& datasetName, te::da::PrimaryKey* pk)
592 {
593  throw Exception(TE_TR("This method is not supported by TerraLib 4.x driver!"));
594 }
595 
596 void terralib4::Transactor::dropPrimaryKey(const std::string& datasetName)
597 {
598  throw Exception(TE_TR("This method is not supported by TerraLib 4.x driver!"));
599 }
600 
601 std::auto_ptr<te::da::ForeignKey> terralib4::Transactor::getForeignKey(const std::string& datasetName, const std::string& name)
602 {
603  throw Exception(TE_TR("This method is not supported by TerraLib 4.x driver!"));
604 }
605 
606 std::vector<std::string> terralib4::Transactor::getForeignKeyNames(const std::string& datasetName)
607 {
608  throw Exception(TE_TR("This method is not supported by TerraLib 4.x driver!"));
609 }
610 
611 bool terralib4::Transactor::foreignKeyExists(const std::string& datasetName, const std::string& name)
612 {
613  throw Exception(TE_TR("This method is not supported by TerraLib 4.x driver!"));
614 }
615 
616 void terralib4::Transactor::addForeignKey(const std::string& datasetName, te::da::ForeignKey* fk)
617 {
618  throw Exception(TE_TR("This method is not supported by TerraLib 4.x driver!"));
619 }
620 
621 void terralib4::Transactor::dropForeignKey(const std::string& datasetName, const std::string& fkName)
622 {
623  throw Exception(TE_TR("This method is not supported by TerraLib 4.x driver!"));
624 }
625 
626 std::auto_ptr<te::da::UniqueKey> terralib4::Transactor::getUniqueKey(const std::string& datasetName, const std::string& name)
627 {
628  throw Exception(TE_TR("This method is not supported by TerraLib 4.x driver!"));
629 }
630 
631 std::vector<std::string> terralib4::Transactor::getUniqueKeyNames(const std::string& datasetName)
632 {
633  throw Exception(TE_TR("This method is not supported by TerraLib 4.x driver!"));
634 }
635 
636 bool terralib4::Transactor::uniqueKeyExists(const std::string& datasetName, const std::string& name)
637 {
638  throw Exception(TE_TR("This method is not supported by TerraLib 4.x driver!"));
639 }
640 
641 void terralib4::Transactor::addUniqueKey(const std::string& datasetName, te::da::UniqueKey* uk)
642 {
643  throw Exception(TE_TR("This method is not supported by TerraLib 4.x driver!"));
644 }
645 
646 void terralib4::Transactor::dropUniqueKey(const std::string& datasetName, const std::string& name)
647 {
648  throw Exception(TE_TR("This method is not supported by TerraLib 4.x driver!"));
649 }
650 
651 std::auto_ptr<te::da::CheckConstraint> terralib4::Transactor::getCheckConstraint(const std::string& datasetName, const std::string& name)
652 {
653  throw Exception(TE_TR("This method is not supported by TerraLib 4.x driver!"));
654 }
655 
656 std::vector<std::string> terralib4::Transactor::getCheckConstraintNames(const std::string& datasetName)
657 {
658  throw Exception(TE_TR("This method is not supported by TerraLib 4.x driver!"));
659 }
660 
661 bool terralib4::Transactor::checkConstraintExists(const std::string& datasetName, const std::string& name)
662 {
663  throw Exception(TE_TR("This method is not supported by TerraLib 4.x driver!"));
664 }
665 
667 {
668  throw Exception(TE_TR("This method is not supported by TerraLib 4.x driver!"));
669 }
670 
671 void terralib4::Transactor::dropCheckConstraint(const std::string& datasetName, const std::string& name)
672 {
673  throw Exception(TE_TR("This method is not supported by TerraLib 4.x driver!"));
674 }
675 
676 std::auto_ptr<te::da::Index> terralib4::Transactor::getIndex(const std::string& datasetName, const std::string& name)
677 {
678  throw Exception(TE_TR("This method is not supported by TerraLib 4.x driver!"));
679 }
680 
681 std::vector<std::string> terralib4::Transactor::getIndexNames(const std::string& datasetName)
682 {
683  throw Exception(TE_TR("This method is not supported by TerraLib 4.x driver!"));
684 }
685 
686 bool terralib4::Transactor::indexExists(const std::string& datasetName, const std::string& name)
687 {
688  throw Exception(TE_TR("This method is not supported by TerraLib 4.x driver!"));
689 }
690 
691 void terralib4::Transactor::addIndex(const std::string& datasetName, te::da::Index* idx,
692  const std::map<std::string, std::string>& options)
693 {
694  throw Exception(TE_TR("This method is not supported by TerraLib 4.x driver!"));
695 }
696 
697 void terralib4::Transactor::dropIndex(const std::string& datasetName, const std::string& idxName)
698 {
699  throw Exception(TE_TR("This method is not supported by TerraLib 4.x driver!"));
700 }
701 
702 std::auto_ptr<te::da::Sequence> terralib4::Transactor::getSequence(const std::string& name)
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::getSequenceNames()
708 {
709  throw Exception(TE_TR("This method is not supported by TerraLib 4.x driver!"));
710 }
711 
712 bool terralib4::Transactor::sequenceExists(const std::string& name)
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::dropSequence(const std::string& name)
723 {
724  throw Exception(TE_TR("This method is not supported by TerraLib 4.x driver!"));
725 }
726 
727 std::auto_ptr<te::gm::Envelope> terralib4::Transactor::getExtent(const std::string& datasetName,
728  const std::string& /*propertyName*/)
729 {
730  throw Exception(TE_TR("This method is not supported by TerraLib 4.x driver!"));
731 }
732 
733 std::auto_ptr<te::gm::Envelope> terralib4::Transactor::getExtent(const std::string& datasetName,
734  std::size_t /*propertyPos*/)
735 {
736  throw Exception(TE_TR("This method is not supported by TerraLib 4.x driver!"));
737 }
738 
739 std::size_t terralib4::Transactor::getNumberOfItems(const std::string& datasetName)
740 {
741  throw Exception(TE_TR("This method is not supported by TerraLib 4.x driver!"));
742 }
743 
745 {
746  throw Exception(TE_TR("This method is not supported by TerraLib 4.x driver!"));
747 }
748 
749 bool terralib4::Transactor::dataSetExists(const std::string& name)
750 {
751  std::vector<std::string> names = getDataSetNames();
752 
753  for(std::size_t i = 0; i < names.size(); ++i)
754  if(names[i] == name)
755  return true;
756 
757  return false;
758 }
759 
760 void terralib4::Transactor::createDataSet(te::da::DataSetType* dt, const std::map<std::string, std::string>& options)
761 {
762  throw Exception(TE_TR("This method is not supported by TerraLib 4.x driver!"));
763 }
764 
765 void terralib4::Transactor::cloneDataSet(const std::string& name,
766  const std::string& cloneName,
767  const std::map<std::string, std::string>& options)
768 {
769  throw Exception(TE_TR("This method is not supported by TerraLib 4.x driver!"));
770 }
771 
772 void terralib4::Transactor::dropDataSet(const std::string& name)
773 {
774  throw Exception(TE_TR("This method is not supported by TerraLib 4.x driver!"));
775 }
776 
777 void terralib4::Transactor::renameDataSet(const std::string& name, const std::string& newName)
778 {
779  throw Exception(TE_TR("This method is not supported by TerraLib 4.x driver!"));
780 }
781 
782 void terralib4::Transactor::add(const std::string& datasetName,
783  te::da::DataSet* d,
784  const std::map<std::string, std::string>& options,
785  std::size_t limit)
786 {
787  throw Exception(TE_TR("This method is not supported by TerraLib 4.x driver!"));
788 }
789 
790 void terralib4::Transactor::remove(const std::string& datasetName, const te::da::ObjectIdSet* oids)
791 {
792  throw Exception(TE_TR("This method is not supported by TerraLib 4.x driver!"));
793 }
794 
795 void terralib4::Transactor::update(const std::string& datasetName,
796  te::da::DataSet* dataset,
797  const std::vector<std::size_t>& properties,
798  const te::da::ObjectIdSet* oids,
799  const std::map<std::string, std::string>& options,
800  std::size_t limit)
801 {
802  throw Exception(TE_TR("This method is not supported by TerraLib 4.x driver!"));
803 }
804 
805 void terralib4::Transactor::optimize(const std::map<std::string, std::string>& opInfo)
806 {
807  throw Exception(TE_TR("This method is not supported by TerraLib 4.x driver!"));
808 }
809 
810 std::vector<std::string> terralib4::Transactor::getTL4Layers()
811 {
812  std::vector<std::string> layers;
813 
814  std::map<int, TeLayer*>::iterator it = m_layerMap.begin();
815 
816  while(it != m_layerMap.end())
817  {
818  if(!it->second->hasGeometry(TeRASTER))
819  layers.push_back(it->second->name());
820 
821  ++it;
822  }
823 
824  return layers;
825 }
826 
827 std::vector<std::string> terralib4::Transactor::getTL4Tables()
828 {
829  std::vector<std::string> tablesVec;
830 
831  TeAttrTableVector tables;
832  m_db->getAttrTables(tables, TeAttrExternal);
833 
834  for(std::size_t i = 0; i < tables.size(); i++)
835  tablesVec.push_back(tables[i].name());
836 
837  return tablesVec;
838 }
839 
840 std::vector<std::string> terralib4::Transactor::getTL4Rasters()
841 {
842  std::vector<std::string> rasters;
843 
844  std::map<int, TeLayer*>::iterator it = m_layerMap.begin();
845 
846  while(it != m_layerMap.end())
847  {
848  if(it->second->hasGeometry(TeRASTER))
849  {
850  rasters.push_back(it->second->name());
851  }
852  ++it;
853  }
854 
855  return rasters;
856 }
857 
858 std::vector<::terralib4::ThemeInfo> terralib4::Transactor::getTL4Themes()
859 {
860  std::vector<::terralib4::ThemeInfo> themes;
861 
862  TeViewMap& vMap = m_db->viewMap();
863  TeThemeMap& tMap = m_db->themeMap();
864 
865  std::map<int, TeView*>::iterator it = vMap.begin();
866 
867  while(it != vMap.end())
868  {
869  TeView* view = it->second;
870 
871  std::map<int, TeAbstractTheme*>::iterator itT = tMap.begin();
872 
873  while(itT != tMap.end())
874  {
875  TeAbstractTheme* abTheme = itT->second;
876 
877  if(abTheme->type() == TeTHEME)
878  {
879  TeTheme* theme = dynamic_cast<TeTheme*>(abTheme);
880 
881  if(theme->view() == view->id())
882  {
883  ::terralib4::ThemeInfo themeInfo;
884  themeInfo.m_name = theme->name();
885  themeInfo.m_viewName = view->name();
886  themeInfo.m_layerName = theme->layer()->name();
887 
888  themes.push_back(themeInfo);
889  }
890  }
891  ++itT;
892  }
893  ++it;
894  }
895 
896  return themes;
897 }
898 
899 TeTheme* terralib4::Transactor::getTL4Theme(const ::terralib4::ThemeInfo theme)
900 {
901  std::map<int, TeAbstractTheme*>::iterator it = m_themeMap.begin();
902 
903  while(it != m_themeMap.end())
904  {
905  if(it->second->view() == getViewId(theme.m_viewName, m_viewMap))
906  {
907  TeAbstractTheme* abTheme = it->second;
908 
909  if(abTheme->type() == TeTHEME)
910  {
911  TeTheme* tl4Theme = dynamic_cast<TeTheme*>(abTheme);
912 
913  if(tl4Theme->layer()->name() == theme.m_layerName)
914  {
915  return tl4Theme;
916  }
917  }
918  }
919 
920  ++it;
921  }
922 
923  return 0;
924 }
925 
926 int terralib4::Transactor::getLayerSRID(const std::string & layerName)
927 {
928  std::map<int, TeLayer*>::iterator it = m_layerMap.begin();
929 
930  while(it != m_layerMap.end())
931  {
932  if(it->second->name() == layerName)
933  {
934  int srid = it->second->projection()->epsgCode();
935  if(srid == 4979)
936  srid = 4326;
937 
938  return srid;
939  }
940 
941  ++it;
942  }
943 
944  return 0;
945 }
946 
948 {
949  return te::common::UTF8;
950 }
TeAttrDataType Convert2T4GeomType(te::gm::GeomType type)
Definition: Utils.cpp:329
std::auto_ptr< te::da::ForeignKey > getForeignKey(const std::string &datasetName, const std::string &name)
It retrieves the foreign key from the given dataset.
Definition: Transactor.cpp:601
std::vector< std::string > getTL4Rasters()
Definition: Transactor.cpp:840
bool isInTransaction() const
It returns true if a transaction is in progress, otherwise, it returns false.
Definition: Transactor.cpp:136
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.
Definition: Transactor.cpp:686
Utility functions for the data access module.
void addProperty(const std::string &datasetName, te::dt::Property *p)
It adds a new property to the dataset schema.
Definition: Transactor.cpp:521
std::string m_layerName
Definition: ThemeInfo.h:41
boost::int64_t getLastGeneratedId()
It returns the last id generated by an insertion command.
Definition: Transactor.cpp:263
CharEncoding
Supported charsets (character encoding).
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.
Definition: Transactor.cpp:765
DataSourceTransactor implementation for TerraLib 4.x API.
An static class with global definitions.
bool primaryKeyExists(const std::string &datasetName, const std::string &name)
It checks if a primary key exists in the dataset.
Definition: Transactor.cpp:581
std::vector< std::string > getDataSetNames()
It It gets the dataset names available in the data source.
Definition: Transactor.cpp:283
A class that models the description of a dataset.
Definition: DataSetType.h:72
int getViewId(const std::string &viewName, TeViewMap &viewMap)
Definition: Transactor.cpp:84
bool propertyExists(const std::string &datasetName, const std::string &name)
It checks if a property with the given name exists in the dataset.
Definition: Transactor.cpp:509
std::vector< std::string > getForeignKeyNames(const std::string &datasetName)
It gets the foreign key names of the given dataset.
Definition: Transactor.cpp:606
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.
Definition: Transactor.cpp:760
virtual Property * clone() const =0
It returns a clone of the object.
bool uniqueKeyExists(const std::string &datasetName, const std::string &name)
It checks if a unique key with the given name exists in the dataset.
Definition: Transactor.cpp:636
Implements the DataSource class for the TerraLib 4.x Data Access Driver.
void dropIndex(const std::string &datasetName, const std::string &idxName)
It removes the index from the dataset schema.
Definition: Transactor.cpp:697
SpatialRelation
Spatial relations between geometric objects.
Definition: Enums.h:122
It describes a sequence (a number generator).
Definition: Sequence.h:56
void renameProperty(const std::string &datasetName, const std::string &propertyName, const std::string &newPropertyName)
It renames a property of the given dataset.
Definition: Transactor.cpp:567
bool dataSetExists(const std::string &name)
It checks if a dataset with the given name exists in the data source.
Definition: Transactor.cpp:749
bool hasDataSets()
It checks if the data source has any dataset.
Definition: Transactor.cpp:744
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...
Definition: Transactor.cpp:805
A class that describes a check constraint.
std::string escape(const std::string &value)
It escapes a string for using in commands and queries.
Definition: Transactor.cpp:268
An abstract class for data providers like a DBMS, Web Services or a regular file. ...
Definition: DataSource.h:118
#define TE_TR(message)
It marks a string in order to get translated.
Definition: Translator.h:347
std::vector< std::string > getTL4Tables()
Definition: Transactor.cpp:827
Transactor(DataSource *ds, TeDatabase *db)
Definition: Transactor.cpp:99
void cancel()
It requests that the data source stop the processing of the current command.
Definition: Transactor.cpp:259
std::auto_ptr< te::da::BatchExecutor > getBatchExecutor()
It creates a batch command executor.
Definition: Transactor.cpp:254
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.
Definition: Transactor.cpp:455
void dropForeignKey(const std::string &datasetName, const std::string &fkName)
It removes the foreign key constraint from the dataset schema.
Definition: Transactor.cpp:621
std::vector< std::string > getPropertyNames(const std::string &datasetName)
It gets the property names of the given dataset.
Definition: Transactor.cpp:488
std::auto_ptr< te::dt::Property > Convert2T5(const TeAttributeRep &attRep)
It creates a valid TerraLib 5 property given a valid TerraLib 4.x attribute representation.
Definition: Utils.cpp:53
The basic information about a Terralib 4.x Theme.
void rollBack()
It aborts the transaction. Any changes will be rolled-back.
Definition: Transactor.cpp:130
AccessPolicy
Supported data access policies (can be used as bitfield).
Definition: Enums.h:40
TraverseType
A dataset can be traversed in two ways:
Definition: Enums.h:53
void remove(const std::string &datasetName, const te::da::ObjectIdSet *oids=0)
It removes all the informed items from the dataset.
Definition: Transactor.cpp:790
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.
Definition: Transactor.cpp:795
std::auto_ptr< te::da::PrimaryKey > getPrimaryKey(const std::string &datasetName)
It retrieves the primary key of the dataset.
Definition: Transactor.cpp:574
void renameDataSet(const std::string &name, const std::string &newName)
It renames a dataset.
Definition: Transactor.cpp:777
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.
Definition: Transactor.cpp:656
te::gm::GeomType Convert2T5GeomType(TeAttrDataType type)
Definition: Utils.cpp:197
An Envelope defines a 2D rectangular region.
Definition: Envelope.h:51
This class represents a set of unique ids created in the same context. i.e. from the same data set...
Definition: ObjectIdSet.h:55
std::auto_ptr< te::da::Sequence > getSequence(const std::string &name)
It gets the sequence with the given name in the data source.
Definition: Transactor.cpp:702
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.
Definition: Transactor.cpp:611
bool sequenceExists(const std::string &name)
It checks if a sequence with the given name exists in the data source.
Definition: Transactor.cpp:712
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.
Definition: Transactor.cpp:591
std::size_t getNumberOfProperties(const std::string &datasetName)
It gets the number of properties of the given dataset.
Definition: Transactor.cpp:502
std::auto_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.
Definition: Transactor.cpp:651
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.
Definition: Transactor.cpp:596
std::vector< std::string > getIndexNames(const std::string &datasetName)
It gets the index names of the given dataset.
Definition: Transactor.cpp:681
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.
Definition: Transactor.cpp:691
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.
Definition: Transactor.cpp:239
It models a foreign key constraint for a DataSetType.
Definition: ForeignKey.h:50
TeTheme * getTL4Theme(const ::terralib4::ThemeInfo theme)
Definition: Transactor.cpp:899
std::vector< std::string > getUniqueKeyNames(const std::string &datasetName)
It gets the unique key names of the given dataset.
Definition: Transactor.cpp:631
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.
Definition: Transactor.cpp:739
bool isPropertyNameValid(const std::string &propertyName)
It checks if the given property name is valid.
Definition: Transactor.cpp:278
GeomType getGeomTypeId() const
It returns the geometry subclass type identifier.
Definition: Geometry.h:178
Geometry is the root class of the geometries hierarchy, it follows OGC and ISO standards.
Definition: Geometry.h:73
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.
Definition: Transactor.cpp:616
std::auto_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.
Definition: Transactor.cpp:626
te::common::CharEncoding getEncoding()
It return the DataSource current encoding.
Definition: Transactor.cpp:947
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.
Definition: DataSet.h:112
std::auto_ptr< te::da::DataSetType > getDataSetType(const std::string &name)
It gets information about the given dataset.
Definition: Transactor.cpp:313
void addSequence(te::da::Sequence *sequence)
It creates a new sequence in the data source.
Definition: Transactor.cpp:717
std::auto_ptr< te::dt::Property > getProperty(const std::string &datasetName, const std::string &name)
It retrieves the property with the given name from the dataset.
Definition: Transactor.cpp:469
int getLayerSRID(const std::string &layerName)
Definition: Transactor.cpp:926
Implementation of a dataset for the TerraLib 4 driver.
Definition: VectorDataSet.h:61
It describes a primary key (pk) constraint.
Definition: PrimaryKey.h:52
void dropCheckConstraint(const std::string &datasetName, const std::string &name)
It removes the check constraint from the dataset.
Definition: Transactor.cpp:671
std::auto_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.
Definition: Transactor.cpp:141
std::auto_ptr< te::da::Index > getIndex(const std::string &datasetName, const std::string &name)
It gets the index with the given name from the dataset.
Definition: Transactor.cpp:676
void dropUniqueKey(const std::string &datasetName, const std::string &name)
It removes the unique key constraint from the dataset.
Definition: Transactor.cpp:646
void addCheckConstraint(const std::string &datasetName, te::da::CheckConstraint *cc)
It adds a check constraint to the dataset.
Definition: Transactor.cpp:666
void commit()
It commits the transaction.
Definition: Transactor.cpp:124
std::size_t getNumberOfDataSets()
It retrieves the number of data sets available in the data source.
Definition: Transactor.cpp:308
void begin()
It starts a new transaction.
Definition: Transactor.cpp:118
std::auto_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...
Definition: Transactor.cpp:223
std::auto_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.
Definition: Transactor.cpp:249
TeAttrDataType Convert2T4(int type)
It converts a Terralib 5 data type to Terralib 4.x data type.
Definition: Utils.cpp:287
std::vector< std::string > getTL4Layers()
Definition: Transactor.cpp:810
bool isDataSetNameValid(const std::string &datasetName)
It returns true if the given string is a valid dataset name.
Definition: Transactor.cpp:273
std::vector< std::string > getSequenceNames()
It gets the sequence names available in the data source.
Definition: Transactor.cpp:707
std::string m_viewName
Definition: ThemeInfo.h:40
void add(const std::string &datasetName, te::da::DataSet *d, const std::map< std::string, std::string > &options, std::size_t limit=0)
It adds data items to the dataset in the data source.
Definition: Transactor.cpp:782
std::auto_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.
Definition: Transactor.cpp:727
void dropDataSet(const std::string &name)
It removes the dataset schema from the data source.
Definition: Transactor.cpp:772
void dropSequence(const std::string &name)
It removes the sequence from the data source.
Definition: Transactor.cpp:722
A Query is independent from the data source language/dialect.
Definition: Query.h:46
It describes an index associated to a DataSetType.
Definition: Index.h:54
te::da::DataSource * getDataSource() const
It returns the parent data source of the transactor.
Definition: Transactor.cpp:113
void addUniqueKey(const std::string &datasetName, te::da::UniqueKey *uk)
It adds a unique key constraint to the dataset.
Definition: Transactor.cpp:641
std::vector<::terralib4::ThemeInfo > getTL4Themes()
Definition: Transactor.cpp:858
void dropProperty(const std::string &datasetName, const std::string &name)
It removes a property from the given dataset.
Definition: Transactor.cpp:562
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.
Definition: Transactor.cpp:661
const std::string & getName() const
It returns the property name.
Definition: Property.h:127