File: pgTextSearchConfiguration.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 (277 lines) | stat: -rw-r--r-- 8,629 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
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
//////////////////////////////////////////////////////////////////////////
//
// pgAdmin III - PostgreSQL Tools
//
// Copyright (C) 2002 - 2014, The pgAdmin Development Team
// This software is released under the PostgreSQL Licence
//
// pgTextSearchConfiguration.cpp - Text Search Configuration class
//
//////////////////////////////////////////////////////////////////////////

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

// App headers
#include "pgAdmin3.h"
#include "utils/misc.h"
#include "schema/pgTextSearchConfiguration.h"


pgTextSearchConfiguration::pgTextSearchConfiguration(pgSchema *newSchema, const wxString &newName)
	: pgSchemaObject(newSchema, textSearchConfigurationFactory, newName)
{
}

pgTextSearchConfiguration::~pgTextSearchConfiguration()
{
}

wxString pgTextSearchConfiguration::GetTranslatedMessage(int kindOfMessage) const
{
	wxString message = wxEmptyString;

	switch (kindOfMessage)
	{
		case RETRIEVINGDETAILS:
			message = _("Retrieving details on FTS configuration");
			message += wxT(" ") + GetName();
			break;
		case REFRESHINGDETAILS:
			message = _("Refreshing FTS configuration");
			message += wxT(" ") + GetName();
			break;
		case DROPINCLUDINGDEPS:
			message = wxString::Format(_("Are you sure you wish to drop FTS configuration \"%s\" including all objects that depend on it?"),
			                           GetFullIdentifier().c_str());
			break;
		case DROPEXCLUDINGDEPS:
			message = wxString::Format(_("Are you sure you wish to drop FTS configuration \"%s\"?"),
			                           GetFullIdentifier().c_str());
			break;
		case DROPCASCADETITLE:
			message = _("Drop FTS configuration cascaded?");
			break;
		case DROPTITLE:
			message = _("Drop FTS configuration?");
			break;
		case PROPERTIESREPORT:
			message = _("FTS configuration properties report");
			message += wxT(" - ") + GetName();
			break;
		case PROPERTIES:
			message = _("FTS configuration properties");
			break;
		case DDLREPORT:
			message = _("FTS configuration DDL report");
			message += wxT(" - ") + GetName();
			break;
		case DDL:
			message = _("FTS configuration DDL");
			break;
		case DEPENDENCIESREPORT:
			message = _("FTS configuration dependencies report");
			message += wxT(" - ") + GetName();
			break;
		case DEPENDENCIES:
			message = _("FTS configuration dependencies");
			break;
		case DEPENDENTSREPORT:
			message = _("FTS configuration dependents report");
			message += wxT(" - ") + GetName();
			break;
		case DEPENDENTS:
			message = _("FTS configuration dependents");
			break;
	}

	return message;
}

bool pgTextSearchConfiguration::DropObject(wxFrame *frame, ctlTree *browser, bool cascaded)
{
	wxString sql = wxT("DROP TEXT SEARCH CONFIGURATION ") + this->GetSchema()->GetQuotedIdentifier() + wxT(".") + qtIdent(this->GetIdentifier());

	if (cascaded)
		sql += wxT(" CASCADE");

	return GetDatabase()->ExecuteVoid(sql);
}


wxString pgTextSearchConfiguration::GetSql(ctlTree *browser)
{
	if (sql.IsNull())
	{
		sql = wxT("-- Text Search Configuration: ") + GetFullIdentifier() + wxT("\n\n")
		      + wxT("-- DROP TEXT SEARCH CONFIGURATION ") + GetFullIdentifier() + wxT("\n\n")
		      + wxT("CREATE TEXT SEARCH CONFIGURATION ") + GetFullIdentifier() + wxT(" (")
		      + wxT("\n  PARSER = ") + qtTypeIdent(GetParser())
		      + wxT("\n);\n");

		for (size_t i = 0 ; i < tokens.GetCount() ; i++)
			sql += wxT("ALTER TEXT SEARCH CONFIGURATION ") + GetQuotedFullIdentifier()
			       +  wxT(" ADD MAPPING FOR ") + tokens.Item(i).BeforeFirst('/')
			       +  wxT(" WITH ") + tokens.Item(i).AfterFirst('/')
			       +  wxT(";\n");

		if (!GetComment().IsNull())
			sql += wxT("COMMENT ON TEXT SEARCH CONFIGURATION ") + GetFullIdentifier()
			       + wxT(" IS ") + qtDbString(GetComment()) + wxT(";\n");
	}

	return sql;
}


void pgTextSearchConfiguration::ShowTreeDetail(ctlTree *browser, frmMain *form, ctlListView *properties, ctlSQLBox *sqlPane)
{
	if (properties)
	{
		CreateListColumns(properties);

		properties->AppendItem(_("Name"), GetName());
		properties->AppendItem(_("OID"), GetOid());
		properties->AppendItem(_("Owner"), GetOwner());
		properties->AppendItem(_("Parser"), GetParser());
		properties->AppendItem(_("Comment"), firstLineOnly(GetComment()));
	}
}



pgObject *pgTextSearchConfiguration::Refresh(ctlTree *browser, const wxTreeItemId item)
{
	pgObject *config = 0;
	pgCollection *coll = browser->GetParentCollection(item);
	if (coll)
		config = textSearchConfigurationFactory.CreateObjects(coll, 0, wxT("\n   AND cfg.oid=") + GetOidStr());

	return config;
}


///////////////////////////////////////////////////


pgTextSearchConfigurationCollection::pgTextSearchConfigurationCollection(pgaFactory *factory, pgSchema *sch)
	: pgSchemaObjCollection(factory, sch)
{
}


wxString pgTextSearchConfigurationCollection::GetTranslatedMessage(int kindOfMessage) const
{
	wxString message = wxEmptyString;

	switch (kindOfMessage)
	{
		case RETRIEVINGDETAILS:
			message = _("Retrieving details on FTS configurations");
			break;
		case REFRESHINGDETAILS:
			message = _("Refreshing FTS configurations");
			break;
		case OBJECTSLISTREPORT:
			message = _("FTS configurations list report");
			break;
	}

	return message;
}


//////////////////////////////////////////////////////


pgObject *pgTextSearchConfigurationFactory::CreateObjects(pgCollection *collection, ctlTree *browser, const wxString &restriction)
{
	pgTextSearchConfiguration *config = 0;

	pgSet *configurations;
	configurations = collection->GetDatabase()->ExecuteSet(
	                     wxT("SELECT cfg.oid, cfg.cfgname, pg_get_userbyid(cfg.cfgowner) as cfgowner, cfg.cfgparser, parser.prsname as parsername, description\n")
	                     wxT("  FROM pg_ts_config cfg\n")
	                     wxT("  LEFT OUTER JOIN pg_ts_parser parser ON parser.oid=cfg.cfgparser\n")
	                     wxT("  LEFT OUTER JOIN pg_description des ON (des.objoid=cfg.oid AND des.classoid='pg_ts_config'::regclass)\n")
	                     wxT(" WHERE cfg.cfgnamespace = ") + collection->GetSchema()->GetOidStr()
	                     + restriction + wxT("\n")
	                     wxT(" ORDER BY cfg.cfgname"));

	if (configurations)
	{
		while (!configurations->Eof())
		{
			config = new pgTextSearchConfiguration(collection->GetSchema(), configurations->GetVal(wxT("cfgname")));
			config->iSetOid(configurations->GetOid(wxT("oid")));
			config->iSetOwner(configurations->GetVal(wxT("cfgowner")));
			config->iSetComment(configurations->GetVal(wxT("description")));
			config->iSetParser(configurations->GetVal(wxT("parsername")));
			config->iSetParserOid(configurations->GetOid(wxT("cfgparser")));

			pgSet *maps;
			maps = collection->GetDatabase()->ExecuteSet(
			           wxT("SELECT\n")
			           wxT("  (SELECT t.alias FROM pg_catalog.ts_token_type(cfgparser) AS t")
			           wxT("    WHERE t.tokid = maptokentype) AS tokenalias,\n")
			           wxT("  dictname\n")
			           wxT("FROM pg_ts_config_map\n")
			           wxT("  LEFT OUTER JOIN pg_ts_config ON mapcfg=pg_ts_config.oid\n")
			           wxT("  LEFT OUTER JOIN pg_ts_dict ON mapdict=pg_ts_dict.oid\n")
			           wxT("WHERE mapcfg=") + config->GetOidStr() + wxT("\n")
			           wxT("ORDER BY 1, mapseqno"));

			if (maps)
			{
				wxString tokenToAdd;
				while (!maps->Eof())
				{
					if (tokenToAdd.Length() > 0 &&
					        !tokenToAdd.BeforeFirst('/').IsSameAs(maps->GetVal(wxT("tokenalias")), false))
					{
						config->GetTokens().Add(tokenToAdd);
						tokenToAdd = wxT("");
					}

					if (tokenToAdd.Length() == 0)
						tokenToAdd = maps->GetVal(wxT("tokenalias")) + wxT("/") + maps->GetVal(wxT("dictname"));
					else
						tokenToAdd += wxT(",") + maps->GetVal(wxT("dictname"));

					maps->MoveNext();
				}

				delete maps;
			}

			if (browser)
			{
				browser->AppendObject(collection, config);
				configurations->MoveNext();
			}
			else
				break;
		}

		delete configurations;
	}
	return config;
}


#include "images/configuration.pngc"
#include "images/configurations.pngc"

pgTextSearchConfigurationFactory::pgTextSearchConfigurationFactory()
	: pgSchemaObjFactory(__("FTS Configuration"), __("New FTS Configuration..."), __("Create a new FTS Configuration."), configuration_png_img)
{
}


pgCollection *pgTextSearchConfigurationFactory::CreateCollection(pgObject *obj)
{
	return new pgTextSearchConfigurationCollection(GetCollectionFactory(), (pgSchema *)obj);
}

pgTextSearchConfigurationFactory textSearchConfigurationFactory;
static pgaCollectionFactory cf(&textSearchConfigurationFactory, __("FTS Configurations"), configurations_png_img);