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