CUBRID Engine  latest
oid.h
Go to the documentation of this file.
1 /*
2  * Copyright 2008 Search Solution Corporation
3  * Copyright 2016 CUBRID Corporation
4  *
5  * Licensed under the Apache License, Version 2.0 (the "License");
6  * you may not use this file except in compliance with the License.
7  * You may obtain a copy of the License at
8  *
9  * http://www.apache.org/licenses/LICENSE-2.0
10  *
11  * Unless required by applicable law or agreed to in writing, software
12  * distributed under the License is distributed on an "AS IS" BASIS,
13  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14  * See the License for the specific language governing permissions and
15  * limitations under the License.
16  *
17  */
18 
19 
20 /*
21  * oid.h - OBJECT IDENTIFIER (OID) MODULE (AT CLIENT AND SERVER)
22  */
23 
24 #ifndef _OID_H_
25 #define _OID_H_
26 
27 #ident "$Id$"
28 
29 #include "storage_common.h"
30 #include "dbtype_def.h"
31 
32 #define ROOTCLASS_NAME "Rootclass" /* Name of Rootclass */
33 
34 #define VIRTUAL_CLASS_DIR_OID_MASK (1 << 15)
35 
36 #define OID_INITIALIZER \
37  {NULL_PAGEID, NULL_SLOTID, NULL_VOLID}
38 
39 #define OID_AS_ARGS(oidp) (oidp)->volid, (oidp)->pageid, (oidp)->slotid
40 
41 #if !defined(SERVER_MODE)
42 #define OID_TEMPID_MIN INT_MIN
43 #define OID_INIT_TEMPID() (oid_Next_tempid = NULL_PAGEID)
44 
45 /* The next tempid will NULL_PAGEID if the next tempid value is underflow */
46 #define OID_NEXT_TEMPID() \
47  ((--oid_Next_tempid <= OID_TEMPID_MIN) ? NULL_PAGEID : oid_Next_tempid)
48 
49 #define OID_ASSIGN_TEMPOID(oidp) ((oidp)->volid = NULL_VOLID, \
50  (oidp)->pageid = OID_NEXT_TEMPID(), \
51  (oidp)->slotid = - tm_Tran_index)
52 #endif /* !SERVER_MODE */
53 
54 #define SET_OID(dest_oid_ptr, vol_id, page_id, slot_id) \
55  do \
56  { \
57  (dest_oid_ptr)->volid = vol_id; \
58  (dest_oid_ptr)->pageid = page_id; \
59  (dest_oid_ptr)->slotid = slot_id; \
60  } \
61  while (0)
62 
63 #define COPY_OID(dest_oid_ptr, src_oid_ptr) \
64  do \
65  { \
66  *(dest_oid_ptr) = *(src_oid_ptr); \
67  } \
68  while (0)
69 
70 #define SAFE_COPY_OID(dest_oid_ptr, src_oid_ptr) \
71  if (src_oid_ptr) \
72  { \
73  *(dest_oid_ptr) = *(src_oid_ptr); \
74  } \
75  else \
76  { \
77  OID_SET_NULL (dest_oid_ptr); \
78  }
79 
80 #define OID_ISTEMP(oidp) ((oidp)->pageid < NULL_PAGEID)
81 #define OID_ISNULL(oidp) ((oidp)->pageid == NULL_PAGEID)
82 #define OID_IS_ROOTOID(oidp) (OID_EQ((oidp), oid_Root_class_oid))
83 #define OID_IS_PSEUDO_OID(oidp) ((oidp)->volid < NULL_VOLID)
84 
85 #define OID_SET_NULL(oidp) \
86  do { \
87  (oidp)->pageid = NULL_PAGEID; \
88  (oidp)->slotid = NULL_SLOTID; \
89  (oidp)->volid = NULL_VOLID; \
90  } while(0)
91 
92 #define OID_EQ(oidp1, oidp2) \
93  ((oidp1) == (oidp2) || ((oidp1)->pageid == (oidp2)->pageid && \
94  (oidp1)->slotid == (oidp2)->slotid && \
95  (oidp1)->volid == (oidp2)->volid))
96 
97 #define OID_GT(oidp1, oidp2) \
98  ((oidp1) != (oidp2) && \
99  ((oidp1)->volid > (oidp2)->volid || \
100  ((oidp1)->volid == (oidp2)->volid && (oidp1)->pageid > (oidp2)->pageid) ||\
101  ((oidp1)->volid == (oidp2)->volid && (oidp1)->pageid == (oidp2)->pageid \
102  && (oidp1)->slotid > (oidp2)->slotid)))
103 
104 #define OID_GTE(oidp1, oidp2) \
105  ((oidp1) == (oidp2) || \
106  ((oidp1)->volid > (oidp2)->volid || \
107  ((oidp1)->volid == (oidp2)->volid && (oidp1)->pageid > (oidp2)->pageid) ||\
108  ((oidp1)->volid == (oidp2)->volid && (oidp1)->pageid == (oidp2)->pageid \
109  && (oidp1)->slotid > (oidp2)->slotid) || \
110  ((oidp1)->volid == (oidp2)->volid && (oidp1)->pageid == (oidp2)->pageid \
111  && (oidp1)->slotid == (oidp2)->slotid)))
112 
113 #define OID_LT(oidp1, oidp2) \
114  ((oidp1) != (oidp2) && \
115  ((oidp1)->volid < (oidp2)->volid || \
116  ((oidp1)->volid == (oidp2)->volid && (oidp1)->pageid < (oidp2)->pageid) ||\
117  ((oidp1)->volid == (oidp2)->volid && (oidp1)->pageid == (oidp2)->pageid \
118  && (oidp1)->slotid < (oidp2)->slotid)))
119 
120 #define OID_LTE(oidp1, oidp2) \
121  ((oidp1) == (oidp2) || \
122  ((oidp1)->volid < (oidp2)->volid || \
123  ((oidp1)->volid == (oidp2)->volid && (oidp1)->pageid < (oidp2)->pageid) ||\
124  ((oidp1)->volid == (oidp2)->volid && (oidp1)->pageid == (oidp2)->pageid \
125  && (oidp1)->slotid < (oidp2)->slotid) || \
126  ((oidp1)->volid == (oidp2)->volid && (oidp1)->pageid == (oidp2)->pageid \
127  && (oidp1)->slotid == (oidp2)->slotid)))
128 
129 /* It is used for hashing purposes */
130 #define OID_PSEUDO_KEY(oidp) \
131  ((OID_ISTEMP(oidp)) ? (unsigned int) -((oidp)->pageid) : \
132  ((oidp)->slotid | (((unsigned int)(oidp)->pageid) << 8)) ^ \
133  ((((unsigned int)(oidp)->pageid) >> 8) | \
134  (((unsigned int)(oidp)->volid) << 24)))
135 
136 #define OID_IS_VIRTUAL_CLASS_OF_DIR_OID(oidp) \
137  ((((oidp)->slotid & VIRTUAL_CLASS_DIR_OID_MASK) \
138  == VIRTUAL_CLASS_DIR_OID_MASK) ? true : false)
139 
140 #define OID_GET_VIRTUAL_CLASS_OF_DIR_OID(class_oidp,virtual_oidp) \
141  do \
142  { \
143  (virtual_oidp)->volid = (class_oidp)->volid; \
144  (virtual_oidp)->pageid = (class_oidp)->pageid; \
145  (virtual_oidp)->slotid = ((class_oidp)->slotid) \
146  | VIRTUAL_CLASS_DIR_OID_MASK; \
147  } \
148  while (0)
149 
150 #define OID_GET_REAL_CLASS_OF_DIR_OID(virtual_oidp,class_oidp) \
151  do \
152  { \
153  (class_oidp)->volid = (virtual_oidp)->volid; \
154  (class_oidp)->pageid = (virtual_oidp)->pageid; \
155  (class_oidp)->slotid = ((virtual_oidp)->slotid) \
156  & (~VIRTUAL_CLASS_DIR_OID_MASK); \
157  } \
158  while (0)
159 
160 enum
161 {
188 
190 };
191 
192 extern const OID oid_Null_oid;
193 extern OID *oid_Root_class_oid;
194 extern OID *oid_Serial_class_oid;
195 extern OID *oid_User_class_oid;
196 extern PAGEID oid_Next_tempid;
197 
198 extern void oid_set_root (const OID * oid);
199 extern bool oid_is_root (const OID * oid);
200 
201 extern void oid_set_serial (const OID * oid);
202 extern bool oid_is_serial (const OID * oid);
203 extern void oid_get_serial_oid (OID * oid);
204 
205 extern void oid_set_partition (const OID * oid);
206 extern bool oid_is_partition (const OID * oid);
207 extern void oid_get_partition_oid (OID * oid);
208 
209 extern bool oid_is_db_class (const OID * oid);
210 extern bool oid_is_db_attribute (const OID * oid);
211 
212 extern int oid_compare (const void *oid1, const void *oid2);
213 extern unsigned int oid_hash (const void *key_oid, unsigned int htsize);
214 extern int oid_compare_equals (const void *key_oid1, const void *key_oid2);
215 extern bool oid_check_cached_class_oid (const int cache_id, const OID * oid);
216 extern void oid_set_cached_class_oid (const int cache_id, const OID * oid);
217 extern const char *oid_get_cached_class_name (const int cache_id);
218 extern bool oid_is_cached_class_oid (const OID * class_oid);
219 extern OID *oid_get_rep_read_tran_oid (void);
220 extern bool oid_is_system_class (const OID * class_oid);
221 #endif /* _OID_H_ */
void oid_get_serial_oid(OID *oid)
Definition: oid.c:171
int oid_compare(const void *oid1, const void *oid2)
Definition: oid.c:243
void oid_get_partition_oid(OID *oid)
Definition: oid.c:207
bool oid_is_cached_class_oid(const OID *class_oid)
Definition: oid.c:364
const OID oid_Null_oid
Definition: oid.c:68
unsigned int oid_hash(const void *key_oid, unsigned int htsize)
Definition: oid.c:294
bool oid_is_partition(const OID *oid)
Definition: oid.c:195
bool oid_is_root(const OID *oid)
Definition: oid.c:135
OID * oid_get_rep_read_tran_oid(void)
Definition: oid.c:386
void oid_set_cached_class_oid(const int cache_id, const OID *oid)
Definition: oid.c:339
bool oid_is_db_attribute(const OID *oid)
Definition: oid.c:231
OID * oid_Root_class_oid
Definition: oid.c:73
Definition: btree.h:536
bool oid_is_system_class(const OID *class_oid)
Definition: oid.c:400
void oid_set_serial(const OID *oid)
Definition: oid.c:147
bool oid_is_serial(const OID *oid)
Definition: oid.c:159
int oid_compare_equals(const void *key_oid1, const void *key_oid2)
Definition: oid.c:310
OID * oid_Serial_class_oid
Definition: oid.c:76
void oid_set_root(const OID *oid)
Definition: oid.c:118
const char * oid_get_cached_class_name(const int cache_id)
Definition: oid.c:351
PAGEID oid_Next_tempid
Definition: oid.c:70
void oid_set_partition(const OID *oid)
Definition: oid.c:183
OID * oid_User_class_oid
Definition: oid.c:78
bool oid_check_cached_class_oid(const int cache_id, const OID *oid)
Definition: oid.c:327
INT32 PAGEID
bool oid_is_db_class(const OID *oid)
Definition: oid.c:219