All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
Transactor.cpp
Go to the documentation of this file.
1 /* Copyright (C) 2008-2013 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 "Transactor.h"
60 #include "Utils.h"
61 
62 // Terralib 4.x
63 #include <terralib/kernel/TeDatabase.h>
64 #include <terralib/kernel/TeLayer.h>
65 
66 // STL
67 #include <cassert>
68 //#include <cstring>
69 #include <memory>
70 #include <iostream>
71 
72 // Boost
73 //#include <boost/algorithm/string/case_conv.hpp>
74 #include <boost/format.hpp>
75 #include <boost/lexical_cast.hpp>
76 //#include <boost/thread.hpp>
77 
79  : m_ds(ds),
80  m_db(db),
81  m_isInTransaction(false)
82 {
83 }
84 
86 {
87 }
88 
90 {
91  return m_ds;
92 }
93 
95 {
96  m_db->beginTransaction();
97  m_isInTransaction = true;
98 }
99 
101 {
102  m_db->commitTransaction();
103  m_isInTransaction = false;
104 }
105 
107 {
108  m_db->rollbackTransaction();
109  m_isInTransaction = false;
110 }
111 
113 {
114  return m_isInTransaction;
115 }
116 
117 std::auto_ptr<te::da::DataSet> terralib4::Transactor::getDataSet(const std::string& name,
118  te::common::TraverseType /*travType*/,
119  bool /*connected*/,
120  const te::common::AccessPolicy /*accessPolicy*/)
121 {
122  TeLayerMap map = m_db->layerMap();
123 
124  std::map<int, TeLayer*>::iterator it = map.begin();
125 
126  TeLayer* layer = 0;
127 
128  while(it != map.end())
129  {
130  if(it->second->name() == name)
131  {
132  layer = it->second;
133  break;
134  }
135  ++it;
136  }
137 
138  if(layer->hasGeometry(TeRASTER))
139  {
140  return std::auto_ptr<te::da::DataSet>(new RasterDataSet(layer->raster()));
141  }
142  else
143  return std::auto_ptr<te::da::DataSet>(new VectorDataSet(layer));
144 }
145 
146 std::auto_ptr<te::da::DataSet> terralib4::Transactor::getDataSet(const std::string& name,
147  const std::string& propertyName,
148  const te::gm::Envelope* e,
150  te::common::TraverseType travType,
151  bool /*connected*/,
152  const te::common::AccessPolicy /*accessPolicy*/)
153 {
154  throw Exception(TR_TERRALIB4("This method is not supported by TerraLib 4.x driver!"));
155 }
156 
157 std::auto_ptr<te::da::DataSet> terralib4::Transactor::getDataSet(const std::string& name,
158  const std::string& propertyName,
159  const te::gm::Geometry* g,
161  te::common::TraverseType travType,
162  bool /*connected*/,
163  const te::common::AccessPolicy /*accessPolicy*/)
164 {
165  throw Exception(TR_TERRALIB4("This method is not supported by TerraLib 4.x driver!"));
166 }
167 
168 std::auto_ptr<te::da::DataSet> terralib4::Transactor::getDataSet(const std::string& name,
169  const ObjectIdSet* oids,
170  te::common::TraverseType travType,
171  bool /*connected*/,
172  const te::common::AccessPolicy /*accessPolicy*/)
173 {
174  throw Exception(TR_TERRALIB4("This method is not supported by TerraLib 4.x driver!"));
175 }
176 
177 
178 
179 std::auto_ptr<te::da::DataSet> terralib4::Transactor::query(const te::da::Select& /*q*/,
180  te::common::TraverseType /*travType*/,
181  bool /*connected*/,
182  const te::common::AccessPolicy /*accessPolicy*/)
183 {
184  throw Exception(TR_TERRALIB4("TerraLib 4.x driver doesn't support queries!"));
185 }
186 
187 std::auto_ptr<te::da::DataSet> terralib4::Transactor::query(const std::string& /*query*/,
188  te::common::TraverseType /*travType*/,
189  bool /*connected*/,
190  const te::common::AccessPolicy /*accessPolicy*/)
191 {
192  throw Exception(TR_TERRALIB4("TerraLib 4.x driver doesn't support queries!"));
193 }
194 
196 {
197  throw Exception(TR_TERRALIB4("TerraLib 4.x driver doesn't support command execution!"));
198 }
199 
200 void terralib4::Transactor::execute(const std::string& /*command*/)
201 {
202  throw Exception(TR_TERRALIB4("TerraLib 4.x driver doesn't support command execution!"));
203 }
204 
205 std::auto_ptr<te::da::PreparedQuery> terralib4::Transactor::getPrepared(const std::string& qName)
206 {
207  throw Exception(TR_TERRALIB4("TerraLib 4.x driver doesn't support prepared queries!"));
208 }
209 
210 std::auto_ptr<te::da::BatchExecutor> terralib4::Transactor::getBatchExecutor()
211 {
212  throw Exception(TR_TERRALIB4("TerraLib 4.x driver doesn't support prepared batch executors!"));
213 }
214 
216 {
217 }
218 
220 {
221  throw Exception(TR_TERRALIB4("TerraLib 4.x driver is read-only!"));
222 }
223 
224 std::string terralib4::Transactor::escape(const std::string& value)
225 {
226  throw Exception(TR_TERRALIB4("This method is not supported by TerraLib 4.x driver!"));
227 }
228 
229 bool terralib4::Transactor::isDataSetNameValid(const std::string& /*datasetName*/)
230 {
231  throw Exception(TR_TERRALIB4("TerraLib 4.x driver is read-only!"));
232 }
233 
234 bool terralib4::Transactor::isPropertyNameValid(const std::string& /*propertyName*/)
235 {
236  throw Exception(TR_TERRALIB4("TerraLib 4.x driver is read-only!"));
237 }
238 
239 std::vector<std::string> terralib4::Transactor::getDataSetNames()
240 {
241  m_db->loadLayerSet(true);
242 
243  TeLayerMap map = m_db->layerMap();
244 
245  std::map<int, TeLayer*>::iterator it = map.begin();
246 
247  std::vector<std::string> layers;
248 
249  TeLayer* layer = 0;
250 
251  while(it != map.end())
252  {
253  layers.push_back(it->second->name());
254 
255  ++it;
256  }
257 
258  return layers;
259 }
260 
262 {
263  return m_db->layerMap().size();
264 }
265 
266 std::auto_ptr<te::da::DataSetType> terralib4::Transactor::getDataSetType(const std::string& name)
267 {
268  if(!m_db->layerExist(name))
269  return std::auto_ptr<te::da::DataSetType>(0);
270 
271  TeLayerMap map = m_db->layerMap();
272 
273  std::map<int, TeLayer*>::iterator it = map.begin();
274 
275  TeLayer* layer = 0;
276 
277  while(it != map.end())
278  {
279  if(it->second->name() == name)
280  {
281  layer = it->second;
282  break;
283  }
284  ++it;
285  }
286 
287  if(layer->hasGeometry(TeRASTER))
288  {
289  std::auto_ptr<te::da::DataSetType> dst(new te::da::DataSetType(layer->name(), 0));
290 
291 // TODO: handle rasters with multiple objectid!
292  te::rst::RasterProperty* prop = Convert2T5(layer->raster()->params());
293  dst->add(prop);
294  return dst;
295  }
296 
297  TeAttrTableVector tables;
298  layer->getAttrTables(tables);
299 
300  TeTable table = tables[0];
301 
302  std::auto_ptr<te::da::DataSetType> mainDst(terralib4::Convert2T5(table));
303  mainDst->setTitle(layer->name());
304 
305  std::vector<std::string> pkey;
306  table.primaryKeys(pkey);
307 
308  te::da::PrimaryKey* pk = 0;
309 
310  if(!pkey.empty())
311  {
312  pk = new te::da::PrimaryKey(table.name() + "_pk", mainDst.get());
313 
314  std::vector<te::dt::Property*> pkProps;
315  for(std::size_t i = 0; i < pkey.size(); ++i)
316  {
317  te::dt::Property* p = mainDst->getProperty(pkey[i]);
318  pkProps.push_back(p);
319  }
320 
321  pk->setProperties(pkProps);
322  }
323 
324  if(tables.size() > 1)
325  {
326  for(std::size_t i = 1; i < tables.size(); ++i)
327  {
328  TeTable table = tables[i];
329 
330  std::auto_ptr<te::da::DataSetType> dst(terralib4::Convert2T5(table));
331 
332  std::vector<te::dt::Property*> props = dst->getProperties();
333 
334  for(std::size_t j = 0; j < props.size(); ++j)
335  {
336  te::dt::Property* prop = props[j]->clone();
337  prop->setName(dst->getName() + "_" + prop->getName());
338 
339  mainDst->add(prop);
340  }
341  }
342  }
343 
344  TeRepresPointerVector vec = layer->vectRepres();
345 
346  if(!vec.empty())
347  {
348  TeGeomRep geomRep = vec[0]->geomRep_;
349 
350  te::gm::GeometryProperty* geomProp = new te::gm::GeometryProperty("spatial_data",
351  layer->projection()->epsgCode(), terralib4::Convert2T5GeomType(geomRep));
352  mainDst->add(geomProp);
353  }
354 
355  return mainDst;
356 }
357 
358 boost::ptr_vector<te::dt::Property> terralib4::Transactor::getProperties(const std::string& datasetName)
359 {
360  std::auto_ptr<te::da::DataSetType> dt = getDataSetType(datasetName);
361 
362  std::vector<te::dt::Property*> dtProperties = dt->getProperties();
363 
364  boost::ptr_vector<te::dt::Property> properties;
365 
366  for(std::size_t i = 0; i < dtProperties.size(); ++i)
367  properties.push_back(dtProperties[i]->clone());
368 
369  return properties;
370 }
371 
372 std::auto_ptr<te::dt::Property> terralib4::Transactor::getProperty(const std::string& datasetName, const std::string& name)
373 {
374  if(!propertyExists(datasetName, name))
375  throw Exception((boost::format(TR_TERRALIB4("The dataset \"%1%\" has no property with this name \"%2%\"!")) % datasetName % name).str());
376 
377  std::auto_ptr<te::da::DataSetType> dt(getDataSetType(datasetName));
378 
379  return std::auto_ptr<te::dt::Property>(dt->getProperty(name)->clone());
380 }
381 
382 std::auto_ptr<te::dt::Property> terralib4::Transactor::getProperty(const std::string& datasetName, std::size_t propertyPos)
383 {
384  std::auto_ptr<te::da::DataSetType> dt(getDataSetType(datasetName));
385 
386  assert(propertyPos < dt->size());
387 
388  return std::auto_ptr<te::dt::Property>(dt->getProperty(propertyPos)->clone());
389 }
390 
391 std::vector<std::string> terralib4::Transactor::getPropertyNames(const std::string& datasetName)
392 {
393  std::auto_ptr<te::da::DataSetType> dt(getDataSetType(datasetName));
394 
395  std::vector<std::string> pNames;
396 
397  std::size_t numProperties = dt->size();
398 
399  for(std::size_t i = 0; i < numProperties; ++i)
400  pNames.push_back(dt->getProperty(i)->getName());
401 
402  return pNames;
403 }
404 
405 std::size_t terralib4::Transactor::getNumberOfProperties(const std::string& datasetName)
406 {
407  std::auto_ptr<te::da::DataSetType> dt(getDataSetType(datasetName));
408 
409  return dt->size();
410 }
411 
412 bool terralib4::Transactor::propertyExists(const std::string& datasetName, const std::string& name)
413 {
414  std::auto_ptr<te::da::DataSetType> dt(getDataSetType(datasetName));
415 
416  std::vector<std::string> pNames = getPropertyNames(datasetName);
417 
418  if(std::find(pNames.begin(), pNames.end(), name) != pNames.end())
419  return true;
420 
421  return false;
422 }
423 
424 void terralib4::Transactor::addProperty(const std::string& datasetName, te::dt::Property* p)
425 {
426  std::string name = p->getName();
427  if(propertyExists(datasetName, name))
428  throw Exception((boost::format(TR_TERRALIB4("The dataset already \"%1%\" has a property with this name \"%2%\"!")) % datasetName % name).str());
429 
430  int pType = p->getType();
431 
432  TeAttributeRep newProperty;
433 
434  newProperty.name_ = name;
435 
436  if(p->getType() != te::dt::GEOMETRY_TYPE)
437  newProperty.type_ = terralib4::Convert2T4(p->getType());
438  else
439  {
440  te::gm::Geometry* geom = dynamic_cast<te::gm::Geometry*>(p);
441  newProperty.type_ = terralib4::Convert2T4GeomType(geom->getGeomTypeId());
442  }
443 
444  TeLayerMap map = m_db->layerMap();
445 
446  std::map<int, TeLayer*>::iterator it = map.begin();
447 
448  TeLayer* layer = 0;
449 
450  while(it != map.end())
451  {
452  if(it->second->name() == datasetName)
453  {
454  layer = it->second;
455  break;
456  }
457  ++it;
458  }
459 
460  TeAttrTableVector tables;
461  layer->getAttrTables(tables);
462  std::string tableName = tables[0].name();
463 
464  m_db->addColumn(tableName, newProperty);
465 }
466 
467 void terralib4::Transactor::dropProperty(const std::string& datasetName, const std::string& name)
468 {
469  throw;
470 }
471 
472 void terralib4::Transactor::renameProperty(const std::string& datasetName,
473  const std::string& propertyName,
474  const std::string& newPropertyName)
475 {
476  throw Exception(TR_TERRALIB4("This method is not supported by TerraLib 4.x driver!"));
477 }
478 
479 std::auto_ptr<te::da::PrimaryKey> terralib4::Transactor::getPrimaryKey(const std::string& datasetName)
480 {
481  std::auto_ptr<te::da::DataSetType> dt(getDataSetType(datasetName));
482 
483  return std::auto_ptr<te::da::PrimaryKey>(static_cast<te::da::PrimaryKey*>(dt->getPrimaryKey()->clone()));
484 }
485 
486 bool terralib4::Transactor::primaryKeyExists(const std::string& datasetName, const std::string& name)
487 {
488  std::auto_ptr<te::da::DataSetType> dt(getDataSetType(datasetName));
489 
490  if(dt->getPrimaryKey()->getName() == name)
491  return true;
492 
493  return false;
494 }
495 
496 void terralib4::Transactor::addPrimaryKey(const std::string& datasetName, te::da::PrimaryKey* pk)
497 {
498  throw Exception(TR_TERRALIB4("This method is not supported by TerraLib 4.x driver!"));
499 }
500 
501 void terralib4::Transactor::dropPrimaryKey(const std::string& datasetName)
502 {
503  throw Exception(TR_TERRALIB4("This method is not supported by TerraLib 4.x driver!"));
504 }
505 
506 std::auto_ptr<te::da::ForeignKey> terralib4::Transactor::getForeignKey(const std::string& datasetName, const std::string& name)
507 {
508  throw Exception(TR_TERRALIB4("This method is not supported by TerraLib 4.x driver!"));
509 }
510 
511 std::vector<std::string> terralib4::Transactor::getForeignKeyNames(const std::string& datasetName)
512 {
513  throw Exception(TR_TERRALIB4("This method is not supported by TerraLib 4.x driver!"));
514 }
515 
516 bool terralib4::Transactor::foreignKeyExists(const std::string& datasetName, const std::string& name)
517 {
518  throw Exception(TR_TERRALIB4("This method is not supported by TerraLib 4.x driver!"));
519 }
520 
521 void terralib4::Transactor::addForeignKey(const std::string& datasetName, te::da::ForeignKey* fk)
522 {
523  throw Exception(TR_TERRALIB4("This method is not supported by TerraLib 4.x driver!"));
524 }
525 
526 void terralib4::Transactor::dropForeignKey(const std::string& datasetName, const std::string& fkName)
527 {
528  throw Exception(TR_TERRALIB4("This method is not supported by TerraLib 4.x driver!"));
529 }
530 
531 std::auto_ptr<te::da::UniqueKey> terralib4::Transactor::getUniqueKey(const std::string& datasetName, const std::string& name)
532 {
533  throw Exception(TR_TERRALIB4("This method is not supported by TerraLib 4.x driver!"));
534 }
535 
536 std::vector<std::string> terralib4::Transactor::getUniqueKeyNames(const std::string& datasetName)
537 {
538  throw Exception(TR_TERRALIB4("This method is not supported by TerraLib 4.x driver!"));
539 }
540 
541 bool terralib4::Transactor::uniqueKeyExists(const std::string& datasetName, const std::string& name)
542 {
543  throw Exception(TR_TERRALIB4("This method is not supported by TerraLib 4.x driver!"));
544 }
545 
546 void terralib4::Transactor::addUniqueKey(const std::string& datasetName, te::da::UniqueKey* uk)
547 {
548  throw Exception(TR_TERRALIB4("This method is not supported by TerraLib 4.x driver!"));
549 }
550 
551 void terralib4::Transactor::dropUniqueKey(const std::string& datasetName, const std::string& name)
552 {
553  throw Exception(TR_TERRALIB4("This method is not supported by TerraLib 4.x driver!"));
554 }
555 
556 std::auto_ptr<te::da::CheckConstraint> terralib4::Transactor::getCheckConstraint(const std::string& datasetName, const std::string& name)
557 {
558  throw Exception(TR_TERRALIB4("This method is not supported by TerraLib 4.x driver!"));
559 }
560 
561 std::vector<std::string> terralib4::Transactor::getCheckConstraintNames(const std::string& datasetName)
562 {
563  throw Exception(TR_TERRALIB4("This method is not supported by TerraLib 4.x driver!"));
564 }
565 
566 bool terralib4::Transactor::checkConstraintExists(const std::string& datasetName, const std::string& name)
567 {
568  throw Exception(TR_TERRALIB4("This method is not supported by TerraLib 4.x driver!"));
569 }
570 
572 {
573  throw Exception(TR_TERRALIB4("This method is not supported by TerraLib 4.x driver!"));
574 }
575 
576 void terralib4::Transactor::dropCheckConstraint(const std::string& datasetName, const std::string& name)
577 {
578  throw Exception(TR_TERRALIB4("This method is not supported by TerraLib 4.x driver!"));
579 }
580 
581 std::auto_ptr<te::da::Index> terralib4::Transactor::getIndex(const std::string& datasetName, const std::string& name)
582 {
583  throw Exception(TR_TERRALIB4("This method is not supported by TerraLib 4.x driver!"));
584 }
585 
586 std::vector<std::string> terralib4::Transactor::getIndexNames(const std::string& datasetName)
587 {
588  throw Exception(TR_TERRALIB4("This method is not supported by TerraLib 4.x driver!"));
589 }
590 
591 bool terralib4::Transactor::indexExists(const std::string& datasetName, const std::string& name)
592 {
593  throw Exception(TR_TERRALIB4("This method is not supported by TerraLib 4.x driver!"));
594 }
595 
596 void terralib4::Transactor::addIndex(const std::string& datasetName, te::da::Index* idx,
597  const std::map<std::string, std::string>& options)
598 {
599  throw Exception(TR_TERRALIB4("This method is not supported by TerraLib 4.x driver!"));
600 }
601 
602 void terralib4::Transactor::dropIndex(const std::string& datasetName, const std::string& idxName)
603 {
604  throw Exception(TR_TERRALIB4("This method is not supported by TerraLib 4.x driver!"));
605 }
606 
607 std::auto_ptr<te::da::Sequence> terralib4::Transactor::getSequence(const std::string& name)
608 {
609  throw Exception(TR_TERRALIB4("This method is not supported by TerraLib 4.x driver!"));
610 }
611 
612 std::vector<std::string> terralib4::Transactor::getSequenceNames()
613 {
614  throw Exception(TR_TERRALIB4("This method is not supported by TerraLib 4.x driver!"));
615 }
616 
617 bool terralib4::Transactor::sequenceExists(const std::string& name)
618 {
619  throw Exception(TR_TERRALIB4("This method is not supported by TerraLib 4.x driver!"));
620 }
621 
623 {
624  throw Exception(TR_TERRALIB4("This method is not supported by TerraLib 4.x driver!"));
625 }
626 
627 void terralib4::Transactor::dropSequence(const std::string& name)
628 {
629  throw Exception(TR_TERRALIB4("This method is not supported by TerraLib 4.x driver!"));
630 }
631 
632 std::auto_ptr<te::gm::Envelope> terralib4::Transactor::getExtent(const std::string& datasetName,
633  const std::string& /*propertyName*/)
634 {
635  throw Exception(TR_TERRALIB4("This method is not supported by TerraLib 4.x driver!"));
636 }
637 
638 std::auto_ptr<te::gm::Envelope> terralib4::Transactor::getExtent(const std::string& datasetName,
639  std::size_t /*propertyPos*/)
640 {
641  throw Exception(TR_TERRALIB4("This method is not supported by TerraLib 4.x driver!"));
642 }
643 
644 std::size_t terralib4::Transactor::getNumberOfItems(const std::string& datasetName)
645 {
646  throw Exception(TR_TERRALIB4("This method is not supported by TerraLib 4.x driver!"));
647 }
648 
650 {
651  throw Exception(TR_TERRALIB4("This method is not supported by TerraLib 4.x driver!"));
652 }
653 
654 bool terralib4::Transactor::dataSetExists(const std::string& name)
655 {
656  std::vector<std::string> names = getDataSetNames();
657 
658  for(std::size_t i = 0; i < names.size(); ++i)
659  if(names[i] == name)
660  return true;
661 
662  return false;
663 }
664 
665 void terralib4::Transactor::createDataSet(te::da::DataSetType* dt, const std::map<std::string, std::string>& options)
666 {
667  throw Exception(TR_TERRALIB4("This method is not supported by TerraLib 4.x driver!"));
668 }
669 
670 void terralib4::Transactor::cloneDataSet(const std::string& name,
671  const std::string& cloneName,
672  const std::map<std::string, std::string>& options)
673 {
674  throw Exception(TR_TERRALIB4("This method is not supported by TerraLib 4.x driver!"));
675 }
676 
677 void terralib4::Transactor::dropDataSet(const std::string& name)
678 {
679  throw Exception(TR_TERRALIB4("This method is not supported by TerraLib 4.x driver!"));
680 }
681 
682 void terralib4::Transactor::renameDataSet(const std::string& name, const std::string& newName)
683 {
684  throw Exception(TR_TERRALIB4("This method is not supported by TerraLib 4.x driver!"));
685 }
686 
687 void terralib4::Transactor::add(const std::string& datasetName,
688  te::da::DataSet* d,
689  const std::map<std::string, std::string>& options,
690  std::size_t limit)
691 {
692  throw Exception(TR_TERRALIB4("This method is not supported by TerraLib 4.x driver!"));
693 }
694 
695 void terralib4::Transactor::remove(const std::string& datasetName, const te::da::ObjectIdSet* oids)
696 {
697  throw Exception(TR_TERRALIB4("This method is not supported by TerraLib 4.x driver!"));
698 }
699 
700 void terralib4::Transactor::update(const std::string& datasetName,
701  te::da::DataSet* dataset,
702  const std::vector<std::size_t>& properties,
703  const te::da::ObjectIdSet* oids,
704  const std::map<std::string, std::string>& options,
705  std::size_t limit)
706 {
707  throw Exception(TR_TERRALIB4("This method is not supported by TerraLib 4.x driver!"));
708 }
709 
710 void terralib4::Transactor::optimize(const std::map<std::string, std::string>& opInfo)
711 {
712  throw Exception(TR_TERRALIB4("This method is not supported by TerraLib 4.x driver!"));
713 }
Implementation of a dataset for the TerraLib 4 driver.
Definition: VectorDataSet.h:61
std::auto_ptr< te::da::PrimaryKey > getPrimaryKey(const std::string &datasetName)
It retrieves the primary key of the dataset.
Definition: Transactor.cpp:479
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:531
void dropCheckConstraint(const std::string &datasetName, const std::string &name)
It removes the check constraint from the dataset.
Definition: Transactor.cpp:576
It describes an index associated to a DataSetType.
Definition: Index.h:54
void dropPrimaryKey(const std::string &datasetName)
It removes the primary key constraint from the dataset schema.
Definition: Transactor.cpp:501
void rollBack()
It aborts the transaction. Any changes will be rolled-back.
Definition: Transactor.cpp:106
This class represents a set of unique ids created in the same context. i.e. from the same data set...
Definition: ObjectIdSet.h:53
DataSourceTransactor implementation for TerraLib 4.x API.
std::auto_ptr< te::da::BatchExecutor > getBatchExecutor()
It creates a batch command executor.
Definition: Transactor.cpp:210
bool dataSetExists(const std::string &name)
It checks if a dataset with the given name exists in the data source.
Definition: Transactor.cpp:654
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:516
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:591
void dropProperty(const std::string &datasetName, const std::string &name)
It removes a property from the given dataset.
Definition: Transactor.cpp:467
std::size_t getNumberOfItems(const std::string &datasetName)
It retrieves the number of items of the given dataset.
Definition: Transactor.cpp:644
A Select models a query to be used when retrieving data from a DataSource.
Definition: Select.h:65
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:52
#define TR_TERRALIB4(message)
It marks a string in order to get translated. This is a special mark used in the DataAccess module of...
Definition: Config.h:119
void addSequence(te::da::Sequence *sequence)
It creates a new sequence in the data source.
Definition: Transactor.cpp:622
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:506
std::vector< std::string > getDataSetNames()
It It gets the dataset names available in the data source.
Definition: Transactor.cpp:239
void dropDataSet(const std::string &name)
It removes the dataset schema from the data source.
Definition: Transactor.cpp:677
bool isPropertyNameValid(const std::string &propertyName)
It checks if the given property name is valid.
Definition: Transactor.cpp:234
std::auto_ptr< te::da::DataSetType > getDataSetType(const std::string &name)
It gets information about the given dataset.
Definition: Transactor.cpp:266
std::vector< std::string > getSequenceNames()
It gets the sequence names available in the data source.
Definition: Transactor.cpp:612
TeAttrDataType Convert2T4GeomType(te::gm::GeomType type)
Definition: Utils.cpp:325
It describes a primary key (pk) constraint.
Definition: PrimaryKey.h:52
te::gm::GeomType Convert2T5GeomType(TeAttrDataType type)
Definition: Utils.cpp:193
const std::string & getName() const
It returns the property name.
Definition: Property.h:126
bool hasDataSets()
It checks if the data source has any dataset.
Definition: Transactor.cpp:649
It describes a sequence (a number generator).
Definition: Sequence.h:56
void addPrimaryKey(const std::string &datasetName, te::da::PrimaryKey *pk)
It adds a primary key constraint to the dataset schema.
Definition: Transactor.cpp:496
SpatialRelation
Spatial relations between geometric objects.
Definition: Enums.h:122
It models a foreign key constraint for a DataSetType.
Definition: ForeignKey.h:50
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:472
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:205
std::size_t getNumberOfDataSets()
It retrieves the number of data sets available in the data source.
Definition: Transactor.cpp:261
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:670
void setName(const std::string &name)
It sets the property name.
Definition: Property.h:136
AccessPolicy
Supported data access policies (can be used as bitfield).
Definition: Enums.h:40
void dropForeignKey(const std::string &datasetName, const std::string &fkName)
It removes the foreign key constraint from the dataset schema.
Definition: Transactor.cpp:526
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:412
Utility functions for the data access module.
A Query is independent from the data source language/dialect.
Definition: Query.h:46
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:665
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:710
Geometry is the root class of the geometries hierarchy, it follows OGC and ISO standards.
Definition: Geometry.h:73
bool isDataSetNameValid(const std::string &datasetName)
It returns true if the given string is a valid dataset name.
Definition: Transactor.cpp:229
bool isInTransaction() const
It returns true if a transaction is in progress, otherwise, it returns false.
Definition: Transactor.cpp:112
void addCheckConstraint(const std::string &datasetName, te::da::CheckConstraint *cc)
It adds a check constraint to the dataset.
Definition: Transactor.cpp:571
std::size_t getNumberOfProperties(const std::string &datasetName)
It gets the number of properties of the given dataset.
Definition: Transactor.cpp:405
void dropSequence(const std::string &name)
It removes the sequence from the data source.
Definition: Transactor.cpp:627
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:117
It describes a unique key (uk) constraint.
Definition: UniqueKey.h:53
An static class with global definitions.
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:700
Transactor(DataSource *ds, TeDatabase *db)
Definition: Transactor.cpp:78
GeomType getGeomTypeId() const
It returns the geometry subclass type identifier.
Definition: Geometry.h:178
void cancel()
It requests that the data source stop the processing of the current command.
Definition: Transactor.cpp:215
void remove(const std::string &datasetName, const te::da::ObjectIdSet *oids=0)
It removes all the informed items from the dataset.
Definition: Transactor.cpp:695
Implements the DataSource class for the TerraLib 4.x Data Access Driver.
TraverseType
A dataset can be traversed in two ways:
Definition: Enums.h:53
void begin()
It starts a new transaction.
Definition: Transactor.cpp:94
void addForeignKey(const std::string &datasetName, te::da::ForeignKey *fk)
It adds a foreign key constraint to a dataset.
Definition: Transactor.cpp:521
std::vector< std::string > getUniqueKeyNames(const std::string &datasetName)
It gets the unique key names of the given dataset.
Definition: Transactor.cpp:536
An abstract class for data providers like a DBMS, Web Services or a regular file. ...
Definition: DataSource.h:116
std::vector< std::string > getIndexNames(const std::string &datasetName)
It gets the index names of the given dataset.
Definition: Transactor.cpp:586
A class that models the description of a dataset.
Definition: DataSetType.h:72
boost::ptr_vector< te::dt::Property > getProperties(const std::string &datasetName)
It retrieves the properties of the dataset.
Definition: Transactor.cpp:358
TeAttrDataType Convert2T4(int type)
It converts a Terralib 5 data type to Terralib 4.x data type.
Definition: Utils.cpp:283
Raster property.
It models a property definition.
Definition: Property.h:59
std::vector< std::string > getPropertyNames(const std::string &datasetName)
It gets the property names of the given dataset.
Definition: Transactor.cpp:391
std::vector< std::string > getForeignKeyNames(const std::string &datasetName)
It gets the foreign key names of the given dataset.
Definition: Transactor.cpp:511
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:687
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:607
int getType() const
It returns the property data type.
Definition: Property.h:143
void execute(const te::da::Query &command)
It executes the specified command using a generic query representation.
Definition: Transactor.cpp:195
bool primaryKeyExists(const std::string &datasetName, const std::string &name)
It checks if a primary key exists in the dataset.
Definition: Transactor.cpp:486
bool sequenceExists(const std::string &name)
It checks if a sequence with the given name exists in the data source.
Definition: Transactor.cpp:617
void dropUniqueKey(const std::string &datasetName, const std::string &name)
It removes the unique key constraint from the dataset.
Definition: Transactor.cpp:551
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:581
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:541
A class that describes a check constraint.
An Envelope defines a 2D rectangular region.
Definition: Envelope.h:51
void renameDataSet(const std::string &name, const std::string &newName)
It renames a dataset.
Definition: Transactor.cpp:682
boost::int64_t getLastGeneratedId()
It returns the last id generated by an insertion command.
Definition: Transactor.cpp:219
void addProperty(const std::string &datasetName, te::dt::Property *p)
It adds a new property to the dataset schema.
Definition: Transactor.cpp:424
void setProperties(const std::vector< te::dt::Property * > &properties)
It sets the properties that form the primary key.
Definition: PrimaryKey.h:116
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:372
void commit()
It commits the transaction.
Definition: Transactor.cpp:100
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:632
Geometric property.
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:179
virtual Property * clone() const =0
It returns a clone of the object.
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:596
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:566
te::da::DataSource * getDataSource() const
It returns the parent data source of the transactor.
Definition: Transactor.cpp:89
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:556
A dataset is the unit of information manipulated by the data access module of TerraLib.
Definition: DataSet.h:111
std::vector< std::string > getCheckConstraintNames(const std::string &datasetName)
It gets the check constraint names of the given dataset.
Definition: Transactor.cpp:561
void dropIndex(const std::string &datasetName, const std::string &idxName)
It removes the index from the dataset schema.
Definition: Transactor.cpp:602
std::string escape(const std::string &value)
It escapes a string for using in commands and queries.
Definition: Transactor.cpp:224
void addUniqueKey(const std::string &datasetName, te::da::UniqueKey *uk)
It adds a unique key constraint to the dataset.
Definition: Transactor.cpp:546