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 = m_ds->getOGRDataSource();
70 // OGRDataSource* ds = OGRSFDriverRegistrar::Open(m_ds->getOGRDataSource()->GetName());
71 
72  std::string sql = "SELECT FID, * FROM \'" + name + "\'";
73  OGRLayer* layer = ds->ExecuteSQL(sql.c_str(), 0, 0);
74 
75  if(layer == 0)
76  throw Exception(TE_TR("The informed data set could not be found in the data source!"));
77 
78  //char** fields = new char*[1];
79  //fields[0] = "OGR_GEOMETRY";
80 
81  //layer->SetIgnoredFields((const char**) fields);
82 
83  return std::auto_ptr<te::da::DataSet>(new te::ogr::DataSet(ds, layer));
84 }
85 
86 std::auto_ptr<te::da::DataSet> te::wfs::Transactor::getDataSet(const std::string& name,
87  const std::string& /*propertyName*/,
88  const te::gm::Envelope* e,
90  te::common::TraverseType /*travType*/,
91  bool /*connected*/,
92  const te::common::AccessPolicy /*accessPolicy*/)
93 {
94  assert(m_ds->getOGRDataSource());
95 
96  OGRDataSource* ds = m_ds->getOGRDataSource();
97 // OGRDataSource* ds = OGRSFDriverRegistrar::Open(m_ds->getOGRDataSource()->GetName());
98 
99  std::string sql = "SELECT FID, * FROM \'" + name + "\'";
100  OGRLayer* layer = ds->ExecuteSQL(sql.c_str(), 0, 0);
101 
102  if(layer == 0)
103  throw Exception(TE_TR("The informed data set could not be found in the data source!"));
104 
105 // layer->SetSpatialFilterRect(e->m_llx, e->m_lly, e->m_urx, e->m_ury);
106 
107  return std::auto_ptr<te::da::DataSet>(new te::ogr::DataSet(ds, layer));
108 }
109 
110 std::auto_ptr<te::da::DataSet> te::wfs::Transactor::getDataSet(const std::string& name,
111  const std::string& /*propertyName*/,
112  const te::gm::Geometry* g,
114  te::common::TraverseType /*travType*/,
115  bool /*connected*/,
116  const te::common::AccessPolicy /*accessPolicy*/)
117 {
118  assert(m_ds->getOGRDataSource());
119 
120  OGRDataSource* ds = m_ds->getOGRDataSource();
121  // OGRDataSource* ds = OGRSFDriverRegistrar::Open(m_ds->getOGRDataSource()->GetName());
122 
123  std::string sql = "SELECT FID, * FROM \'" + name + "\'";
124  OGRLayer* layer = ds->ExecuteSQL(sql.c_str(), 0, 0);
125 
126  if(layer == 0)
127  throw Exception(TE_TR("The informed data set could not be found in the data source!"));
128 
129  OGRGeometry* ogrg = te::ogr::Convert2OGR(g);
130 
131  layer->SetSpatialFilter(ogrg);
132 
133  OGRGeometryFactory::destroyGeometry(ogrg);
134 
135  return std::auto_ptr<te::da::DataSet>(new te::ogr::DataSet(ds, layer));
136 }
137 
138 std::auto_ptr<te::da::DataSet> te::wfs::Transactor::query(const te::da::Select& q,
139  te::common::TraverseType /*travType*/,
140  bool /*connected*/,
141  const te::common::AccessPolicy /*accessPolicy*/)
142 {
143  assert(m_ds->getOGRDataSource());
144 
145  OGRDataSource* ds = m_ds->getOGRDataSource();
146  // OGRDataSource* ds = OGRSFDriverRegistrar::Open(m_ds->getOGRDataSource()->GetName());
147 
148  std::string sql;
149 
150  te::ogr::SQLVisitor visitor(*m_ds->getDialect(), sql);
151 
152  q.accept(visitor);
153 
154  sql = te::ogr::RemoveSpatialSql(sql);
155 
156  OGRLayer* layer = ds->ExecuteSQL(sql.c_str(), 0, 0);
157 
158  if(layer == 0)
159  throw Exception(TE_TR("The informed data set could not be found in the data source!"));
160 
161  te::gm::Envelope* e = visitor.getMBR();
162 
163  if(e != 0)
164  layer->SetSpatialFilterRect(e->m_llx, e->m_lly, e->m_urx, e->m_ury);
165 
166  return std::auto_ptr<te::da::DataSet>(new te::ogr::DataSet(ds, layer));
167 }
168 
169 std::auto_ptr<te::da::DataSet> te::wfs::Transactor::query(const std::string& query,
170  te::common::TraverseType /*travType*/,
171  bool /*connected*/,
172  const te::common::AccessPolicy /*accessPolicy*/)
173 {
174  assert(m_ds->getOGRDataSource());
175 
176  OGRDataSource* ds = m_ds->getOGRDataSource();
177  // OGRDataSource* ds = OGRSFDriverRegistrar::Open(m_ds->getOGRDataSource()->GetName());
178 
179  OGRLayer* layer = ds->ExecuteSQL(query.c_str(), 0, 0);
180 
181  if(layer == 0)
182  throw Exception(TE_TR("The informed data set could not be found in the data source!"));
183 
184  return std::auto_ptr<te::da::DataSet>(new te::ogr::DataSet(ds, layer));
185 }
186 
187 std::vector<std::string> te::wfs::Transactor::getDataSetNames()
188 {
189  std::vector<std::string> names;
190 
191  if(!m_ds->getOGRDataSource())
192  return names;
193 
194  for(int i = 0; i < m_ds->getOGRDataSource()->GetLayerCount(); ++i)
195  names.push_back(m_ds->getOGRDataSource()->GetLayer(i)->GetName());
196 
197  return names;
198 }
199 
201 {
202  if(!m_ds->getOGRDataSource())
203  return 0;
204 
205  return m_ds->getOGRDataSource()->GetLayerCount();
206 }
207 
208 std::auto_ptr<te::da::DataSetType> te::wfs::Transactor::getDataSetType(const std::string& name)
209 {
210  assert(m_ds->getOGRDataSource());
211 
212  std::string sql("SELECT FID, * FROM \'");
213  sql += name + "\'";
214 
215  OGRLayer* layer = m_ds->getOGRDataSource()->ExecuteSQL(sql.c_str(), 0, 0);
216 
217  if(layer == 0)
218  throw Exception(TE_TR("Could not retrieve the informed data set!"));
219 
220  std::auto_ptr<te::da::DataSetType> type(te::ogr::Convert2TerraLib(layer->GetLayerDefn()));
221  type->setName(name);
222 
223  const char* colIdName = layer->GetFIDColumn();
224 
225  if(colIdName == 0 || colIdName[0] == '\0')
226  colIdName = "FID";
227 
228  int pos = layer->GetLayerDefn()->GetFieldIndex(colIdName);
229  if(pos >= 0)
230  {
231  te::da::PrimaryKey* pk = new te::da::PrimaryKey(colIdName, type.get());
232  pk->add(type->getProperty(pos));
233  }
234 
235  int srs = te::ogr::Convert2TerraLibProjection(layer->GetSpatialRef());
236 
238 
239  if(gp != 0)
240  gp->setSRID(srs);
241 
242  m_ds->getOGRDataSource()->ReleaseResultSet(layer);
243 
244  return type;
245 }
246 
247 boost::ptr_vector<te::dt::Property> te::wfs::Transactor::getProperties(const std::string& datasetName)
248 {
249  boost::ptr_vector<te::dt::Property> properties;
250 
251  std::auto_ptr<te::da::DataSetType> type = getDataSetType(datasetName);
252 
253  const std::vector<te::dt::Property*>& props = type->getProperties();
254  for(std::size_t i = 0; i < props.size(); ++i)
255  properties.push_back(props[i]->clone());
256 
257  return properties;
258 }
259 
260 std::auto_ptr<te::dt::Property> te::wfs::Transactor::getProperty(const std::string& datasetName, const std::string& name)
261 {
262  assert(m_ds->getOGRDataSource());
263 
264  std::string sql("SELECT FID, * FROM \'");
265  sql += datasetName + "\'";
266 
267  OGRLayer* layer = m_ds->getOGRDataSource()->ExecuteSQL(sql.c_str(), 0, 0);
268 
269  if(layer == 0)
270  throw Exception(TE_TR("Could not retrieve the informed data set!"));
271 
272  int propertyPos = layer->GetLayerDefn()->GetFieldIndex(name.c_str());
273 
274  m_ds->getOGRDataSource()->ReleaseResultSet(layer);
275 
276  return getProperty(datasetName, static_cast<std::size_t>(propertyPos));
277 }
278 
279 std::auto_ptr<te::dt::Property> te::wfs::Transactor::getProperty(const std::string& datasetName, std::size_t propertyPos)
280 {
281  assert(m_ds->getOGRDataSource());
282 
283  std::string sql("SELECT FID, * FROM \'");
284  sql += datasetName + "\'";
285 
286  OGRLayer* layer = m_ds->getOGRDataSource()->ExecuteSQL(sql.c_str(), 0, 0);
287 
288  if(layer == 0)
289  throw Exception(TE_TR("Could not retrieve the informed data set!"));
290 
291  OGRFeatureDefn* def = layer->GetLayerDefn();
292  OGRFieldDefn* fdef = def->GetFieldDefn(propertyPos);
293 
294  std::auto_ptr<te::dt::Property> prop;
295  if(fdef != 0)
296  prop.reset(te::ogr::Convert2TerraLib(fdef));
297 
298  m_ds->getOGRDataSource()->ReleaseResultSet(layer);
299 
300  return prop;
301 }
302 
303 std::vector<std::string> te::wfs::Transactor::getPropertyNames(const std::string& datasetName)
304 {
305  assert(m_ds->getOGRDataSource());
306 
307  std::string sql("SELECT FID, * FROM \'");
308  sql += datasetName + "\'";
309 
310  OGRLayer* layer = m_ds->getOGRDataSource()->ExecuteSQL(sql.c_str(), 0, 0);
311 
312  if(layer == 0)
313  throw Exception(TE_TR("Could not retrieve the informed data set!"));
314 
315  std::vector<std::string> propertyNames;
316 
317  OGRFeatureDefn* def = layer->GetLayerDefn();
318 
319  for(int i = 0; i < def->GetFieldCount(); ++i)
320  propertyNames.push_back(def->GetFieldDefn(i)->GetNameRef());
321 
322  m_ds->getOGRDataSource()->ReleaseResultSet(layer);
323 
324  return propertyNames;
325 }
326 
327 std::size_t te::wfs::Transactor::getNumberOfProperties(const std::string& datasetName)
328 {
329  return getPropertyNames(datasetName).size();
330 }
331 
332 bool te::wfs::Transactor::propertyExists(const std::string& datasetName, const std::string& name)
333 {
334  std::vector<std::string> propertyNames = getPropertyNames(datasetName);
335 
336  for(std::size_t i = 0; i < propertyNames.size(); ++i)
337  if(propertyNames[i] == name)
338  return true;
339 
340  return false;
341 }
342 
343 std::auto_ptr<te::gm::Envelope> te::wfs::Transactor::getExtent(const std::string& datasetName,
344  const std::string& propertyName)
345 {
346  assert(m_ds->getOGRDataSource());
347 
348  std::string sql("SELECT ");
349  sql += propertyName + " FROM \'";
350  sql += datasetName + "\'";
351 
352  OGRLayer* layer = m_ds->getOGRDataSource()->ExecuteSQL(sql.c_str(), 0, 0);
353 
354  if(layer == 0)
355  throw Exception(TE_TR("Could not retrieve the informed data set!"));
356 
357  std::auto_ptr<OGREnvelope> ogrEnv(new OGREnvelope);
358 
359  if(layer->GetExtent(ogrEnv.get()) != OGRERR_NONE)
360  {
361  m_ds->getOGRDataSource()->ReleaseResultSet(layer);
362  throw Exception(TE_TR("Error when attempting to get the extent!"));
363  }
364 
365  std::auto_ptr<te::gm::Envelope> teEnv(te::ogr::Convert2TerraLib(ogrEnv.get()));
366 
367  m_ds->getOGRDataSource()->ReleaseResultSet(layer);
368 
369  return teEnv;
370 }
371 
372 std::auto_ptr<te::gm::Envelope> te::wfs::Transactor::getExtent(const std::string& datasetName,
373  std::size_t /*propertyPos*/)
374 {
375  return getExtent(datasetName, "OGR_GEOMETRY");
376 }
377 
378 std::size_t te::wfs::Transactor::getNumberOfItems(const std::string& datasetName)
379 {
380  assert(m_ds->getOGRDataSource());
381 
382  OGRLayer* layer = m_ds->getOGRDataSource()->GetLayerByName(datasetName.c_str());
383 
384  if(layer == 0)
385  throw Exception(TE_TR("Could not retrieve the informed data set!"));
386 
387  return layer->GetFeatureCount();
388 }
389 
391 {
392  if(!m_ds->getOGRDataSource())
393  return false;
394 
395  return (m_ds->getOGRDataSource()->GetLayerCount() > 0);
396 }
397 
398 bool te::wfs::Transactor::dataSetExists(const std::string& name)
399 {
400  if(!m_ds->getOGRDataSource())
401  return false;
402 
403  return (m_ds->getOGRDataSource()->GetLayerByName(name.c_str()) != 0);
404 }
405 
406 /** NOT SUPPORTED METHODS */
407 //@{
408 
410 {
411  throw Exception(TE_TR("The method begin() is not supported by the WFS driver!"));
412 }
413 
415 {
416  throw Exception(TE_TR("The method commit() is not supported by the WFS driver!"));
417 }
418 
420 {
421  throw Exception(TE_TR("The method rollBack() is not supported by the WFS driver!"));
422 }
423 
425 {
426  throw Exception(TE_TR("The method isInTransaction() is not supported by the WFS driver!"));
427 }
428 
430 {
431  throw Exception(TE_TR("The method execute() is not supported by the WFS driver!"));
432 }
433 
434 void te::wfs::Transactor::execute(const std::string& /*command*/)
435 {
436  throw Exception(TE_TR("The method execute() is not supported by the WFS driver!"));
437 }
438 
439 std::auto_ptr<te::da::PreparedQuery> te::wfs::Transactor::getPrepared(const std::string& /*qName*/)
440 {
441  throw Exception(TE_TR("The method getPrepared() is not supported by the WFS driver!"));
442 }
443 
444 std::auto_ptr<te::da::BatchExecutor> te::wfs::Transactor::getBatchExecutor()
445 {
446  throw Exception(TE_TR("The method getBatchExecutor() is not supported by the WFS driver!"));
447 }
448 
450 {
451  throw Exception(TE_TR("The method cancel() is not supported by the WFS driver!"));
452 }
453 
455 {
456  throw Exception(TE_TR("The method getLastGeneratedId() is not supported by the WFS driver!"));
457 }
458 
459 std::string te::wfs::Transactor::escape(const std::string& /*value*/)
460 {
461  throw Exception(TE_TR("The method escape() is not supported by the WFS driver!"));
462 }
463 
464 bool te::wfs::Transactor::isDataSetNameValid(const std::string& /*datasetName*/)
465 {
466  throw Exception(TE_TR("The method isDataSetNameValid() is not supported by the WFS driver!"));
467 }
468 
469 bool te::wfs::Transactor::isPropertyNameValid(const std::string& /*propertyName*/)
470 {
471  throw Exception(TE_TR("The method isPropertyNameValid() is not supported by the WFS driver!"));
472 }
473 
474 void te::wfs::Transactor::addProperty(const std::string& /*datasetName*/, te::dt::Property* /*p*/)
475 {
476  throw Exception(TE_TR("The method addProperty() is not supported by the WFS driver!"));
477 }
478 
479 void te::wfs::Transactor::dropProperty(const std::string& /*datasetName*/, const std::string& /*name*/)
480 {
481  throw Exception(TE_TR("The method dropProperty() is not supported by the WFS driver!"));
482 }
483 
484 void te::wfs::Transactor::renameProperty(const std::string& /*datasetName*/, const std::string& /*propertyName*/, const std::string& /*newPropertyName*/)
485 {
486  throw Exception(TE_TR("The method renameProperty() is not supported by the WFS driver!"));
487 }
488 
489 std::auto_ptr<te::da::PrimaryKey> te::wfs::Transactor::getPrimaryKey(const std::string& /*datasetName*/)
490 {
491  throw Exception(TE_TR("The method getPrimaryKey() is not supported by the WFS driver!"));
492 }
493 
494 bool te::wfs::Transactor::primaryKeyExists(const std::string& /*datasetName*/, const std::string& /*name*/)
495 {
496  throw Exception(TE_TR("The method primaryKeyExists() is not supported by the WFS driver!"));
497 }
498 
499 void te::wfs::Transactor::addPrimaryKey(const std::string& /*datasetName*/, te::da::PrimaryKey* /*pk*/)
500 {
501  throw Exception(TE_TR("The method addPrimaryKey() is not supported by the WFS driver!"));
502 }
503 
504 void te::wfs::Transactor::dropPrimaryKey(const std::string& /*datasetName*/)
505 {
506  throw Exception(TE_TR("The method dropPrimaryKey() is not supported by the WFS driver!"));
507 }
508 
509 std::auto_ptr<te::da::ForeignKey> te::wfs::Transactor::getForeignKey(const std::string& /*datasetName*/, const std::string& /*name*/)
510 {
511  throw Exception(TE_TR("The method getForeignKey() is not supported by the WFS driver!"));
512 }
513 
514 std::vector<std::string> te::wfs::Transactor::getForeignKeyNames(const std::string& /*datasetName*/)
515 {
516  throw Exception(TE_TR("The method getForeignKeyNames() is not supported by the WFS driver!"));
517 }
518 
519 bool te::wfs::Transactor::foreignKeyExists(const std::string& /*datasetName*/, const std::string& /*name*/)
520 {
521  throw Exception(TE_TR("The method foreignKeyExists() is not supported by the WFS driver!"));
522 }
523 
524 void te::wfs::Transactor::addForeignKey(const std::string& /*datasetName*/, te::da::ForeignKey* /*fk*/)
525 {
526  throw Exception(TE_TR("The method addForeignKey() is not supported by the WFS driver!"));
527 }
528 
529 void te::wfs::Transactor::dropForeignKey(const std::string& /*datasetName*/, const std::string& /*fkName*/)
530 {
531  throw Exception(TE_TR("The method dropForeignKey() is not supported by the WFS driver!"));
532 }
533 
534 std::auto_ptr<te::da::UniqueKey> te::wfs::Transactor::getUniqueKey(const std::string& /*datasetName*/, const std::string& /*name*/)
535 {
536  throw Exception(TE_TR("The method getUniqueKey() is not supported by the WFS driver!"));
537 }
538 
539 std::vector<std::string> te::wfs::Transactor::getUniqueKeyNames(const std::string& /*datasetName*/)
540 {
541  throw Exception(TE_TR("The method getUniqueKeyNames() is not supported by the WFS driver!"));
542 }
543 
544 bool te::wfs::Transactor::uniqueKeyExists(const std::string& /*datasetName*/, const std::string& /*name*/)
545 {
546  throw Exception(TE_TR("The method uniqueKeyExists() is not supported by the WFS driver!"));
547 }
548 
549 void te::wfs::Transactor::addUniqueKey(const std::string& /*datasetName*/, te::da::UniqueKey* /*uk*/)
550 {
551  throw Exception(TE_TR("The method addUniqueKey() is not supported by the WFS driver!"));
552 }
553 
554 void te::wfs::Transactor::dropUniqueKey(const std::string& /*datasetName*/, const std::string& /*name*/)
555 {
556  throw Exception(TE_TR("The method dropUniqueKey() is not supported by the WFS driver!"));
557 }
558 
559 std::auto_ptr<te::da::CheckConstraint> te::wfs::Transactor::getCheckConstraint(const std::string& /*datasetName*/, const std::string& /*name*/)
560 {
561  throw Exception(TE_TR("The method getCheckConstraint() is not supported by the WFS driver!"));
562 }
563 
564 std::vector<std::string> te::wfs::Transactor::getCheckConstraintNames(const std::string& /*datasetName*/)
565 {
566  throw Exception(TE_TR("The method getCheckConstraintNames() is not supported by the WFS driver!"));
567 }
568 
569 bool te::wfs::Transactor::checkConstraintExists(const std::string& /*datasetName*/, const std::string& /*name*/)
570 {
571  throw Exception(TE_TR("The method checkConstraintExists() is not supported by the WFS driver!"));
572 }
573 
574 void te::wfs::Transactor::addCheckConstraint(const std::string& /*datasetName*/, te::da::CheckConstraint* /*cc*/)
575 {
576  throw Exception(TE_TR("The method addCheckConstraint() is not supported by the WFS driver!"));
577 }
578 
579 void te::wfs::Transactor::dropCheckConstraint(const std::string& /*datasetName*/, const std::string& /*name*/)
580 {
581  throw Exception(TE_TR("The method dropCheckConstraint() is not supported by the WFS driver!"));
582 }
583 
584 std::auto_ptr<te::da::Index> te::wfs::Transactor::getIndex(const std::string& /*datasetName*/, const std::string& /*name*/)
585 {
586  throw Exception(TE_TR("The method getIndex() is not supported by the WFS driver!"));
587 }
588 
589 std::vector<std::string> te::wfs::Transactor::getIndexNames(const std::string& /*datasetName*/)
590 {
591  throw Exception(TE_TR("The method getIndexNames() is not supported by the WFS driver!"));
592 }
593 
594 bool te::wfs::Transactor::indexExists(const std::string& /*datasetName*/, const std::string& /*name*/)
595 {
596  throw Exception(TE_TR("The method indexExists() is not supported by the WFS driver!"));
597 }
598 
599 void te::wfs::Transactor::addIndex(const std::string& /*datasetName*/, te::da::Index* /*idx*/, const std::map<std::string, std::string>& /*options*/)
600 {
601  throw Exception(TE_TR("The method addIndex() is not supported by the WFS driver!"));
602 }
603 
604 void te::wfs::Transactor::dropIndex(const std::string& /*datasetName*/, const std::string& /*idxName*/)
605 {
606  throw Exception(TE_TR("The method dropIndex() is not supported by the WFS driver!"));
607 }
608 
609 std::auto_ptr<te::da::Sequence> te::wfs::Transactor::getSequence(const std::string& /*name*/)
610 {
611  throw Exception(TE_TR("The method getSequence() is not supported by the WFS driver!"));
612 }
613 
614 std::vector<std::string> te::wfs::Transactor::getSequenceNames()
615 {
616  throw Exception(TE_TR("The method getSequenceNames() is not supported by the WFS driver!"));
617 }
618 
619 bool te::wfs::Transactor::sequenceExists(const std::string& /*name*/)
620 {
621  throw Exception(TE_TR("The method sequenceExists() is not supported by the WFS driver!"));
622 }
623 
625 {
626  throw Exception(TE_TR("The method addSequence() is not supported by the WFS driver!"));
627 }
628 
629 void te::wfs::Transactor::dropSequence(const std::string& /*name*/)
630 {
631  throw Exception(TE_TR("The method dropSequence() is not supported by the WFS driver!"));
632 }
633 
635  const std::map<std::string, std::string>& /*options*/)
636 {
637  throw Exception(TE_TR("The method createDataSet() is not supported by the WFS driver!"));
638 }
639 
640 void te::wfs::Transactor::cloneDataSet(const std::string& /*name*/,
641  const std::string& /*cloneName*/,
642  const std::map<std::string, std::string>& /*options*/)
643 {
644  throw Exception(TE_TR("The method cloneDataSet() is not supported by the WFS driver!"));
645 }
646 
647 void te::wfs::Transactor::dropDataSet(const std::string& /*name*/)
648 {
649  throw Exception(TE_TR("The method dropDataSet() is not supported by the WFS driver!"));
650 }
651 
652 void te::wfs::Transactor::renameDataSet(const std::string& /*name*/,
653  const std::string& /*newName*/)
654 {
655  throw Exception(TE_TR("The method renameDataSet() is not supported by the WFS driver!"));
656 }
657 
658 void te::wfs::Transactor::add(const std::string& /*datasetName*/,
659  te::da::DataSet* /*d*/,
660  const std::map<std::string, std::string>& /*options*/,
661  std::size_t /*limit*/)
662 {
663  throw Exception(TE_TR("The method add() is not supported by the WFS driver!"));
664 }
665 
666 void te::wfs::Transactor::remove(const std::string& /*datasetName*/, const te::da::ObjectIdSet* /*oids*/)
667 {
668  throw Exception(TE_TR("The method remove() is not supported by the WFS driver!"));
669 }
670 
671 void te::wfs::Transactor::update(const std::string& /*datasetName*/,
672  te::da::DataSet* /*dataset*/,
673  const std::vector<std::size_t>& /*properties*/,
674  const te::da::ObjectIdSet* /*oids*/,
675  const std::map<std::string, std::string>& /*options*/,
676  std::size_t /*limit*/)
677 {
678  throw Exception(TE_TR("The method update() is not supported by the WFS driver!"));
679 }
680 
681 void te::wfs::Transactor::optimize(const std::map<std::string, std::string>& /*opInfo*/)
682 {
683  throw Exception(TE_TR("The method optimize() is not supported by the WFS driver!"));
684 }
685 
687 {
688  return te::common::UTF8;
689 }
690 
691 //@}
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:652
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:327
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:634
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:303
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:519
CharEncoding
Supported charsets (character encoding).
void dropPrimaryKey(const std::string &datasetName)
It removes the primary key constraint from the dataset schema.
Definition: Transactor.cpp:504
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:499
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:260
void dropUniqueKey(const std::string &datasetName, const std::string &name)
It removes the unique key constraint from the dataset.
Definition: Transactor.cpp:554
void addCheckConstraint(const std::string &datasetName, te::da::CheckConstraint *cc)
It adds a check constraint to the dataset.
Definition: Transactor.cpp:574
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:584
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:539
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:187
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:671
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:469
void dropDataSet(const std::string &name)
It removes the dataset schema from the data source.
Definition: Transactor.cpp:647
#define TE_TR(message)
It marks a string in order to get translated.
Definition: Translator.h:346
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:378
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:658
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:666
std::vector< std::string > getForeignKeyNames(const std::string &datasetName)
It gets the foreign key names of the given dataset.
Definition: Transactor.cpp:514
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:559
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:681
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:549
std::auto_ptr< te::da::BatchExecutor > getBatchExecutor()
It creates a batch command executor.
Definition: Transactor.cpp:444
bool hasDataSets()
It checks if the data source has any dataset.
Definition: Transactor.cpp:390
void cancel()
It requests that the data source stop the processing of the current command.
Definition: Transactor.cpp:449
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:343
bool dataSetExists(const std::string &name)
It checks if a dataset with the given name exists in the data source.
Definition: Transactor.cpp:398
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:564
std::auto_ptr< te::da::DataSetType > getDataSetType(const std::string &name)
It gets information about the given dataset.
Definition: Transactor.cpp:208
TEOGREXPORT te::gm::Geometry * Convert2TerraLib(OGRGeometry *ogrGeom)
It converts the OGR Geometry to TerraLib Geometry.
Definition: Utils.cpp:55
URI C++ Library.
boost::ptr_vector< te::dt::Property > getProperties(const std::string &datasetName)
It retrieves the properties of the dataset.
Definition: Transactor.cpp:247
void dropIndex(const std::string &datasetName, const std::string &idxName)
It removes the index from the dataset schema.
Definition: Transactor.cpp:604
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:509
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:579
bool isDataSetNameValid(const std::string &datasetName)
It returns true if the given string is a valid dataset name.
Definition: Transactor.cpp:464
bool sequenceExists(const std::string &name)
It checks if a sequence with the given name exists in the data source.
Definition: Transactor.cpp:619
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:489
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:640
void begin()
NOT SUPPORTED METHODS.
Definition: Transactor.cpp:409
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:424
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:138
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:544
void execute(const te::da::Query &command)
It executes the specified command using a generic query representation.
Definition: Transactor.cpp:429
void addSequence(te::da::Sequence *sequence)
It creates a new sequence in the data source.
Definition: Transactor.cpp:624
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:569
boost::int64_t getLastGeneratedId()
It returns the last id generated by an insertion command.
Definition: Transactor.cpp:454
bool primaryKeyExists(const std::string &datasetName, const std::string &name)
It checks if a primary key exists in the dataset.
Definition: Transactor.cpp:494
std::size_t getNumberOfDataSets()
It retrieves the number of data sets available in the data source.
Definition: Transactor.cpp:200
void addProperty(const std::string &datasetName, te::dt::Property *p)
It adds a new property to the dataset schema.
Definition: Transactor.cpp:474
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:599
void addForeignKey(const std::string &datasetName, te::da::ForeignKey *fk)
It adds a foreign key constraint to a dataset.
Definition: Transactor.cpp:524
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:332
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:439
std::string escape(const std::string &value)
It escapes a string for using in commands and queries.
Definition: Transactor.cpp:459
void dropProperty(const std::string &datasetName, const std::string &name)
It removes a property from the given dataset.
Definition: Transactor.cpp:479
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:484
te::common::CharEncoding getEncoding()
It return the DataSource current encoding.
Definition: Transactor.cpp:686
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:594
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:629
void rollBack()
It aborts the transaction. Any changes will be rolled-back.
Definition: Transactor.cpp:419
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:534
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:609
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:614
void commit()
It commits the transaction.
Definition: Transactor.cpp:414
void dropForeignKey(const std::string &datasetName, const std::string &fkName)
It removes the foreign key constraint from the dataset schema.
Definition: Transactor.cpp:529
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:589