1
//////////////////////////////////////////////////////////////////////////
3
// pgAdmin III - PostgreSQL Tools
4
// RCS-ID: $Id: slSubscription.cpp 4874 2006-01-06 17:33:27Z dpage $
5
// Copyright (C) 2002 - 2006, The pgAdmin Development Team
6
// This software is released under the Artistic Licence
8
// slSubscription.cpp PostgreSQL Slony-I subscription
10
//////////////////////////////////////////////////////////////////////////
18
#include "slSubscription.h"
20
#include "slSequence.h"
25
slSubscription::slSubscription(slSet *s, const wxString& newName)
26
: slSetObject(s, subscriptionFactory, newName)
28
wxLogInfo(wxT("Creating a slSubscription object"));
31
slSubscription::~slSubscription()
33
wxLogInfo(wxT("Destroying a slSubscription object"));
38
int slSubscription::GetIconId()
40
if (GetReceiverId() == GetCluster()->GetLocalNodeID())
41
return subscriptionFactory.GetIconId();
43
return subscriptionFactory.GetExportedIconId();
47
bool slSubscription::DropObject(wxFrame *frame, ctlTree *browser, bool cascaded)
49
return GetDatabase()->ExecuteVoid(
50
wxT("SELECT ") + GetCluster()->GetSchemaPrefix()
51
+ wxT("unsubscribeset(") + NumToStr(GetSet()->GetSlId())
52
+ wxT(", ") + NumToStr(GetReceiverId())
58
bool slSubscription::CanCreate()
60
return GetSet()->GetOriginId() != GetReceiverId() && slSetObject::CanCreate();
64
bool slSubscription::CanDrop()
66
return GetReceiverId() == GetCluster()->GetLocalNodeID();
70
wxString slSubscription::GetSql(ctlTree *browser)
74
if (GetReceiverId() != GetCluster()->GetLocalNodeID())
75
sql = wxT("-- Subscription must be maintained on receiver node.\n");
77
sql = wxT("-- subscribe replication set\n\n")
78
wxT(" SELECT ") + GetCluster()->GetSchemaPrefix() + wxT("subscribeset(")
79
+ NumToStr(GetSet()->GetSlId()) + wxT(", ")
80
+ NumToStr(GetProviderId()) + wxT(", ")
81
+ NumToStr(GetReceiverId()) + wxT(", ")
82
+ BoolToStr(GetForward()) + wxT(");");
88
bool slSubscription::WantDummyChild()
90
return GetSet()->GetOriginId() != GetCluster()->GetLocalNodeID();
94
void slSubscription::ShowTreeDetail(ctlTree *browser, frmMain *form, ctlListView *properties, ctlSQLBox *sqlPane)
100
browser->RemoveDummyChild(this);
103
if (WantDummyChild())
105
wxTreeItemId id=browser->GetItemParent(browser->GetItemParent(GetId()));
108
slSet *set=(slSet*)browser->GetObject(id);
109
if (set && set->IsCreatedBy(setFactory))
111
wxLogInfo(wxT("Adding child object to subscription ") + GetIdentifier());
113
browser->AppendCollection(this, slSequenceFactory);
114
browser->AppendCollection(this, slTableFactory);
123
wxLogInfo(wxT("Displaying properties for subscription ") + GetIdentifier());
125
CreateListColumns(properties);
127
properties->AppendItem(_("Provider ID"), GetProviderId());
128
properties->AppendItem(_("Provider Name"), GetProviderNode());
129
properties->AppendItem(_("Receiver ID"), GetReceiverId());
130
properties->AppendItem(_("Receiver Name"), GetReceiverNode());
132
properties->AppendItem(_("Active"), GetActive());
133
properties->AppendItem(_("May forward"), GetForward());
135
properties->AppendItem(_("Is forwarded"), GetIsSubscribed());
141
pgObject *slSubscription::Refresh(ctlTree *browser, const wxTreeItemId item)
143
pgObject *subscription=0;
144
pgCollection *coll=browser->GetParentCollection(item);
146
subscription = subscriptionFactory.CreateObjects(coll, 0, wxT(" WHERE sub_set=") + NumToStr(GetSet()->GetSlId())
147
+ wxT(" AND sub_receiver = ") + NumToStr(GetReceiverId()) + wxT("\n"));
153
pgObject *slSubscriptionFactory::CreateObjects(pgCollection *coll, ctlTree *browser, const wxString &restr)
155
slSetObjCollection *collection=(slSetObjCollection*)coll;
156
slSubscription *subscription=0;
157
wxString restriction;
159
restriction = wxT(" WHERE sub_set = ") + NumToStr(collection->GetSlId());
163
wxString prefix=collection->GetCluster()->GetSchemaPrefix();
164
pgSet *subscriptions = collection->GetDatabase()->ExecuteSet(
165
wxT("SELECT sub_set, sub_provider, sub_receiver, sub_forward, sub_active,\n")
166
wxT(" re.no_comment as receiver_name, pr.no_comment as provider_name,\n")
167
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")
168
wxT(" FROM ") + prefix + wxT("sl_subscribe s1\n")
169
wxT(" JOIN ") + prefix + wxT("sl_set ON set_id = sub_set\n")
170
wxT(" JOIN ") + prefix + wxT("sl_node pr ON pr.no_id = sub_provider\n")
171
wxT(" JOIN ") + prefix + wxT("sl_node re ON re.no_id = sub_receiver\n")
173
wxT(" ORDER BY sub_provider, sub_receiver"));
177
while (!subscriptions->Eof())
179
subscription = new slSubscription(collection->GetSet(), subscriptions->GetVal(wxT("receiver_name")));
180
subscription->iSetActive(subscriptions->GetBool(wxT("sub_active")));
181
subscription->iSetForward(subscriptions->GetBool(wxT("sub_forward")));
182
subscription->iSetReceiverId(subscriptions->GetLong(wxT("sub_receiver")));
183
subscription->iSetProviderId(subscriptions->GetLong(wxT("sub_provider")));
184
subscription->iSetReceiverNode(subscriptions->GetVal(wxT("receiver_name")));
185
subscription->iSetProviderNode(subscriptions->GetVal(wxT("provider_name")));
186
subscription->iSetIsSubscribed(subscriptions->GetBool(wxT("is_subscribed")));
190
browser->AppendObject(coll, subscription);
191
subscriptions->MoveNext();
197
delete subscriptions;
203
///////////////////////////////////////////////////
205
#include "images/slsubscription.xpm"
206
#include "images/slsubscriptions.xpm"
208
slSubscriptionFactory::slSubscriptionFactory()
209
: slSetObjFactory(__("Subscription"), __("New Subscription"), __("Create a new Subscription."), slsubscription_xpm)
211
metaType = SLM_SUBSCRIPTION;
215
slSubscriptionFactory subscriptionFactory;
216
static pgaCollectionFactory cf(&subscriptionFactory, __("Subscriptions"), slsubscriptions_xpm);