Join.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/query/Join.h
22 
23  \brief A Join clause combines two FromItems.
24 */
25 
26 #ifndef __TERRALIB_DATAACCESS_INTERNAL_JOIN_H
27 #define __TERRALIB_DATAACCESS_INTERNAL_JOIN_H
28 
29 // TerraLib
30 #include "../Enums.h"
31 #include "FromItem.h"
32 
33 // STL
34 #include <memory>
35 
36 namespace te
37 {
38  namespace da
39  {
40 // Forward declaration
41  class JoinCondition;
42 
43  /*!
44  \class Join
45 
46  \brief A Join clause combines two FromItems.
47 
48  \sa FromItem, DataSetName, FromFunctionCall, SubSelect
49  */
51  {
52  public:
53 
55 
56  /*!
57  \brief Constructor.
58 
59  \param first The first FromItem to be combined.
60  \param second The second FromItem to be combined.
61  \param t The join type.
62  \param c The join condition.
63 
64  \note The Join will take the ownership of the First, Second and JoinCondition.
65  */
66  Join(FromItem* first, FromItem* second, JoinType t, JoinCondition* c);
67 
68  /*!
69  \brief Constructor.
70 
71  \param first The first FromItem to be combined.
72  \param second The second FromItem to be combined.
73  \param t The join type.
74  \param c The join condition.
75  */
76  Join(const FromItem& first, const FromItem& second, JoinType t, const JoinCondition& c);
77 
78  /*! \brief Copy constructor. */
79  Join(const Join& rhs);
80 
81  /*! \brief Destructor. */
82  ~Join();
83 
84  /*! Assignment operator. */
85  Join& operator=(const Join& rhs);
86 
87  /*! \brief It creates a new copy of this FromItem. */
88  FromItem* clone() const;
89 
90  /*!
91  \brief It returns the first from item involved in the join.
92 
93  \return The first item involved in the join.
94  */
95  FromItem* getFirst() const;
96 
97  /*!
98  \brief It sets first item involved in the join.
99 
100  \param item The first item involved in the join.
101 
102  \note The Join will take the ownership of the given item.
103  */
104  void setFirst(FromItem* item);
105 
106  /*!
107  \brief It returns the second item involved in the join.
108 
109  \return The second item involved in the join.
110  */
111  FromItem* getSecond() const;
112 
113  /*!
114  \brief It sets second item involved in the join.
115 
116  \param item The second item involved in the join.
117 
118  \note The Join will take the ownership of the given item.
119  */
120  void setSecond(FromItem* item);
121 
122  /*!
123  \brief It returns the join type.
124 
125  \return The join type.
126  */
127  JoinType getType() const;
128 
129  /*!
130  \brief It sets join type.
131 
132  \param t The join type.
133  */
134  void setType(JoinType t);
135 
136  /*!
137  \brief It tells if the join is Natural.
138 
139  \return True if it is a Natural join, otherwise, false.
140  */
141  bool isNatural() const { return m_isNatural; }
142 
143  /*!
144  \brief It marks if the join is a natural join.
145 
146  \param n If true this will be a natural join.
147  */
148  void setNatural(bool n) { m_isNatural = n; }
149 
150  /*!
151  \brief It returns the join condition.
152 
153  \return The join condition.
154  */
155  JoinCondition* getCondition() const;
156 
157  /*!
158  \brief It sets the join condition.
159 
160  \param c The join condition.
161 
162  \note The Join will take the ownership of the given condition.
163  */
164  void setCondition(JoinCondition* c);
165 
166  private:
167 
168  std::auto_ptr<FromItem> m_first; //!< The first item involved in the join.
169  std::auto_ptr<FromItem> m_second; //!< The first item involved in the join.
170  std::auto_ptr<JoinCondition> m_condition; //!< The join condition.
171  JoinType m_type; //!< The join type.
172  bool m_isNatural; //!< Natural is a shorthand for a JoinConditionUsing list that mentions all columns in the two tables that have the same names.
173  };
174 
175  } // end namespace da
176 } // end namespace te
177 
178 #endif // __TERRALIB_DATAACCESS_INTERNAL_JOIN_H
179 
An abstract class that models a source of data in a query.
An abstract class that models a source of data in a query.
Definition: FromItem.h:50
std::auto_ptr< JoinCondition > m_condition
The join condition.
Definition: Join.h:170
JoinType m_type
The join type.
Definition: Join.h:171
void setNatural(bool n)
It marks if the join is a natural join.
Definition: Join.h:148
bool isNatural() const
It tells if the join is Natural.
Definition: Join.h:141
URI C++ Library.
A condition to be used in a Join clause.
Definition: JoinCondition.h:44
JoinType
The type of join in a query.
Definition: Enums.h:49
std::auto_ptr< FromItem > m_second
The first item involved in the join.
Definition: Join.h:169
A Join clause combines two FromItems.
Definition: Join.h:50
#define TE_DEFINE_VISITABLE
Definition: BaseVisitable.h:75
std::auto_ptr< FromItem > m_first
The first item involved in the join.
Definition: Join.h:168
bool m_isNatural
Natural is a shorthand for a JoinConditionUsing list that mentions all columns in the two tables that...
Definition: Join.h:172
#define TEDATAACCESSEXPORT
You can use this macro in order to export/import classes and functions from this module.
Definition: Config.h:97