File: ddDBReverseEngineering.h

package info (click to toggle)
pgadmin3 1.20.0~beta2-1
  • links: PTS, VCS
  • area: main
  • in suites: jessie, jessie-kfreebsd
  • size: 73,704 kB
  • ctags: 18,591
  • sloc: cpp: 193,786; ansic: 18,736; sh: 5,154; pascal: 1,120; yacc: 927; makefile: 516; lex: 421; xml: 126; perl: 40
file content (249 lines) | stat: -rw-r--r-- 6,424 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
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
//////////////////////////////////////////////////////////////////////////
//
// pgAdmin III - PostgreSQL Tools
//
// Copyright (C) 2002 - 2014, The pgAdmin Development Team
// This software is released under the PostgreSQL Licence
//
// ddDBReverseEngineering.h - Reverse engineering database functions for database designer.
//
//////////////////////////////////////////////////////////////////////////

#ifndef DDDBREVERSEENGINEERING_H
#define DDDBREVERSEENGINEERING_H
#include "wx/wizard.h"
#include "hotdraw/main/hdObject.h"
#include "dd/dditems/utilities/ddDataType.h"
#include "schema/pgDatatype.h"
#include "dd/dditems/figures/ddTableFigure.h"
#include "dd/ddmodel/ddDatabaseDesign.h"

class SelSchemaPage;
class SelTablesPage;
class ReportPage;
class ddStubTable;

enum
{
    DDALLSCHEMAS = 7001,
    DDALLTABS,
    DDSELTABS,
    DDADD,
    DDADDALL,
    DDREMOVE,
    DDREMOVEALL
};

WX_DECLARE_STRING_HASH_MAP( ddStubTable *, stubTablesHashMap);
WX_DEFINE_SORTED_ARRAY_INT(int, wxSortedArrayInt);

// Stub tables related classes
class ddImportDBUtils : public hdObject
{
public:
	// Implement and replace at this and other dd related classes as Generation Wizard static wxArrayString getSchemasNames(...);
	static wxArrayString getTablesNames(pgConn *connection, wxString schemaName);
	static ddStubTable *getTable(pgConn *connection, wxString tableName, OID tableOid);
	static ddTableFigure *getTableFigure(ddStubTable *table);
	static void getAllRelationships(pgConn *connection, stubTablesHashMap &tables, ddDatabaseDesign *design);
	static int getPgColumnNum(pgConn *connection, wxString schemaName, wxString tableName, wxString columnName);
	static OID getTableOID(pgConn *connection, wxString schemaName, wxString tableName);
	static OID getSchemaOID(pgConn *connection, wxString schemaName);
	static bool existsFk(pgConn *connection, OID destTableOid, wxString schemaName, wxString fkName, wxString sourceTableName);
	static wxArrayString getFkAtDbNotInModel(pgConn *connection, OID destTableOid, wxString schemaName, wxArrayString existingFkList, ddDatabaseDesign *design);
	static bool isModelSameDbFk(pgConn *connection, OID destTableOid, wxString schemaName, wxString fkName, wxString sourceTableName, wxString destTableName, ddStubTable *destStubTable, ddRelationshipFigure *relation);

private:
	static bool setUniqueConstraints(pgConn *connection, ddStubTable *table);
	static bool setPkName(pgConn *connection, ddStubTable *table);
	static int sortFunc(int n1, int n2)
	{
		return n1 - n2;
	}
};

class ddStubColumn : public hdObject
{
public:
	ddStubColumn();
	ddStubColumn(const ddStubColumn &copy);
	ddStubColumn(wxString name, OID oidSource, bool notNull, bool pk, pgDatatype *type, int ukIndex = -1);
	ddStubColumn(wxString name, OID oidSource);
	~ddStubColumn();
	wxString columnName;
	bool isNotNull;
	bool isPrimaryKey;
	bool isUniqueKey();
	int uniqueKeyIndex;
	OID OIDTable;
	pgDatatype *typeColumn;
	int pgColNumber;
};

WX_DECLARE_STRING_HASH_MAP( ddStubColumn *, stubColsHashMap);

class ddStubTable : public hdObject
{
public:
	ddStubTable();
	ddStubTable(wxString name, OID tableOID);
	ddStubColumn *getColumnByNumber(int pgColNumber);
	~ddStubTable();
	wxString tableName;
	OID OIDTable;
	stubColsHashMap cols;
	wxString PrimaryKeyName;
	wxArrayString UniqueKeysNames;
};

//
//
// Wizard related classes
//
//
//

WX_DECLARE_STRING_HASH_MAP( OID, oidsHashMap);

class ddDBReverseEngineering : public wxWizard
{
public:
	ddDBReverseEngineering(wxFrame *frame, ddDatabaseDesign *design, pgConn *connection, bool useSizer = true);
	~ddDBReverseEngineering();

	//Wizard related functions
	wxWizardPage *GetFirstPage() const
	{
		return initialPage;
	}

	// Reverse Enginnering related functions
	wxArrayString getTables();
	pgConn *getConnection()
	{
		return conn;
	};

	//transfer data between pages
	OID OIDSelectedSchema;
	wxString schemaName;
	oidsHashMap tablesOIDHM;
	stubTablesHashMap stubsHM;
	SelSchemaPage *page2;
	SelTablesPage *page3;
	ReportPage *page4;
	ddDatabaseDesign *getDesign()
	{
		return figuresDesign;
	};

private:
	void OnFinishPressed(wxWizardEvent &event);
	pgConn *conn;
	wxWizardPageSimple *initialPage;
	wxStaticText *frontText;
	ddDatabaseDesign *figuresDesign;
	DECLARE_EVENT_TABLE()
};

class SelSchemaPage : public wxWizardPage
{
public:
	SelSchemaPage(wxWizard *parent, wxWizardPage *prev);
	~SelSchemaPage();
	virtual wxWizardPage *GetPrev() const
	{
		return m_prev;
	};
	virtual wxWizardPage *GetNext() const
	{
		return m_next;
	};
	void SetPrev(wxWizardPage *prev)
	{
		m_prev = prev;
	}
	void SetNext(wxWizardPage *next)
	{
		m_next = next;
	}
private:
	void OnWizardPageChanging(wxWizardEvent &event);
	void refreshSchemas(pgConn *connection);
	wxStaticText *message;
	wxWizardPage *m_prev, *m_next;
	wxListBox *m_allSchemas;
	wxArrayString schemasNames;
	oidsHashMap schemasHM;
	ddDBReverseEngineering *wparent;
	DECLARE_EVENT_TABLE()
};


class SelTablesPage : public wxWizardPage
{
public:
	SelTablesPage(wxWizard *parent, wxWizardPage *prev);
	~SelTablesPage();
	virtual wxWizardPage *GetPrev() const
	{
		return m_prev;
	};
	virtual wxWizardPage *GetNext() const
	{
		return m_next;
	};
	void SetPrev(wxWizardPage *prev)
	{
		m_prev = prev;
	}
	void SetNext(wxWizardPage *next)
	{
		m_next = next;
	}
	void RefreshTablesList();
	void OnButtonAdd(wxCommandEvent &);
	void OnButtonAddAll(wxCommandEvent &);
	void OnButtonRemove(wxCommandEvent &);
	void OnButtonRemoveAll(wxCommandEvent &);
private:
	void OnWizardPageChanging(wxWizardEvent &event);
	wxStaticText *leftText, *rightText, *centerText;
	wxWizardPage *m_prev, *m_next;
	wxListBox *m_allTables, *m_selTables;
	ddDBReverseEngineering *wparent;
	wxArrayString tablesNames;
	wxBitmapButton *buttonAdd, *buttonAddAll, *buttonRemove, *buttonRemoveAll;
	wxBitmap addBitmap, addAllBitmap, removeBitmap, removeAllBitmap;
	DECLARE_EVENT_TABLE()
};

class ReportPage : public wxWizardPage
{
public:
	ReportPage(wxWizard *parent, wxWizardPage *prev);
	~ReportPage();
	virtual wxWizardPage *GetPrev() const
	{
		return m_prev;
	};
	virtual wxWizardPage *GetNext() const
	{
		return m_next;
	};
	void SetPrev(wxWizardPage *prev)
	{
		m_prev = prev;
	}
	void SetNext(wxWizardPage *next)
	{
		m_next = next;
	}
	wxTextCtrl *results;
private:
	void OnWizardPageChanging(wxWizardEvent &event);
	wxWizardPage *m_prev, *m_next;
	ddDBReverseEngineering *wparent;
	DECLARE_EVENT_TABLE()
};
#endif