File: table.h

package info (click to toggle)
pgmodeler 1.2.3-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 14,276 kB
  • sloc: cpp: 99,283; xml: 27; sh: 15; makefile: 6
file content (189 lines) | stat: -rw-r--r-- 6,480 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
/*
# PostgreSQL Database Modeler (pgModeler)
#
# (c) Copyright 2006-2026 - Raphael Araújo e Silva <raphael@pgmodeler.io>
#
# DEVELOPMENT, MAINTENANCE AND COMMERCIAL DISTRIBUTION BY:
# Nullptr Labs Software e Tecnologia LTDA <contact@nullptrlabs.io>
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation version 3.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
#
# The complete text of GPLv3 is at LICENSE file on source code root directory.
# Also, you can get the complete GNU General Public License at <http://www.gnu.org/licenses/>
*/

/**
\ingroup libcore
\brief Implements the operations to manipulate tables on the database.
\note <strong>Creation date:</strong> 17/09/2006
*/

#ifndef TABLE_H
#define TABLE_H

#include "index.h"
#include "rule.h"
#include "policy.h"
#include "physicaltable.h"
#include <QStringList>

class __libcore Table: public PhysicalTable {
	private:
		//! \brief Stores the indexes
		std::vector<TableObject *> indexes;

		//! \brief Stores the rules
		std::vector<TableObject *> rules;

		//! \brief Stores the policies
		std::vector<TableObject *> policies;

		//! \brief Indicates if the table is unlogged, which means, is not controled by the WAL (write ahead logs)
		bool unlogged,

		//! \brief Indicates if the row level security is enabled
		rls_enabled,

		//! \brief Indicates if the row level security is enforced
		rls_forced,

		//! \brief Indicates if the table accepts OIDs
		with_oid;

	public:
		Table();

		virtual ~Table();

		//! \brief Defines if the table is unlogged
		void setUnlogged(bool value);

		//! \brief Defines if the row level security on table is enabled
		void setRLSEnabled(bool value);

		//! \brief Defines if the row level security on table is forced for the table owner
		void setRLSForced(bool value);

		//! \brief Defines if the table accepts OIDs
		void setWithOIDs(bool value);

		//! \brief Returns if the table is configured with oids
		bool isWithOIDs();

		virtual void addObject(BaseObject *object, int obj_idx = -1) override;

		virtual void removeObject(unsigned obj_idx, ObjectType obj_type) override;

		virtual void removeObject(const QString &name, ObjectType obj_type) override;

		virtual void removeObject(BaseObject *obj) override;

		//! \brief Adds a index to table (optionally the user can add the object at the specified index 'idx')
		void addIndex(Index *ind, int idx=-1);

		//! \brief Adds a rule to table (optionally the user can add the object at the specified index 'idx')
		void addRule(Rule *reg, int idx_reg=-1);

		//! \brief Adds a policy to table (optionally the user can add the object at the specified index 'idx')
		void addPolicy(Policy *pol, int idx_pol=-1);

		//! \brief Gets a index object through its name
		Index *getIndex(const QString &name);

		//! \brief Gets a index object through its position
		Index *getIndex(unsigned idx);

		//! \brief Gets a rule through its name
		Rule *getRule(const QString &name);

		//! \brief Gets a rule through its index
		Rule *getRule(unsigned idx);

		//! \brief Gets a policy through its name
		Policy *getPolicy(const QString &name);

		//! \brief Gets a policy through its index
		Policy *getPolicy(unsigned idx);

		//! \brief Gets the index count
		unsigned getIndexCount();

		//! \brief Gets the rule count
		unsigned getRuleCount();

		//! \brief Gets the policy count
		unsigned getPolicyCount();

		//! \brief Removes a index through its name
		void removeIndex(const QString &name);

		//! \brief Removes a index through its position
		void removeIndex(unsigned idx);

		//! \brief Removes a rule through its name
		void removeRule(const QString &name);

		//! \brief Removes a rule through its index
		void removeRule(unsigned idx);

		//! \brief Removes a policy through its name
		void removePolicy(const QString &name);

		//! \brief Removes a policy through its index
		void removePolicy(unsigned idx);

		//! \brief Returns the SQL / XML definition for table
		virtual QString getSourceCode(SchemaParser::CodeType def_type) final;

		/*! \brief Stores on the specified vector 'fks' the foreign key present on table. The
		 boolean paramenter is used to include those foreign keys includes by relationship. The third parameter
		is used to filter the search, including only the foreign keys that references the specified table */
		void getForeignKeys(std::vector<Constraint *> &fks, bool inc_added_by_rel=false, Table *ref_table=nullptr);

		//! \brief Returns if the table is configured as unlogged
		bool isUnlogged();

		//! \brief Returns if RLS is enabled on the table
		bool isRLSEnabled();

		//! \brief Returns if RLS is forced on the table
		bool isRLSForced();

		//! \brief Copy the attributes between two tables
		void operator = (Table &tabela);

		//! \brief Returns the specified object type list
		virtual std::vector<TableObject *> *getObjectList(ObjectType obj_type) override;

		/*! \brief Returns if some of the foreign keys references the specified table. This method only considers the foreign keys
		 created by the user. Relationship created foreign keys are discarded from the search. */
		bool isReferTableOnForeignKey(Table *ref_tab);

		//! \brief Returns the alter definition comparing the this table against the one provided via parameter
		virtual QString getAlterCode(BaseObject *object) final;

		//! \brief Returns the truncate definition for this table
		QString getTruncateDefinition(bool cascade);

		/*! \brief Generates the table's SQL code considering adding the relationship added object or not.
		 * Note if the method is called with incl_rel_added_objs = true it can produce an SQL/XML code
		 * that does not reflect the real semantics of the table. So take care to use this method and always
		 * invalidate the tables code (see setCodeInvalidated()) after retrieving the resulting code */
		QString __getSourceCode(SchemaParser::CodeType def_type, bool incl_rel_added_objs, bool incl_constraints = true);

		virtual QString getDataDictionary(bool split, bool md_format, const attribs_map & extra_attribs = {}) override;

		virtual void updateDependencies() override;

		friend class Relationship;
		friend class OperationList;
};

#endif