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