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 // TerraLib
21 #include "../common/Translator.h"
22 #include "../dataaccess/dataset/ObjectId.h"
23 #include "../dataaccess/dataset/ObjectIdSet.h"
24 #include "../dataaccess/query/DataSetName.h"
25 #include "../dataaccess/query/Query.h"
26 #include "../dataaccess/query/Select.h"
27 #include "../dataaccess/utils/Utils.h"
28 #include "../datatype/ByteArray.h"
29 #include "../datatype/Date.h"
30 #include "../datatype/TimeInstant.h"
31 #include "../geometry/Envelope.h"
32 #include "../geometry/GeometryProperty.h"
33 #include "../srs/Config.h"
34 #include "DataSource.h"
35 #include "DataSet.h"
36 #include "SQLVisitor.h"
37 #include "Transactor.h"
38 #include "Utils.h"
39 
40 // OGR
41 #include <ogrsf_frmts.h>
42 
43 std::string RemoveSpatialSql(const std::string& sql)
44 {
45  // Try find AND
46  std::size_t pos = sql.find("AND Intersection");
47 
48  // Try find without AND
49  if(pos == std::string::npos)
50  pos = sql.find("WHERE Intersection");
51 
52  if(pos == std::string::npos)
53  return sql;
54 
55  std::string newQuery;
56 
57  std::size_t pos2 = sql.find("))", pos);
58  newQuery = sql.substr(0, pos);
59  newQuery += sql.substr(pos2 + 2);
60 
61  return newQuery;
62 }
63 
65  : te::da::DataSourceTransactor(),
66  m_ogrDs(ds)
67 {
68 }
69 
71 {
72 }
73 
75 {
76  return 0;
77 }
78 
80 {
81 }
82 
84 {
85  if (!m_ogrDs->getOGRDataSource())
86  return;
87 
88  // we have to reopen datasource so pending data gets synched to disk!
89  m_ogrDs->open();
90 }
91 
93 {
94 }
95 
97 {
98  return false;
99 }
100 
101 std::auto_ptr<te::da::DataSet> te::ogr::Transactor::getDataSet(const std::string& name,
102  te::common::TraverseType /*travType*/,
103  bool /*connected*/,
105 {
106  if (!m_ogrDs->getOGRDataSource())
107  return std::auto_ptr<te::da::DataSet>();
108 
109  OGRDataSource* ds = OGRSFDriverRegistrar::Open(m_ogrDs->getOGRDataSource()->GetName());
110 
111  std::string sql = "SELECT FID, * FROM \'" + name + "\'";
112  OGRLayer* layer = ds->ExecuteSQL(sql.c_str(), 0, 0);
113 
114  if(layer == 0)
115  throw Exception(TR_OGR("The informed data set could not be found in the data source."));
116 
117  return std::auto_ptr<te::da::DataSet>(new DataSet(ds, layer));
118 }
119 
120 std::auto_ptr<te::da::DataSet> te::ogr::Transactor::getDataSet(const std::string& name,
121  const std::string& /*propertyName*/,
122  const te::gm::Envelope* e,
124  te::common::TraverseType /*travType*/,
125  bool /*connected*/,
127 {
128  if (!m_ogrDs->getOGRDataSource())
129  return std::auto_ptr<te::da::DataSet>();
130 
131  OGRDataSource* ds = OGRSFDriverRegistrar::Open(m_ogrDs->getOGRDataSource()->GetName());
132 
133  std::string sql = "SELECT FID, * FROM \'" + name + "\'";
134  OGRLayer* layer = ds->ExecuteSQL(sql.c_str(), 0, 0);
135 
136  if(layer == 0)
137  throw Exception(TR_OGR("The informed data set could not be found in the data source."));
138 
139  layer->SetSpatialFilterRect(e->m_llx, e->m_lly, e->m_urx, e->m_ury);
140 
141  return std::auto_ptr<te::da::DataSet>(new DataSet(ds, layer));
142 }
143 
144 std::auto_ptr<te::da::DataSet> te::ogr::Transactor::getDataSet(const std::string& name,
145  const std::string& /*propertyName*/,
146  const te::gm::Geometry* g,
148  te::common::TraverseType /*travType*/,
149  bool /*connected*/,
151 {
152  if (!m_ogrDs->getOGRDataSource())
153  return std::auto_ptr<te::da::DataSet>();
154 
155  OGRDataSource* ds = OGRSFDriverRegistrar::Open(m_ogrDs->getOGRDataSource()->GetName());
156 
157  std::string sql = "SELECT FID, * FROM \'" + name + "\'";
158  OGRLayer* layer = ds->ExecuteSQL(sql.c_str(), 0, 0);
159 
160  if(layer == 0)
161  throw Exception(TR_OGR("The informed data set could not be found in the data source."));
162 
163  OGRGeometry* ogrg = Convert2OGR(g);
164 
165  layer->SetSpatialFilter(ogrg);
166 
167  OGRGeometryFactory::destroyGeometry(ogrg);
168 
169  return std::auto_ptr<te::da::DataSet>(new DataSet(ds, layer));
170 }
171 
172 std::auto_ptr<te::da::DataSet> te::ogr::Transactor::query(const te::da::Select& q,
173  te::common::TraverseType /*travType*/,
174  bool /*connected*/,
176 {
177  if (!m_ogrDs->getOGRDataSource())
178  return std::auto_ptr<te::da::DataSet>();
179 
180  OGRDataSource* ds = OGRSFDriverRegistrar::Open(m_ogrDs->getOGRDataSource()->GetName());
181 
182  std::string sql;
183 
184  SQLVisitor visitor(*m_ogrDs->getDialect(), sql);
185 
186  q.accept(visitor);
187 
188  sql = RemoveSpatialSql(sql);
189 
190  OGRLayer* layer = ds->ExecuteSQL(sql.c_str(), 0, 0);
191 
192  if(layer == 0)
193  throw Exception(TR_OGR("Could not retrieve the DataSet from data source."));
194 
195  te::gm::Envelope* e = visitor.getMBR();
196 
197  if(e != 0)
198  layer->SetSpatialFilterRect(e->m_llx, e->m_lly, e->m_urx, e->m_ury);
199 
200  return std::auto_ptr<te::da::DataSet>(new DataSet(ds, layer));
201 }
202 
203 std::auto_ptr<te::da::DataSet> te::ogr::Transactor::query(const std::string& query,
204  te::common::TraverseType /*travType*/,
205  bool /*connected*/,
207 {
208  if (!m_ogrDs->getOGRDataSource())
209  return std::auto_ptr<te::da::DataSet>();
210 
211  OGRDataSource* ds = OGRSFDriverRegistrar::Open(m_ogrDs->getOGRDataSource()->GetName());
212 
213  OGRLayer* layer = ds->ExecuteSQL(query.c_str(), 0, 0);
214 
215  if(layer == 0)
216  throw Exception(TR_OGR("Could not retrieve the DataSet from data source."));
217 
218  return std::auto_ptr<te::da::DataSet>(new DataSet(ds, layer));
219 }
220 
222 {
223  std::string sql;
224  SQLVisitor v(*m_ogrDs->getDialect(), sql);
225 
226  command.accept(v);
227 
228  execute(sql);
229 }
230 
231 void te::ogr::Transactor::execute(const std::string& command)
232 {
233  if (!m_ogrDs->getOGRDataSource())
234  return;
235 
236  OGRLayer* layer = m_ogrDs->getOGRDataSource()->ExecuteSQL(command.c_str(), 0, "");
237 
238  if(layer != 0)
239  m_ogrDs->getOGRDataSource()->ReleaseResultSet(layer);
240 }
241 
242 std::auto_ptr<te::da::PreparedQuery> te::ogr::Transactor::getPrepared(const std::string& /*qName*/)
243 {
244  return std::auto_ptr<te::da::PreparedQuery>(0);
245 }
246 
247 std::auto_ptr<te::da::BatchExecutor> te::ogr::Transactor::getBatchExecutor()
248 {
249  return std::auto_ptr<te::da::BatchExecutor>(0);
250 }
251 
253 {
254 }
255 
257 {
258  return 0;
259 }
260 
261 std::string te::ogr::Transactor::escape(const std::string& value)
262 {
263  return value;
264 }
265 
266 bool te::ogr::Transactor::isDataSetNameValid(const std::string& /*datasetName*/)
267 {
268  return true;
269 }
270 
271 bool te::ogr::Transactor::isPropertyNameValid(const std::string& /*propertyName*/)
272 {
273  return true;
274 }
275 
276 std::vector<std::string> te::ogr::Transactor::getDataSetNames()
277 {
278  std::vector<std::string> names;
279 
280  if (!m_ogrDs->getOGRDataSource())
281  return names;
282 
283  for(int i=0; i<m_ogrDs->getOGRDataSource()->GetLayerCount(); i++)
284  names.push_back(m_ogrDs->getOGRDataSource()->GetLayer(i)->GetName());
285 
286  return names;
287 }
288 
290 {
291  if (!m_ogrDs->getOGRDataSource())
292  return 0;
293 
294  return m_ogrDs->getOGRDataSource()->GetLayerCount();
295 }
296 
297 std::auto_ptr<te::da::DataSetType> te::ogr::Transactor::getDataSetType(const std::string& name)
298 {
299  if (!m_ogrDs->getOGRDataSource())
300  return std::auto_ptr<te::da::DataSetType>();
301 
302  std::string sql("SELECT FID, * FROM \'");
303  sql += name + "\'";
304 
305  OGRLayer* l = m_ogrDs->getOGRDataSource()->ExecuteSQL(sql.c_str(), 0, 0);
306 
307  if(l==0)
308  return std::auto_ptr<te::da::DataSetType>();
309 
310  std::auto_ptr<te::da::DataSetType> type(Convert2TerraLib(l->GetLayerDefn()));
311 
312  type->setName(name);
313 
314  const char* colIdName = l->GetFIDColumn();
315 
316  if(colIdName == 0 || colIdName[0] == '\0')
317  colIdName = "FID";
318 
319  int pos = l->GetLayerDefn()->GetFieldIndex(colIdName);
320  if(pos >= 0)
321  {
322  te::da::PrimaryKey* pk = new te::da::PrimaryKey(colIdName, type.get());
323  pk->add(type->getProperty(pos));
324  }
325 
326  int srs = te::ogr::Convert2TerraLibProjection(l->GetSpatialRef());
327 
329 
330  if(gp != 0)
331  gp->setSRID(srs);
332 
333  m_ogrDs->getOGRDataSource()->ReleaseResultSet(l);
334 
335  return type;
336 }
337 
338 boost::ptr_vector<te::dt::Property> te::ogr::Transactor::getProperties(const std::string& datasetName)
339 {
340  boost::ptr_vector<te::dt::Property> ps;
341 
342  if (!m_ogrDs->getOGRDataSource())
343  return ps;
344 
345  std::string sql("SELECT FID, * FROM \'");
346  sql += datasetName + "\'";
347 
348  OGRLayer* l = m_ogrDs->getOGRDataSource()->ExecuteSQL(sql.c_str(), 0, 0);
349 
350  if(l!=0)
351  {
352  int srs = te::ogr::Convert2TerraLibProjection(l->GetSpatialRef());
353  std::auto_ptr<te::da::DataSetType> dt(Convert2TerraLib(l->GetLayerDefn(),srs));
354  std::vector<te::dt::Property*> props = dt->getProperties();
355  std::vector<te::dt::Property*>::iterator it;
356 
357  for(it=props.begin(); it!=props.end(); ++it)
358  ps.push_back((*it)->clone());
359  }
360 
361  m_ogrDs->getOGRDataSource()->ReleaseResultSet(l);
362 
363  return ps;
364 }
365 
366 std::auto_ptr<te::dt::Property> te::ogr::Transactor::getProperty(const std::string& datasetName, const std::string& name)
367 {
368  if (!m_ogrDs->getOGRDataSource())
369  return std::auto_ptr<te::dt::Property>();
370 
371  int idx = -1;
372  std::string sql("SELECT FID, * FROM \'");
373  sql += datasetName + "\'";
374 
375  OGRLayer* l = m_ogrDs->getOGRDataSource()->ExecuteSQL(sql.c_str(), 0, 0);
376 
377  if(l != 0)
378  idx = l->GetLayerDefn()->GetFieldIndex(name.c_str());
379 
380  m_ogrDs->getOGRDataSource()->ReleaseResultSet(l);
381 
382  return getProperty(datasetName, idx);
383 }
384 
385 std::auto_ptr<te::dt::Property> te::ogr::Transactor::getProperty(const std::string& datasetName, std::size_t propertyPos)
386 {
387  OGRDataSource* ogrds = m_ogrDs->getOGRDataSource();
388  if (!ogrds)
389  return std::auto_ptr<te::dt::Property>();
390 
391  std::auto_ptr<te::dt::Property> res;
392  std::string sql ("SELECT FID, * FROM \'");
393  sql += datasetName + "\'";
394 
395  OGRLayer* l = ogrds->ExecuteSQL(sql.c_str(), 0, 0);
396 
397  if(l != 0)
398  {
399  OGRFeatureDefn* def = l->GetLayerDefn();
400  OGRFieldDefn* fdef = def->GetFieldDefn(propertyPos);
401 
402  if(fdef != 0)
403  res.reset(Convert2TerraLib(fdef));
404  }
405 
406  m_ogrDs->getOGRDataSource()->ReleaseResultSet(l);
407 
408  return res;
409 }
410 
411 std::vector<std::string> te::ogr::Transactor::getPropertyNames(const std::string& datasetName)
412 {
413  OGRDataSource* ogrds = m_ogrDs->getOGRDataSource();
414  if (!ogrds)
415  return std::vector<std::string>();
416 
417  std::vector<std::string> res;
418  std::string sql ("SELECT FID, * FROM \'");
419  sql += datasetName + "\'";
420 
421  OGRLayer* l = ogrds->ExecuteSQL(sql.c_str(), 0, 0);
422 
423  if(l != 0)
424  {
425  OGRFeatureDefn* def = l->GetLayerDefn();
426 
427  for(int i=0; i<def->GetFieldCount(); i++)
428  res.push_back(def->GetFieldDefn(i)->GetNameRef());
429  }
430 
431  ogrds->ReleaseResultSet(l);
432 
433  return res;
434 }
435 
436 std::size_t te::ogr::Transactor::getNumberOfProperties(const std::string& datasetName)
437 {
438  OGRDataSource* ogrds = m_ogrDs->getOGRDataSource();
439  if (!ogrds)
440  return 0;
441 
442  std::string sql("SELECT FID, * FROM \'");
443  sql += datasetName + "\'";
444 
445  OGRLayer* l = ogrds->ExecuteSQL(sql.c_str(), 0, 0);
446 
447  int res = 0;
448 
449  if(l != 0)
450  {
451  res = l->GetLayerDefn()->GetFieldCount();
452  ogrds->ReleaseResultSet(l);
453  }
454 
455  return res;
456 }
457 
458 bool te::ogr::Transactor::propertyExists(const std::string& datasetName, const std::string& name)
459 {
460  OGRDataSource* ogrds = m_ogrDs->getOGRDataSource();
461  if (!ogrds)
462  return false;
463 
464  std::string sql("SELECT FID, * FROM \'");
465  sql += datasetName + "\'";
466  bool res = false;
467 
468  OGRLayer* l = ogrds->ExecuteSQL(sql.c_str(), 0, 0);
469 
470  if(l != 0)
471  {
472  res = (l->GetLayerDefn()->GetFieldIndex(name.c_str()) != -1);
473  ogrds->ReleaseResultSet(l);
474  }
475 
476  return res;
477 }
478 
479 void te::ogr::Transactor::addProperty(const std::string& datasetName, te::dt::Property* p)
480 {
481  if (!m_ogrDs->getOGRDataSource())
482  return;
483 
484  OGRLayer* l = m_ogrDs->getOGRDataSource()->GetLayerByName(datasetName.c_str());
485 
486  if(l != 0)
487  {
488  if(p->getType() != te::dt::GEOMETRY_TYPE)
489  {
490 // if(!l->TestCapability(OLCCreateField))
491 // throw Exception(TR_OGR("This dataset do not support add fields operation."));
492 
493  OGRFieldDefn* nField = Convert2OGR(p);
494  OGRErr error = l->CreateField(nField);
495 
496  delete nField;
497 
498  if(error != OGRERR_NONE)
499  throw Exception(TR_OGR("Error when attempting add the property."));
500 
501  error = l->SyncToDisk();
502 
503  if(error != OGRERR_NONE)
504  throw Exception(TR_OGR("Error saving changes on the file."));
505  }
506  }
507 }
508 
509 void te::ogr::Transactor::dropProperty(const std::string& datasetName, const std::string& name)
510 {
511  OGRLayer* l = m_ogrDs->getOGRDataSource()->GetLayerByName(datasetName.c_str());
512 
513  if(l != 0)
514  {
515  if(!l->TestCapability(OLCDeleteField))
516  throw Exception(TR_OGR("This dataset do not support remove properties operation."));
517 
518  int fPos = l->GetLayerDefn()->GetFieldIndex(name.c_str());
519 
520  if(fPos < 0)
521  throw Exception(TR_OGR("Field not found."));
522 
523  OGRErr error = l->DeleteField(fPos);
524 
525  if(error != OGRERR_NONE)
526  throw Exception(TR_OGR("Error when attempting remove the property."));
527 
528  error = l->SyncToDisk();
529 
530  if(error != OGRERR_NONE)
531  throw Exception(TR_OGR("Error saving changes on the file."));
532  }
533 }
534 
535 void te::ogr::Transactor::renameProperty(const std::string& datasetName,
536  const std::string& propertyName,
537  const std::string& newPropertyName)
538 {
539  if (!m_ogrDs->getOGRDataSource())
540  return;
541 
542  OGRLayer* l = m_ogrDs->getOGRDataSource()->GetLayerByName(datasetName.c_str());
543 
544  if(l != 0)
545  {
546  int idx = l->GetLayerDefn()->GetFieldIndex(propertyName.c_str());
547 
548  if(idx == -1)
549  throw Exception(TR_OGR("Field to be renamed does not exists."));
550 
551  OGRFieldDefn* df = l->GetLayerDefn()->GetFieldDefn(idx);
552 
553  df->SetName(newPropertyName.c_str());
554  }
555 }
556 
557 std::auto_ptr<te::da::PrimaryKey> te::ogr::Transactor::getPrimaryKey(const std::string& datasetName)
558 {
559  if (!m_ogrDs->getOGRDataSource())
560  return std::auto_ptr<te::da::PrimaryKey>();
561 
562  std::auto_ptr<te::da::PrimaryKey> res;
563  std::string sql("SELECT FID, * FROM \'");
564  sql += datasetName + "\'";
565 
566  OGRLayer* layer = m_ogrDs->getOGRDataSource()->ExecuteSQL(sql.c_str(), 0, 0);
567 
568  if(layer != 0)
569  {
570  const char* colIdName = layer->GetFIDColumn();
571 
572  if(colIdName == 0 || colIdName[0] == '\0')
573  colIdName = "FID";
574 
575  int pos = layer->GetLayerDefn()->GetFieldIndex(colIdName);
576 
577  if(pos >= 0)
578  {
579  res.reset(new te::da::PrimaryKey);
580  res->add(getProperty(datasetName, pos).get());
581  }
582  }
583 
584  m_ogrDs->getOGRDataSource()->ReleaseResultSet(layer);
585 
586  return res;
587 }
588 
589 bool te::ogr::Transactor::primaryKeyExists(const std::string& /*datasetName*/, const std::string& /*name*/)
590 {
591  return false;
592 }
593 
594 void te::ogr::Transactor::addPrimaryKey(const std::string& /*datasetName*/, te::da::PrimaryKey* /*pk*/)
595 {
596 }
597 
598 void te::ogr::Transactor::dropPrimaryKey(const std::string& /*datasetName*/)
599 {
600 }
601 
602 std::auto_ptr<te::da::ForeignKey> te::ogr::Transactor::getForeignKey(const std::string& /*datasetName*/, const std::string& /*name*/)
603 {
604  return std::auto_ptr<te::da::ForeignKey>();
605 }
606 
607 std::vector<std::string> te::ogr::Transactor::getForeignKeyNames(const std::string& /*datasetName*/)
608 {
609  return std::vector<std::string>();
610 }
611 
612 bool te::ogr::Transactor::foreignKeyExists(const std::string& /*datasetName*/, const std::string& /*name*/)
613 {
614  return false;
615 }
616 
617 void te::ogr::Transactor::addForeignKey(const std::string& /*datasetName*/, te::da::ForeignKey* /*fk*/)
618 {
619 }
620 
621 void te::ogr::Transactor::dropForeignKey(const std::string& /*datasetName*/, const std::string& /*fkName*/)
622 {
623 }
624 
625 std::auto_ptr<te::da::UniqueKey> te::ogr::Transactor::getUniqueKey(const std::string& /*datasetName*/, const std::string& /*name*/)
626 {
627  return std::auto_ptr<te::da::UniqueKey>();
628 }
629 
630 std::vector<std::string> te::ogr::Transactor::getUniqueKeyNames(const std::string& /*datasetName*/)
631 {
632  return std::vector<std::string>();
633 }
634 
635 bool te::ogr::Transactor::uniqueKeyExists(const std::string& /*datasetName*/, const std::string& /*name*/)
636 {
637  return false;
638 }
639 
640 void te::ogr::Transactor::addUniqueKey(const std::string& /*datasetName*/, te::da::UniqueKey* /*uk*/)
641 {
642 }
643 
644 void te::ogr::Transactor::dropUniqueKey(const std::string& /*datasetName*/, const std::string& /*name*/)
645 {
646 }
647 
648 std::auto_ptr<te::da::CheckConstraint> te::ogr::Transactor::getCheckConstraint(const std::string& /*datasetName*/, const std::string& /*name*/)
649 {
650  return std::auto_ptr<te::da::CheckConstraint>();
651 }
652 
653 std::vector<std::string> te::ogr::Transactor::getCheckConstraintNames(const std::string& /*datasetName*/)
654 {
655  return std::vector<std::string>();
656 }
657 
658 bool te::ogr::Transactor::checkConstraintExists(const std::string& /*datasetName*/, const std::string& /*name*/)
659 {
660  return false;
661 }
662 
663 void te::ogr::Transactor::addCheckConstraint(const std::string& /*datasetName*/, te::da::CheckConstraint* /*cc*/)
664 {
665 }
666 
667 void te::ogr::Transactor::dropCheckConstraint(const std::string& /*datasetName*/, const std::string& /*name*/)
668 {
669 }
670 
671 std::auto_ptr<te::da::Index> te::ogr::Transactor::getIndex(const std::string& /*datasetName*/, const std::string& /*name*/)
672 {
673  return std::auto_ptr<te::da::Index>();
674 }
675 
676 std::vector<std::string> te::ogr::Transactor::getIndexNames(const std::string& /*datasetName*/)
677 {
678  return std::vector<std::string>();
679 }
680 
681 bool te::ogr::Transactor::indexExists(const std::string& /*datasetName*/, const std::string& /*name*/)
682 {
683  return false;
684 }
685 
686 void te::ogr::Transactor::addIndex(const std::string& /*datasetName*/, te::da::Index* /*idx*/,
687  const std::map<std::string, std::string>& /*options*/)
688 {
689 }
690 
691 void te::ogr::Transactor::dropIndex(const std::string& /*datasetName*/, const std::string& /*idxName*/)
692 {
693 }
694 
695 std::auto_ptr<te::da::Sequence> te::ogr::Transactor::getSequence(const std::string& /*name*/)
696 {
697  return std::auto_ptr<te::da::Sequence>();
698 }
699 
700 std::vector<std::string> te::ogr::Transactor::getSequenceNames()
701 {
702  return std::vector<std::string>();
703 }
704 
705 bool te::ogr::Transactor::sequenceExists(const std::string& /*name*/)
706 {
707  return false;
708 }
709 
711 {
712 }
713 
714 void te::ogr::Transactor::dropSequence(const std::string& /*name*/)
715 {
716 }
717 
718 std::auto_ptr<te::gm::Envelope> te::ogr::Transactor::getExtent(const std::string& datasetName,
719  const std::string& propertyName)
720 {
721  if (!m_ogrDs->getOGRDataSource())
722  return std::auto_ptr<te::gm::Envelope>();
723 
724  std::auto_ptr<te::gm::Envelope> res;
725  std::string sql("SELECT ");
726  sql += propertyName + " FROM \'";
727  sql += datasetName + "\'";
728 
729  OGRLayer* l = m_ogrDs->getOGRDataSource()->ExecuteSQL(sql.c_str(), 0, 0);
730 
731  if(l != 0)
732  {
733  std::auto_ptr<OGREnvelope> env(new OGREnvelope);
734 
735  if(l->GetExtent(env.get()) != OGRERR_NONE)
736  {
737  m_ogrDs->getOGRDataSource()->ReleaseResultSet(l);
738  throw Exception(TR_OGR("Error when attempting get extent."));
739  }
740 
741  res.reset(Convert2TerraLib(env.get()));
742 
743  m_ogrDs->getOGRDataSource()->ReleaseResultSet(l);
744  }
745 
746  return res;
747 }
748 
749 std::auto_ptr<te::gm::Envelope> te::ogr::Transactor::getExtent(const std::string& datasetName,
750  std::size_t /*propertyPos*/)
751 {
752  return getExtent(datasetName, "OGR_GEOMETRY");
753 }
754 
755 std::size_t te::ogr::Transactor::getNumberOfItems(const std::string& datasetName)
756 {
757  if (!m_ogrDs->getOGRDataSource())
758  return 0;
759 
760  OGRLayer* l = m_ogrDs->getOGRDataSource()->GetLayerByName(datasetName.c_str());
761 
762  if(l != 0)
763  return l->GetFeatureCount();
764 
765  return 0;
766 }
767 
769 {
770  if (!m_ogrDs->getOGRDataSource())
771  return false;
772 
773  return (m_ogrDs->getOGRDataSource()->GetLayerCount() > 0);
774 }
775 
776 bool te::ogr::Transactor::dataSetExists(const std::string& name)
777 {
778  if (!m_ogrDs->getOGRDataSource())
779  return false;
780 
781  return (m_ogrDs->getOGRDataSource()->GetLayerByName(name.c_str()) != 0);
782 }
783 
784 void te::ogr::Transactor::createDataSet(te::da::DataSetType* dt, const std::map<std::string, std::string>& /*options*/)
785 {
786  if (!m_ogrDs->getOGRDataSource())
787  return;
788 
789  if(!m_ogrDs->getOGRDataSource()->TestCapability(ODsCCreateLayer))
790  throw Exception(TR_OGR("This driver does not support dataset creation."));
791 
792  OGRwkbGeometryType geomType = wkbUnknown;
793  OGRSpatialReference* srs = 0;
794  if(dt->hasGeom())
795  {
796  geomType = Convert2OGR(te::da::GetFirstGeomProperty(dt)->getGeometryType());
797  int srid = te::da::GetFirstGeomProperty(dt)->getSRID();
798  if (srid != TE_UNKNOWN_SRS)
799  {
800  srs = new OGRSpatialReference();
801  srs->importFromEPSG(srid);
802  }
803  }
804 
805  char** papszOptions = 0;
806  std::map<std::string, std::string>::const_iterator it = m_ogrDs->getConnectionInfo().begin();
807  while(it != m_ogrDs->getConnectionInfo().end())
808  {
809  if(it->first == "URI" || it->first == "SOURCE" || it->first == "DRIVER")
810  {
811  ++it;
812  continue;
813  }
814  papszOptions = CSLSetNameValue(papszOptions, it->first.c_str(), it->second.c_str());
815  ++it;
816  }
817 
818  OGRLayer* newLayer = m_ogrDs->getOGRDataSource()->CreateLayer(dt->getName().c_str(), srs, geomType, papszOptions);
819 
820  if(papszOptions)
821  CSLDestroy(papszOptions);
822 
823  if(newLayer == 0)
824  throw Exception(TR_OGR("Error when attempting create the dataset type."));
825 
826  dt->setName(newLayer->GetName());
827 
828 // add the properties
829  for(size_t i = 0; i < dt->size(); ++i)
830  addProperty(dt->getName(), dt->getProperty(i));
831 }
832 
833 void te::ogr::Transactor::cloneDataSet(const std::string& name,
834  const std::string& cloneName,
835  const std::map<std::string, std::string>& /*options*/)
836 {
837  if (!m_ogrDs->getOGRDataSource())
838  return;
839 
840  if(!m_ogrDs->getOGRDataSource()->TestCapability(ODsCCreateLayer))
841  throw Exception(TR_OGR("This driver does not support creates a dataset."));
842 
843  OGRLayer* l = m_ogrDs->getOGRDataSource()->GetLayerByName(name.c_str());
844 
845  if(l == 0)
846  throw Exception(TR_OGR("Could not retrieve the DataSet from data source."));
847 
848  OGRLayer* cl = m_ogrDs->getOGRDataSource()->CopyLayer(l, cloneName.c_str());
849 
850  if(cl == 0)
851  throw Exception(TR_OGR("Error when attempting clone the dataset."));
852 }
853 
854 void te::ogr::Transactor::dropDataSet(const std::string& name)
855 {
856  if (!m_ogrDs->getOGRDataSource())
857  return;
858 
859  if(!m_ogrDs->getOGRDataSource()->TestCapability(ODsCDeleteLayer))
860  throw Exception(TR_OGR("This driver does not support remove a dataset."));
861 
862  int i=0;
863 
864  for(; i<m_ogrDs->getOGRDataSource()->GetLayerCount(); i++)
865  if(name.compare(m_ogrDs->getOGRDataSource()->GetLayer(i)->GetName()) == 0)
866  break;
867 
868  if(i == m_ogrDs->getOGRDataSource()->GetLayerCount())
869  throw Exception(TR_OGR("Could not retrieve the DataSet from data source."));
870 
871  if(m_ogrDs->getOGRDataSource()->DeleteLayer(i) != OGRERR_NONE)
872  throw Exception(TR_OGR("Error when attempting to remove the dataset."));
873 }
874 
875 void te::ogr::Transactor::renameDataSet(const std::string& /*name*/, const std::string& /*newName*/)
876 {
877 }
878 
879 void te::ogr::Transactor::add(const std::string& datasetName,
880  te::da::DataSet* d,
881  const std::map<std::string, std::string>& options,
882  std::size_t limit)
883 {
884  if(limit == 0)
885  limit = std::string::npos;
886 
887  if (!m_ogrDs->getOGRDataSource())
888  return;
889 
890  OGRLayer* layer = m_ogrDs->getOGRDataSource()->GetLayerByName(datasetName.c_str());
891 
892  if(layer == 0)
893  throw Exception(TR_OGR("Could not retrieve the DataSet from data source."));
894 
895  try
896  {
897  begin();
898 
899  std::size_t nproperties = d->getNumProperties();
900 
901  std::size_t nProcessedRows = 0;
902 
903  while(d->moveNext() && (nProcessedRows != limit))
904  {
905  OGRFeature* feat = OGRFeature::CreateFeature(layer->GetLayerDefn());
906 
907  std::size_t currfield = 0;
908 
909  for(std::size_t i = 0; i != nproperties; ++i)
910  {
911  if(d->isNull(i))
912  {
914  ++currfield;
915 
916  continue;
917  }
918 
919  switch(d->getPropertyDataType(i))
920  {
921  case te::dt::INT16_TYPE:
922  feat->SetField(currfield, d->getInt16(i));
923  ++currfield;
924  break;
925 
926  case te::dt::INT32_TYPE:
927  feat->SetField(currfield, d->getInt32(i));
928  ++currfield;
929  break;
930 
931  case te::dt::STRING_TYPE:
932  feat->SetField(currfield, d->getAsString(i).c_str());
933  ++currfield;
934  break;
935 
936  case te::dt::DOUBLE_TYPE:
937  feat->SetField(currfield, d->getDouble(i));
938  ++currfield;
939  break;
940 
942  feat->SetField(currfield, atof(d->getNumeric(i).c_str()));
943  ++currfield;
944  break;
945 
947  {
948  std::auto_ptr<te::dt::ByteArray> ba(d->getByteArray(i));
949  feat->SetField(currfield, ba->bytesUsed(), reinterpret_cast<unsigned char*>(ba->getData()));
950  ++currfield;
951  }
952  break;
953 
955  {
956  std::auto_ptr<te::dt::DateTime> dtm(d->getDateTime(i));
957 
958  te::dt::Date* dtime = dynamic_cast<te::dt::Date*>(dtm.get());
959 
960  if(dtime)
961  {
962  feat->SetField(currfield,
963  static_cast<int>(dtime->getYear()),
964  static_cast<int>(dtime->getMonth()),
965  static_cast<int>(dtime->getDay()));
966  ++currfield;
967  break;
968  }
969 
970  te::dt::TimeDuration* tduration = dynamic_cast<te::dt::TimeDuration*>(dtm.get());
971 
972  if(tduration)
973  {
974  feat->SetField(currfield, 0, 0, 0,
975  static_cast<int>(tduration->getHours()),
976  static_cast<int>(tduration->getMinutes()),
977  static_cast<int>(tduration->getSeconds()));
978  ++currfield;
979  break;
980  }
981 
982  te::dt::TimeInstant* tinst = dynamic_cast<te::dt::TimeInstant*>(dtm.get());
983 
984  if(tinst)
985  {
986  feat->SetField(currfield,
987  static_cast<int>(dtime->getYear()),
988  static_cast<int>(dtime->getMonth()),
989  static_cast<int>(dtime->getDay()),
990  static_cast<int>(tduration->getHours()),
991  static_cast<int>(tduration->getMinutes()),
992  static_cast<int>(tduration->getSeconds()));
993  ++currfield;
994  break;
995  }
996 
997  throw Exception (TR_OGR("Unsupported date and time type by OGR."));
998  }
999  break;
1000 
1001  case te::dt::GEOMETRY_TYPE:
1002  {
1003  std::auto_ptr<te::gm::Geometry> geom(d->getGeometry(i));
1004  OGRGeometry* OGRgeom = Convert2OGR(geom.get());
1005  feat->SetGeometryDirectly(OGRgeom);
1006  }
1007  break;
1008 
1009  default:
1010  throw Exception(TR_OGR("Unsupported data type by OGR."));
1011  }
1012  }
1013 
1014  if(layer->CreateFeature(feat) != OGRERR_NONE)
1015  {
1016  OGRFeature::DestroyFeature(feat);
1017  throw Exception(TR_OGR("Fail to insert dataset item."));
1018  }
1019 
1020  OGRFeature::DestroyFeature(feat);
1021  nProcessedRows++;
1022  }
1023 
1024  commit();
1025  }
1026  catch(Exception& e)
1027  {
1028  rollBack();
1029  throw e;
1030  }
1031 }
1032 
1033 void te::ogr::Transactor::remove(const std::string& datasetName, const te::da::ObjectIdSet* oids)
1034 {
1035  if(!m_ogrDs->getOGRDataSource())
1036  return;
1037 
1038  OGRLayer* l = m_ogrDs->getOGRDataSource()->GetLayerByName(datasetName.c_str());
1039 
1040  if(l == 0)
1041  throw Exception(TR_OGR("Could not retrieve the DataSet from data source."));
1042 
1043  if(!l->TestCapability(OLCDeleteFeature))
1044  throw Exception(TR_OGR("Driver does not support removal of features."));
1045 
1046  std::set<te::da::ObjectId*, te::common::LessCmp<te::da::ObjectId*> >::const_iterator it = oids->begin();
1047 
1048  while(it != oids->end())
1049  {
1050  begin();
1051 
1052  if(l->DeleteFeature(atoi((*it)->getValue()[0].toString().c_str())) != OGRERR_NONE)
1053  {
1054  rollBack();
1055  throw Exception(TR_OGR("Error when attempting to remove the feature."));
1056  }
1057 
1058  ++it;
1059  }
1060 
1061  commit();
1062 }
1063 
1064 void te::ogr::Transactor::update(const std::string& /*datasetName*/,
1065  te::da::DataSet* /*dataset*/,
1066  const std::vector<std::size_t>& /*properties*/,
1067  const te::da::ObjectIdSet* /*oids*/,
1068  const std::map<std::string, std::string>& /*options*/,
1069  std::size_t /*limit*/)
1070 {
1071 }
1072 
1073 void te::ogr::Transactor::optimize(const std::map<std::string, std::string>& /*opInfo*/)
1074 {
1075 }
virtual double getDouble(std::size_t i) const =0
Method for retrieving a double attribute value.
std::vector< std::string > getSequenceNames()
It gets the sequence names available in the data source.
Definition: Transactor.cpp:700
TEOGREXPORT int Convert2TerraLibProjection(OGRSpatialReference *osrs)
It converts the OGR Projection to TerraLib Projection.
Definition: Utils.cpp:125
std::string escape(const std::string &value)
It escapes a string for using in commands and queries.
Definition: Transactor.cpp:261
bool primaryKeyExists(const std::string &datasetName, const std::string &name)
It checks if a primary key exists in the dataset.
Definition: Transactor.cpp:589
std::auto_ptr< te::da::DataSetType > getDataSetType(const std::string &name)
It gets information about the given dataset.
Definition: Transactor.cpp:297
It describes an index associated to a DataSetType.
Definition: Index.h:54
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...
std::size_t getNumberOfItems(const std::string &datasetName)
It retrieves the number of items of the given dataset.
Definition: Transactor.cpp:755
virtual std::size_t getNumProperties() const =0
It returns the number of properties that composes an item of the dataset.
This class represents a set of unique ids created in the same context. i.e. from the same data set...
Definition: ObjectIdSet.h:53
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:681
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:242
Property * getProperty(std::size_t i) const
It returns the i-th property.
std::size_t size() const
It returns the number of properties of the CompositeProperty.
bool isDataSetNameValid(const std::string &datasetName)
It returns true if the given string is a valid dataset name.
Definition: Transactor.cpp:266
std::vector< std::string > getDataSetNames()
It It gets the dataset names available in the data source.
Definition: Transactor.cpp:276
std::string RemoveSpatialSql(const std::string &sql)
Definition: Transactor.cpp:43
void dropUniqueKey(const std::string &datasetName, const std::string &name)
It removes the unique key constraint from the dataset.
Definition: Transactor.cpp:644
TEDATAACCESSEXPORT te::gm::GeometryProperty * GetFirstGeomProperty(const DataSetType *dt)
Definition: Utils.cpp:504
bool isPropertyNameValid(const std::string &propertyName)
It checks if the given property name is valid.
Definition: Transactor.cpp:271
virtual std::string getAsString(std::size_t i, int precision=0) const
Method for retrieving a data value as a string plain representation.
Definition: DataSet.cpp:218
void remove(const std::string &datasetName, const te::da::ObjectIdSet *oids=0)
It removes all the informed items from the dataset.
A Select models a query to be used when retrieving data from a DataSource.
Definition: Select.h:65
int getSRID() const
It returns the spatial reference system identifier associated to this property.
virtual std::auto_ptr< te::dt::DateTime > getDateTime(std::size_t i) const =0
Method for retrieving a date and time attribute value.
void dropProperty(const std::string &datasetName, const std::string &name)
It removes a property from the given dataset.
Definition: Transactor.cpp:509
virtual boost::int32_t getInt32(std::size_t i) const =0
Method for retrieving a 32-bit integer attribute value (4 bytes long).
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:602
A class for data providers of OGR.
std::size_t getNumberOfProperties(const std::string &datasetName)
It gets the number of properties of the given dataset.
Definition: Transactor.cpp:436
void addUniqueKey(const std::string &datasetName, te::da::UniqueKey *uk)
It adds a unique key constraint to the dataset.
Definition: Transactor.cpp:640
void begin()
It starts a new transaction.
Definition: Transactor.cpp:79
virtual bool moveNext()=0
It moves the internal pointer to the next item of the collection.
It describes a primary key (pk) constraint.
Definition: PrimaryKey.h:52
const std::string & getName() const
It returns the property name.
Definition: Property.h:126
virtual std::string getNumeric(std::size_t i) const =0
Method for retrieving a numeric attribute value.
std::vector< std::string > getPropertyNames(const std::string &datasetName)
It gets the property names of the given dataset.
Definition: Transactor.cpp:411
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.
virtual bool isNull(std::size_t i) const =0
It checks if the attribute value is NULL.
#define TE_UNKNOWN_SRS
A numeric value to represent a unknown SRS identification in TerraLib.
Definition: Config.h:72
It describes a sequence (a number generator).
Definition: Sequence.h:56
void dropForeignKey(const std::string &datasetName, const std::string &fkName)
It removes the foreign key constraint from the dataset schema.
Definition: Transactor.cpp:621
SpatialRelation
Spatial relations between geometric objects.
Definition: Enums.h:122
It models a foreign key constraint for a DataSetType.
Definition: ForeignKey.h:50
A base class for date data types.
Definition: Date.h:53
boost::ptr_vector< te::dt::Property > getProperties(const std::string &datasetName)
It retrieves the properties of the dataset.
Definition: Transactor.cpp:338
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
bool isInTransaction() const
It returns true if a transaction is in progress, otherwise, it returns false.
Definition: Transactor.cpp:96
void cancel()
It requests that the data source stop the processing of the current command.
Definition: Transactor.cpp:252
void dropDataSet(const std::string &name)
It removes the dataset schema from the data source.
Definition: Transactor.cpp:854
std::size_t getNumberOfDataSets()
It retrieves the number of data sets available in the data source.
Definition: Transactor.cpp:289
virtual boost::int16_t getInt16(std::size_t i) const =0
Method for retrieving a 16-bit integer attribute value (2 bytes long).
double m_lly
Lower left corner y-coordinate.
Definition: Envelope.h:345
void rollBack()
It aborts the transaction. Any changes will be rolled-back.
Definition: Transactor.cpp:92
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:718
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:695
Utility functions for the data access module.
A Query is independent from the data source language/dialect.
Definition: Query.h:46
boost::int64_t getLastGeneratedId()
It returns the last id generated by an insertion command.
Definition: Transactor.cpp:256
TEOGREXPORT OGRGeometry * Convert2OGR(const te::gm::Geometry *teGeom)
It converts the TerraLib Geometry to OGR Geometry.
Definition: Utils.cpp:79
bool hasGeom() const
It returns true if the DataSetType has at least one geometry property; otherwise, it returns false...
Definition: DataSetType.h:655
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:366
double m_ury
Upper right corner y-coordinate.
Definition: Envelope.h:347
Geometry is the root class of the geometries hierarchy, it follows OGC and ISO standards.
Definition: Geometry.h:73
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:658
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:671
Implementation of a DataSet for OGR data provider.
virtual int getPropertyDataType(std::size_t i) const =0
It returns the underlying data type of the property at position pos.
std::vector< std::string > getIndexNames(const std::string &datasetName)
It gets the index names of the given dataset.
Definition: Transactor.cpp:676
It describes a unique key (uk) constraint.
Definition: UniqueKey.h:53
virtual std::auto_ptr< te::dt::ByteArray > getByteArray(std::size_t i) const =0
Method for retrieving a byte array.
te::da::DataSource * getDataSource() const
It returns the parent data source of the transactor.
Definition: Transactor.cpp:74
void dropCheckConstraint(const std::string &datasetName, const std::string &name)
It removes the check constraint from the dataset.
Definition: Transactor.cpp:667
long getSeconds() const
It returns the seconds of a minute - from 0 to 59.
Definition: TimeDuration.h:105
void renameDataSet(const std::string &name, const std::string &newName)
It renames a dataset.
Definition: Transactor.cpp:875
#define TR_OGR(message)
It marks a string in order to get translated. This is a special mark used in the DataAccess module of...
Definition: Config.h:62
double m_urx
Upper right corner x-coordinate.
Definition: Envelope.h:346
std::set< ObjectId *, te::common::LessCmp< ObjectId * > >::const_iterator begin() const
Returns an iterator for the object ids in container.
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:833
std::set< ObjectId *, te::common::LessCmp< ObjectId * > >::const_iterator end() const
Returns an iterator for the object ids in container.
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:458
bool dataSetExists(const std::string &name)
It checks if a dataset with the given name exists in the data source.
Definition: Transactor.cpp:776
TraverseType
A dataset can be traversed in two ways:
Definition: Enums.h:53
The OGR data source provider.
Definition: DataSource.h:48
void addForeignKey(const std::string &datasetName, te::da::ForeignKey *fk)
It adds a foreign key constraint to a dataset.
Definition: Transactor.cpp:617
An abstract class for data providers like a DBMS, Web Services or a regular file. ...
Definition: DataSource.h:116
long getMinutes() const
It returns the minutes of a hour - from 0 to 59.
Definition: TimeDuration.h:98
void commit()
It commits the transaction.
Definition: Transactor.cpp:83
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:686
void addSequence(te::da::Sequence *sequence)
It creates a new sequence in the data source.
Definition: Transactor.cpp:710
long getHours() const
It returns the hours of a day - from 0 to 23.
Definition: TimeDuration.h:91
A class that models the description of a dataset.
Definition: DataSetType.h:72
TEOGREXPORT te::gm::Geometry * Convert2TerraLib(OGRGeometry *ogrGeom)
It converts the OGR Geometry to TerraLib Geometry.
Definition: Utils.cpp:54
std::auto_ptr< te::da::BatchExecutor > getBatchExecutor()
It creates a batch command executor.
Definition: Transactor.cpp:247
bool hasDataSets()
It checks if the data source has any dataset.
Definition: Transactor.cpp:768
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:101
Transactor(DataSource *ds)
Definition: Transactor.cpp:64
std::vector< std::string > getCheckConstraintNames(const std::string &datasetName)
It gets the check constraint names of the given dataset.
Definition: Transactor.cpp:653
void addProperty(const std::string &datasetName, te::dt::Property *p)
It adds a new property to the dataset schema.
Definition: Transactor.cpp:479
void execute(const te::da::Query &command)
It executes the specified command using a generic query representation.
Definition: Transactor.cpp:221
A class to represent time instant.
Definition: TimeInstant.h:55
void add(te::dt::Property *p)
It adds a property to the list of properties of the primary key.
Definition: PrimaryKey.h:123
It models a property definition.
Definition: Property.h:59
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:625
double m_llx
Lower left corner x-coordinate.
Definition: Envelope.h:344
virtual ReturnType accept(VisitorType &guest) const =0
It call the visit method from the guest object.
std::vector< std::string > getUniqueKeyNames(const std::string &datasetName)
It gets the unique key names of the given dataset.
Definition: Transactor.cpp:630
int getType() const
It returns the property data type.
Definition: Property.h:143
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:879
A visitor for building an SQL statement using OGR dialect.
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:172
virtual std::auto_ptr< te::gm::Geometry > getGeometry(std::size_t i) const =0
Method for retrieving a geometric attribute value.
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:612
void setSRID(int srid)
It sets the spatial reference system identifier associated to this property.
A class that describes a check constraint.
An Envelope defines a 2D rectangular region.
Definition: Envelope.h:51
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:535
Geometric property.
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:784
void addCheckConstraint(const std::string &datasetName, te::da::CheckConstraint *cc)
It adds a check constraint to the dataset.
Definition: Transactor.cpp:663
Implementation of a DataSet for OGR data provider.
Definition: DataSet.h:59
void dropIndex(const std::string &datasetName, const std::string &idxName)
It removes the index from the dataset schema.
Definition: Transactor.cpp:691
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:648
A dataset is the unit of information manipulated by the data access module of TerraLib.
Definition: DataSet.h:111
std::auto_ptr< te::da::PrimaryKey > getPrimaryKey(const std::string &datasetName)
It retrieves the primary key of the dataset.
Definition: Transactor.cpp:557
std::vector< std::string > getForeignKeyNames(const std::string &datasetName)
It gets the foreign key names of the given dataset.
Definition: Transactor.cpp:607
void addPrimaryKey(const std::string &datasetName, te::da::PrimaryKey *pk)
It adds a primary key constraint to the dataset schema.
Definition: Transactor.cpp:594
A class to represent time duration with nano-second/micro-second resolution.
Definition: TimeDuration.h:51
void dropSequence(const std::string &name)
It removes the sequence from the data source.
Definition: Transactor.cpp:714
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:635
bool sequenceExists(const std::string &name)
It checks if a sequence with the given name exists in the data source.
Definition: Transactor.cpp:705
void dropPrimaryKey(const std::string &datasetName)
It removes the primary key constraint from the dataset schema.
Definition: Transactor.cpp:598