rasdaman complete source
oidif.hh
Go to the documentation of this file.
1 #ifndef _OIDIF_HH_
2 #define _OIDIF_HH_
3 
4 /*
5 * This file is part of rasdaman community.
6 *
7 * Rasdaman community is free software: you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation, either version 3 of the License, or
10 * (at your option) any later version.
11 *
12 * Rasdaman community is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
16 *
17 * You should have received a copy of the GNU General Public License
18 * along with rasdaman community. If not, see <http://www.gnu.org/licenses/>.
19 *
20 * Copyright 2003, 2004, 2005, 2006, 2007, 2008, 2009 Peter Baumann /
21 rasdaman GmbH.
22 *
23 * For more information please see <http://www.rasdaman.org>
24 * or contact Peter Baumann via <baumann@rasdaman.com>.
25 */
26 /************************************************************************
27  *
28  *
29  * PURPOSE:
30  *
31  *
32  * COMMENTS:
33  *
34  ***********************************************************************/
35 
36 //@ManMemo: Module: {\bf adminif}.
37 
38 class OId;
39 
40 #include <iostream>
41 
42 #include "raslib/error.hh"
43 
44 #ifdef RMANBENCHMARK
45 #include "raslib/rmdebug.hh"
46 #endif
47 
48 //@ManMemo: Module: {\bf reladminif}.
49 /*@Doc:
50 the oid is a structure containing a counter and a type field. based on the type
51 it is possible to determine the type of the object the oid is refering to.
52 the counter is used to pinpoint the exact instance of the object.
53 
54 currently there are 19 different persistent classes.
55 
56 the counter and type information is encoded into a double:
57 ID_MULTIPLIER * counter + type;
58 the counters for each oid type are stored in the database. their exact value is read
59 when the transaction starts. the values are updated in the database at the end of a
60 transaction. this can be a problem with multiple concurrent open read/write
61 transactions.
62 */
63 
67 class OId
68 {
69 public:
70  enum OIdType { INVALID = 0,
90  };
91  /*@Doc:
92  every persistent class needs a unique OIdType.
93  There is as always an exception: INNEROID is only used by DBTCIndex internally
94  */
95 
96  typedef int OIdCounter;
97  /*@Doc:
98  every persistent object needs a unique OIdCounter within all persistent objects
99  with the same OIdType.
100  */
101 
102  typedef double OIdPrimitive;
103  /*@Doc:
104  an oid can be converted from and to a primitive of this type.
105  */
106 
108  /*@Doc:
109  is used to calculate the actual id and type from a given double
110  */
111 
112  static void allocateOId(OId& id, OIdType type, OIdCounter howMany = 1);
113  /*@Doc:
114  allocates a OId for an object of the specified type or a whole bunch of them.
115  */
116 
117  static void deinitialize();
118  /*@Doc:
119  writes the current state of the oid counters back
120  into the database.
121  */
122 
123  static void initialize();
124  /*@Doc:
125  reads the state of the oid counters from the database.
126  */
127 
128  OId::OIdType getType() const;
129  /*@Doc:
130  Returns type of the object with this OId.
131  */
132 
133  OId(const OId& oldOId);
134  /*@Doc:
135  Copy constructor
136  */
137 
138  OId(OIdCounter newId, OIdType type);
139  /*@Doc:
140  New OId with counter = newId, oidtype = type
141  */
142 
143  OId(OIdPrimitive oidd);
144  /*@Doc:
145  generate a oid from a double.
146  */
147 
148  OId();
149  /*@Doc:
150  invalid oid
151  */
152 
153  OIdCounter getCounter() const;
154  /*@Doc:
155  returns the counter part of the oid.
156  */
157 
158  void print_status(std::ostream& s = std::cout) const;
159  /*@Doc:
160  prints a double
161  */
162 
163  operator double() const;
164  /*@Doc:
165  converts the oid to a double:
166  oid * OId::ID_MULTIPLIER + oidtype;
167  */
168 
169  static const char* counterNames[];
170  /*@Doc:
171  holds the names of the counters in RAS_ADMIN, to go with counterIds
172  */
173 
174  static unsigned int maxCounter;
175 
176  OId& operator=(const OId& old);
177 
178  bool operator== (const OId& one) const;
179 
180  bool operator!= (const OId& one) const;
181 
182  bool operator< (const OId& old) const;
183 
184  bool operator> (const OId& old) const;
185 
186  bool operator<= (const OId& old) const;
187 
188  bool operator>= (const OId& old) const;
189 
190 #ifdef RMANBENCHMARK
191  static RMTimer oidAlloc;
192  static RMTimer oidResolve;
193 #endif
194 protected:
195  // protection agains writing back unloaded counters => inconsistent DB!!
196  static bool loadedOk;
197 
198 
200  /*@Doc:
201  the counter inside the oid
202  */
203 
205  /*@Doc:
206  the type of object
207  */
208 
210  /*@Doc:
211  counter which holds the next oid
212  */
213 
215  /*@Doc:
216  counter which holds the next oid
217  */
218 
220  /*@Doc:
221  counter which holds the next oid
222  */
223 
225  /*@Doc:
226  counter which holds the next oid
227  */
228 
230  /*@Doc:
231  counter which holds the next oid
232  */
233 
235  /*@Doc:
236  counter which holds the next oid
237  */
238 
240  /*@Doc:
241  counter which holds the next oid
242  */
243 
245  /*@Doc:
246  counter which holds the next oid
247  */
248 
250  /*@Doc:
251  counter which holds the next oid
252  */
253 
255  /*@Doc:
256  counter which holds the next oid
257  */
258 
260  /*@Doc:
261  counter which holds the next oid
262  */
263 
265  /*@Doc:
266  counter which holds the next oid
267  */
268 
269  //static OIdCounter nextDBTCINDEXOID;
270  /*@Doc:
271  this counter is not used because mddhierix takes care of that
272  */
273 
274  //static OIdCounter nextINLINETILEOID;
275  /*@Doc:
276  not used because they are the same as bloboid counter
277  */
278 
280  /*@Doc:
281  not used now because they are hard coded
282  */
283 
285  /*@Doc:
286  counter which holds the next oid
287  */
288 
290  /*@Doc:
291  counter which holds the next oid
292  */
293 
295  /*@Doc:
296  counter which holds the next oid
297  */
298 
300  /*@Doc:
301  holds all OIdCounters of next* sort, to go with the counterNames.
302  */
303 };
304 
305 extern std::ostream& operator<<(std::ostream& in, const OId& d);
306 
307 extern std::ostream& operator<<(std::ostream& in, OId::OIdType d);
308 
309 extern bool operator== (const OId::OIdPrimitive one, const OId& two);
310 
311 extern bool operator== (const OId& two, const OId::OIdPrimitive one);
312 
313 #endif
OIdType
Definition: oidif.hh:70
static const char * counterNames[]
Definition: oidif.hh:169
Definition: oidif.hh:82
Definition: oidif.hh:71
Definition: oidif.hh:85
OIdCounter oid
Definition: oidif.hh:199
std::ostream & operator<<(std::ostream &in, const OId &d)
static OIdCounter nextMDDTYPEOID
Definition: oidif.hh:219
Definition: oidif.hh:80
bool operator!=(const OId &one) const
static void allocateOId(OId &id, OIdType type, OIdCounter howMany=1)
static OIdCounter nextUDFPACKAGEOID
Definition: oidif.hh:294
bool operator==(const OId &one) const
void print_status(std::ostream &s=std::cout) const
Definition: oidif.hh:83
Definition: oidif.hh:88
Definition: oidif.hh:78
static OIdCounter nextATOMICTYPEOID
Definition: oidif.hh:279
Definition: oidif.hh:76
Definition: oidif.hh:67
static OIdCounter nextMDDDIMTYPEOID
Definition: oidif.hh:229
bool operator>(const OId &old) const
Definition: oidif.hh:81
Definition: oidif.hh:89
Definition: oidif.hh:87
Definition: oidif.hh:79
static OIdCounter nextMDDBASETYPEOID
Definition: oidif.hh:224
OId::OIdType getType() const
static OIdCounter nextUDFOID
Definition: oidif.hh:289
bool operator<=(const OId &old) const
OIdCounter getCounter() const
int OIdCounter
Definition: oidif.hh:96
double OIdPrimitive
Definition: oidif.hh:102
bool operator<(const OId &old) const
static OIdCounter nextBLOBOID
Definition: oidif.hh:249
Definition: oidif.hh:72
static OIdCounter nextSETTYPEOID
Definition: oidif.hh:244
static OIdCounter nextMDDRCIXOID
Definition: oidif.hh:284
static OIdCounter nextMDDCOLLOID
Definition: oidif.hh:214
static void initialize()
Definition: oidif.hh:84
Definition: oidif.hh:77
static OIdCounter nextSTORAGEOID
Definition: oidif.hh:259
Definition: oidif.hh:86
bool operator==(const OId::OIdPrimitive one, const OId &two)
static OIdCounter nextDBMINTERVALOID
Definition: oidif.hh:254
static OIdCounter nextMDDDOMTYPEOID
Definition: oidif.hh:234
static OIdCounter nextMDDOID
Definition: oidif.hh:209
Module: { raslib}.
Definition: rmdebug.hh:298
static OIdCounter nextMDDHIERIXOID
Definition: oidif.hh:264
OIdType oidtype
Definition: oidif.hh:204
static OIdCounter nextSTRUCTTYPEOID
Definition: oidif.hh:239
static bool loadedOk
Definition: oidif.hh:196
OId & operator=(const OId &old)
static OIdPrimitive ID_MULTIPLIER
Definition: oidif.hh:107
bool operator>=(const OId &old) const
Definition: oidif.hh:73
Definition: oidif.hh:75
static void deinitialize()
static OIdCounter * counterIds[]
Definition: oidif.hh:299
static unsigned int maxCounter
Definition: oidif.hh:174
Definition: oidif.hh:74
Definition: oidif.hh:70