1 /*
2 * Copyright 2006-2008 The FLWOR Foundation.
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16 #ifndef ZORBA_STORE_UPDATE_CONSTS_H
17 #define ZORBA_STORE_UPDATE_CONSTS_H
18
19 #include <string>
20 #include <zorba/config.h>
21
22 namespace zorba { namespace store {
23
24 /*******************************************************************************
25
26 ********************************************************************************/
27 class UpdateConsts
28 {
29 public:
30 typedef enum
31 {
32 INTO,
33 AS_FIRST_INTO,
34 AS_LAST_INTO,
35 AFTER,
36 BEFORE
37 }
38 InsertType;
39
40 typedef enum
41 {
42 VALUE_OF_NODE,
43 NODE
44 }
45 ReplaceType;
46
47
48 enum UpdPrimKind
49 {
50 UP_DELETE,
51 UP_INSERT_INTO,
52 UP_INSERT_INTO_FIRST,
53 UP_INSERT_INTO_LAST,
54 UP_INSERT_BEFORE,
55 UP_INSERT_AFTER,
56 UP_INSERT_ATTRIBUTES,
57 UP_REPLACE_CHILD,
58 UP_REPLACE_ATTRIBUTE,
59 UP_REPLACE_CONTENT,
60 UP_REPLACE_ATTR_VALUE,
61 UP_REPLACE_TEXT_VALUE,
62 UP_REPLACE_PI_VALUE,
63 UP_REPLACE_COMMENT_VALUE,
64 UP_RENAME_ELEM,
65 UP_RENAME_ATTR,
66 UP_RENAME_PI,
67 UP_SET_ATTRIBUTE_TYPE,
68 UP_SET_ELEMENT_TYPE,
69 UP_REVALIDATE,
70 UP_PUT,
71
72 // collection primitives
73 UP_CREATE_COLLECTION,
74 UP_COLLECTION,
75 UP_DELETE_COLLECTION,
76 UP_INSERT_INTO_COLLECTION,
77 UP_INSERT_FIRST_INTO_COLLECTION,
78 UP_INSERT_LAST_INTO_COLLECTION,
79 UP_INSERT_BEFORE_INTO_COLLECTION,
80 UP_INSERT_AFTER_INTO_COLLECTION,
81 UP_INSERT_AT_INTO_COLLECTION,
82 UP_REMOVE_FROM_COLLECTION,
83 UP_REMOVE_AT_FROM_COLLECTION,
84 UP_TRUNCATE_COLLECTION,
85
86 // index primitives
87 UP_CREATE_INDEX,
88 UP_DROP_INDEX,
89 UP_REBUILD_INDEX,
90
91 // ic primitives
92 UP_ACTIVATE_IC,
93 UP_ACTIVATE_FOREIGN_KEY_IC,
94 UP_DEACTIVATE_IC,
95
96 // doc primitives
97 UP_CREATE_DOCUMENT,
98 UP_DELETE_DOCUMENT,
99
100 // hashmap primitives
101 UP_CREATE_HASHMAP,
102 UP_DESTROY_HASHMAP,
103 UP_INSERT_INTO_HASHMAP,
104 UP_REMOVE_FROM_HASHMAP
105
106 #ifdef ZORBA_WITH_JSON
107 ,
108 UP_JSON_OBJECT_INSERT,
109 UP_JSON_OBJECT_DELETE,
110 UP_JSON_OBJECT_REPLACE_VALUE,
111 UP_JSON_OBJECT_RENAME,
112 UP_JSON_ARRAY_INSERT,
113 UP_JSON_ARRAY_APPEND,
114 UP_JSON_ARRAY_DELETE,
115 UP_JSON_ARRAY_REPLACE_VALUE,
116 #endif
117 };
118
isRename(UpdPrimKind k)119 static bool isRename(UpdPrimKind k)
120 {
121 return (k == UP_RENAME_ELEM || k == UP_RENAME_ATTR || k == UP_RENAME_PI);
122 }
123
isReplaceValue(UpdPrimKind k)124 static bool isReplaceValue(UpdPrimKind k)
125 {
126 return (k == UP_REPLACE_ATTR_VALUE ||
127 k == UP_REPLACE_TEXT_VALUE ||
128 k == UP_REPLACE_PI_VALUE ||
129 k == UP_REPLACE_COMMENT_VALUE);
130 }
131
isReplaceNode(UpdPrimKind k)132 static bool isReplaceNode(UpdPrimKind k)
133 {
134 return (k == UP_REPLACE_CHILD || k == UP_REPLACE_ATTRIBUTE);
135 }
136
137
toString(UpdPrimKind k)138 static std::string toString(UpdPrimKind k)
139 {
140 switch(k)
141 {
142 case UP_DELETE:
143 return "delete";
144 case UP_INSERT_INTO:
145 return "insertInto";
146 case UP_INSERT_INTO_FIRST:
147 return "insertIntoAsFirst";
148 case UP_INSERT_INTO_LAST:
149 return "insertIntoAsLast";
150 case UP_INSERT_BEFORE:
151 return "insertBefore";
152 case UP_INSERT_AFTER:
153 return "insertAfter";
154 case UP_INSERT_ATTRIBUTES:
155 return "insertAttributes";
156 case UP_REPLACE_CHILD:
157 case UP_REPLACE_ATTRIBUTE:
158 return "replaceNode";
159 case UP_REPLACE_CONTENT:
160 return "replaceElementContent";
161 case UP_REPLACE_ATTR_VALUE:
162 case UP_REPLACE_TEXT_VALUE:
163 case UP_REPLACE_PI_VALUE:
164 case UP_REPLACE_COMMENT_VALUE:
165 return "replaceValue";
166 case UP_RENAME_ELEM:
167 case UP_RENAME_ATTR:
168 case UP_RENAME_PI:
169 return "rename";
170 case UP_PUT:
171 return "put";
172 case UP_CREATE_COLLECTION:
173 return "createCollection";
174 case UP_COLLECTION:
175 return "updateCollection";
176 case UP_DELETE_COLLECTION:
177 return "deleteCollection";
178 case UP_INSERT_INTO_COLLECTION:
179 return "insertIntoCollection";
180 case UP_INSERT_FIRST_INTO_COLLECTION:
181 return "insertFirstIntoCollection";
182 case UP_INSERT_LAST_INTO_COLLECTION:
183 return "insertLastIntoCollection";
184 case UP_INSERT_BEFORE_INTO_COLLECTION:
185 return "insertBeforeIntoCollection";
186 case UP_INSERT_AFTER_INTO_COLLECTION:
187 return "insertAfterIntoCollection";
188 case UP_INSERT_AT_INTO_COLLECTION:
189 return "insertAtIntoCollection";
190 case UP_REMOVE_FROM_COLLECTION:
191 return "removeFromCollection";
192 case UP_TRUNCATE_COLLECTION:
193 return "truncateCollection";
194 case UP_REMOVE_AT_FROM_COLLECTION:
195 return "removeAtFromCollection";
196 case UP_CREATE_INDEX:
197 return "createIndex";
198 case UP_DROP_INDEX:
199 return "dropIndex";
200 case UP_REBUILD_INDEX:
201 return "rebuildIndex";
202 case UP_ACTIVATE_IC:
203 return "activateIC";
204 case UP_ACTIVATE_FOREIGN_KEY_IC:
205 return "activateForeignKeyIC";
206 case UP_DEACTIVATE_IC:
207 return "deactivateIC";
208 case UP_CREATE_DOCUMENT:
209 return "createDocument";
210 case UP_DELETE_DOCUMENT:
211 return "deleteDocument";
212 case UP_CREATE_HASHMAP:
213 return "createHashmap";
214 case UP_DESTROY_HASHMAP:
215 return "destroyHashmap";
216 case UP_INSERT_INTO_HASHMAP:
217 return "insertIntoHashmap";
218 case UP_REMOVE_FROM_HASHMAP:
219 return "removeFromHashmap";
220 case UP_SET_ATTRIBUTE_TYPE:
221 return "setAttributeType";
222 case UP_SET_ELEMENT_TYPE:
223 return "setElementType";
224 case UP_REVALIDATE:
225 return "revalidate";
226 #ifdef ZORBA_WITH_JSON
227 case UP_JSON_OBJECT_INSERT:
228 return "jsonObjectInsert";
229 case UP_JSON_OBJECT_DELETE:
230 return "jsonObjectDelete";
231 case UP_JSON_OBJECT_REPLACE_VALUE:
232 return "jsonObjectReplaceValue";
233 case UP_JSON_OBJECT_RENAME:
234 return "jsonObjectRename";
235 case UP_JSON_ARRAY_INSERT:
236 return "jsonArrayInsert";
237 case UP_JSON_ARRAY_DELETE:
238 return "jsonArrayDelete";
239 case UP_JSON_ARRAY_REPLACE_VALUE:
240 return "jsonArrayReplaceValue";
241 #endif
242 default:
243 return "unknownUpdatePrimitive";
244 }
245 }
246 };
247
248
249 }
250 }
251
252 #endif
253 /* vim:set et sw=2 ts=2: */
254