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 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565
|
//////////////////////////////////////////////////////////////////////////
//
// pgAdmin III - PostgreSQL Tools
//
// Copyright (C) 2002 - 2014, The pgAdmin Development Team
// This software is released under the PostgreSQL Licence
//
// slSet.cpp PostgreSQL Slony-I Set
//
//////////////////////////////////////////////////////////////////////////
// wxWindows headers
#include <wx/wx.h>
// App headers
#include "pgAdmin3.h"
#include "utils/misc.h"
#include "schema/pgObject.h"
#include "slony/dlgRepSet.h"
#include "slony/slSet.h"
#include "slony/slCluster.h"
#include "slony/slNode.h"
#include "slony/slSequence.h"
#include "slony/slTable.h"
#include "slony/slSubscription.h"
#include "frm/frmMain.h"
slSet::slSet(slCluster *cl, const wxString &newName)
: slObject(cl, setFactory, newName)
{
}
int slSet::GetIconId()
{
if (GetOriginId() == GetCluster()->GetLocalNodeID())
return setFactory.GetExportedIconId();
else
return setFactory.GetIconId();
}
wxMenu *slSet::GetNewMenu()
{
wxMenu *menu = pgObject::GetNewMenu();
if (GetOriginId() == GetCluster()->GetLocalNodeID())
{
slSequenceFactory.AppendMenu(menu);
slTableFactory.AppendMenu(menu);
}
subscriptionFactory.AppendMenu(menu);
return menu;
}
bool slSet::DropObject(wxFrame *frame, ctlTree *browser, bool cascaded)
{
return GetDatabase()->ExecuteVoid(
wxT("SELECT ") + GetCluster()->GetSchemaPrefix()
+ wxT("dropset(") + NumToStr(GetSlId()) + wxT(");\n"));
}
wxString slSet::GetTranslatedMessage(int kindOfMessage) const
{
wxString message = wxEmptyString;
switch (kindOfMessage)
{
case RETRIEVINGDETAILS:
message = _("Retrieving details on Slony set");
message += wxT(" ") + GetName();
break;
case REFRESHINGDETAILS:
message = _("Refreshing Slony set");
message += wxT(" ") + GetName();
break;
case DROPINCLUDINGDEPS:
message = wxString::Format(_("Are you sure you wish to drop Slony set \"%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 set \"%s\"?"),
GetFullIdentifier().c_str());
break;
case DROPCASCADETITLE:
message = _("Drop Slony set cascaded?");
break;
case DROPTITLE:
message = _("Drop Slony set?");
break;
case PROPERTIESREPORT:
message = _("Slony set properties report");
message += wxT(" - ") + GetName();
break;
case PROPERTIES:
message = _("Slony set properties");
break;
case DDLREPORT:
message = _("Slony set DDL report");
message += wxT(" - ") + GetName();
break;
case DDL:
message = _("Slony set DDL");
break;
case DEPENDENCIESREPORT:
message = _("Slony set dependencies report");
message += wxT(" - ") + GetName();
break;
case DEPENDENCIES:
message = _("Slony set dependencies");
break;
case DEPENDENTSREPORT:
message = _("Slony set dependents report");
message += wxT(" - ") + GetName();
break;
case DEPENDENTS:
message = _("Slony set dependents");
break;
}
return message;
}
wxString slSet::GetSql(ctlTree *browser)
{
if (sql.IsNull())
{
sql = wxT("-- Create replication set ") + GetName() + wxT(".\n\n")
wxT("SELECT ") + GetCluster()->GetSchemaPrefix() + wxT("storeset(")
+ NumToStr(GetSlId()) + wxT(", ")
+ qtDbString(GetComment()) + wxT(");\n");
}
return sql;
}
void slSet::ShowDependencies(frmMain *form, ctlListView *list, const wxString &wh)
{
list->ClearAll();
list->AddColumn(_("Type"), 60);
list->AddColumn(_("Name"), 100);
list->AddColumn(_("Comment"), 200);
wxString where;
if (wh.IsEmpty())
where = wxT(" WHERE set_id=") + NumToStr(GetSlId());
else
where = wh;
pgSet *set = GetDatabase()->ExecuteSet(
wxT("SELECT relkind, nspname, relname, id, comment\n")
wxT(" FROM pg_class cl\n")
wxT(" JOIN pg_namespace nsp ON nsp.oid=cl.relnamespace\n")
wxT(" JOIN (\n")
wxT(" SELECT tab_id AS id, tab_reloid AS oid, tab_altered AS altered, tab_comment AS comment\n")
wxT(" FROM ") + GetCluster()->GetSchemaPrefix() + wxT("sl_table t\n")
wxT(" JOIN ") + GetCluster()->GetSchemaPrefix() + wxT("sl_set s ON tab_set=set_id ") + where + wxT("\n")
wxT(" UNION\n")
wxT(" SELECT seq_id, seq_reloid, NULL, seq_comment\n")
wxT(" FROM ") + GetCluster()->GetSchemaPrefix() + wxT("sl_sequence t\n")
wxT(" JOIN ") + GetCluster()->GetSchemaPrefix() + wxT("sl_set s ON seq_set=set_id ") + where + wxT("\n")
wxT(" ) AS set ON set.oid=cl.oid"));
if (set)
{
while (!set->Eof())
{
wxString name = set->GetVal(wxT("nspname")) + wxT(".") + set->GetVal(wxT("relname"));
wxString typestr = set->GetVal(wxT("relkind"));
wxString comment = set->GetVal(wxT("comment"));
wxString typname;
int icon = -1;
switch ( (wxChar)typestr.c_str()[0])
{
case 'S':
typname = _("Sequence");
icon = -1;
break;
case 'r':
typname = _("Table");
icon = -1;
break;
}
list->AppendItem(icon, typname, name, comment);
set->MoveNext();
}
delete set;
}
}
wxString slSet::GetLockXXID()
{
return GetConnection()->ExecuteScalar(
wxT("SELECT set_locked FROM ")
+ GetCluster()->GetSchemaPrefix() + wxT("sl_set\n")
wxT(" WHERE set_id=") + NumToStr(GetSlId()));
}
bool slSet::Lock()
{
return GetConnection()->ExecuteVoid(wxT("SELECT ") + GetCluster()->GetSchemaPrefix()
+ wxT("lockSet(") + NumToStr(GetSlId()) + wxT(");"));
}
bool slSet::Unlock()
{
return GetConnection()->ExecuteVoid(wxT("SELECT ") + GetCluster()->GetSchemaPrefix()
+ wxT("unlockSet(") + NumToStr(GetSlId()) + wxT(");"));
}
bool slSet::CanDrop()
{
if (GetMetaType() != SLM_SUBSCRIPTION)
return !GetSubscriptionCount() && GetOriginId() == GetCluster()->GetLocalNodeID();
else
return GetOriginId() != GetCluster()->GetLocalNodeID();
}
void slSet::ShowDependents(frmMain *form, ctlListView *referencedBy, const wxString &wh)
{
}
void slSet::ShowTreeDetail(ctlTree *browser, frmMain *form, ctlListView *properties, ctlSQLBox *sqlPane)
{
if (!expandedKids)
{
expandedKids = true;
browser->RemoveDummyChild(this);
// Log
wxLogInfo(wxT("Adding child object to set %s"), GetIdentifier().c_str());
if (GetOriginId() == GetCluster()->GetLocalNodeID())
{
browser->AppendCollection(this, slSequenceFactory);
browser->AppendCollection(this, slTableFactory);
}
browser->AppendCollection(this, subscriptionFactory);
}
if (properties)
{
CreateListColumns(properties);
properties->AppendItem(_("Name"), GetName());
properties->AppendItem(_("ID"), GetSlId());
properties->AppendItem(_("Origin ID"), GetOriginId());
properties->AppendItem(_("Origin Node"), GetOriginNode());
properties->AppendItem(_("Subscriptions"), GetSubscriptionCount());
wxString lockXXID = GetLockXXID();
if (!lockXXID.IsEmpty())
properties->AppendItem(_("Lock XXID"), lockXXID);
properties->AppendItem(_("Comment"), firstLineOnly(GetComment()));
}
}
pgObject *slSet::Refresh(ctlTree *browser, const wxTreeItemId item)
{
pgObject *set = 0;
pgCollection *coll = browser->GetParentCollection(item);
if (coll)
set = setFactory.CreateObjects(coll, 0, wxT(" WHERE set_id=") + NumToStr(GetSlId()) + wxT("\n"));
return set;
}
pgObject *slSetFactory::CreateObjects(pgCollection *coll, ctlTree *browser, const wxString &restriction)
{
slSet *set = 0;
slObjCollection *collection = (slObjCollection *)coll;
wxString prefix = collection->GetCluster()->GetSchemaPrefix();
pgSet *sets = collection->GetDatabase()->ExecuteSet(
wxT("SELECT set_id, set_origin, no_comment, set_comment,\n")
wxT(" (SELECT COUNT(1) FROM ") + prefix + wxT("sl_subscribe where sub_set=set_id) AS subcount\n")
wxT(" FROM ") + prefix + wxT("sl_set\n")
wxT(" JOIN ") + prefix + wxT("sl_node ON set_origin=no_id\n")
+ restriction +
wxT(" ORDER BY set_id"));
if (sets)
{
while (!sets->Eof())
{
set = new slSet(collection->GetCluster(), sets->GetVal(wxT("set_comment")).BeforeFirst('\n'));
set->iSetSlId(sets->GetLong(wxT("set_id")));
set->iSetOriginId(sets->GetLong(wxT("set_origin")));
set->iSetOriginNode(sets->GetVal(wxT("no_comment")));
set->iSetSubscriptionCount(sets->GetLong(wxT("subcount")));
set->iSetComment(sets->GetVal(wxT("set_comment")));
if (browser)
{
browser->AppendObject(coll, set);
sets->MoveNext();
}
else
break;
}
delete sets;
}
return set;
}
wxString slSetCollection::GetTranslatedMessage(int kindOfMessage) const
{
wxString message = wxEmptyString;
switch (kindOfMessage)
{
case RETRIEVINGDETAILS:
message = _("Retrieving details on Slony sets");
break;
case REFRESHINGDETAILS:
message = _("Refreshing Slony sets");
break;
case OBJECTSLISTREPORT:
message = _("Slony sets list report");
break;
}
return message;
}
//////////////////////////////////////////////////
#include "images/slset.pngc"
#include "images/slset2.pngc"
#include "images/slsets.pngc"
slSetFactory::slSetFactory()
: slObjFactory(__("Set"), __("New Replication Set"), __("Create a new Replication Set."), slset2_png_img)
{
exportedIconId = addIcon(slset_png_img);
metaType = SLM_SET;
}
pgCollection *slSetFactory::CreateCollection(pgObject *obj)
{
return new slSetCollection(GetCollectionFactory(), (slCluster *)obj);
}
slSetObject::slSetObject(slSet *s, pgaFactory &factory, const wxString &newName)
: slObject(s->GetCluster(), factory, newName)
{
set = s;
}
bool slSetObject::CanDrop()
{
if (GetMetaType() != SLM_SUBSCRIPTION)
return !set->GetSubscriptionCount() && set->GetOriginId() == GetCluster()->GetLocalNodeID();
else
{
if (GetCluster()->ClusterMinimumVersion(1, 1))
return (set->GetOriginId() == GetCluster()->GetLocalNodeID() || ((slSubscription *)this)->GetForward());
else
return set->GetOriginId() != GetCluster()->GetLocalNodeID();
}
}
bool slSetObject::CanCreate()
{
if (GetMetaType() != SLM_SUBSCRIPTION)
return !set->GetSubscriptionCount() && set->GetOriginId() == GetCluster()->GetLocalNodeID();
else
{
if (GetCluster()->ClusterMinimumVersion(1, 1))
return (set->GetOriginId() == GetCluster()->GetLocalNodeID() || ((slSubscription *)this)->GetForward());
else
return set->GetOriginId() != GetCluster()->GetLocalNodeID();
}
}
slSetObjCollection::slSetObjCollection(pgaFactory *factory, slSet *_set)
: slObjCollection(factory, _set->GetCluster())
{
set = _set;
subscription = 0;
iSetSlId(set->GetSlId());
}
bool slSetObjCollection::CanCreate()
{
switch (GetMetaType())
{
case SLM_SUBSCRIPTION:
if (GetCluster()->ClusterMinimumVersion(1, 1))
return (set->GetOriginId() == GetCluster()->GetLocalNodeID() || ((slSubscription *)this)->GetForward());
else
return set->GetOriginId() != GetCluster()->GetLocalNodeID();
case SLM_TABLE:
case SLM_SEQUENCE:
if (set->GetSubscriptionCount())
return false;
else
return set->GetOriginId() == GetCluster()->GetLocalNodeID();
default:
return false;
}
}
pgCollection *slSetObjFactory::CreateCollection(pgObject *obj)
{
return new slSetObjCollection(GetCollectionFactory(), (slSet *)obj);
}
slSetFactory setFactory;
static pgaCollectionFactory cf(&setFactory, __("Replication Sets"), slsets_png_img);
////////////////////////////////////////////////////////////
slonyMergeSetFactory::slonyMergeSetFactory(menuFactoryList *list, wxMenu *mnu, ctlMenuToolbar *toolbar) : contextActionFactory(list)
{
mnu->Append(id, _("Merge Set"), _("Merge two replication sets."));
}
wxWindow *slonyMergeSetFactory::StartDialog(frmMain *form, pgObject *obj)
{
dlgProperty *dlg = new dlgRepSetMerge(&setFactory, form, (slSet *)obj);
dlg->InitDialog(form, obj);
dlg->CreateAdditionalPages();
dlg->Go(false);
dlg->CheckChange();
return 0;
}
bool slonyMergeSetFactory::CheckEnable(pgObject *obj)
{
if (!obj || !obj->IsCreatedBy(setFactory))
return false;
slSet *set = (slSet *)obj;
return set->GetOriginId() == set->GetCluster()->GetLocalNodeID();
}
/////////////////////////////
slonyLockSetFactory::slonyLockSetFactory(menuFactoryList *list, wxMenu *mnu, ctlMenuToolbar *toolbar) : contextActionFactory(list)
{
mnu->Append(id, _("Lock Set"), _("Lock a replication set against updates."));
}
wxWindow *slonyLockSetFactory::StartDialog(frmMain *form, pgObject *obj)
{
slSet *set = (slSet *)obj;
if (set->GetCluster()->GetLocalNode(form->GetBrowser())->CheckAcksAndContinue(form))
{
if (set->Lock())
form->Refresh(set);
}
return 0;
}
bool slonyLockSetFactory::CheckEnable(pgObject *obj)
{
if (!obj || !obj->IsCreatedBy(setFactory))
return false;
slSet *set = (slSet *)obj;
return set->GetOriginId() == set->GetCluster()->GetLocalNodeID() && set->GetLockXXID().IsEmpty();
}
/////////////////////////////
slonyUnlockSetFactory::slonyUnlockSetFactory(menuFactoryList *list, wxMenu *mnu, ctlMenuToolbar *toolbar) : contextActionFactory(list)
{
mnu->Append(id, _("Unlock Set"), _("Unlock a replication set and re-allow updates."));
}
wxWindow *slonyUnlockSetFactory::StartDialog(frmMain *form, pgObject *obj)
{
slSet *set = (slSet *)obj;
if (set->GetCluster()->GetLocalNode(form->GetBrowser())->CheckAcksAndContinue(form))
{
if (set->Unlock())
form->Refresh(set);
}
return 0;
}
bool slonyUnlockSetFactory::CheckEnable(pgObject *obj)
{
if (!obj || !obj->IsCreatedBy(setFactory))
return false;
slSet *set = (slSet *)obj;
return set->GetOriginId() == set->GetCluster()->GetLocalNodeID() && !set->GetLockXXID().IsEmpty();
}
////////////////////////////////
slonyMoveSetFactory::slonyMoveSetFactory(menuFactoryList *list, wxMenu *mnu, ctlMenuToolbar *toolbar) : contextActionFactory(list)
{
mnu->Append(id, _("Move Set"), _("Move replication set to different node"));
}
wxWindow *slonyMoveSetFactory::StartDialog(frmMain *form, pgObject *obj)
{
dlgProperty *dlg = new dlgRepSetMove(&setFactory, form, (slSet *)obj);
dlg->InitDialog(form, obj);
dlg->CreateAdditionalPages();
dlg->Go(false);
dlg->CheckChange();
return 0;
}
bool slonyMoveSetFactory::CheckEnable(pgObject *obj)
{
if (!obj || ! obj->IsCreatedBy(setFactory))
return false;
slSet *set = (slSet *)obj;
return set->GetOriginId() == set->GetCluster()->GetLocalNodeID() && !set->GetLockXXID().IsEmpty();
}
|