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