~ubuntu-branches/debian/squeeze/pgadmin3/squeeze

« back to all changes in this revision

Viewing changes to src/slony/slSubscription.cpp

  • Committer: Bazaar Package Importer
  • Author(s): Lionel Porcheron
  • Date: 2008-02-07 00:56:22 UTC
  • mto: (2.1.6 hardy) (6.1.2 sid)
  • mto: This revision was merged to the branch mainline in revision 4.
  • Revision ID: james.westby@ubuntu.com-20080207005622-c2ail8p4d0sk3dnw
Tags: upstream-1.8.2
ImportĀ upstreamĀ versionĀ 1.8.2

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
//////////////////////////////////////////////////////////////////////////
2
 
//
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
7
 
//
8
 
// slSubscription.cpp PostgreSQL Slony-I subscription
9
 
//
10
 
//////////////////////////////////////////////////////////////////////////
11
 
 
12
 
// wxWindows headers
13
 
#include <wx/wx.h>
14
 
 
15
 
// App headers
16
 
#include "pgAdmin3.h"
17
 
#include "misc.h"
18
 
#include "slSubscription.h"
19
 
#include "slTable.h"
20
 
#include "slSequence.h"
21
 
#include "frmMain.h"
22
 
 
23
 
 
24
 
 
25
 
slSubscription::slSubscription(slSet *s, const wxString& newName)
26
 
: slSetObject(s, subscriptionFactory, newName)
27
 
{
28
 
    wxLogInfo(wxT("Creating a slSubscription object"));
29
 
}
30
 
 
31
 
slSubscription::~slSubscription()
32
 
{
33
 
    wxLogInfo(wxT("Destroying a slSubscription object"));
34
 
}
35
 
 
36
 
 
37
 
 
38
 
int slSubscription::GetIconId()
39
 
{
40
 
    if (GetReceiverId() == GetCluster()->GetLocalNodeID())
41
 
        return subscriptionFactory.GetIconId();
42
 
    else
43
 
        return subscriptionFactory.GetExportedIconId();
44
 
}
45
 
 
46
 
 
47
 
bool slSubscription::DropObject(wxFrame *frame, ctlTree *browser, bool cascaded)
48
 
{
49
 
    return GetDatabase()->ExecuteVoid(
50
 
        wxT("SELECT ") + GetCluster()->GetSchemaPrefix() 
51
 
            + wxT("unsubscribeset(") + NumToStr(GetSet()->GetSlId())
52
 
            + wxT(", ") + NumToStr(GetReceiverId())
53
 
            + wxT(");"));
54
 
 
55
 
}
56
 
 
57
 
 
58
 
bool slSubscription::CanCreate()
59
 
{
60
 
    return GetSet()->GetOriginId() != GetReceiverId() && slSetObject::CanCreate();
61
 
}
62
 
 
63
 
 
64
 
bool slSubscription::CanDrop()
65
 
{
66
 
    return GetReceiverId() == GetCluster()->GetLocalNodeID();
67
 
}
68
 
 
69
 
 
70
 
wxString slSubscription::GetSql(ctlTree *browser)
71
 
{
72
 
    if (sql.IsNull())
73
 
    {
74
 
        if (GetReceiverId() != GetCluster()->GetLocalNodeID())
75
 
            sql = wxT("-- Subscription must be maintained on receiver node.\n");
76
 
        else
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(");");
83
 
    }
84
 
    return sql;
85
 
}
86
 
 
87
 
 
88
 
bool slSubscription::WantDummyChild()
89
 
{
90
 
    return GetSet()->GetOriginId() != GetCluster()->GetLocalNodeID();
91
 
}
92
 
 
93
 
 
94
 
void slSubscription::ShowTreeDetail(ctlTree *browser, frmMain *form, ctlListView *properties, ctlSQLBox *sqlPane)
95
 
{
96
 
    if (!expandedKids)
97
 
    {
98
 
        expandedKids=true;
99
 
 
100
 
        browser->RemoveDummyChild(this);
101
 
        // Log
102
 
 
103
 
        if (WantDummyChild())
104
 
        {
105
 
            wxTreeItemId id=browser->GetItemParent(browser->GetItemParent(GetId()));
106
 
            if (id)
107
 
            {
108
 
                slSet *set=(slSet*)browser->GetObject(id);
109
 
                if (set && set->IsCreatedBy(setFactory))
110
 
                {
111
 
                    wxLogInfo(wxT("Adding child object to subscription ") + GetIdentifier());
112
 
 
113
 
                    browser->AppendCollection(this, slSequenceFactory);
114
 
                    browser->AppendCollection(this, slTableFactory);
115
 
                }
116
 
            }
117
 
        }
118
 
    }
119
 
 
120
 
 
121
 
    if (properties)
122
 
    {
123
 
        wxLogInfo(wxT("Displaying properties for subscription ") + GetIdentifier());
124
 
 
125
 
        CreateListColumns(properties);
126
 
 
127
 
        properties->AppendItem(_("Provider ID"), GetProviderId());
128
 
        properties->AppendItem(_("Provider Name"), GetProviderNode());
129
 
        properties->AppendItem(_("Receiver ID"), GetReceiverId());
130
 
        properties->AppendItem(_("Receiver Name"), GetReceiverNode());
131
 
 
132
 
        properties->AppendItem(_("Active"), GetActive());
133
 
        properties->AppendItem(_("May forward"), GetForward());
134
 
        if (GetForward())
135
 
            properties->AppendItem(_("Is forwarded"), GetIsSubscribed());
136
 
    }
137
 
}
138
 
 
139
 
 
140
 
 
141
 
pgObject *slSubscription::Refresh(ctlTree *browser, const wxTreeItemId item)
142
 
{
143
 
    pgObject *subscription=0;
144
 
    pgCollection *coll=browser->GetParentCollection(item);
145
 
    if (coll)
146
 
        subscription = subscriptionFactory.CreateObjects(coll, 0, wxT(" WHERE sub_set=") + NumToStr(GetSet()->GetSlId()) 
147
 
                            + wxT(" AND sub_receiver = ") + NumToStr(GetReceiverId()) + wxT("\n"));
148
 
    return subscription;
149
 
}
150
 
 
151
 
 
152
 
 
153
 
pgObject *slSubscriptionFactory::CreateObjects(pgCollection *coll, ctlTree *browser, const wxString &restr)
154
 
{
155
 
    slSetObjCollection *collection=(slSetObjCollection*)coll;
156
 
    slSubscription *subscription=0;
157
 
    wxString restriction;
158
 
    if (restr.IsEmpty())
159
 
        restriction = wxT(" WHERE sub_set = ") + NumToStr(collection->GetSlId());
160
 
    else
161
 
        restriction = restr;
162
 
 
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")
172
 
         + restriction +
173
 
        wxT(" ORDER BY sub_provider, sub_receiver"));
174
 
 
175
 
    if (subscriptions)
176
 
    {
177
 
        while (!subscriptions->Eof())
178
 
        {
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")));
187
 
 
188
 
            if (browser)
189
 
            {
190
 
                browser->AppendObject(coll, subscription);
191
 
                                subscriptions->MoveNext();
192
 
            }
193
 
            else
194
 
                break;
195
 
        }
196
 
 
197
 
                delete subscriptions;
198
 
    }
199
 
    return subscription;
200
 
}
201
 
 
202
 
 
203
 
///////////////////////////////////////////////////
204
 
 
205
 
#include "images/slsubscription.xpm"
206
 
#include "images/slsubscriptions.xpm"
207
 
 
208
 
slSubscriptionFactory::slSubscriptionFactory() 
209
 
: slSetObjFactory(__("Subscription"), __("New Subscription"), __("Create a new Subscription."), slsubscription_xpm)
210
 
{
211
 
    metaType = SLM_SUBSCRIPTION;
212
 
}
213
 
 
214
 
 
215
 
slSubscriptionFactory subscriptionFactory;
216
 
static pgaCollectionFactory cf(&subscriptionFactory, __("Subscriptions"), slsubscriptions_xpm);