File: dlgResourceGroup.cpp

package info (click to toggle)
pgadmin3 1.20.0~beta2-1
  • links: PTS, VCS
  • area: main
  • in suites: jessie, jessie-kfreebsd
  • size: 73,704 kB
  • ctags: 18,591
  • sloc: cpp: 193,786; ansic: 18,736; sh: 5,154; pascal: 1,120; yacc: 927; makefile: 516; lex: 421; xml: 126; perl: 40
file content (141 lines) | stat: -rw-r--r-- 3,618 bytes parent folder | download
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
//////////////////////////////////////////////////////////////////////////
//
// pgAdmin III - PostgreSQL Tools
//
// Copyright (C) 2002 - 2014, The pgAdmin Development Team
// This software is released under the PostgreSQL Licence
//
// dlgResourceGroup.cpp - Resource Group Property
//
//////////////////////////////////////////////////////////////////////////

#include "pgAdmin3.h"

// wxWindows headers
#include <wx/wx.h>

// App headers
#include "dlg/dlgResourceGroup.h"
#include "schema/edbResourceGroup.h"


// pointer to controls
#define txtResGrpName	CTRL_TEXT("txtResGrpName")
#define txtCPURate		CTRL_TEXT("txtCPURate")
#define txtDirtyRate	CTRL_TEXT("txtDirtyRate")

dlgProperty *edbResourceGroupFactory::CreateDialog(frmMain *frame, pgObject *node, pgObject *parent)
{
	return new dlgResourceGroup(this, frame, (edbResourceGroup *)node);
}


BEGIN_EVENT_TABLE(dlgResourceGroup, dlgProperty)
	EVT_TEXT(XRCID("txtCPURate"), dlgResourceGroup::OnChange)
	EVT_TEXT(XRCID("txtDirtyRate"), dlgResourceGroup::OnChange)
	EVT_BUTTON(wxID_OK, dlgResourceGroup::OnOK)
END_EVENT_TABLE();

dlgResourceGroup::dlgResourceGroup(pgaFactory *f, frmMain *frame, edbResourceGroup *node)
	: dlgProperty(f, frame, wxT("dlgResourceGroup"))
{
	resourceGroup = node;
}

pgObject *dlgResourceGroup::GetObject()
{
	return resourceGroup;
}

int dlgResourceGroup::Go(bool modal)
{
	txtCPURate->SetValidator(numericValidator);
	txtDirtyRate->SetValidator(numericValidator);

	if (resourceGroup)
	{
		wxString sql = wxT("SELECT rgrpcpuratelimit, rgrpdirtyratelimit from edb_resource_group WHERE rgrpname = '")
		               + resourceGroup->GetName() + wxT("'");

		pgSet *set = connection->ExecuteSet(sql);
		if (set && set->NumRows() > 0)
		{
			txtCPURate->SetValue(set->GetVal(0));
			txtDirtyRate->SetValue(set->GetVal(1));
			delete set;
		}
	}
	else
	{
		txtCPURate->SetValue(wxT("0"));
		txtDirtyRate->SetValue(wxT("0"));
	}

	return dlgProperty::Go(modal);
}

void dlgResourceGroup::OnChange(wxCommandEvent &event)
{
	CheckChange();
}

void dlgResourceGroup::CheckChange()
{
	if (resourceGroup)
	{
		EnableOK(!GetSql().IsEmpty());
	}
	else
	{
		wxString name = GetName();
		wxString cpuRate = txtCPURate->GetValue();
		wxString dirtyRate = txtDirtyRate->GetValue();

		bool enable = true;
		CheckValid(enable, !name.IsEmpty(), _("Please specify name."));
		CheckValid(enable, !cpuRate.IsEmpty(), _("Please specify CPU rate limit."));
		CheckValid(enable, !dirtyRate.IsEmpty(), _("Please specify Dirty rate limit."));

		EnableOK(enable);
	}
}

pgObject *dlgResourceGroup::CreateObject(pgCollection *collection)
{
	wxString name = GetName();

	pgObject *obj = resourceGroupFactory.CreateObjects(collection, 0, wxT("\n WHERE rgrpname= ") + qtDbString(name));
	return obj;
}

wxString dlgResourceGroup::GetSql()
{
	wxString sql;
	wxString name = GetName();
	wxString cpuRate = txtCPURate->GetValue();
	wxString dirtyRate = txtDirtyRate->GetValue();

	if (resourceGroup)
	{
		// Edit Mode
		AppendNameChange(sql, wxT("RESOURCE GROUP ") + resourceGroup->GetQuotedFullIdentifier());

		sql += wxT("ALTER RESOURCE GROUP ") + qtIdent(name) + wxT(" SET cpu_rate_limit = ") +
		       cpuRate + wxT(", dirty_rate_limit = ") + dirtyRate + wxT(";\n");
	}
	else
	{
		// Create Mode
		wxString name = GetName();

		sql = wxT("CREATE RESOURCE GROUP ") + qtIdent(name) + wxT(";\n");
		sql += wxT("ALTER RESOURCE GROUP ") + qtIdent(name) + wxT(" SET cpu_rate_limit = ") +
		       cpuRate + wxT(", dirty_rate_limit = ") + dirtyRate + wxT(";\n");
	}
	return sql;
}

void dlgResourceGroup::OnOK(wxCommandEvent &ev)
{
	dlgProperty::OnOK(ev);
}