ForeignKey.h
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.h
22 
23  \brief It models a foreign key constraint for a DataSetType.
24 */
25 
26 #ifndef __TERRALIB_DATAACCESS_INTERNAL_FOREIGNKEY_H
27 #define __TERRALIB_DATAACCESS_INTERNAL_FOREIGNKEY_H
28 
29 // TerraLib
30 #include "Constraint.h"
31 #include "../../datatype/Property.h"
32 
33 // STL includes
34 #include <vector>
35 
36 namespace te
37 {
38  namespace da
39  {
40 
41  /*!
42  \class ForeignKey
43 
44  \brief It models a foreign key constraint for a DataSetType.
45 
46  \sa DataSetType, PrimaryKey, UniqueKey, CheckConstraint
47  */
49  {
50  public:
51 
52  /*!
53  \brief Constructor.
54 
55  The default fk will have the actions OnDelete and OnUpdate set as NO_ACTION.
56 
57  \param id The fk identifier.
58 
59  \warning The identifier value (id) may be used by data source implementations. So, don't rely on its value!
60  */
61  ForeignKey(unsigned int id = 0);
62 
63  /*!
64  \brief Constructor.
65 
66  \param name The foreign key constraint name.
67  \param id The fk identifier.
68 
69  \warning The identifier value (id) may be used by data source implementations. So, don't rely on its value!
70  */
71  ForeignKey(const std::string& name, unsigned int id = 0);
72 
73  /*!
74  \brief Copy constructor not allowed.
75 
76  The new object will not have an associated DataSetType.
77 
78  \param rhs Right-hand-side instance.
79  */
80  ForeignKey(const ForeignKey& rhs);
81 
82  /*! \brief Destructor. */
84 
85  /*!
86  \brief Assignment operator.
87 
88  The new object will not have an assigned DataSetType.
89 
90  \param rhs Right-hand-side instance.
91 
92  \return A reference to this.
93  */
95 
96  /*!
97  \brief It returns the properties that take part of the foreign key constraint.
98 
99  \return The properties that take part of the foreign key constraint.
100  */
101  const std::vector<te::dt::Property*>& getProperties() const { return m_properties; }
102 
103  /*!
104  \brief It adds a property to the foreign key constraint.
105 
106  \param p The property to be added to the foreign key constraint.
107 
108  \pre All properties added must belong to the same DataSetType.
109  */
110  void add(const te::dt::Property* p) { m_properties.push_back(p->clone()); }
111 
112  /*!
113  \brief It returns the referenced properties (on the referenced DataSetType) of this foreign key constraint.
114 
115  \return The referenced properties (on the referenced DataSetType) of this foreign key constraint.
116  */
117  const std::vector<te::dt::Property*>& getReferencedProperties() const { return m_refProperties; }
118 
119  /*!
120  \brief It adds a reference property (on the referenced DataSetType) of this foreign key constraint.
121 
122  \param p The referenced property (on the referenced DataSetType) of this foreign key constraint.
123 
124  \pre All properties being added must reference the same DataSetType.
125  */
126  void addRefProperty(const te::dt::Property* p) { m_refProperties.push_back(p->clone()); }
127 
128  /*!
129  \brief It returns the referenced DataSetType of this foreign key constraint.
130 
131  \return The referenced DataSetType of this foreign key constraint.
132  */
133  DataSetType* getReferencedDataSetType() const { return m_refDt; }
134 
135  /*!
136  \brief It sets the referenced DataSetType of this foreign key constraint.
137 
138  \param refDt The referenced DataSetType of this foreign key constraint.
139  */
140  void setReferencedDataSetType(DataSetType* refDt) { m_refDt = refDt; }
141 
142  /*!
143  \brief It returns the action performed when a referenced element value in the referenced DataSetType is being deleted.
144 
145  \return The action performed when a referenced element value in the referenced DataSetType is being deleted.
146  */
147  FKActionType getOnDeleteAction() const { return m_onDelete; }
148 
149  /*!
150  \brief It sets the action to be performed when a referenced element value in the referenced DataSetType is being deleted.
151 
152  \param a The action to be performed when a referenced element value in the referenced DataSetType is being deleted.
153  */
154  void setOnDeleteAction(FKActionType a) { m_onDelete = a; }
155 
156  /*!
157  \brief It returns the action performed when a referenced element value in the referenced DataSetType is being updated to a new value.
158 
159  \return The action performed when a referenced element value in the referenced DataSetType is being updated to a new value.
160  */
161  FKActionType getOnUpdateAction() const { return m_onUpdate; }
162 
163  /*!
164  \brief It sets the action to be performed when a referenced element value in the referenced DataSetType is being updated to a new value.
165 
166  \param a The action to be performed when a referenced element value in the referenced DataSetType is being updated to a new value.
167  */
168  void setOnUpdateAction(FKActionType a) { m_onUpdate = a; }
169 
170  /*!
171  \brief It verifies if Property takes part of the foreign key.
172 
173  \param propertyName The Property name to be verified.
174 
175  \return True if Property takes part of the foreign key, false otherwise.
176  */
177  bool has(const std::string& propertyName);
178 
179  /*!
180  \brief It verifies if Property is referenced by the foreign key.
181 
182  \param propertyName The Property name to be verified.
183 
184  \return True if Property is referenced by the foreign key, false otherwise.
185  */
186  bool isReferenced(const std::string& propertyName);
187 
188  /*!
189  \brief It changes a reference to property p to pp.
190 
191  \param propName A property name that takes part of the foreign key or is referenced by it.
192  \param pp The property that will take p place.
193 
194  \note This method will replace property checking both property list (referenced and the properties in the fk).
195 
196  \note If the property p is not in the fk attribute list this method does nothing.
197  */
198  void replace(const std::string& propName, const te::dt::Property* pp);
199 
200  /*!
201  \brief It returns the constraint type: FOREIGNKEY.
202 
203  \return The constraint type FOREIGNKEY.
204  */
205  ConstraintType getType() const { return FOREIGN_KEY; }
206 
207  /*!
208  \brief It returns a clone of the object.
209 
210  The new object will not have an associated DataSetType.
211 
212  \return A clone of the object.
213  */
215 
216  private:
217 
218  FKActionType m_onDelete; //!< The action to be performed when a referenced element value in the referenced DataSetType is being deleted.
219  FKActionType m_onUpdate; //!< The action to be performed when a referenced element value in the referenced DataSetType is being updated to a new value.
220  DataSetType* m_refDt; //!< The referenced DataSetType of this foreign key constraint.
221  std::vector<te::dt::Property*> m_properties; //!< The properties that are part of the foreign key constraint.
222  std::vector<te::dt::Property*> m_refProperties; //!< The referenced properties (on the referenced DataSetType) of this foreign key constraint.
223  };
224 
225  } // end namespace da
226 } // end namespace te
227 
228 #endif // __TERRALIB_DATAACCESS_INTERNAL_FOREIGNKEY_H
229 
230 
te::da::ForeignKey::m_onUpdate
FKActionType m_onUpdate
The action to be performed when a referenced element value in the referenced DataSetType is being upd...
Definition: ForeignKey.h:219
te::da::ForeignKey::has
bool has(const std::string &propertyName)
It verifies if Property takes part of the foreign key.
te::da::ForeignKey::getType
ConstraintType getType() const
It returns the constraint type: FOREIGNKEY.
Definition: ForeignKey.h:205
te
TerraLib.
Definition: AddressGeocodingOp.h:52
te::da::ForeignKey::m_refDt
DataSetType * m_refDt
The referenced DataSetType of this foreign key constraint.
Definition: ForeignKey.h:220
te::da::FKActionType
FKActionType
Type of action performed on the foreign key data.
Definition: Enums.h:94
te::da::ForeignKey::~ForeignKey
~ForeignKey()
Destructor.
te::da::ForeignKey::add
void add(const te::dt::Property *p)
It adds a property to the foreign key constraint.
Definition: ForeignKey.h:110
te::da::ForeignKey::addRefProperty
void addRefProperty(const te::dt::Property *p)
It adds a reference property (on the referenced DataSetType) of this foreign key constraint.
Definition: ForeignKey.h:126
te::da::ForeignKey::getReferencedProperties
const std::vector< te::dt::Property * > & getReferencedProperties() const
It returns the referenced properties (on the referenced DataSetType) of this foreign key constraint.
Definition: ForeignKey.h:117
te::da::ForeignKey::setOnUpdateAction
void setOnUpdateAction(FKActionType a)
It sets the action to be performed when a referenced element value in the referenced DataSetType is b...
Definition: ForeignKey.h:168
Constraint.h
A class that describes a constraint.
te::da::ForeignKey::m_onDelete
FKActionType m_onDelete
The action to be performed when a referenced element value in the referenced DataSetType is being del...
Definition: ForeignKey.h:218
te::da::ForeignKey::operator=
ForeignKey & operator=(const ForeignKey &rhs)
Assignment operator.
te::da::ForeignKey::getOnUpdateAction
FKActionType getOnUpdateAction() const
It returns the action performed when a referenced element value in the referenced DataSetType is bein...
Definition: ForeignKey.h:161
te::da::ForeignKey::m_properties
std::vector< te::dt::Property * > m_properties
The properties that are part of the foreign key constraint.
Definition: ForeignKey.h:221
TEDATAACCESSEXPORT
#define TEDATAACCESSEXPORT
You can use this macro in order to export/import classes and functions from this module.
Definition: Config.h:97
te::da::ForeignKey::getProperties
const std::vector< te::dt::Property * > & getProperties() const
It returns the properties that take part of the foreign key constraint.
Definition: ForeignKey.h:101
te::da::ForeignKey::getReferencedDataSetType
DataSetType * getReferencedDataSetType() const
It returns the referenced DataSetType of this foreign key constraint.
Definition: ForeignKey.h:133
te::da::ForeignKey::m_refProperties
std::vector< te::dt::Property * > m_refProperties
The referenced properties (on the referenced DataSetType) of this foreign key constraint.
Definition: ForeignKey.h:222
te::da::FOREIGN_KEY
@ FOREIGN_KEY
Definition: Enums.h:69
te::da::ForeignKey::clone
Constraint * clone()
It returns a clone of the object.
te::da::ForeignKey
It models a foreign key constraint for a DataSetType.
Definition: ForeignKey.h:49
te::da::ForeignKey::ForeignKey
ForeignKey(const std::string &name, unsigned int id=0)
Constructor.
te::da::ForeignKey::ForeignKey
ForeignKey(const ForeignKey &rhs)
Copy constructor not allowed.
te::da::ForeignKey::getOnDeleteAction
FKActionType getOnDeleteAction() const
It returns the action performed when a referenced element value in the referenced DataSetType is bein...
Definition: ForeignKey.h:147
te::da::ForeignKey::setOnDeleteAction
void setOnDeleteAction(FKActionType a)
It sets the action to be performed when a referenced element value in the referenced DataSetType is b...
Definition: ForeignKey.h:154
te::da::ForeignKey::setReferencedDataSetType
void setReferencedDataSetType(DataSetType *refDt)
It sets the referenced DataSetType of this foreign key constraint.
Definition: ForeignKey.h:140
te::dt::Property
It models a property definition.
Definition: Property.h:60
te::da::ConstraintType
ConstraintType
A ConstraintType can have one of the following types:
Definition: Enums.h:66
te::da::DataSetType
A class that models the description of a dataset.
Definition: DataSetType.h:73
te::da::Constraint
Definition: Constraint.h:51
te::dt::Property::clone
virtual Property * clone() const =0
It returns a clone of the object.
te::da::ForeignKey::isReferenced
bool isReferenced(const std::string &propertyName)
It verifies if Property is referenced by the foreign key.
te::da::ForeignKey::ForeignKey
ForeignKey(unsigned int id=0)
Constructor.
te::da::ForeignKey::replace
void replace(const std::string &propName, const te::dt::Property *pp)
It changes a reference to property p to pp.