forked from levinsv/pgadmin3
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdlgRepSubscription.cpp
182 lines (147 loc) · 4.96 KB
/
dlgRepSubscription.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
//////////////////////////////////////////////////////////////////////////
//
// pgAdmin III - PostgreSQL Tools
//
// Copyright (C) 2002 - 2016, The pgAdmin Development Team
// This software is released under the PostgreSQL Licence
//
// dlgRepSubscription.cpp - PostgreSQL Slony-I Subscription Property
//
//////////////////////////////////////////////////////////////////////////
// wxWindows headers
#include <wx/wx.h>
// App headers
#include "pgAdmin3.h"
#include "slony/dlgRepSubscription.h"
#include "slony/slCluster.h"
#include "slony/slSubscription.h"
#include "slony/slSet.h"
// pointer to controls
#define txtOrigin CTRL_TEXT("txtOrigin")
#define stReceiver CTRL_STATIC("stReceiver")
#define txtReceiver CTRL_TEXT("txtReceiver")
#define cbProvider CTRL_COMBOBOX("cbProvider")
#define stProvider CTRL_TEXT("stProvider")
#define chkForward CTRL_CHECKBOX("chkForward")
BEGIN_EVENT_TABLE(dlgRepSubscription, dlgProperty)
EVT_COMBOBOX(XRCID("cbProvider"), dlgRepSubscription::OnChange)
EVT_CHECKBOX(XRCID("chkForward"), dlgRepSubscription::OnChange)
END_EVENT_TABLE();
dlgProperty *slSubscriptionFactory::CreateDialog(frmMain *frame, pgObject *node, pgObject *parent)
{
return new dlgRepSubscription(this, frame, (slSubscription *)node, (slSet *)parent);
}
dlgRepSubscription::dlgRepSubscription(pgaFactory *f, frmMain *frame, slSubscription *sub, slSet *s)
: dlgRepProperty(f, frame, s->GetCluster(), wxT("dlgRepSubscription"))
{
subscription = sub;
set = s;
}
pgObject *dlgRepSubscription::GetObject()
{
return subscription;
}
int dlgRepSubscription::Go(bool modal)
{
txtOrigin->SetValue(NumToStr(set->GetOriginId()));
if (subscription)
{
// edit mode
chkForward->SetValue(subscription->GetForward());
txtReceiver->SetValue(IdAndName(subscription->GetReceiverId(), subscription->GetReceiverNode()));
}
else
{
// create mode
txtReceiver->SetValue(IdAndName(cluster->GetLocalNodeID(), cluster->GetLocalNodeName()));
if (cluster->ClusterMinimumVersion(1, 1))
{
// This is very ugly: starting with Slony-I 1.1, this must be called on the provider,
// not on the receiver.
stProvider->SetLabel(_("Receiver"));
stReceiver->SetLabel(_("Provider"));
}
}
if (set->GetOriginId() == cluster->GetLocalNodeID() && subscription)
{
chkForward->SetValue(subscription->GetForward());
cbProvider->Append(IdAndName(subscription->GetProviderId(), subscription->GetProviderNode()));
cbProvider->SetSelection(0);
cbProvider->Disable();
chkForward->Disable();
EnableOK(false);
}
else
{
pgSet *sets = connection->ExecuteSet(
wxT("SELECT no_id, no_comment\n")
wxT(" FROM ") + cluster->GetSchemaPrefix() + wxT("sl_node\n")
wxT(" WHERE no_active AND no_id <> ") + NumToStr(cluster->GetLocalNodeID()));
if (sets)
{
while (!sets->Eof())
{
cbProvider->Append(IdAndName(sets->GetLong(wxT("no_id")), sets->GetVal(wxT("no_comment"))),
(void *)sets->GetLong(wxT("no_id")));
if (subscription && sets->GetLong(wxT("no_id")) == subscription->GetProviderId())
cbProvider->SetSelection(cbProvider->GetCount() - 1);
sets->MoveNext();
}
delete sets;
}
}
if (!subscription && cbProvider->GetCount())
{
cbProvider->SetSelection(0);
EnableOK(true);
}
return dlgProperty::Go(modal);
}
pgObject *dlgRepSubscription::CreateObject(pgCollection *collection)
{
pgObject *obj = slsubscriptionFactory.CreateObjects(collection, 0,
wxT(" WHERE set_id = ") + NumToStr(set->GetSlId()) +
wxT(" AND sub_receiver = ") + NumToStr(cluster->GetLocalNodeID()));
return obj;
}
void dlgRepSubscription::CheckChange()
{
if (subscription)
{
int sel = cbProvider->GetCurrentSelection();
EnableOK(sel >= 0 && (chkForward->GetValue() != subscription->GetForward()
|| (long)cbProvider->wxItemContainer::GetClientData(sel) != subscription->GetProviderId()));
}
else
{
bool enable = true;
EnableOK(enable);
}
}
wxString dlgRepSubscription::GetSql()
{
wxString sql;
sql = wxT("SELECT ") + cluster->GetSchemaPrefix() + wxT("subscribeset(")
+ NumToStr(set->GetSlId()) + wxT(", ");
if (cluster && cluster->ClusterMinimumVersion(1, 1))
{
// Actually, provider and receiver are exchanged here.
sql += NumToStr(cluster->GetLocalNodeID()) + wxT(", ")
+ NumToStr((long)cbProvider->wxItemContainer::GetClientData(cbProvider->GetCurrentSelection()));
}
else
{
sql += NumToStr((long)cbProvider->wxItemContainer::GetClientData(cbProvider->GetCurrentSelection())) + wxT(", ")
+ NumToStr(cluster->GetLocalNodeID());
}
sql += wxT(", ")
+ BoolToStr(chkForward->GetValue());
// Omit copy?
if (cluster && cluster->ClusterMinimumVersion(2, 0) &&
cluster->GetClusterVersion() != wxT("2.0.0") &&
cluster->GetClusterVersion() != wxT("2.0.1") &&
cluster->GetClusterVersion() != wxT("2.0.2"))
sql += wxT(", false");
sql += wxT(");");
return sql;
}