File: dbapi_class.cpp

package info (click to toggle)
tango 9.2.5a%2Bdfsg1-2
  • links: PTS, VCS
  • area: main
  • in suites: buster, stretch
  • size: 21,624 kB
  • ctags: 11,597
  • sloc: cpp: 135,480; sh: 21,772; makefile: 1,103; ansic: 1,083; java: 215; python: 55
file content (325 lines) | stat: -rw-r--r-- 9,182 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
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
static const char *RcsId = "$Id: dbapi_class.cpp 27410 2015-01-27 05:46:17Z taurel $\n$Name$";

//==================================================================================================================
//
// dbapi_class.cpp - C++ source code file for TANGO dbapi class DbClass
//
// programmer 	- Andy Gotz (goetz@esrf.fr) - E. Taurel
//
// original 	- October 2000
//
// Copyright (C) :      2000,2001,2002,2003,2004,2005,2006,2007,2008,2009,2010,2011,2012,2013,2014,2015
//						European Synchrotron Radiation Facility
//                      BP 220, Grenoble 38043
//                      FRANCE
//
// This file is part of Tango.
//
// Tango is free software: you can redistribute it and/or modify
// it under the terms of the GNU Lesser General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// Tango is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
// GNU Lesser General Public License for more details.
//
// You should have received a copy of the GNU Lesser General Public License
// along with Tango.  If not, see <http://www.gnu.org/licenses/>.
//
//====================================================================================================================

#if HAVE_CONFIG_H
#include <ac_config.h>
#endif

#include <tango.h>

using namespace CORBA;

namespace Tango
{

//-------------------------------------------------------------------------------------------------------------------
//
// method:
// 		DbClass::DbClass()
//
// description:
//		Constructor to create a DbClass object for accessing a class of this name in the specified
//		TANGO database (import/export info and properties)
//
// argument:
//		in :
//			- class_name : The class name
//			- class_dbase : The database object ptr
//
//------------------------------------------------------------------------------------------------------------------

DbClass::DbClass(string class_name, Database *class_dbase):ext(Tango_nullptr)
{
	name = string(class_name);
	dbase = class_dbase;
	ext_dbase = true;
}

DbClass::DbClass(string class_name):ext(Tango_nullptr)
{
	name = string(class_name);
	db_ind = ApiUtil::instance()->get_db_ind();
	ext_dbase = false;
}

//--------------------------------------------------------------------------------------------------------------------
//
// method:
// 		DbClass::~DbClass()
//
// description:
//		Destructor to destroy a DbClass object
//
//--------------------------------------------------------------------------------------------------------------------

DbClass::~DbClass()
{
}

//---------------------------------------------------------------------------------------------------------------------
//
// method:
// 		DbClass::get_property()
//
// description:
//		Public method to get class properties from the database
//
//---------------------------------------------------------------------------------------------------------------------

void DbClass::get_property(DbData &db_data)
{
//
// Try to get db server cache in case we are called during a DS startup sequence
//

	ApiUtil *au = ApiUtil::instance();
	DbServerCache *dsc;
	if (au->in_server() == true)
	{
		Tango::Util *tg = Tango::Util::instance();
		dsc = tg->get_db_cache();
	}
	else
		dsc = NULL;

//
// Call DB (or cache)
//

	if (ext_dbase == true)
		dbase->get_class_property(name, db_data, dsc);
	else
	{
		(au->get_db_vect())[db_ind]->get_class_property(name, db_data);
	}
}

//--------------------------------------------------------------------------------------------------------------------
//
// method:
// 		DbClass::put_property()
//
// description:
//		Public method to put class properties from the database
//
//--------------------------------------------------------------------------------------------------------------------

void DbClass::put_property(DbData &db_data)
{

//
// Protect DS code againt a DB exception while the server is in its starting phase
//

	ApiUtil *au = ApiUtil::instance();
	bool forget_except = false;
	if (au->in_server() == true)
	{
		Tango::Util *tg = Tango::Util::instance();
		if (tg->is_svr_starting() == true)
		{
			if (db_data.size() >= 2)
			{
				if ((db_data[0].name == POGO_TITLE) && (db_data[1].name == POGO_DESC))
					forget_except = true;
			}
		}
	}

//
// Call DB
//

	try
	{
		if (ext_dbase == true)
			dbase->put_class_property(name, db_data);
		else
		{
			(au->get_db_vect())[db_ind]->put_class_property(name, db_data);
		}
	}
	catch (Tango::DevFailed &)
	{
		if (forget_except == false)
			throw;
	}
}

//--------------------------------------------------------------------------------------------------------------------
//
// method:
// 		DbClass::delete_property()
//
// description:
//		Public method to delete class properties from the database
//
//--------------------------------------------------------------------------------------------------------------------

void DbClass::delete_property(DbData &db_data)
{
	if (ext_dbase == true)
		dbase->delete_class_property(name, db_data);
	else
	{
		ApiUtil *au = ApiUtil::instance();
		(au->get_db_vect())[db_ind]->delete_class_property(name, db_data);
	}
}

//--------------------------------------------------------------------------------------------------------------------
//
// method:
//		DbClass::get_attribute_property()
//
// description:
//		Public method to get class attribute properties from the database
//
//--------------------------------------------------------------------------------------------------------------------

void DbClass::get_attribute_property(DbData &db_data)
{
	if (ext_dbase == true)
		dbase->get_class_attribute_property(name, db_data);
	else
	{
		ApiUtil *au = ApiUtil::instance();
		(au->get_db_vect())[db_ind]->get_class_attribute_property(name, db_data);
	}
}

//--------------------------------------------------------------------------------------------------------------------
//
// method:
// 		DbClass::put_attribute_property()
//
// description:
//		Public method to put class attribute properties from the database
//
//-------------------------------------------------------------------------------------------------------------------

void DbClass::put_attribute_property(DbData &db_data)
{
	if (ext_dbase == true)
		dbase->put_class_attribute_property(name, db_data);
	else
	{
		ApiUtil *au = ApiUtil::instance();
		(au->get_db_vect())[db_ind]->put_class_attribute_property(name, db_data);
	}
}

//---------------------------------------------------------------------------------------------------------------------
//
// method:
// 		DbClass::delete_attribute_property()
//
// descriptio:
//		Public method to delete class attribute properties from the database
//
//--------------------------------------------------------------------------------------------------------------------

void DbClass::delete_attribute_property(DbData &db_data)
{
	if (ext_dbase == true)
		dbase->delete_class_attribute_property(name, db_data);
	else
	{
		ApiUtil *au = ApiUtil::instance();
		(au->get_db_vect())[db_ind]->delete_class_attribute_property(name, db_data);
	}
}

//--------------------------------------------------------------------------------------------------------------------
//
// method:
// 		DbClass::get_pipe_property()
//
// description:
//		Public method to get class pipe properties from the database
//
//--------------------------------------------------------------------------------------------------------------------

void DbClass::get_pipe_property(DbData &db_data)
{
	if (ext_dbase == true)
		dbase->get_class_pipe_property(name, db_data);
	else
	{
		ApiUtil *au = ApiUtil::instance();
		(au->get_db_vect())[db_ind]->get_class_pipe_property(name, db_data);
	}
}

//--------------------------------------------------------------------------------------------------------------------
//
// method:
// 		DbClass::put_pipe_property()
//
// description:
//		Public method to put class pipe properties from the database
//
//--------------------------------------------------------------------------------------------------------------------

void DbClass::put_pipe_property(DbData &db_data)
{
	if (ext_dbase == true)
		dbase->put_class_pipe_property(name, db_data);
	else
	{
		ApiUtil *au = ApiUtil::instance();
		(au->get_db_vect())[db_ind]->put_class_pipe_property(name, db_data);
	}
}

//---------------------------------------------------------------------------------------------------------------------
//
// method:
// 		DbClass::delete_pipe_property()
//
// description:
//		Public method to delete class pipe properties from the database
//
//--------------------------------------------------------------------------------------------------------------------

void DbClass::delete_pipe_property(DbData &db_data)
{
	if (ext_dbase == true)
		dbase->delete_class_pipe_property(name, db_data);
	else
	{
		ApiUtil *au = ApiUtil::instance();
		(au->get_db_vect())[db_ind]->delete_class_pipe_property(name, db_data);
	}
}

} // End of Tango namespace