1 //////////////////////////////////////////////////////////////////////////
2 //
3 // pgAdmin III - PostgreSQL Tools
4 //
5 // Copyright (C) 2002 - 2016, The pgAdmin Development Team
6 // This software is released under the PostgreSQL Licence
7 //
8 // pgIndex.h PostgreSQL Index
9 //
10 //////////////////////////////////////////////////////////////////////////
11 
12 #ifndef PGINDEX_H
13 #define PGINDEX_H
14 
15 #include "pgTable.h"
16 #include <wx/arrstr.h>
17 
18 
19 
20 
21 class pgIndexBase : public pgSchemaObject
22 {
23 protected:
24 	pgIndexBase(pgSchema *newSchema, pgaFactory &factory, const wxString &newName = wxT(""));
25 
26 public:
27 	wxString GetTranslatedMessage(int kindOfMessage) const;
28 	void ShowTreeDetail(ctlTree *browser, frmMain *form = 0, ctlListView *properties = 0, ctlSQLBox *sqlPane = 0);
29 	void ShowStatistics(frmMain *form, ctlListView *statistics);
CanDropCascaded()30 	bool CanDropCascaded()
31 	{
32 		return GetSchema()->GetMetaType() != PGM_CATALOG;
33 	}
34 
GetProcArgs()35 	wxString GetProcArgs() const
36 	{
37 		return procArgs;
38 	}
GetQuotedTypedColumns()39 	wxString GetQuotedTypedColumns() const
40 	{
41 		return quotedTypedColumns;
42 	}
GetTypedColumns()43 	wxString GetTypedColumns() const
44 	{
45 		return typedColumns;
46 	}
GetOperatorClasses()47 	wxString GetOperatorClasses() const
48 	{
49 		return operatorClasses;
50 	}
GetQuotedColumns()51 	wxString GetQuotedColumns() const
52 	{
53 		return quotedColumns;
54 	}
GetColumns()55 	wxString GetColumns() const
56 	{
57 		return columns;
58 	}
GetColumnList()59 	wxArrayString GetColumnList() const
60 	{
61 		return columnList;
62 	}
63 
GetColumnNumbers()64 	wxString GetColumnNumbers() const
65 	{
66 		return columnNumbers;
67 	}
iSetColumnNumbers(const wxString & s)68 	void iSetColumnNumbers(const wxString &s)
69 	{
70 		columnNumbers = s;
71 	}
GetConstraint()72 	wxString GetConstraint() const
73 	{
74 		return constraint;
75 	}
iSetConstraint(const wxString & s)76 	void iSetConstraint(const wxString &s)
77 	{
78 		constraint = s;
79 	}
GetIndexType()80 	wxString GetIndexType() const
81 	{
82 		return indexType;
83 	}
iSetIndexType(const wxString & s)84 	void iSetIndexType(const wxString &s)
85 	{
86 		indexType = s;
87 	}
GetColumnCount()88 	long GetColumnCount() const
89 	{
90 		return columnCount;
91 	}
iSetColumnCount(const long l)92 	void iSetColumnCount(const long l)
93 	{
94 		columnCount = l;
95 	}
GetIsUnique()96 	bool GetIsUnique() const
97 	{
98 		return isUnique;
99 	}
iSetIsUnique(const bool b)100 	void iSetIsUnique(const bool b)
101 	{
102 		isUnique = b;
103 	}
GetIsExclude()104 	bool GetIsExclude() const
105 	{
106 		return isExclude;
107 	}
iSetIsExclude(const bool b)108 	void iSetIsExclude(const bool b)
109 	{
110 		isExclude = b;
111 	}
GetIsPrimary()112 	bool GetIsPrimary() const
113 	{
114 		return isPrimary;
115 	}
iSetIsPrimary(const bool b)116 	void iSetIsPrimary(const bool b)
117 	{
118 		isPrimary = b;
119 	}
GetIsClustered()120 	bool GetIsClustered() const
121 	{
122 		return isClustered;
123 	}
iSetIsClustered(const bool b)124 	void iSetIsClustered(const bool b)
125 	{
126 		isClustered = b;
127 	}
GetIsValid()128 	bool GetIsValid() const
129 	{
130 		return isValid;
131 	}
iSetIsValid(const bool b)132 	void iSetIsValid(const bool b)
133 	{
134 		isValid = b;
135 	}
GetIdxTable()136 	wxString GetIdxTable() const
137 	{
138 		return idxTable;
139 	}
iSetIdxTable(const wxString & s)140 	void iSetIdxTable(const wxString &s)
141 	{
142 		idxTable = s;
143 	}
GetIdxSchema()144 	wxString GetIdxSchema() const
145 	{
146 		return idxSchema;
147 	}
iSetIdxSchema(const wxString & s)148 	void iSetIdxSchema(const wxString &s)
149 	{
150 		idxSchema = s;
151 	}
GetRelTableOid()152 	OID GetRelTableOid() const
153 	{
154 		return relTableOid;
155 	}
iSetRelTableOid(const OID d)156 	void iSetRelTableOid(const OID d)
157 	{
158 		relTableOid = d;
159 	}
GetTablespace()160 	wxString GetTablespace() const
161 	{
162 		return tablespace;
163 	};
iSetTablespace(const wxString & newVal)164 	void iSetTablespace(const wxString &newVal)
165 	{
166 		tablespace = newVal;
167 	}
GetTablespaceOid()168 	OID GetTablespaceOid() const
169 	{
170 		return tablespaceOid;
171 	};
iSetTablespaceOid(const OID newVal)172 	void iSetTablespaceOid(const OID newVal)
173 	{
174 		tablespaceOid = newVal;
175 	}
GetFillFactor()176 	wxString GetFillFactor()
177 	{
178 		return fillFactor;
179 	}
iSetFillFactor(const wxString & s)180 	void iSetFillFactor(const wxString &s)
181 	{
182 		fillFactor = s;
183 	}
184 
GetProcName()185 	wxString GetProcName() const
186 	{
187 		return procName;
188 	}
iSetProcName(const wxString & s)189 	void iSetProcName(const wxString &s)
190 	{
191 		procName = s;
192 	}
GetProcNamespace()193 	wxString GetProcNamespace() const
194 	{
195 		return procNamespace;
196 	}
iSetProcNamespace(const wxString & s)197 	void iSetProcNamespace(const wxString &s)
198 	{
199 		procNamespace = s;
200 	}
201 
GetDeferrable()202 	bool GetDeferrable() const
203 	{
204 		return deferrable;
205 	}
iSetDeferrable(const bool b)206 	void iSetDeferrable(const bool b)
207 	{
208 		deferrable = b;
209 	}
GetDeferred()210 	bool GetDeferred() const
211 	{
212 		return deferred;
213 	}
iSetDeferred(const bool b)214 	void iSetDeferred(const bool b)
215 	{
216 		deferred = b;
217 	}
218 
iSetOperatorClassList(const wxString & s)219 	void iSetOperatorClassList(const wxString &s)
220 	{
221 		operatorClassList = s;
222 	}
iSetProcArgTypeList(const wxString & s)223 	void iSetProcArgTypeList(const wxString &s)
224 	{
225 		procArgTypeList = s;
226 	}
227 
GetOrdersArray()228 	const wxArrayString &GetOrdersArray()
229 	{
230 		return ordersArray;
231 	}
232 
GetNullsArray()233 	const wxArrayString &GetNullsArray()
234 	{
235 		return nullsArray;
236 	}
237 
GetOpClassesArray()238 	const wxArrayString &GetOpClassesArray()
239 	{
240 		return opclassesArray;
241 	}
242 
GetCollationsArray()243 	const wxArrayString &GetCollationsArray()
244 	{
245 		return collationsArray;
246 	}
247 
248 	bool DropObject(wxFrame *frame, ctlTree *browser, bool cascaded);
249 	wxString GetCreate();
CanRestore()250 	bool CanRestore()
251 	{
252 		return true;
253 	}
254 	wxString GetSql(ctlTree *browser);
255 	pgObject *Refresh(ctlTree *browser, const wxTreeItemId item);
CanMaintenance()256 	bool CanMaintenance()
257 	{
258 		return true;
259 	}
GetShowExtendedStatistics()260 	bool GetShowExtendedStatistics()
261 	{
262 		return showExtendedStatistics;
263 	}
iSetShowExtendedStatistics(bool b)264 	void iSetShowExtendedStatistics(bool b)
265 	{
266 		showExtendedStatistics = b;
267 	}
268 
HasStats()269 	bool HasStats()
270 	{
271 		return true;
272 	}
HasDepends()273 	bool HasDepends()
274 	{
275 		return true;
276 	}
HasReferences()277 	bool HasReferences()
278 	{
279 		return true;
280 	}
281 	bool HasPgstatindex();
282 
283 protected:
284 	void ReadColumnDetails();
285 
286 private:
287 	wxString columnNumbers, columns, quotedColumns, indexType, idxTable, idxSchema, constraint, tablespace;
288 	wxString procName, procNamespace, procArgs, procArgTypeList, typedColumns, quotedTypedColumns, operatorClasses, operatorClassList;
289 	long columnCount;
290 	wxArrayString columnList, ordersArray, nullsArray, opclassesArray, collationsArray;
291 	bool isUnique, isPrimary, isExclude, isClustered, isValid;
292 	bool deferrable, deferred, showExtendedStatistics;
293 	OID relTableOid, tablespaceOid;
294 	wxString fillFactor;
295 };
296 
297 
298 class pgIndex : public pgIndexBase
299 {
300 public:
301 	pgIndex(pgSchema *newSchema, const wxString &newName = wxT(""));
302 };
303 
304 
305 class pgIndexBaseFactory : public pgSchemaObjFactory
306 {
307 public:
308 	virtual pgObject *CreateObjects(pgCollection *obj, ctlTree *browser, const wxString &restr = wxEmptyString);
309 	virtual pgCollection *CreateCollection(pgObject *obj);
310 protected:
pgSchemaObjFactory(tn,ns,nls,img)311 	pgIndexBaseFactory(const wxChar *tn, const wxChar *ns, const wxChar *nls, wxImage *img = 0) : pgSchemaObjFactory(tn, ns, nls, img) {}
312 };
313 
314 class pgIndexFactory : public pgIndexBaseFactory
315 {
316 public:
317 	pgIndexFactory();
318 	virtual dlgProperty *CreateDialog(frmMain *frame, pgObject *node, pgObject *parent);
319 	virtual pgObject *CreateObjects(pgCollection *obj, ctlTree *browser, const wxString &restr = wxEmptyString);
320 };
321 extern pgIndexFactory indexFactory;
322 
323 class pgIndexBaseCollection : public pgSchemaObjCollection
324 {
325 public:
326 	pgIndexBaseCollection(pgaFactory *factory, pgSchema *sch);
327 	wxString GetTranslatedMessage(int kindOfMessage) const;
328 	void ShowStatistics(frmMain *form, ctlListView *statistics);
329 };
330 
331 
332 class executePgstatindexFactory : public contextActionFactory
333 {
334 public:
335 	executePgstatindexFactory(menuFactoryList *list, wxMenu *mnu, ctlMenuToolbar *toolbar);
336 	wxWindow *StartDialog(frmMain *form, pgObject *obj);
337 	bool CheckEnable(pgObject *obj);
338 	bool CheckChecked(pgObject *obj);
339 };
340 
341 
342 #endif
343