CUBRID Engine  latest
object_template.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  * object_template.h - Definitions for the object manager
21  */
22 
23 #ifndef _OBJECT_TEMPLATE_H_
24 #define _OBJECT_TEMPLATE_H_
25 
26 #ident "$Id$"
27 
28 #if defined (SERVER_MODE)
29 #error Does not belong to server module
30 #endif /* defined (SERVER_MODE) */
31 
32 #include <stdarg.h>
33 
34 #include "area_alloc.h"
35 #include "class_object.h"
36 
37 #define OBT_BASE_OBJECT(template_ptr) \
38  (((template_ptr)->base_object != NULL) ? \
39  (template_ptr)->base_object : (template_ptr)->object)
40 
41 #define OBT_BASE_CLASS(template_ptr) \
42  (((template_ptr)->base_class != NULL) ? \
43  (template_ptr)->base_class : (template_ptr)->class_)
44 
45 #define OBT_BASE_CLASSOBJ(template_ptr) \
46  (((template_ptr)->base_classobj != NULL) ? \
47  (template_ptr)->base_classobj : (template_ptr)->classobj)
48 
49 /*
50  * OBJ_TEMPASSIGN
51  *
52  * Note :
53  * Substructure of OBJ_TEMPLATE. Used to store information about
54  * a pending attribute assignment.
55  */
56 typedef struct obj_tempassign
57 {
58 
59  struct obj_template *obj; /* if new object assignment */
60  DB_VALUE *variable; /* if non-object assignment */
61 
62  /*
63  * cache of attribute definition, must be verified as part
64  * of the outer template validation
65  */
67 
68  /* used for UPDATE templates with triggers */
70 
71  unsigned is_default:1;
72  unsigned is_auto_increment:1;
73 
75 
76 /*
77  * OBJ_TEMPLATE
78  *
79  * Note :
80  * Used to define a set of attribute assignments that are to be
81  * considered as a single operation. Either all of the assignments
82  * will be applied or none.
83  */
84 typedef struct obj_template
85 {
86 
87  /* edited object, NULL if insert template */
88  /*
89  * garbage collector tickets are not required for the object & base_object
90  * fields as the entire object template area is registered for scanning by
91  * area_create().
92  */
94 
95  /* class cache, always set, matches the "object" field */
98 
99  /* base class cache, set only if class cache has a virtual class */
103 
104  /* class cache validation info */
105  int tran_id; /* transaction id at the time the template was created */
106  unsigned int schema_id; /* schema counter at the time the template was created */
107 
108  /* template assignment vector */
110 
111  /* optional address to store new object pointer when created */
113 
114  /* Number of assignments allocated for the vector */
115  int nassigns;
116 
117  /* Used to detect cycles in the template hierarchy */
118  unsigned int traversal;
119 
120  /* how to perform pruning on this template */
122 
123  /* write lock flag */
124  unsigned write_lock:1;
125 
126  /* for detection of cycles in template hierarchy */
127  unsigned traversed:1;
128 
129  /*
130  * set if this is being used for the "old" temporary object in
131  * trigger processing
132  */
133  unsigned is_old_template:1;
134 
135  /*
136  * Set if we're updating class attributes rather than instance attributes.
137  * This happens when the object and the class are the same.
138  */
139  unsigned is_class_update:1;
140 
141  /*
142  * Set if we're doing bulk updates to disable unique checking from
143  * templates.
144  */
145  unsigned check_uniques:1;
146 
147  /*
148  * Set if need to check SERIALIZABLE conflicts
149  */
150  unsigned check_serializable_conflict:1;
151 
152  /*
153  * Set if we ever make an assignment for an attribute that has the
154  * UNIQUE constraint. Speeds up a common test.
155  */
156  unsigned uniques_were_modified:1;
157 
158  /* Set if we ever make an assignment for a shared attribute. */
159  unsigned shared_was_modified:1;
160 
161  /* Set if we should free the template after it is applied */
162  unsigned discard_on_finish:1;
163 
164  /*
165  * true if we ever make an assignment for an attribute that has the
166  * FOREIGN KEY constraint. Speeds up a common test.
167  */
168  unsigned fkeys_were_modified:1;
169 
170  /* Set if we want to flush the object to the server regardless of updating the PRIMARY KEY/UNIQUE constraint. */
171  unsigned force_flush:1;
172 
173  /*
174  * true if we want to regard NULL values in NOT NULL AUTO_INCREMENT
175  * attributes as errors (i.e. when executing UPDATE or ON DUPLICATE KEY
176  * UPDATE statements).
177  */
178  unsigned force_check_not_null:1;
179 
180  /*
181  * Set if we ever make an assignment for an attribute that has the
182  * function key constraint.
183  */
184  unsigned function_key_modified:1;
185 
186  /*
187  * Set if at least one autoincrement column has been populated
188  */
189  unsigned is_autoincrement_set:1;
190 } OBJ_TEMPLATE, *OBT;
191 
192 /*
193  * State used when creating templates, to indicate whether unique constraint
194  * checking is enabled.
195  * This state can be modifed using obt_enable_unique_checking()
196  */
197 extern bool obt_Check_uniques;
198 
199 /*
200  * State variable used when creating object template, to indicate whether enable
201  * auto increment feature
202  */
203 extern bool obt_Enable_autoincrement;
204 
205 /*
206  * State variable used when generating AUTO_INCREMENT value,
207  * to set the first generated AUTO_INCREMENT value as LAST_INSERT_ID.
208  * It is only for client-side insertion.
209  */
210 extern bool obt_Last_insert_id_generated;
211 
212 
213 /* OBJECT TEMPLATE FUNCTIONS */
214 
215 extern OBJ_TEMPLATE *obt_def_object (MOP class_);
216 extern OBJ_TEMPLATE *obt_edit_object (MOP object);
217 extern int obt_quit (OBJ_TEMPLATE * template_ptr);
218 
219 extern int obt_set (OBJ_TEMPLATE * template_ptr, const char *attname, DB_VALUE * value);
220 extern int obt_set_obt (OBJ_TEMPLATE * template_ptr, const char *attname, OBJ_TEMPLATE * value);
221 
222 extern void obt_set_label (OBJ_TEMPLATE * template_ptr, DB_VALUE * label);
223 extern void obt_disable_unique_checking (OBJ_TEMPLATE * template_ptr);
224 extern void obt_disable_serializable_conflict_checking (OBJ_TEMPLATE * template_ptr);
225 extern bool obt_enable_unique_checking (bool new_state);
226 extern void obt_set_force_flush (OBJ_TEMPLATE * template_ptr);
227 extern void obt_reset_force_flush (OBJ_TEMPLATE * template_ptr);
228 extern int obt_update (OBJ_TEMPLATE * template_ptr, MOP * newobj);
229 extern int obt_assign (OBJ_TEMPLATE * template_ptr, SM_ATTRIBUTE * att, int base_assignment, DB_VALUE * value,
230  SM_VALIDATION * valid);
231 
232 /* UTILITY FUNCTIONS */
233 
234 extern DB_VALUE *obt_check_assignment (SM_ATTRIBUTE * att, DB_VALUE * proposed_value, SM_VALIDATION * valid,
235  unsigned force_check_not_null);
236 extern int obt_update_internal (OBJ_TEMPLATE * template_ptr, MOP * newobj, int check_non_null);
237 extern int obt_area_init (void);
238 extern void obt_area_final (void);
239 extern int obt_find_attribute (OBJ_TEMPLATE * template_ptr, int use_base_class, const char *name, SM_ATTRIBUTE ** attp);
240 extern int obt_desc_set (OBJ_TEMPLATE * template_ptr, SM_DESCRIPTOR * desc, DB_VALUE * value);
241 extern int obt_check_missing_assignments (OBJ_TEMPLATE * template_ptr);
242 extern int obt_populate_known_arguments (OBJ_TEMPLATE * template_ptr);
243 extern void obt_retain_after_finish (OBJ_TEMPLATE * template_ptr);
244 extern void obt_begin_insert_values (void);
245 #endif /* _OBJECT_TEMPLATE_H_ */
int obt_set_obt(OBJ_TEMPLATE *template_ptr, const char *attname, OBJ_TEMPLATE *value)
struct obj_tempassign OBJ_TEMPASSIGN
void obt_set_force_flush(OBJ_TEMPLATE *template_ptr)
void obt_area_final(void)
bool obt_Check_uniques
DB_VALUE * old_value
bool obt_enable_unique_checking(bool new_state)
void obt_begin_insert_values(void)
DB_VALUE * obt_check_assignment(SM_ATTRIBUTE *att, DB_VALUE *proposed_value, SM_VALIDATION *valid, unsigned force_check_not_null)
unsigned int traversal
DB_VALUE * label
void obt_disable_unique_checking(OBJ_TEMPLATE *template_ptr)
OBJ_TEMPASSIGN ** assignments
int obt_set(OBJ_TEMPLATE *template_ptr, const char *attname, DB_VALUE *value)
int obt_quit(OBJ_TEMPLATE *template_ptr)
void obt_disable_serializable_conflict_checking(OBJ_TEMPLATE *template_ptr)
void obt_reset_force_flush(OBJ_TEMPLATE *template_ptr)
int obt_update(OBJ_TEMPLATE *template_ptr, MOP *newobj)
int obt_check_missing_assignments(OBJ_TEMPLATE *template_ptr)
int obt_assign(OBJ_TEMPLATE *template_ptr, SM_ATTRIBUTE *att, int base_assignment, DB_VALUE *value, SM_VALIDATION *valid)
int obt_desc_set(OBJ_TEMPLATE *template_ptr, SM_DESCRIPTOR *desc, DB_VALUE *value)
struct obj_template * obj
void obt_set_label(OBJ_TEMPLATE *template_ptr, DB_VALUE *label)
struct obj_template OBJ_TEMPLATE
int obt_populate_known_arguments(OBJ_TEMPLATE *template_ptr)
unsigned int schema_id
int obt_area_init(void)
unsigned is_auto_increment
OBJ_TEMPLATE * obt_edit_object(MOP object)
bool obt_Enable_autoincrement
SM_CLASS * base_class
int obt_update_internal(OBJ_TEMPLATE *template_ptr, MOP *newobj, int check_non_null)
DB_VALUE * variable
bool obt_Last_insert_id_generated
unsigned is_default
int obt_find_attribute(OBJ_TEMPLATE *template_ptr, int use_base_class, const char *name, SM_ATTRIBUTE **attp)
SM_ATTRIBUTE * att
OBJ_TEMPLATE * obt_def_object(MOP class_)
void obt_retain_after_finish(OBJ_TEMPLATE *template_ptr)
SM_CLASS * class_
struct obj_template * OBT