summaryrefslogtreecommitdiffstats
path: root/reladminif/oidif.hh
blob: 33ce76016d2e94dd8d751b288664cdb9f597e4ba (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
#ifndef _OIDIF_HH_
#define _OIDIF_HH_

/*
* 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>.
*/
/************************************************************************
 *
 *
 * PURPOSE:
 *	 
 *
 * COMMENTS:
 *
 ***********************************************************************/

 //@ManMemo: Module: {\bf adminif}.

class OId;

#include <iostream>

#include "raslib/error.hh"

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

//@ManMemo: Module: {\bf reladminif}.
/*@Doc:
the oid is a structure containing a counter and a type field.  based on the type
it is possible to determine the type of the object the oid is refering to.
the counter is used to pinpoint the exact instance of the object.

currently there are 19 different persistent classes.

the counter and type information is encoded into a double:
ID_MULTIPLIER * counter + type;
the counters for each oid type are stored in the database.  their exact value is read
when the transaction starts.   the values are updated in the database at the end of a
transaction.  this can be a problem with multiple concurrent open read/write
transactions.
*/


class OId
	{ 
	public:
		enum OIdType {	INVALID = 0,
				MDDOID,
				MDDCOLLOID,
				MDDTYPEOID,
				MDDBASETYPEOID,
				MDDDIMTYPEOID,
				MDDDOMTYPEOID,
				STRUCTTYPEOID,
				SETTYPEOID,
				BLOBOID,
				DBMINTERVALOID,
				STORAGEOID,
				MDDHIERIXOID,
				DBTCINDEXOID,
				INLINETILEOID,
				INNEROID,
				ATOMICTYPEOID,
				UDFOID,
				UDFPACKAGEOID,
				MDDRCIXOID};
		/*@Doc: 
		every persistent class needs a unique OIdType.
		There is as always an exception: INNEROID is only used by DBTCIndex internally
		*/

		typedef int OIdCounter;
		/*@Doc: 
		every persistent object needs a unique OIdCounter within all persistent objects
		with the same OIdType.
		*/

		typedef double OIdPrimitive;
		/*@Doc: 
		an oid can be converted from and to a primitive of this type.
		*/

		static OIdPrimitive ID_MULTIPLIER;
		/*@Doc: 
		is used to calculate the actual id and type from a given double
		*/

		static void allocateOId(OId& id, OIdType type, OIdCounter howMany = 1);
		/*@Doc: 
		allocates a OId for an object of the specified type or a whole bunch of them.
		*/

		static void deinitialize();
		/*@Doc: 
		writes the current state of the oid counters back
		into the database.
		*/

		static void initialize();
		/*@Doc: 
		reads the state of the oid counters from the database.
		*/

		OId::OIdType getType() const;
		/*@Doc: 
		Returns type of the object with this OId.
		*/
		
		OId(const OId& oldOId);
		/*@Doc: 
		Copy constructor
		*/

		OId(OIdCounter newId, OIdType type);
		/*@Doc: 
		New OId with counter = newId, oidtype = type
		*/

		OId(OIdPrimitive oidd);
		/*@Doc: 
		generate a oid from a double.
		*/
	 
		OId();
		/*@Doc: 
		invalid oid
		*/
	 
		OIdCounter getCounter() const;
		/*@Doc: 
		returns the counter part of the oid.
		*/
	 
		void print_status(std::ostream& s = std::cout) const;
		/*@Doc: 
		prints a double
		*/

		operator double() const;
		/*@Doc: 
		converts the oid to a double:
		oid * OId::ID_MULTIPLIER + oidtype;
		*/

		static const char* counterNames[];
		/*@Doc: 
		holds the names of the counters in RAS_ADMIN, to go with counterIds
		*/

		static unsigned int maxCounter;

		OId& operator=(const OId& old);

		bool operator== (const OId& one) const;

		bool operator!= (const OId& one) const;

		bool operator< (const OId& old) const;

		bool operator> (const OId& old) const;

		bool operator<= (const OId& old) const;

		bool operator>= (const OId& old) const;

	protected:
		// protection agains writing back unloaded counters => inconsistent DB!!
		static bool loadedOk;
		
		
		OIdCounter oid;
		/*@Doc: 
		the counter inside the oid
		*/
		
		OIdType oidtype;
		/*@Doc: 
		the type of object
		*/

		static OIdCounter nextMDDOID;
		/*@Doc: 
		counter which holds the next oid
		*/

		static OIdCounter nextMDDCOLLOID;
		/*@Doc: 
		counter which holds the next oid
		*/

		static OIdCounter nextMDDTYPEOID;
		/*@Doc: 
		counter which holds the next oid
		*/

		static OIdCounter nextMDDBASETYPEOID;
		/*@Doc: 
		counter which holds the next oid
		*/

		static OIdCounter nextMDDDIMTYPEOID;
		/*@Doc: 
		counter which holds the next oid
		*/

		static OIdCounter nextMDDDOMTYPEOID;
		/*@Doc: 
		counter which holds the next oid
		*/

		static OIdCounter nextSTRUCTTYPEOID;
		/*@Doc: 
		counter which holds the next oid
		*/

		static OIdCounter nextSETTYPEOID;
		/*@Doc: 
		counter which holds the next oid
		*/

		static OIdCounter nextBLOBOID;
		/*@Doc: 
		counter which holds the next oid
		*/

		static OIdCounter nextDBMINTERVALOID;
		/*@Doc: 
		counter which holds the next oid
		*/

		static OIdCounter nextSTORAGEOID;
		/*@Doc: 
		counter which holds the next oid
		*/

		static OIdCounter nextMDDHIERIXOID;
		/*@Doc: 
		counter which holds the next oid
		*/

		//static OIdCounter nextDBTCINDEXOID;
		/*@Doc: 
		this counter is not used because mddhierix takes care of that
		*/

		//static OIdCounter nextINLINETILEOID;
		/*@Doc: 
		not used because they are the same as bloboid counter
		*/

		static OIdCounter nextATOMICTYPEOID;
		/*@Doc:
		not used now because they are hard coded
		*/

		static OIdCounter nextMDDRCIXOID;
		/*@Doc: 
		counter which holds the next oid
		*/

		static OIdCounter nextUDFOID;
		/*@Doc: 
		counter which holds the next oid
		*/

		static OIdCounter nextUDFPACKAGEOID;
		/*@Doc: 
		counter which holds the next oid
		*/

		static OIdCounter* counterIds[];
		/*@Doc: 
		holds all OIdCounters of next* sort, to go with the counterNames.
		*/

	};

extern std::ostream& operator<<(std::ostream& in, const OId& d);

extern std::ostream& operator<<(std::ostream& in, OId::OIdType d);

extern bool operator== (const OId::OIdPrimitive one, const OId& two);

extern bool operator== (const OId& two, const OId::OIdPrimitive one);

#endif