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