All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
Transactor.cpp
Go to the documentation of this file.
1 /* Copyright (C) 2008 National Institute For Space Research (INPE) - Brazil.
2 
3  This file is part of the TerraLib - a Framework for building GIS enabled applications.
4 
5  TerraLib is free software: you can redistribute it and/or modify
6  it under the terms of the GNU Lesser General Public License as published by
7  the Free Software Foundation, either version 3 of the License,
8  or (at your option) any later version.
9 
10  TerraLib is distributed in the hope that it will be useful,
11  but WITHOUT ANY WARRANTY; without even the implied warranty of
12  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13  GNU Lesser General Public License for more details.
14 
15  You should have received a copy of the GNU Lesser General Public License
16  along with TerraLib. See COPYING. If not, write to
17  TerraLib Team at <terralib-team@terralib.org>.
18  */
19 
20 /*!
21  \file terralib/wfs/Transactor.cpp
22 
23  \brief Implementation of the transactor for the WFS driver.
24 */
25 
26 // TerraLib
27 #include "../common/Translator.h"
28 #include "../dataaccess/utils/Utils.h"
29 #include "../datatype/Property.h"
30 #include "../geometry/Envelope.h"
31 #include "../geometry/Geometry.h"
32 #include "../geometry/GeometryProperty.h"
33 #include "../ogr/DataSet.h"
34 #include "../ogr/SQLVisitor.h"
35 #include "../ogr/Utils.h"
36 #include "DataSource.h"
37 #include "Exception.h"
38 #include "Transactor.h"
39 #include "Utils.h"
40 
41 // OGR
42 #include <ogrsf_frmts.h>
43 
44 // STL
45 #include <vector>
46 
48  : te::da::DataSourceTransactor(),
49  m_ds(ds)
50 {
51 }
52 
54 {
55 }
56 
58 {
59  return m_ds;
60 }
61 
62 std::auto_ptr<te::da::DataSet> te::wfs::Transactor::getDataSet(const std::string& name,
63  te::common::TraverseType /*travType*/,
64  bool /*connected*/,
65  const te::common::AccessPolicy /*accessPolicy*/)
66 {
67  assert(m_ds->getOGRDataSource());
68 
69  OGRDataSource* ds = OGRSFDriverRegistrar::Open(m_ds->getOGRDataSource()->GetName());
70 
71  std::string sql = "SELECT FID, * FROM \'" + name + "\'";
72  OGRLayer* layer = ds->ExecuteSQL(sql.c_str(), 0, 0);
73 
74  if(layer == 0)
75  throw Exception(TE_TR("The informed data set could not be found in the data source!"));
76 
77  return std::auto_ptr<te::da::DataSet>(new te::ogr::DataSet(ds, layer));
78 }
79 
80 std::auto_ptr<te::da::DataSet> te::wfs::Transactor::getDataSet(const std::string& name,
81  const std::string& /*propertyName*/,
82  const te::gm::Envelope* e,
84  te::common::TraverseType /*travType*/,
85  bool /*connected*/,
86  const te::common::AccessPolicy /*accessPolicy*/)
87 {
88  assert(m_ds->getOGRDataSource());
89 
90  OGRDataSource* ds = OGRSFDriverRegistrar::Open(m_ds->getOGRDataSource()->GetName());
91 
92  std::string sql = "SELECT FID, * FROM \'" + name + "\'";
93  OGRLayer* layer = ds->ExecuteSQL(sql.c_str(), 0, 0);
94 
95  if(layer == 0)
96  throw Exception(TE_TR("The informed data set could not be found in the data source!"));
97 
98  layer->SetSpatialFilterRect(e->m_llx, e->m_lly, e->m_urx, e->m_ury);
99 
100  return std::auto_ptr<te::da::DataSet>(new te::ogr::DataSet(ds, layer));
101 }
102 
103 std::auto_ptr<te::da::DataSet> te::wfs::Transactor::getDataSet(const std::string& name,
104  const std::string& /*propertyName*/,
105  const te::gm::Geometry* g,
107  te::common::TraverseType /*travType*/,
108  bool /*connected*/,
109  const te::common::AccessPolicy /*accessPolicy*/)
110 {
111  assert(m_ds->getOGRDataSource());
112 
113  OGRDataSource* ds = OGRSFDriverRegistrar::Open(m_ds->getOGRDataSource()->GetName());
114 
115  std::string sql = "SELECT FID, * FROM \'" + name + "\'";
116  OGRLayer* layer = ds->ExecuteSQL(sql.c_str(), 0, 0);
117 
118  if(layer == 0)
119  throw Exception(TE_TR("The informed data set could not be found in the data source!"));
120 
121  OGRGeometry* ogrg = te::ogr::Convert2OGR(g);
122 
123  layer->SetSpatialFilter(ogrg);
124 
125  OGRGeometryFactory::destroyGeometry(ogrg);
126 
127  return std::auto_ptr<te::da::DataSet>(new te::ogr::DataSet(ds, layer));
128 }
129 
130 std::auto_ptr<te::da::DataSet> te::wfs::Transactor::query(const te::da::Select& q,
131  te::common::TraverseType /*travType*/,
132  bool /*connected*/,
133  const te::common::AccessPolicy /*accessPolicy*/)
134 {
135  assert(m_ds->getOGRDataSource());
136 
137  OGRDataSource* ds = OGRSFDriverRegistrar::Open(m_ds->getOGRDataSource()->GetName());
138 
139  std::string sql;
140 
141  te::ogr::SQLVisitor visitor(*m_ds->getDialect(), sql);
142 
143  q.accept(visitor);
144 
145  sql = te::ogr::RemoveSpatialSql(sql);
146 
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  te::gm::Envelope* e = visitor.getMBR();
153 
154  if(e != 0)
155  layer->SetSpatialFilterRect(e->m_llx, e->m_lly, e->m_urx, e->m_ury);
156 
157  return std::auto_ptr<te::da::DataSet>(new te::ogr::DataSet(ds, layer));
158 }
159 
160 std::auto_ptr<te::da::DataSet> te::wfs::Transactor::query(const std::string& query,
161  te::common::TraverseType /*travType*/,
162  bool /*connected*/,
163  const te::common::AccessPolicy /*accessPolicy*/)
164 {
165  assert(m_ds->getOGRDataSource());
166 
167  OGRDataSource* ds = OGRSFDriverRegistrar::Open(m_ds->getOGRDataSource()->GetName());
168 
169  OGRLayer* layer = ds->ExecuteSQL(query.c_str(), 0, 0);
170 
171  if(layer == 0)
172  throw Exception(TE_TR("The informed data set could not be found in the data source!"));
173 
174  return std::auto_ptr<te::da::DataSet>(new te::ogr::DataSet(ds, layer));
175 }
176 
177 std::vector<std::string> te::wfs::Transactor::getDataSetNames()
178 {
179  std::vector<std::string> names;
180 
181  if(!m_ds->getOGRDataSource())
182  return names;
183 
184  for(int i = 0; i < m_ds->getOGRDataSource()->GetLayerCount(); ++i)
185  names.push_back(m_ds->getOGRDataSource()->GetLayer(i)->GetName());
186 
187  return names;
188 }
189 
191 {
192  if(!m_ds->getOGRDataSource())
193  return 0;
194 
195  return m_ds->getOGRDataSource()->GetLayerCount();
196 }
197 
198 std::auto_ptr<te::da::DataSetType> te::wfs::Transactor::getDataSetType(const std::string& name)
199 {
200  assert(m_ds->getOGRDataSource());
201 
202  std::string sql("SELECT FID, * FROM \'");
203  sql += name + "\'";
204 
205  OGRLayer* layer = m_ds->getOGRDataSource()->ExecuteSQL(sql.c_str(), 0, 0);
206 
207  if(layer == 0)
208  throw Exception(TE_TR("Could not retrieve the informed data set!"));
209 
210  std::auto_ptr<te::da::DataSetType> type(te::ogr::Convert2TerraLib(layer->GetLayerDefn()));
211  type->setName(name);
212 
213  const char* colIdName = layer->GetFIDColumn();
214 
215  if(colIdName == 0 || colIdName[0] == '\0')
216  colIdName = "FID";
217 
218  int pos = layer->GetLayerDefn()->GetFieldIndex(colIdName);
219  if(pos >= 0)
220  {
221  te::da::PrimaryKey* pk = new te::da::PrimaryKey(colIdName, type.get());
222  pk->add(type->getProperty(pos));
223  }
224 
225  int srs = te::ogr::Convert2TerraLibProjection(layer->GetSpatialRef());
226 
228 
229  if(gp != 0)
230  gp->setSRID(srs);
231 
232  m_ds->getOGRDataSource()->ReleaseResultSet(layer);
233 
234  return type;
235 }
236 
237 boost::ptr_vector<te::dt::Property> te::wfs::Transactor::getProperties(const std::string& datasetName)
238 {
239  boost::ptr_vector<te::dt::Property> properties;
240 
241  std::auto_ptr<te::da::DataSetType> type = getDataSetType(datasetName);
242 
243  const std::vector<te::dt::Property*>& props = type->getProperties();
244  for(std::size_t i = 0; i < props.size(); ++i)
245  properties.push_back(props[i]->clone());
246 
247  return properties;
248 }
249 
250 std::auto_ptr<te::dt::Property> te::wfs::Transactor::getProperty(const std::string& datasetName, const std::string& name)
251 {
252  assert(m_ds->getOGRDataSource());
253 
254  std::string sql("SELECT FID, * FROM \'");
255  sql += datasetName + "\'";
256 
257  OGRLayer* layer = m_ds->getOGRDataSource()->ExecuteSQL(sql.c_str(), 0, 0);
258 
259  if(layer == 0)
260  throw Exception(TE_TR("Could not retrieve the informed data set!"));
261 
262  int propertyPos = layer->GetLayerDefn()->GetFieldIndex(name.c_str());
263 
264  m_ds->getOGRDataSource()->ReleaseResultSet(layer);
265 
266  return getProperty(datasetName, static_cast<std::size_t>(propertyPos));
267 }
268 
269 std::auto_ptr<te::dt::Property> te::wfs::Transactor::getProperty(const std::string& datasetName, std::size_t propertyPos)
270 {
271  assert(m_ds->getOGRDataSource());
272 
273  std::string sql("SELECT FID, * FROM \'");
274  sql += datasetName + "\'";
275 
276  OGRLayer* layer = m_ds->getOGRDataSource()->ExecuteSQL(sql.c_str(), 0, 0);
277 
278  if(layer == 0)
279  throw Exception(TE_TR("Could not retrieve the informed data set!"));
280 
281  OGRFeatureDefn* def = layer->GetLayerDefn();
282  OGRFieldDefn* fdef = def->GetFieldDefn(propertyPos);
283 
284  std::auto_ptr<te::dt::Property> prop;
285  if(fdef != 0)
286  prop.reset(te::ogr::Convert2TerraLib(fdef));
287 
288  m_ds->getOGRDataSource()->ReleaseResultSet(layer);
289 
290  return prop;
291 }
292 
293 std::vector<std::string> te::wfs::Transactor::getPropertyNames(const std::string& datasetName)
294 {
295  assert(m_ds->getOGRDataSource());
296 
297  std::string sql("SELECT FID, * FROM \'");
298  sql += datasetName + "\'";
299 
300  OGRLayer* layer = m_ds->getOGRDataSource()->ExecuteSQL(sql.c_str(), 0, 0);
301 
302  if(layer == 0)
303  throw Exception(TE_TR("Could not retrieve the informed data set!"));
304 
305  std::vector<std::string> propertyNames;
306 
307  OGRFeatureDefn* def = layer->GetLayerDefn();
308 
309  for(int i = 0; i < def->GetFieldCount(); ++i)
310  propertyNames.push_back(def->GetFieldDefn(i)->GetNameRef());
311 
312  m_ds->getOGRDataSource()->ReleaseResultSet(layer);
313 
314  return propertyNames;
315 }
316 
317 std::size_t te::wfs::Transactor::getNumberOfProperties(const std::string& datasetName)
318 {
319  return getPropertyNames(datasetName).size();
320 }
321 
322 bool te::wfs::Transactor::propertyExists(const std::string& datasetName, const std::string& name)
323 {
324  std::vector<std::string> propertyNames = getPropertyNames(datasetName);
325 
326  for(std::size_t i = 0; i < propertyNames.size(); ++i)
327  if(propertyNames[i] == name)
328  return true;
329 
330  return false;
331 }
332 
333 std::auto_ptr<te::gm::Envelope> te::wfs::Transactor::getExtent(const std::string& datasetName,
334  const std::string& propertyName)
335 {
336  assert(m_ds->getOGRDataSource());
337 
338  std::string sql("SELECT ");
339  sql += propertyName + " FROM \'";
340  sql += datasetName + "\'";
341 
342  OGRLayer* layer = m_ds->getOGRDataSource()->ExecuteSQL(sql.c_str(), 0, 0);
343 
344  if(layer == 0)
345  throw Exception(TE_TR("Could not retrieve the informed data set!"));
346 
347  std::auto_ptr<OGREnvelope> ogrEnv(new OGREnvelope);
348 
349  if(layer->GetExtent(ogrEnv.get()) != OGRERR_NONE)
350  {
351  m_ds->getOGRDataSource()->ReleaseResultSet(layer);
352  throw Exception(TE_TR("Error when attempting to get the extent!"));
353  }
354 
355  std::auto_ptr<te::gm::Envelope> teEnv(te::ogr::Convert2TerraLib(ogrEnv.get()));
356 
357  m_ds->getOGRDataSource()->ReleaseResultSet(layer);
358 
359  return teEnv;
360 }
361 
362 std::auto_ptr<te::gm::Envelope> te::wfs::Transactor::getExtent(const std::string& datasetName,
363  std::size_t /*propertyPos*/)
364 {
365  return getExtent(datasetName, "OGR_GEOMETRY");
366 }
367 
368 std::size_t te::wfs::Transactor::getNumberOfItems(const std::string& datasetName)
369 {
370  assert(m_ds->getOGRDataSource());
371 
372  OGRLayer* layer = m_ds->getOGRDataSource()->GetLayerByName(datasetName.c_str());
373 
374  if(layer == 0)
375  throw Exception(TE_TR("Could not retrieve the informed data set!"));
376 
377  return layer->GetFeatureCount();
378 }
379 
381 {
382  if(!m_ds->getOGRDataSource())
383  return false;
384 
385  return (m_ds->getOGRDataSource()->GetLayerCount() > 0);
386 }
387 
388 bool te::wfs::Transactor::dataSetExists(const std::string& name)
389 {
390  if(!m_ds->getOGRDataSource())
391  return false;
392 
393  return (m_ds->getOGRDataSource()->GetLayerByName(name.c_str()) != 0);
394 }
395 
396 /** NOT SUPPORTED METHODS */
397 //@{
398 
400 {
401  throw Exception(TE_TR("The method begin() is not supported by the WFS driver!"));
402 }
403 
405 {
406  throw Exception(TE_TR("The method commit() is not supported by the WFS driver!"));
407 }
408 
410 {
411  throw Exception(TE_TR("The method rollBack() is not supported by the WFS driver!"));
412 }
413 
415 {
416  throw Exception(TE_TR("The method isInTransaction() is not supported by the WFS driver!"));
417 }
418 
420 {
421  throw Exception(TE_TR("The method execute() is not supported by the WFS driver!"));
422 }
423 
424 void te::wfs::Transactor::execute(const std::string& /*command*/)
425 {
426  throw Exception(TE_TR("The method execute() is not supported by the WFS driver!"));
427 }
428 
429 std::auto_ptr<te::da::PreparedQuery> te::wfs::Transactor::getPrepared(const std::string& /*qName*/)
430 {
431  throw Exception(TE_TR("The method getPrepared() is not supported by the WFS driver!"));
432 }
433 
434 std::auto_ptr<te::da::BatchExecutor> te::wfs::Transactor::getBatchExecutor()
435 {
436  throw Exception(TE_TR("The method getBatchExecutor() is not supported by the WFS driver!"));
437 }
438 
440 {
441  throw Exception(TE_TR("The method cancel() is not supported by the WFS driver!"));
442 }
443 
445 {
446  throw Exception(TE_TR("The method getLastGeneratedId() is not supported by the WFS driver!"));
447 }
448 
449 std::string te::wfs::Transactor::escape(const std::string& /*value*/)
450 {
451  throw Exception(TE_TR("The method escape() is not supported by the WFS driver!"));
452 }
453 
454 bool te::wfs::Transactor::isDataSetNameValid(const std::string& /*datasetName*/)
455 {
456  throw Exception(TE_TR("The method isDataSetNameValid() is not supported by the WFS driver!"));
457 }
458 
459 bool te::wfs::Transactor::isPropertyNameValid(const std::string& /*propertyName*/)
460 {
461  throw Exception(TE_TR("The method isPropertyNameValid() is not supported by the WFS driver!"));
462 }
463 
464 void te::wfs::Transactor::addProperty(const std::string& /*datasetName*/, te::dt::Property* /*p*/)
465 {
466  throw Exception(TE_TR("The method addProperty() is not supported by the WFS driver!"));
467 }
468 
469 void te::wfs::Transactor::dropProperty(const std::string& /*datasetName*/, const std::string& /*name*/)
470 {
471  throw Exception(TE_TR("The method dropProperty() is not supported by the WFS driver!"));
472 }
473 
474 void te::wfs::Transactor::renameProperty(const std::string& /*datasetName*/, const std::string& /*propertyName*/, const std::string& /*newPropertyName*/)
475 {
476  throw Exception(TE_TR("The method renameProperty() is not supported by the WFS driver!"));
477 }
478 
479 std::auto_ptr<te::da::PrimaryKey> te::wfs::Transactor::getPrimaryKey(const std::string& /*datasetName*/)
480 {
481  throw Exception(TE_TR("The method getPrimaryKey() is not supported by the WFS driver!"));
482 }
483 
484 bool te::wfs::Transactor::primaryKeyExists(const std::string& /*datasetName*/, const std::string& /*name*/)
485 {
486  throw Exception(TE_TR("The method primaryKeyExists() is not supported by the WFS driver!"));
487 }
488 
489 void te::wfs::Transactor::addPrimaryKey(const std::string& /*datasetName*/, te::da::PrimaryKey* /*pk*/)
490 {
491  throw Exception(TE_TR("The method addPrimaryKey() is not supported by the WFS driver!"));
492 }
493 
494 void te::wfs::Transactor::dropPrimaryKey(const std::string& /*datasetName*/)
495 {
496  throw Exception(TE_TR("The method dropPrimaryKey() is not supported by the WFS driver!"));
497 }
498 
499 std::auto_ptr<te::da::ForeignKey> te::wfs::Transactor::getForeignKey(const std::string& /*datasetName*/, const std::string& /*name*/)
500 {
501  throw Exception(TE_TR("The method getForeignKey() is not supported by the WFS driver!"));
502 }
503 
504 std::vector<std::string> te::wfs::Transactor::getForeignKeyNames(const std::string& /*datasetName*/)
505 {
506  throw Exception(TE_TR("The method getForeignKeyNames() is not supported by the WFS driver!"));
507 }
508 
509 bool te::wfs::Transactor::foreignKeyExists(const std::string& /*datasetName*/, const std::string& /*name*/)
510 {
511  throw Exception(TE_TR("The method foreignKeyExists() is not supported by the WFS driver!"));
512 }
513 
514 void te::wfs::Transactor::addForeignKey(const std::string& /*datasetName*/, te::da::ForeignKey* /*fk*/)
515 {
516  throw Exception(TE_TR("The method addForeignKey() is not supported by the WFS driver!"));
517 }
518 
519 void te::wfs::Transactor::dropForeignKey(const std::string& /*datasetName*/, const std::string& /*fkName*/)
520 {
521  throw Exception(TE_TR("The method dropForeignKey() is not supported by the WFS driver!"));
522 }
523 
524 std::auto_ptr<te::da::UniqueKey> te::wfs::Transactor::getUniqueKey(const std::string& /*datasetName*/, const std::string& /*name*/)
525 {
526  throw Exception(TE_TR("The method getUniqueKey() is not supported by the WFS driver!"));
527 }
528 
529 std::vector<std::string> te::wfs::Transactor::getUniqueKeyNames(const std::string& /*datasetName*/)
530 {
531  throw Exception(TE_TR("The method getUniqueKeyNames() is not supported by the WFS driver!"));
532 }
533 
534 bool te::wfs::Transactor::uniqueKeyExists(const std::string& /*datasetName*/, const std::string& /*name*/)
535 {
536  throw Exception(TE_TR("The method uniqueKeyExists() is not supported by the WFS driver!"));
537 }
538 
539 void te::wfs::Transactor::addUniqueKey(const std::string& /*datasetName*/, te::da::UniqueKey* /*uk*/)
540 {
541  throw Exception(TE_TR("The method addUniqueKey() is not supported by the WFS driver!"));
542 }
543 
544 void te::wfs::Transactor::dropUniqueKey(const std::string& /*datasetName*/, const std::string& /*name*/)
545 {
546  throw Exception(TE_TR("The method dropUniqueKey() is not supported by the WFS driver!"));
547 }
548 
549 std::auto_ptr<te::da::CheckConstraint> te::wfs::Transactor::getCheckConstraint(const std::string& /*datasetName*/, const std::string& /*name*/)
550 {
551  throw Exception(TE_TR("The method getCheckConstraint() is not supported by the WFS driver!"));
552 }
553 
554 std::vector<std::string> te::wfs::Transactor::getCheckConstraintNames(const std::string& /*datasetName*/)
555 {
556  throw Exception(TE_TR("The method getCheckConstraintNames() is not supported by the WFS driver!"));
557 }
558 
559 bool te::wfs::Transactor::checkConstraintExists(const std::string& /*datasetName*/, const std::string& /*name*/)
560 {
561  throw Exception(TE_TR("The method checkConstraintExists() is not supported by the WFS driver!"));
562 }
563 
564 void te::wfs::Transactor::addCheckConstraint(const std::string& /*datasetName*/, te::da::CheckConstraint* /*cc*/)
565 {
566  throw Exception(TE_TR("The method addCheckConstraint() is not supported by the WFS driver!"));
567 }
568 
569 void te::wfs::Transactor::dropCheckConstraint(const std::string& /*datasetName*/, const std::string& /*name*/)
570 {
571  throw Exception(TE_TR("The method dropCheckConstraint() is not supported by the WFS driver!"));
572 }
573 
574 std::auto_ptr<te::da::Index> te::wfs::Transactor::getIndex(const std::string& /*datasetName*/, const std::string& /*name*/)
575 {
576  throw Exception(TE_TR("The method getIndex() is not supported by the WFS driver!"));
577 }
578 
579 std::vector<std::string> te::wfs::Transactor::getIndexNames(const std::string& /*datasetName*/)
580 {
581  throw Exception(TE_TR("The method getIndexNames() is not supported by the WFS driver!"));
582 }
583 
584 bool te::wfs::Transactor::indexExists(const std::string& /*datasetName*/, const std::string& /*name*/)
585 {
586  throw Exception(TE_TR("The method indexExists() is not supported by the WFS driver!"));
587 }
588 
589 void te::wfs::Transactor::addIndex(const std::string& /*datasetName*/, te::da::Index* /*idx*/, const std::map<std::string, std::string>& /*options*/)
590 {
591  throw Exception(TE_TR("The method addIndex() is not supported by the WFS driver!"));
592 }
593 
594 void te::wfs::Transactor::dropIndex(const std::string& /*datasetName*/, const std::string& /*idxName*/)
595 {
596  throw Exception(TE_TR("The method dropIndex() is not supported by the WFS driver!"));
597 }
598 
599 std::auto_ptr<te::da::Sequence> te::wfs::Transactor::getSequence(const std::string& /*name*/)
600 {
601  throw Exception(TE_TR("The method getSequence() is not supported by the WFS driver!"));
602 }
603 
604 std::vector<std::string> te::wfs::Transactor::getSequenceNames()
605 {
606  throw Exception(TE_TR("The method getSequenceNames() is not supported by the WFS driver!"));
607 }
608 
609 bool te::wfs::Transactor::sequenceExists(const std::string& /*name*/)
610 {
611  throw Exception(TE_TR("The method sequenceExists() is not supported by the WFS driver!"));
612 }
613 
615 {
616  throw Exception(TE_TR("The method addSequence() is not supported by the WFS driver!"));
617 }
618 
619 void te::wfs::Transactor::dropSequence(const std::string& /*name*/)
620 {
621  throw Exception(TE_TR("The method dropSequence() is not supported by the WFS driver!"));
622 }
623 
625  const std::map<std::string, std::string>& /*options*/)
626 {
627  throw Exception(TE_TR("The method createDataSet() is not supported by the WFS driver!"));
628 }
629 
630 void te::wfs::Transactor::cloneDataSet(const std::string& /*name*/,
631  const std::string& /*cloneName*/,
632  const std::map<std::string, std::string>& /*options*/)
633 {
634  throw Exception(TE_TR("The method cloneDataSet() is not supported by the WFS driver!"));
635 }
636 
637 void te::wfs::Transactor::dropDataSet(const std::string& /*name*/)
638 {
639  throw Exception(TE_TR("The method dropDataSet() is not supported by the WFS driver!"));
640 }
641 
642 void te::wfs::Transactor::renameDataSet(const std::string& /*name*/,
643  const std::string& /*newName*/)
644 {
645  throw Exception(TE_TR("The method renameDataSet() is not supported by the WFS driver!"));
646 }
647 
648 void te::wfs::Transactor::add(const std::string& /*datasetName*/,
649  te::da::DataSet* /*d*/,
650  const std::map<std::string, std::string>& /*options*/,
651  std::size_t /*limit*/)
652 {
653  throw Exception(TE_TR("The method add() is not supported by the WFS driver!"));
654 }
655 
656 void te::wfs::Transactor::remove(const std::string& /*datasetName*/, const te::da::ObjectIdSet* /*oids*/)
657 {
658  throw Exception(TE_TR("The method remove() is not supported by the WFS driver!"));
659 }
660 
661 void te::wfs::Transactor::update(const std::string& /*datasetName*/,
662  te::da::DataSet* /*dataset*/,
663  const std::vector<std::size_t>& /*properties*/,
664  const te::da::ObjectIdSet* /*oids*/,
665  const std::map<std::string, std::string>& /*options*/,
666  std::size_t /*limit*/)
667 {
668  throw Exception(TE_TR("The method update() is not supported by the WFS driver!"));
669 }
670 
671 void te::wfs::Transactor::optimize(const std::map<std::string, std::string>& /*opInfo*/)
672 {
673  throw Exception(TE_TR("The method optimize() is not supported by the WFS driver!"));
674 }
675 
677 {
678  return te::common::UTF8;
679 }
680 
681 //@}
Implementation of the data source for the WFS driver.
void renameDataSet(const std::string &name, const std::string &newName)
It renames a dataset.
Definition: Transactor.cpp:642
Geometric property.
Implementation of the transactor for the WFS driver.
void add(te::dt::Property *p)
It adds a property to the list of properties of the primary key.
Definition: PrimaryKey.h:123
Utility functions for the data access module.
std::size_t getNumberOfProperties(const std::string &datasetName)
It gets the number of properties of the given dataset.
Definition: Transactor.cpp:317
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:624
TEOGREXPORT OGRGeometry * Convert2OGR(const te::gm::Geometry *teGeom)
It converts the TerraLib Geometry to OGR Geometry.
Definition: Utils.cpp:80
std::vector< std::string > getPropertyNames(const std::string &datasetName)
It gets the property names of the given dataset.
Definition: Transactor.cpp:293
void setSRID(int srid)
It sets the spatial reference system identifier associated to this property.
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:509
CharEncoding
Supported charsets (character encoding).
void dropPrimaryKey(const std::string &datasetName)
It removes the primary key constraint from the dataset schema.
Definition: Transactor.cpp:494
A class that models the description of a dataset.
Definition: DataSetType.h:72
void addPrimaryKey(const std::string &datasetName, te::da::PrimaryKey *pk)
It adds a primary key constraint to the dataset schema.
Definition: Transactor.cpp:489
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:250
void dropUniqueKey(const std::string &datasetName, const std::string &name)
It removes the unique key constraint from the dataset.
Definition: Transactor.cpp:544
void addCheckConstraint(const std::string &datasetName, te::da::CheckConstraint *cc)
It adds a check constraint to the dataset.
Definition: Transactor.cpp:564
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:574
double m_urx
Upper right corner x-coordinate.
Definition: Envelope.h:346
std::vector< std::string > getUniqueKeyNames(const std::string &datasetName)
It gets the unique key names of the given dataset.
Definition: Transactor.cpp:529
SpatialRelation
Spatial relations between geometric objects.
Definition: Enums.h:122
It describes a sequence (a number generator).
Definition: Sequence.h:56
std::vector< std::string > getDataSetNames()
It It gets the dataset names available in the data source.
Definition: Transactor.cpp:177
void update(const std::string &datasetName, te::da::DataSet *dataset, const std::vector< std::size_t > &properties, const te::da::ObjectIdSet *oids, const std::map< std::string, std::string > &options, std::size_t limit=0)
It updates the contents of a dataset for the set of data items.
Definition: Transactor.cpp:661
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
bool isPropertyNameValid(const std::string &propertyName)
It checks if the given property name is valid.
Definition: Transactor.cpp:459
void dropDataSet(const std::string &name)
It removes the dataset schema from the data source.
Definition: Transactor.cpp:637
#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::size_t getNumberOfItems(const std::string &datasetName)
It retrieves the number of items of the given dataset.
Definition: Transactor.cpp:368
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:648
Implementation of a DataSet for OGR data provider.
Definition: DataSet.h:59
It models a property definition.
Definition: Property.h:59
Transactor(DataSource *ds)
Definition: Transactor.cpp:47
void remove(const std::string &datasetName, const te::da::ObjectIdSet *oids=0)
It removes all the informed items from the dataset.
Definition: Transactor.cpp:656
std::vector< std::string > getForeignKeyNames(const std::string &datasetName)
It gets the foreign key names of the given dataset.
Definition: Transactor.cpp:504
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:549
void optimize(const std::map< std::string, std::string > &opInfo)
For some data access drivers, this method will perform some operations to optimize the data storage...
Definition: Transactor.cpp:671
Implementation of the data source for the WFS driver.
Definition: DataSource.h:52
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
double m_llx
Lower left corner x-coordinate.
Definition: Envelope.h:344
void addUniqueKey(const std::string &datasetName, te::da::UniqueKey *uk)
It adds a unique key constraint to the dataset.
Definition: Transactor.cpp:539
std::auto_ptr< te::da::BatchExecutor > getBatchExecutor()
It creates a batch command executor.
Definition: Transactor.cpp:434
bool hasDataSets()
It checks if the data source has any dataset.
Definition: Transactor.cpp:380
void cancel()
It requests that the data source stop the processing of the current command.
Definition: Transactor.cpp:439
An Envelope defines a 2D rectangular region.
Definition: Envelope.h:51
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:333
bool dataSetExists(const std::string &name)
It checks if a dataset with the given name exists in the data source.
Definition: Transactor.cpp:388
This class represents a set of unique ids created in the same context. i.e. from the same data set...
Definition: ObjectIdSet.h:55
std::vector< std::string > getCheckConstraintNames(const std::string &datasetName)
It gets the check constraint names of the given dataset.
Definition: Transactor.cpp:554
std::auto_ptr< te::da::DataSetType > getDataSetType(const std::string &name)
It gets information about the given dataset.
Definition: Transactor.cpp:198
TEOGREXPORT te::gm::Geometry * Convert2TerraLib(OGRGeometry *ogrGeom)
It converts the OGR Geometry to TerraLib Geometry.
Definition: Utils.cpp:55
boost::ptr_vector< te::dt::Property > getProperties(const std::string &datasetName)
It retrieves the properties of the dataset.
Definition: Transactor.cpp:237
void dropIndex(const std::string &datasetName, const std::string &idxName)
It removes the index from the dataset schema.
Definition: Transactor.cpp:594
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:499
It models a foreign key constraint for a DataSetType.
Definition: ForeignKey.h:50
void dropCheckConstraint(const std::string &datasetName, const std::string &name)
It removes the check constraint from the dataset.
Definition: Transactor.cpp:569
bool isDataSetNameValid(const std::string &datasetName)
It returns true if the given string is a valid dataset name.
Definition: Transactor.cpp:454
bool sequenceExists(const std::string &name)
It checks if a sequence with the given name exists in the data source.
Definition: Transactor.cpp:609
It describes a unique key (uk) constraint.
Definition: UniqueKey.h:53
std::auto_ptr< te::da::PrimaryKey > getPrimaryKey(const std::string &datasetName)
It retrieves the primary key of the dataset.
Definition: Transactor.cpp:479
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:630
void begin()
NOT SUPPORTED METHODS.
Definition: Transactor.cpp:399
Geometry is the root class of the geometries hierarchy, it follows OGC and ISO standards.
Definition: Geometry.h:73
A Select models a query to be used when retrieving data from a DataSource.
Definition: Select.h:65
bool isInTransaction() const
It returns true if a transaction is in progress, otherwise, it returns false.
Definition: Transactor.cpp:414
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:130
double m_lly
Lower left corner y-coordinate.
Definition: Envelope.h:345
A dataset is the unit of information manipulated by the data access module of TerraLib.
Definition: DataSet.h:112
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:534
void execute(const te::da::Query &command)
It executes the specified command using a generic query representation.
Definition: Transactor.cpp:419
void addSequence(te::da::Sequence *sequence)
It creates a new sequence in the data source.
Definition: Transactor.cpp:614
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.
It describes a primary key (pk) constraint.
Definition: PrimaryKey.h:52
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:559
boost::int64_t getLastGeneratedId()
It returns the last id generated by an insertion command.
Definition: Transactor.cpp:444
bool primaryKeyExists(const std::string &datasetName, const std::string &name)
It checks if a primary key exists in the dataset.
Definition: Transactor.cpp:484
std::size_t getNumberOfDataSets()
It retrieves the number of data sets available in the data source.
Definition: Transactor.cpp:190
void addProperty(const std::string &datasetName, te::dt::Property *p)
It adds a new property to the dataset schema.
Definition: Transactor.cpp:464
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:589
void addForeignKey(const std::string &datasetName, te::da::ForeignKey *fk)
It adds a foreign key constraint to a dataset.
Definition: Transactor.cpp:514
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:322
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:429
std::string escape(const std::string &value)
It escapes a string for using in commands and queries.
Definition: Transactor.cpp:449
void dropProperty(const std::string &datasetName, const std::string &name)
It removes a property from the given dataset.
Definition: Transactor.cpp:469
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:474
te::common::CharEncoding getEncoding()
It return the DataSource current encoding.
Definition: Transactor.cpp:676
te::da::DataSource * getDataSource() const
It returns the parent data source of the transactor.
Definition: Transactor.cpp:57
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:584
TEDATAACCESSEXPORT te::gm::GeometryProperty * GetFirstGeomProperty(const DataSetType *dt)
Definition: Utils.cpp:557
void dropSequence(const std::string &name)
It removes the sequence from the data source.
Definition: Transactor.cpp:619
void rollBack()
It aborts the transaction. Any changes will be rolled-back.
Definition: Transactor.cpp:409
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:524
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
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:599
An exception class for the TerraLib WFS module.
TEOGREXPORT int Convert2TerraLibProjection(OGRSpatialReference *osrs)
It converts the OGR Projection to TerraLib Projection.
Definition: Utils.cpp:126
std::vector< std::string > getSequenceNames()
It gets the sequence names available in the data source.
Definition: Transactor.cpp:604
void commit()
It commits the transaction.
Definition: Transactor.cpp:404
void dropForeignKey(const std::string &datasetName, const std::string &fkName)
It removes the foreign key constraint from the dataset schema.
Definition: Transactor.cpp:519
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:62
std::vector< std::string > getIndexNames(const std::string &datasetName)
It gets the index names of the given dataset.
Definition: Transactor.cpp:579