dataaccess/dataset/ForeignKey.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/dataaccess/dataset/ForeignKey.cpp
22 
23  \brief It models a foreign key constraint for a DataSetType.
24 */
25 
26 // TerraLib
27 #include "../../datatype/Property.h"
28 #include "DataSetType.h"
29 #include "ForeignKey.h"
30 
32  : Constraint(id),
33  m_onDelete(NO_ACTION),
34  m_onUpdate(NO_ACTION),
35  m_refDt(nullptr)
36 {
37 }
38 
39 te::da::ForeignKey::ForeignKey(const std::string& name,
40  unsigned int id)
41  : Constraint(name, id),
44  m_refDt(nullptr)
45 {
46 }
47 
49 
50  = default;
51 
53 {
54  if(this != &rhs)
55  {
57 
58  m_onDelete = rhs.m_onDelete;
59 
60  m_onUpdate = rhs.m_onUpdate;
61 
62  m_refDt = rhs.m_refDt;
63 
65 
67  }
68 
69  return *this;
70 }
71 
73 {
74  size_t size = m_properties.size();
75 
76  for(size_t i = 0; i < size; ++i)
77  if(m_properties[i] == p)
78  return true;
79 
80  return false;
81 }
82 
84 {
85  size_t size = m_refProperties.size();
86 
87  for(size_t i = 0; i < size; ++i)
88  if(m_refProperties[i] == p)
89  return true;
90 
91  return false;
92 }
93 
95 {
96  {
97  std::size_t size = m_properties.size();
98 
99  for(std::size_t i = 0; i < size; ++i)
100  if(m_properties[i] == p)
101  {
102  m_properties[i] = pp;
103  break;
104  }
105  }
106 
107  {
108  std::size_t size = m_refProperties.size();
109 
110  for(std::size_t i = 0; i < size; ++i)
111  if(m_refProperties[i] == p)
112  {
113  m_properties[i] = pp;
114  break;
115  }
116  }
117 }
118 
120 {
121  return new ForeignKey(*this);
122 }
123 
std::vector< te::dt::Property * > m_properties
The properties that are part of the foreign key constraint.
Definition: ForeignKey.h:241
FKActionType m_onDelete
The action to be performed when a referenced element value in the referenced DataSetType is being del...
Definition: ForeignKey.h:238
ForeignKey & operator=(const ForeignKey &rhs)
Assignment operator.
void replace(te::dt::Property *p, te::dt::Property *pp)
It changes a reference to property p to pp.
bool has(te::dt::Property *p)
It verifies if Property takes part of the foreign key.
ForeignKey(unsigned int id=0)
Constructor.
Constraint & operator=(const Constraint &rhs)
Assignment operator not allowed.
DataSetType * m_refDt
The referenced DataSetType of this foreign key constraint.
Definition: ForeignKey.h:240
It models a property definition.
Definition: Property.h:59
FKActionType m_onUpdate
The action to be performed when a referenced element value in the referenced DataSetType is being upd...
Definition: ForeignKey.h:239
bool isReferenced(te::dt::Property *p)
It verifies if Property is referenced by the foreign key.
te::gm::Polygon * p
It models a foreign key constraint for a DataSetType.
Definition: ForeignKey.h:50
It models a foreign key constraint for a DataSetType.
A class that models the description of a dataset.
std::vector< te::dt::Property * > m_refProperties
The referenced properties (on the referenced DataSetType) of this foreign key constraint.
Definition: ForeignKey.h:242
Constraint * clone()
It returns a clone of the object.