summaryrefslogtreecommitdiffstats
path: root/reladminif/objectbroker.hh
blob: bb8d4293698e88fce84e1be7cc6d99ab272048ae (plain)
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
/*
* This file is part of rasdaman community.
*
* Rasdaman community is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* Rasdaman community 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 General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with rasdaman community.  If not, see <http://www.gnu.org/licenses/>.
*
* Copyright 2003, 2004, 2005, 2006, 2007, 2008, 2009 Peter Baumann /
rasdaman GmbH.
*
* For more information please see <http://www.rasdaman.org>
* or contact Peter Baumann via <baumann@rasdaman.com>.
*/
#ifndef _OBJECTBROKER_HH_
#define _OBJECTBROKER_HH_

class ObjectBroker;
class ULongType;
class LongType;
class CharType;
class BoolType;
class UShortType;
class ShortType;
class OctetType;
class DoubleType;
class FloatType;
class ComplexType1;
class ComplexType2;
class StructType;
class BaseType;
class SetType;
class MDDType;
class Type;
class DBObject;

#include "oidif.hh"
#include "raslib/error.hh"
#include "lists.h"

#ifdef RMANBENCHMARK
#include "raslib/rmdebug.hh"
#endif

//@ManMemo: Module: {\bf reladminif}.
/*@Doc:
the ObjectBroker is one of the three columns one which the persistence layer rests:
ObjectBroker, DBRef, DBObject.
the ObjectBroker keeps track of all persistent objects which are loaded into memory.
objects register themselves at this facility and deregister themselves when they are 
deleted.

The ObjectBroker supplies functionality for accessing persistent objects by oid and by
name.
The ObjectBroker can be configured to serve as a cross transaction cache.
The ObejctBroker can retrieve the oids of all objects of a specific type which are stored
in the database.
The list of objects which are kept by the ObjectBroker are cleared by TransactionIf.
*/

class ObjectBroker
	{
	public:
		static bool freeMemory() throw (r_Error);
		/*@Doc: 
		this will handle the memory issue.
		returns true if memory was freed, false otherwise.
		if false is returned there is really to much memory allocated and the transaction should be stopped.
		*/

		static void deregisterTileIndexMapping(const OId& tileoid, const OId& indexoid);
		/*@Doc: 
		deletes the object in the correct list
		*/

		static void registerTileIndexMapping(const OId& tileoid, const OId& indexoid);
		/*@Doc: 
		inserts the object in the correct list
		*/

		static void registerDBObject(DBObject* object);
		/*@Doc: 
		inserts the object in the correct list
		*/

		static void deregisterDBObject(const OId& id);
		/*@Doc: 
		removes the object with the specified oid from the list
		*/
	
		static DBObject* getObjectByOId(const OId& id) throw (r_Error);
		/*@Doc: 
		retrieve a dbobject from db.  passes (r_Error)s from DBObject up.
		*/

		static DBObject* isInMemory(const OId& id) throw (r_Error);
		/*@Doc: 
		does not retrieve the object from db.  only retrieves from memory.
		if there is no matching object a 0 pointer is returned.
		throws an (r_Error) if the OId has a invalid type 
		*/

		static OIdSet* getAllObjects(OId::OIdType type);
		/*@Doc: 
		generates a list of all objects in the db and in memory with the
		specified type.  the vector must be deleted by the calling function
		*/

		static MDDType* getMDDTypeByName(const char* name) throw (r_Error);
		/*@Doc:
		retrieves an object with that name and that type from the db.
		this method was introduced to remove the spurious sqlwarnings.
		passes (r_Error)s from DBObject up or ObjectNotFound when there is
		no matching object
		*/

		static DBObject* getObjectByName(OId::OIdType type, const char* name) throw (r_Error);
		/*@Doc:
		retrieves an object with that name and that type from the db.
		passes (r_Error)s from DBObject up or ObjectNotFound when there is
		no matching object
		*/

		static void clearBroker() throw (r_Error);
		/*@Doc:
		deletes persistent objects from memory, depending on cache ofcourse.
		any (r_Error)s thrown during the deletion/update/insert process are
		handed up.  the objects are removed before errors can occur.  multiple
		calls to clearBroker until the method completes are possible.  memory
		leaks may occur in this event.
		*/

		static void clearCache() throw (r_Error);
		/*@Doc:
		deletes _all_ persistent objects from memory.
		any (r_Error)s thrown during the deletion/update/insert process are
		handed up.  the objects are removed before errors can occur.  multiple
		calls to clearBroker until the method completes are possible.  memory
		leaks may occur in this event.
		*/

		static void init();
		/*@Doc:
		initialize the atomic types and maps 
		*/
		
		static void deinit();
		/*@Doc:
		delete the atomic types and maps 
		*/
		
		static DBObjectPMap& getMap(OId::OIdType type) throw (r_Error);
		/*@Doc:
		returns a pointer to the store of objects of that particular type.
		(r_Error) is thrown if there is no map for that type
		*/

	protected:
		static DBObject* loadDBMDDObj(const OId& id) throw (r_Error);
		/*@Doc:
		retrieves MDDObjects from memory and from database
		*/

		static DBObject* loadMDDSet(const OId& id) throw (r_Error);
		/*@Doc:
		retrieves MDDSets from memory and from database
		*/

		static DBObject* loadMDDType(const OId& id) throw (r_Error);
		/*@Doc:
		retrieves MDDTypes from memory and from database
		*/

		static DBObject* loadMDDBaseType(const OId& id) throw (r_Error);
		/*@Doc:
		retrieves MDDBaseTypes from memory and from database
		*/

		static DBObject* loadMDDDimensionType(const OId& id) throw (r_Error);
		/*@Doc:
		retrieves MDDDimTypes from memory and from database
		*/

		static DBObject* loadMDDDomainType(const OId& id) throw (r_Error);
		/*@Doc:
		retrieves MDDDomTypes from memory and from database
		*/

		static DBObject* loadStructType(const OId& id) throw (r_Error);
		/*@Doc:
		retrieves StructTypes from memory and from database
		*/

		static DBObject* loadSetType(const OId& id) throw (r_Error);
		/*@Doc:
		retrieves SetTypes from memory and from database
		*/

		static DBObject* loadBLOBTile(const OId& id) throw (r_Error);
		/*@Doc:
		retrieves BLOBTiles from memory and from database.
		knows how to get a inlinetile from a dbtcindex.
		*/

		static DBObject* loadDBMinterval(const OId& id) throw (r_Error);
		/*@Doc:
		retrieves DBMintervals from memory and from database
		*/

		static DBObject* loadDBStorage(const OId& id) throw (r_Error);
		/*@Doc:
		retrieves DBStorageLayout from memory and from database
		*/

		static DBObject* loadDBHierIndex(const OId& id) throw (r_Error);
		/*@Doc:
		retrieves HierIxs from memory and from database
		*/

		static DBObject* loadDBTCIndex(const OId& id) throw (r_Error);
		/*@Doc:
		retrieves DBTCIndex from memory and from database
		*/

		static DBObject* loadInlineTile(const OId& id) throw (r_Error);
		/*@Doc:
		retrieves InlineTiles from memory and from database
		*/

		static DBObject* loadDBRCIndexDS(const OId& id) throw (r_Error);
		/*@Doc:
		retrieves DBRCIndexDS from memory and from database
		*/

		static OId getOIdByName(OId::OIdType type, const char* name) throw (r_Error);
		/*@Doc:
		finds the oid of an object with the given type and name
		*/

		static void clearMap(DBObjectPMap& theMap) throw (r_Error);
		/*@Doc:
		deletes entries in this map as long as they are not cached
		(r_Error) is thrown when there is a problem in ~DBObject.
		the object is removed from the map though.
		*/

		static void completelyClearMap(DBObjectPMap& theMap) throw (r_Error);
		/*@Doc:
		deletes entries in this map
		(r_Error) is thrown when there is a problem in ~DBObject.
		the object is removed from the map though.
		*/


		static OId getOIdOfMDDSet(const char* name) throw (r_Error);
		/*@Doc:
		retrieves MDDSets from memory and from database
		*/

		static OId getOIdOfMDDType(const char* name) throw (r_Error);
		/*@Doc:
		retrieves MDDTypes from memory and from database
		*/

		static OId getOIdOfMDDBaseType(const char* name) throw (r_Error);
		/*@Doc:
		retrieves MDDBaseTypes from memory and from database
		*/

		static OId getOIdOfMDDDimensionType(const char* name) throw (r_Error);
		/*@Doc:
		retrieves MDDDimTypes from memory and from database
		*/

		static OId getOIdOfMDDDomainType(const char* name) throw (r_Error);
		/*@Doc:
		retrieves MDDDomTypes from memory and from database
		*/

		static OId getOIdOfStructType(const char* name) throw (r_Error);
		/*@Doc:
		retrieves StructTypes from memory and from database
		*/

		static OId getOIdOfSetType(const char* name) throw (r_Error);
		/*@Doc:
		retrieves SetTypes from memory and from database
		*/

		static OIdSet* getAllMDDObjects() throw (r_Error);
		/*@Doc:
		retrieves the oids of all MDD Objects from memory and from database
		oidlist must be deallocated by the caller
		(r_Error) occures in a database failure
		*/

		static OIdSet* getAllMDDSets() throw (r_Error);
		/*@Doc:
		retrieves the oids of all MDDSets from memory and from database
		oidlist must be deallocated by the caller
		(r_Error) occures in a database failure
		*/

		static OIdSet* getAllMDDTypes() throw (r_Error);
		/*@Doc:
		retrieves the oids of all MDDTypes from memory and from database
		oidlist must be deallocated by the caller
		(r_Error) occures in a database failure
		*/

		static OIdSet* getAllMDDBaseTypes() throw (r_Error);
		/*@Doc:
		retrieves the oids of all MDDBaseTypes from memory and from database
		oidlist must be deallocated by the caller
		(r_Error) occures in a database failure
		*/

		static OIdSet* getAllMDDDimensionTypes() throw (r_Error);
		/*@Doc:
		retrieves the oids of all MDDDimTypes from memory and from database
		oidlist must be deallocated by the caller
		(r_Error) occures in a database failure
		*/

		static OIdSet* getAllMDDDomainTypes() throw (r_Error);
		/*@Doc:
		retrieves the oids of all MDDDomTypes from memory and from database
		oidlist must be deallocated by the caller
		(r_Error) occures in a database failure
		*/

		static OIdSet* getAllStructTypes() throw (r_Error);
		/*@Doc:
		retrieves the oids of all StructTypes from memory and from database
		oidlist must be deallocated by the caller
		(r_Error) occures in a database failure
		*/

		static OIdSet* getAllSetTypes() throw (r_Error);
		/*@Doc:
		retrieves the oids of all SetTypes from memory and from database
		oidlist must be deallocated by the caller
		(r_Error) occures in a database failure
		*/

		static OIdSet* getAllAtomicTypes() throw (r_Error);
		/*@Doc:
		retrieves the oids of all AtomicTypes from memory
		oidlist must be deallocated by the caller
		(r_Error) should never occur 
		*/

	private:
		///the types have to be in fornt of* the maps because of static destructor!
		static ULongType* theULong;
		/*@Doc:
		a pointer to this member is returned by getObjectByOId().
		*/

		static CharType* theChar;
		/*@Doc:
		a pointer to this member is returned by getObjectByOId().
		*/

		static BoolType* theBool;
		/*@Doc:
		a pointer to this member is returned by getObjectByOId().
		*/
	
		static UShortType* theUShort;
		/*@Doc:
		a pointer to this member is returned by getObjectByOId().
		*/
		
		static LongType* theLong;
		/*@Doc:
		a pointer to this member is returned by getObjectByOId().
		*/
		
		static ShortType* theShort;
		/*@Doc:
		a pointer to this member is returned by getObjectByOId().
		*/
		
		static OctetType* theOctet;
		/*@Doc:
		a pointer to this member is returned by getObjectByOId().
		*/
		
		static DoubleType* theDouble;
		/*@Doc:
		a pointer to this member is returned by getObjectByOId().
		*/
		
		static FloatType* theFloat;
		/*@Doc:
		a pointer to this member is returned by getObjectByOId().
		*/
		
		static ComplexType1* theComplex1;
		/*@Doc:
	 	a pointer to this member is returned by getObjectByOId().
		*/
	
		static ComplexType2* theComplex2;
		/*@Doc:
	 	a pointer to this member is returned by getObjectByOId().
		*/
	
		static DBObjectPMap theDBMDDObjs;
		/*@Doc:
		holds all MDDObjects in memory
		*/

		static DBObjectPMap theMDDSets;
		/*@Doc:
		holds all MDDSets in memory
		*/

		static DBObjectPMap theMDDTypes;
		/*@Doc:
		holds all MDDTypes in memory
		*/

		static DBObjectPMap theMDDBaseTypes;
		/*@Doc:
		holds all MDDBaseTypes in memory
		*/

		static DBObjectPMap theMDDDimensionTypes;
		/*@Doc:
		holds all MDDDimTypes in memory
		*/

		static DBObjectPMap theMDDDomainTypes;
		/*@Doc:
		holds all MDDDomTypes in memory
		*/

		static DBObjectPMap theStructTypes;
		/*@Doc:
		holds all StructTypes in memory
		*/

		static DBObjectPMap theSetTypes;
		/*@Doc:
		holds all SetTypes in memory
		*/

		static DBObjectPMap theBLOBTiles;
		/*@Doc:
		holds all BLOBTiles in memory
		*/

		static DBObjectPMap theDBMintervals;
		/*@Doc:
		holds all DBMintervals in memory
		*/

		static DBObjectPMap theDBStorages;
		/*@Doc:
		holds all MDDEntries in memory
		*/

		static DBObjectPMap theDBHierIndexs;
		/*@Doc:
		holds all HierIxs in memory
		*/

		static DBObjectPMap theDBTCIndexs;
		/*@Doc:
		holds all HierIxs in memory
		*/

		static DBObjectPMap theInlineTiles;
		/*@Doc:
		holds all InlineTiles in memory
		*/

		static DBObjectPMap theAtomicTypes;
		/*@Doc:
		holds all SetTypes in memory
		*/

		static DBObjectPMap theRCIndexes;
		/*@Doc:
		holds all RC Indexes in memory
		*/

		static OIdMap theTileIndexMappings;
		/*@Doc:
		key (first/double) is oid of tile, value (second/oid) is oid of index.
		*/

	};

#endif