All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
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(0)
36 {
37 }
38 
39 te::da::ForeignKey::ForeignKey(const std::string& name,
40  unsigned int id)
41  : Constraint(name, id),
42  m_onDelete(NO_ACTION),
43  m_onUpdate(NO_ACTION),
44  m_refDt(0)
45 {
46 }
47 
49  : Constraint(rhs),
50  m_onDelete(rhs.m_onDelete),
51  m_onUpdate(rhs.m_onUpdate),
52  m_refDt(rhs.m_refDt),
53  m_properties(rhs.m_properties),
54  m_refProperties(rhs.m_refProperties)
55 {
56 }
57 
59 {
60  if(this != &rhs)
61  {
63 
64  m_onDelete = rhs.m_onDelete;
65 
66  m_onUpdate = rhs.m_onUpdate;
67 
68  m_refDt = rhs.m_refDt;
69 
70  m_properties = rhs.m_properties;
71 
72  m_refProperties = rhs.m_refProperties;
73  }
74 
75  return *this;
76 }
77 
79 {
80  size_t size = m_properties.size();
81 
82  for(size_t i = 0; i < size; ++i)
83  if(m_properties[i] == p)
84  return true;
85 
86  return false;
87 }
88 
90 {
91  size_t size = m_refProperties.size();
92 
93  for(size_t i = 0; i < size; ++i)
94  if(m_refProperties[i] == p)
95  return true;
96 
97  return false;
98 }
99 
101 {
102  {
103  std::size_t size = m_properties.size();
104 
105  for(std::size_t i = 0; i < size; ++i)
106  if(m_properties[i] == p)
107  {
108  m_properties[i] = pp;
109  break;
110  }
111  }
112 
113  {
114  std::size_t size = m_refProperties.size();
115 
116  for(std::size_t i = 0; i < size; ++i)
117  if(m_refProperties[i] == p)
118  {
119  m_properties[i] = pp;
120  break;
121  }
122  }
123 }
124 
126 {
127  return new ForeignKey(*this);
128 }
129 
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.
Definition: ForeignKey.cpp:58
void replace(te::dt::Property *p, te::dt::Property *pp)
It changes a reference to property p to pp.
Definition: ForeignKey.cpp:100
bool has(te::dt::Property *p)
It verifies if Property takes part of the foreign key.
Definition: ForeignKey.cpp:78
ForeignKey(unsigned int id=0)
Constructor.
Definition: ForeignKey.cpp:31
Constraint & operator=(const Constraint &rhs)
Assignment operator not allowed.
Definition: Constraint.cpp:52
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.
Definition: ForeignKey.cpp:89
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.
Definition: ForeignKey.cpp:125