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