forked from levinsv/pgadmin3
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathslSubscription.cpp
294 lines (243 loc) · 8.63 KB
/
slSubscription.cpp
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
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
//////////////////////////////////////////////////////////////////////////
//
// pgAdmin III - PostgreSQL Tools
//
// Copyright (C) 2002 - 2016, The pgAdmin Development Team
// This software is released under the PostgreSQL Licence
//
// slSubscription.cpp PostgreSQL Slony-I subscription
//
//////////////////////////////////////////////////////////////////////////
// wxWindows headers
#include <wx/wx.h>
// App headers
#include "pgAdmin3.h"
#include "utils/misc.h"
#include "slony/slSubscription.h"
#include "slony/slTable.h"
#include "slony/slSequence.h"
#include "frm/frmMain.h"
slSubscription::slSubscription(slSet *s, const wxString &newName)
: slSetObject(s, slsubscriptionFactory, newName)
{
}
int slSubscription::GetIconId()
{
if (GetReceiverId() == GetCluster()->GetLocalNodeID())
return slsubscriptionFactory.GetIconId();
else
return slsubscriptionFactory.GetExportedIconId();
}
bool slSubscription::DropObject(wxFrame *frame, ctlTree *browser, bool cascaded)
{
return GetDatabase()->ExecuteVoid(
wxT("SELECT ") + GetCluster()->GetSchemaPrefix()
+ wxT("unsubscribeset(") + NumToStr(GetSet()->GetSlId())
+ wxT(", ") + NumToStr(GetReceiverId())
+ wxT(");"));
}
wxString slSubscription::GetTranslatedMessage(int kindOfMessage) const
{
wxString message = wxEmptyString;
switch (kindOfMessage)
{
case RETRIEVINGDETAILS:
message = _("Retrieving details on Slony subscription");
message += wxT(" ") + GetName();
break;
case REFRESHINGDETAILS:
message = _("Refreshing Slony subscription");
message += wxT(" ") + GetName();
break;
case DROPINCLUDINGDEPS:
message = wxString::Format(_("Are you sure you wish to drop Slony subscription \"%s\" including all objects that depend on it?"),
GetFullIdentifier().c_str());
break;
case DROPEXCLUDINGDEPS:
message = wxString::Format(_("Are you sure you wish to drop Slony subscription \"%s\"?"),
GetFullIdentifier().c_str());
break;
case DROPCASCADETITLE:
message = _("Drop Slony subscription cascaded?");
break;
case DROPTITLE:
message = _("Drop Slony subscription?");
break;
case PROPERTIESREPORT:
message = _("Slony subscription properties report");
message += wxT(" - ") + GetName();
break;
case PROPERTIES:
message = _("Slony subscription properties");
break;
case DDLREPORT:
message = _("Slony subscription DDL report");
message += wxT(" - ") + GetName();
break;
case DDL:
message = _("Slony subscription DDL");
break;
case DEPENDENCIESREPORT:
message = _("Slony subscription dependencies report");
message += wxT(" - ") + GetName();
break;
case DEPENDENCIES:
message = _("Slony subscription dependencies");
break;
case DEPENDENTSREPORT:
message = _("Slony subscription dependents report");
message += wxT(" - ") + GetName();
break;
case DEPENDENTS:
message = _("Slony subscription dependents");
break;
}
return message;
}
bool slSubscription::CanCreate()
{
return GetSet()->GetOriginId() != GetReceiverId() && slSetObject::CanCreate();
}
bool slSubscription::CanDrop()
{
return GetReceiverId() == GetCluster()->GetLocalNodeID();
}
wxString slSubscription::GetSql(ctlTree *browser)
{
if (sql.IsNull())
{
if (GetReceiverId() != GetCluster()->GetLocalNodeID())
sql = wxT("-- Subscription must be maintained on receiver node.\n");
else
sql = wxT("-- subscribe replication set\n\n")
wxT(" SELECT ") + GetCluster()->GetSchemaPrefix() + wxT("subscribeset(")
+ NumToStr(GetSet()->GetSlId()) + wxT(", ")
+ NumToStr(GetProviderId()) + wxT(", ")
+ NumToStr(GetReceiverId()) + wxT(", ")
+ BoolToStr(GetForward()) + wxT(");");
}
return sql;
}
bool slSubscription::WantDummyChild()
{
return GetSet()->GetOriginId() != GetCluster()->GetLocalNodeID();
}
void slSubscription::ShowTreeDetail(ctlTree *browser, frmMain *form, ctlListView *properties, ctlSQLBox *sqlPane)
{
if (!expandedKids)
{
expandedKids = true;
browser->RemoveDummyChild(this);
// Log
if (WantDummyChild())
{
wxTreeItemId id = browser->GetItemParent(browser->GetItemParent(GetId()));
if (id)
{
slSet *set = (slSet *)browser->GetObject(id);
if (set && set->IsCreatedBy(setFactory))
{
wxLogInfo(wxT("Adding child object to subscription %s"), GetIdentifier().c_str());
browser->AppendCollection(this, slSequenceFactory);
browser->AppendCollection(this, slTableFactory);
}
}
}
}
if (properties)
{
CreateListColumns(properties);
properties->AppendItem(_("Provider ID"), GetProviderId());
properties->AppendItem(_("Provider Name"), GetProviderNode());
properties->AppendItem(_("Receiver ID"), GetReceiverId());
properties->AppendItem(_("Receiver Name"), GetReceiverNode());
properties->AppendYesNoItem(_("Active"), GetActive());
properties->AppendYesNoItem(_("May forward"), GetForward());
if (GetForward())
properties->AppendYesNoItem(_("Is forwarded"), GetIsSubscribed());
}
}
pgObject *slSubscription::Refresh(ctlTree *browser, const wxTreeItemId item)
{
pgObject *subscription = 0;
pgCollection *coll = browser->GetParentCollection(item);
if (coll)
subscription = slsubscriptionFactory.CreateObjects(coll, 0, wxT(" WHERE sub_set=") + NumToStr(GetSet()->GetSlId())
+ wxT(" AND sub_receiver = ") + NumToStr(GetReceiverId()) + wxT("\n"));
return subscription;
}
pgObject *slSubscriptionFactory::CreateObjects(pgCollection *coll, ctlTree *browser, const wxString &restr)
{
slSetObjCollection *collection = (slSetObjCollection *)coll;
slSubscription *subscription = 0;
wxString restriction;
if (restr.IsEmpty())
restriction = wxT(" WHERE sub_set = ") + NumToStr(collection->GetSlId());
else
restriction = restr;
wxString prefix = collection->GetCluster()->GetSchemaPrefix();
pgSet *subscriptions = collection->GetDatabase()->ExecuteSet(
wxT("SELECT sub_set, sub_provider, sub_receiver, sub_forward, sub_active,\n")
wxT(" re.no_comment as receiver_name, pr.no_comment as provider_name,\n")
wxT(" EXISTS (SELECT 1 FROM ") + prefix + wxT("sl_subscribe s2 WHERE s2.sub_provider = s1.sub_receiver AND s1.sub_set=s2.sub_set) AS is_subscribed\n")
wxT(" FROM ") + prefix + wxT("sl_subscribe s1\n")
wxT(" JOIN ") + prefix + wxT("sl_set ON set_id = sub_set\n")
wxT(" JOIN ") + prefix + wxT("sl_node pr ON pr.no_id = sub_provider\n")
wxT(" JOIN ") + prefix + wxT("sl_node re ON re.no_id = sub_receiver\n")
+ restriction +
wxT(" ORDER BY sub_provider, sub_receiver"));
if (subscriptions)
{
while (!subscriptions->Eof())
{
subscription = new slSubscription(collection->GetSet(), subscriptions->GetVal(wxT("receiver_name")));
subscription->iSetActive(subscriptions->GetBool(wxT("sub_active")));
subscription->iSetForward(subscriptions->GetBool(wxT("sub_forward")));
subscription->iSetReceiverId(subscriptions->GetLong(wxT("sub_receiver")));
subscription->iSetProviderId(subscriptions->GetLong(wxT("sub_provider")));
subscription->iSetReceiverNode(subscriptions->GetVal(wxT("receiver_name")));
subscription->iSetProviderNode(subscriptions->GetVal(wxT("provider_name")));
subscription->iSetIsSubscribed(subscriptions->GetBool(wxT("is_subscribed")));
if (browser)
{
browser->AppendObject(coll, subscription);
subscriptions->MoveNext();
}
else
break;
}
delete subscriptions;
}
return subscription;
}
wxString slSubscriptionCollection::GetTranslatedMessage(int kindOfMessage) const
{
wxString message = wxEmptyString;
switch (kindOfMessage)
{
case RETRIEVINGDETAILS:
message = _("Retrieving details on Slony subscriptions");
break;
case REFRESHINGDETAILS:
message = _("Refreshing Slony subscriptions");
break;
case OBJECTSLISTREPORT:
message = _("Slony subscriptions list report");
break;
}
return message;
}
///////////////////////////////////////////////////
#include "images/slsubscription.pngc"
#include "images/slsubscriptions.pngc"
slSubscriptionFactory::slSubscriptionFactory()
: slSetObjFactory(__("Subscription"), __("New Subscription"), __("Create a new Subscription."), slsubscription_png_img)
{
metaType = SLM_SUBSCRIPTION;
}
pgCollection *slSubscriptionFactory::CreateCollection(pgObject *obj)
{
return new slSubscriptionCollection(GetCollectionFactory(), (slSet *)obj);
}
slSubscriptionFactory slsubscriptionFactory;
static pgaCollectionFactory cf(&slsubscriptionFactory, __("Subscriptions"), slsubscriptions_png_img);