UniqueKey.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/UniqueKey.h
22 
23  \brief It describes a unique key (uk) constraint.
24 */
25 
26 #ifndef __TERRALIB_DATAACCESS_INTERNAL_UNIQUEKEY_H
27 #define __TERRALIB_DATAACCESS_INTERNAL_UNIQUEKEY_H
28 
29 // TerraLib
30 #include "Constraint.h"
31 
32 // STL
33 #include <string>
34 #include <vector>
35 
36 namespace te
37 {
38 // Forward declarations
39  namespace dt { class Property; }
40 
41  namespace da
42  {
43 // Forward declarations
44  class Index;
45 
46  /*!
47  \class UniqueKey
48 
49  \brief It describes a unique key (uk) constraint.
50 
51  \sa DataSetType, Index, PrimaryKey, ForeignKey, DataSetTypeCheckRestriction
52  */
54  {
55  public:
56 
57  /*!
58  \brief Constructor.
59 
60  \param dt The DataSetType associated to this uk.
61  \param id The uk identifier.
62 
63  \post If dt is provided, the uk will belong to the given DataSetType.
64 
65  \warning The identifier value (id) may be used by data source implementations. So, don't rely on its value!
66  */
67  UniqueKey(DataSetType* dt = 0, unsigned int id = 0);
68 
69  /*!
70  \brief Constructor.
71 
72  \param name The unique key (uk) constraint name.
73  \param dt The DataSetType associated to this uk.
74  \param id The uk identifier.
75 
76  \post If dt is provided, the uk will belong to the given DataSetType.
77 
78  \warning The identifier value (id) may be used by data source implementations. So, don't rely on its value!
79  */
80  UniqueKey(const std::string& name, DataSetType* dt = 0, unsigned int id = 0);
81 
82  /*!
83  \brief Copy constructor.
84 
85  The new object will not have an associated DataSetType.
86 
87  \param rhs Right-hand-side instance.
88  */
89  UniqueKey(const UniqueKey& rhs);
90 
91  /*! \brief Destructor. */
93 
94  /*!
95  \brief Assignment operator.
96 
97  The new object will not have an assigned DataSetType.
98 
99  \param rhs Right-hand-side instance.
100 
101  \return A reference to this.
102  */
103  UniqueKey& operator=(const UniqueKey& rhs);
104 
105  /*!
106  \brief It returns the properties that form the unique key.
107 
108  \return The properties that form the unique key.
109  */
110  const std::vector<te::dt::Property*>& getProperties() const { return m_properties; }
111 
112  /*!
113  \brief It sets the properties that form the unique key.
114 
115  \param properties The properties that form the unique key.
116  */
117  void setProperties(const std::vector<te::dt::Property*>& properties) { m_properties = properties; }
118 
119  /*!
120  \brief It adds the property to the list of properties that participates in the unique key.
121 
122  \param p The Property that will take part of the unique key.
123  */
124  void add(te::dt::Property* p) { m_properties.push_back(p); }
125 
126  /*!
127  \brief It returns the associated index if one exists.
128 
129  \return An associated index if one exists.
130  */
131  Index* getAssociatedIndex() const { return m_index; }
132 
133  /*!
134  \brief It sets the associated index.
135 
136  \param idx A index associated to the unique key.
137  */
138  void setAssociatedIndex(Index* idx) { m_index = idx; }
139 
140  /*!
141  \brief It verifies if Property is associated to the unique key.
142 
143  \param p The Property to be verified.
144 
145  \return True if Property is associated to the unique key, false otherwise.
146  */
147  bool has(const te::dt::Property* p) const;
148 
149  /*
150  \brief It changes a reference to property p to pp.
151 
152  \param p A property that takes part of the unique key.
153  \param pp The property that will take p place.
154 
155  \note If the property p is not in the uk attribute list this method does nothing.
156  */
157  void replace(te::dt::Property* p, te::dt::Property* pp);
158 
159  /*!
160  \brief It returns the constraint type: UNIQUEKEY.
161 
162  \return The constraint type UNIQUEKEY.
163  */
164  ConstraintType getType() const { return UNIQUE_KEY; }
165 
166  /*!
167  \brief It returns a clone of the object.
168 
169  The new object will not have an associated DataSetType.
170 
171  \return A clone of the object.
172  */
173  Constraint* clone();
174 
175  private:
176 
177  Index* m_index; //!< A pointer to an associated index.
178  std::vector<te::dt::Property*> m_properties; //!< The properties that are part of the unique key constraint.
179  };
180 
181  } // end namespace da
182 } // end namespace terralib
183 
184 #endif // __TERRALIB_DATAACCESS_INTERNAL_UNIQUEKEY_H
185 
186 
187 
void add(te::dt::Property *p)
It adds the property to the list of properties that participates in the unique key.
Definition: UniqueKey.h:124
Index * getAssociatedIndex() const
It returns the associated index if one exists.
Definition: UniqueKey.h:131
void setProperties(const std::vector< te::dt::Property * > &properties)
It sets the properties that form the unique key.
Definition: UniqueKey.h:117
A class that models the description of a dataset.
Definition: DataSetType.h:72
ConstraintType getType() const
It returns the constraint type: UNIQUEKEY.
Definition: UniqueKey.h:164
It models a property definition.
Definition: Property.h:59
ConstraintType
A ConstraintType can have one of the following types:
Definition: Enums.h:65
URI C++ Library.
~UniqueKey()
Destructor.
Definition: UniqueKey.h:92
It describes a unique key (uk) constraint.
Definition: UniqueKey.h:53
void setAssociatedIndex(Index *idx)
It sets the associated index.
Definition: UniqueKey.h:138
A class that describes a constraint.
const std::vector< te::dt::Property * > & getProperties() const
It returns the properties that form the unique key.
Definition: UniqueKey.h:110
Index * m_index
A pointer to an associated index.
Definition: UniqueKey.h:177
std::vector< te::dt::Property * > m_properties
The properties that are part of the unique key constraint.
Definition: UniqueKey.h:178
#define TEDATAACCESSEXPORT
You can use this macro in order to export/import classes and functions from this module.
Definition: Config.h:97
It describes an index associated to a DataSetType.
Definition: Index.h:54