~smartboyhw/ubuntu/raring/calligra/2.6.0-0ubuntu1

« back to all changes in this revision

Viewing changes to libs/db/relationship.h

  • Committer: Package Import Robot
  • Author(s): Philip Muškovac
  • Date: 2012-10-23 21:09:16 UTC
  • mfrom: (1.1.13)
  • Revision ID: package-import@ubuntu.com-20121023210916-m82w6zxnxhaxz7va
Tags: 1:2.5.90-0ubuntu1
* New upstream alpha release (LP: #1070436)
  - Add libkactivities-dev and libopenimageio-dev to build-depends
  - Add kubuntu_build_calligraactive.diff to build calligraactive by default
  - Add package for calligraauthor and move files that are shared between
    calligrawords and calligraauthor to calligrawords-common
* Document the patches
* Remove numbers from patches so they follow the same naming scheme as
  the rest of our patches.
* calligra-data breaks replaces krita-data (<< 1:2.5.3) (LP: #1071686)

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/* This file is part of the KDE project
 
2
   Copyright (C) 2003-2004 Jarosław Staniek <staniek@kde.org>
 
3
 
 
4
   This library is free software; you can redistribute it and/or
 
5
   modify it under the terms of the GNU Library General Public
 
6
   License as published by the Free Software Foundation; either
 
7
   version 2 of the License, or (at your option) any later version.
 
8
 
 
9
   This library is distributed in the hope that it will be useful,
 
10
   but WITHOUT ANY WARRANTY; without even the implied warranty of
 
11
   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 
12
   Library General Public License for more details.
 
13
 
 
14
   You should have received a copy of the GNU Library General Public License
 
15
   along with this library; see the file COPYING.LIB.  If not, write to
 
16
   the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
 
17
 * Boston, MA 02110-1301, USA.
 
18
 */
 
19
 
 
20
#ifndef KEXIDB_RELATIONSHIP_H
 
21
#define KEXIDB_RELATIONSHIP_H
 
22
 
 
23
#include "field.h"
 
24
 
 
25
namespace KexiDB
 
26
{
 
27
 
 
28
/*! KexiDB::Relationship provides information about one-to-many relationship between two tables.
 
29
 Relationship is defined by a pair of (potentially multi-field) indices:
 
30
 - "one" or "master" side: unique key
 
31
 - "many" or "details" side: referenced foreign key
 
32
 <pre>
 
33
 [unique key, master] ----< [foreign key, details]
 
34
 </pre>
 
35
 
 
36
 In this documentation, we will call table that owns fields of "one" side as
 
37
 "master side of the relationship", and the table that owns foreign key fields of
 
38
 as "details side of the relationship".
 
39
 Use masterTable(), and detailsTable() to get one-side table and many-side table, respectively.
 
40
 
 
41
 Note: some engines (e.g. MySQL with InnoDB) requires that indices at both sides
 
42
 have to be explicitly created.
 
43
 
 
44
 \todo (js) It is planned that this will be handled by KexiDB internally and transparently.
 
45
 
 
46
 Each (of the two) key can be defined (just like index) as list of fields owned by one table.
 
47
 Indeed, relationship info can retrieved from Relationship object in two ways:
 
48
 -# pair of indices; use masterIndex(), detailsIndex() for that
 
49
 -# ordered list of field pairs (<master-side-field, details-side-field>); use fieldPairs() for that
 
50
 
 
51
 No assigned objects (like fields, indices) are owned by Relationship object. The exception is that
 
52
 list of field-pairs is internally created (on demand) and owned.
 
53
 
 
54
 Relationship object is owned by IndexSchema object (the one that is defined at master-side of the
 
55
 relationship).
 
56
 Note also that IndexSchema objects are owned by appropriate tables, so thus
 
57
 there is implicit ownership between TableSchema and Relationship.
 
58
 
 
59
 If Relationship object is not attached to IndexSchema object,
 
60
 you should care about destroying it by hand.
 
61
 
 
62
  Example:
 
63
  <pre>
 
64
            ----------
 
65
   ---r1--<|          |
 
66
           | Table A [uk]----r3---<
 
67
   ---r2--<|          |
 
68
            ----------
 
69
  </pre>
 
70
  Table A has two relationships (r1, r2) at details side and one (r3) at master side.
 
71
  [uk] stands for unique key.
 
72
*/
 
73
 
 
74
class IndexSchema;
 
75
class TableSchema;
 
76
class QuerySchema;
 
77
 
 
78
class CALLIGRADB_EXPORT Relationship
 
79
{
 
80
public:
 
81
    typedef QList<Relationship*> List;
 
82
    typedef QList<Relationship*>::ConstIterator ListIterator;
 
83
 
 
84
    /*! Creates uninitialized Relationship object.
 
85
      setIndices() will be required to call.
 
86
    */
 
87
    Relationship();
 
88
 
 
89
    /*! Creates Relationship object and initialises it just by
 
90
     calling setIndices(). If setIndices() failed, object is still uninitialised.
 
91
    */
 
92
    Relationship(IndexSchema* masterIndex, IndexSchema* detailsIndex);
 
93
 
 
94
    virtual ~Relationship();
 
95
 
 
96
    /*! \return index defining master side of this relationship
 
97
     or null if there is no information defined. */
 
98
    IndexSchema* masterIndex() const {
 
99
        return m_masterIndex;
 
100
    }
 
101
 
 
102
    /*! \return index defining referenced side of this relationship.
 
103
     or null if there is no information defined. */
 
104
    IndexSchema* detailsIndex() const {
 
105
        return m_detailsIndex;
 
106
    }
 
107
 
 
108
    /*! \return ordered list of field pairs -- alternative form
 
109
     for representation of relationship or null if there is no information defined.
 
110
     Each pair has a form of <master-side-field, details-side-field>. */
 
111
    Field::PairList* fieldPairs() {
 
112
        return &m_pairs;
 
113
    }
 
114
 
 
115
    bool isEmpty() const {
 
116
        return m_pairs.isEmpty();
 
117
    }
 
118
 
 
119
    /*! \return table assigned at "master / one" side of this relationship.
 
120
     or null if there is no information defined. */
 
121
    TableSchema* masterTable() const;
 
122
 
 
123
    /*! \return table assigned at "details / many / foreign" side of this relationship.
 
124
     or null if there is no information defined. */
 
125
    TableSchema* detailsTable() const;
 
126
 
 
127
    /*! Sets \a masterIndex and \a detailsIndex indices for this relationship.
 
128
     This also sets information about tables for master- and details- sides.
 
129
     Notes:
 
130
     - both indices must contain the same number of fields
 
131
     - both indices must not be owned by the same table, and table (owner) must be not null.
 
132
     - corresponding field types must be the same
 
133
     - corresponding field types' signedness must be the same
 
134
     If above rules are not fulfilled, information about this relationship is cleared.
 
135
     On success, this Relationship object is detached from previous IndexSchema objects that were
 
136
     assigned before, and new are attached.
 
137
     */
 
138
    void setIndices(IndexSchema* masterIndex, IndexSchema* detailsIndex);
 
139
 
 
140
protected:
 
141
    Relationship(QuerySchema *query, Field *field1, Field *field2);
 
142
 
 
143
    void createIndices(QuerySchema *query, Field *field1, Field *field2);
 
144
 
 
145
    /*! Internal version of setIndices(). \a ownedByMaster parameter is passed
 
146
     to IndexSchema::attachRelationship() */
 
147
    void setIndices(IndexSchema* masterIndex, IndexSchema* detailsIndex, bool ownedByMaster);
 
148
 
 
149
    IndexSchema *m_masterIndex;
 
150
    IndexSchema *m_detailsIndex;
 
151
 
 
152
    Field::PairList m_pairs;
 
153
 
 
154
    bool m_masterIndexOwned : 1;
 
155
    bool m_detailsIndexOwned : 1;
 
156
 
 
157
    friend class Connection;
 
158
    friend class TableSchema;
 
159
    friend class QuerySchema;
 
160
    friend class IndexSchema;
 
161
};
 
162
 
 
163
} //namespace KexiDB
 
164
 
 
165
#endif