Merge lp:~zorba-coders/zorba/bug-938934 into lp:zorba
- bug-938934
- Merge into trunk
Status: | Superseded | ||||
---|---|---|---|---|---|
Proposed branch: | lp:~zorba-coders/zorba/bug-938934 | ||||
Merge into: | lp:zorba | ||||
Diff against target: |
1268 lines (+648/-9) 41 files modified
ChangeLog (+1/-0) include/zorba/pregenerated/diagnostic_list.h (+2/-0) modules/com/zorba-xquery/www/modules/pregenerated/errors.xq (+4/-0) modules/com/zorba-xquery/www/modules/store/dynamic/collections/dml.xq (+16/-3) modules/com/zorba-xquery/www/modules/store/static/collections/dml.xq (+15/-0) src/diagnostics/diagnostic_en.xml (+4/-0) src/diagnostics/pregenerated/diagnostic_list.cpp (+3/-0) src/diagnostics/pregenerated/dict_en.cpp (+1/-0) src/functions/func_collections_impl.cpp (+15/-0) src/functions/pregenerated/func_collections.cpp (+25/-0) src/functions/pregenerated/func_collections.h (+19/-0) src/functions/pregenerated/function_enum.h (+2/-0) src/runtime/collections/collections_impl.cpp (+87/-0) src/runtime/collections/pregenerated/collections.cpp (+28/-0) src/runtime/collections/pregenerated/collections.h (+44/-0) src/runtime/core/apply_updates.cpp (+13/-1) src/runtime/spec/collections/collections.xml (+46/-0) src/runtime/visitors/pregenerated/planiter_visitor.h (+5/-0) src/runtime/visitors/pregenerated/printer_visitor.cpp (+14/-0) src/runtime/visitors/pregenerated/printer_visitor.h (+3/-0) src/store/api/pul.h (+11/-1) src/store/api/update_consts.h (+3/-0) src/store/naive/collection.h (+2/-0) src/store/naive/pul_primitive_factory.cpp (+12/-0) src/store/naive/pul_primitive_factory.h (+10/-0) src/store/naive/pul_primitives.cpp (+25/-0) src/store/naive/pul_primitives.h (+31/-0) src/store/naive/simple_collection.cpp (+11/-0) src/store/naive/simple_collection.h (+3/-0) src/store/naive/simple_index.h (+2/-0) src/store/naive/simple_index_general.cpp (+40/-0) src/store/naive/simple_index_general.h (+4/-0) src/store/naive/simple_pul.cpp (+65/-2) src/store/naive/simple_pul.h (+14/-1) test/rbkt/ExpQueryResults/zorba/collections/delete_nodes/truncate_001.xml.res (+1/-0) test/rbkt/ExpQueryResults/zorba/collections/dynamic6.xml.res (+1/-0) test/rbkt/ExpQueryResults/zorba/index/auctions2.xml.res (+1/-0) test/rbkt/Queries/zorba/collections/collection_002.xqdata (+3/-1) test/rbkt/Queries/zorba/collections/delete_nodes/truncate_001.xq (+27/-0) test/rbkt/Queries/zorba/collections/dynamic6.xq (+10/-0) test/rbkt/Queries/zorba/index/auctions2.xq (+25/-0) |
||||
To merge this branch: | bzr merge lp:~zorba-coders/zorba/bug-938934 | ||||
Related bugs: |
|
Reviewer | Review Type | Date Requested | Status |
---|---|---|---|
Markos Zaharioudakis | Approve | ||
Matthias Brantner | Approve | ||
Till Westmann | Pending | ||
Review via email: mp+96501@code.launchpad.net |
This proposal supersedes a proposal from 2012-02-28.
This proposal has been superseded by a proposal from 2012-03-08.
Commit message
- fix bug #938934 "collection dml:truncate function missing"
- fixes documentation bug: raise zerr:ZDDY0003 instead of zerr:ZDDY0009
Description of the change
- fix bug #938934 "collection dml:truncate function missing"
- fixes documentation bug: raise zerr:ZDDY0003 instead of zerr:ZDDY0009
Matthias Brantner (matthias-brantner) wrote : Posted in a previous version of this proposal | # |
Zorba Build Bot (zorba-buildbot) wrote : Posted in a previous version of this proposal | # |
Validation queue starting for merge proposal.
Log at: http://
Zorba Build Bot (zorba-buildbot) wrote : Posted in a previous version of this proposal | # |
Validation queue job bug-938934-2012-02-
All tests succeeded!
Zorba Build Bot (zorba-buildbot) wrote : Posted in a previous version of this proposal | # |
Voting does not meet specified criteria. Required: Approve > 1, Disapprove < 1. Got: 2 Pending.
Matthias Brantner (matthias-brantner) : Posted in a previous version of this proposal | # |
Markos Zaharioudakis (markos-za) : Posted in a previous version of this proposal | # |
Markos Zaharioudakis (markos-za) wrote : Posted in a previous version of this proposal | # |
Index maintenance has not been taken into account.
Also, a possible optimization is to skip the application of insertion and deletion primitives on a collection, if there is a truncate primiive.
Markos Zaharioudakis (markos-za) wrote : Posted in a previous version of this proposal | # |
Another bug: the UpdTruncateColl
Matthias Brantner (matthias-brantner) wrote : Posted in a previous version of this proposal | # |
- index maintenance
- optimization to skip apply if a collection is truncated
- couldn't figure out why multiple truncate primitives can't exist in the same pul (added a test)
Matthias Brantner (matthias-brantner) : | # |
Zorba Build Bot (zorba-buildbot) wrote : | # |
There are additional revisions which have not been approved in review. Please seek review and approval of these new revisions.
Zorba Build Bot (zorba-buildbot) wrote : | # |
Validation queue starting for merge proposal.
Log at: http://
Zorba Build Bot (zorba-buildbot) wrote : | # |
The attempt to merge lp:~zorba-coders/zorba/bug-938934 into lp:zorba failed. Below is the output from the failed tests.
CMake Error at /home/ceej/
Validation queue job bug-938934-2012-03-
final status was:
No tests were run - build or configure step must have failed.
Not commiting changes.
Error in read script: /home/ceej/
Zorba Build Bot (zorba-buildbot) wrote : | # |
Validation queue starting for merge proposal.
Log at: http://
Zorba Build Bot (zorba-buildbot) wrote : | # |
The attempt to merge lp:~zorba-coders/zorba/bug-938934 into lp:zorba failed. Below is the output from the failed tests.
CMake Error at /home/ceej/
Validation queue job bug-938934-2012-03-
final status was:
No tests were run - build or configure step must have failed.
Not commiting changes.
Error in read script: /home/ceej/
- 10686. By Matthias Brantner
-
merge
Markos Zaharioudakis (markos-za) : | # |
Markos Zaharioudakis (markos-za) wrote : | # |
About the multiple truncates in same PUL, it was my mistake. But in the undo method you clear theXmlTrees. The vector should be empty already, no? If you agree, then remove the clear() and add an assertion for emptiness.
- 10687. By Matthias Brantner
-
removed obsolete member of the truncate primitive because undo is not possible anyway
- 10688. By Matthias Brantner
-
improved error message
Unmerged revisions
Preview Diff
1 | === modified file 'ChangeLog' |
2 | --- ChangeLog 2012-03-07 15:49:25 +0000 |
3 | +++ ChangeLog 2012-03-08 18:55:32 +0000 |
4 | @@ -10,6 +10,7 @@ |
5 | %ann:must-copy-input-nodes to be used by the no-copy optimization. |
6 | * Caching of results for recursive functions with atomic parameter and return types. |
7 | * Added %ann:cache and %ann:no-cache to enable or disable caching of results of functions with atomic parameter and return types. |
8 | + * Added truncate function to the collection modules for efficient deletion of all nodes in a collection. |
9 | * Fixed bug 917923 (bug in copying outer var values into the eval dynamic context) |
10 | * Fixed bug 867509 (Can not handle largest xs:unsignedLong values) |
11 | * Fixed bug 924063 (sentence is incorrectly incremented when token characters end without sentence terminator) |
12 | |
13 | === modified file 'include/zorba/pregenerated/diagnostic_list.h' |
14 | --- include/zorba/pregenerated/diagnostic_list.h 2012-03-07 13:11:43 +0000 |
15 | +++ include/zorba/pregenerated/diagnostic_list.h 2012-03-08 18:55:32 +0000 |
16 | @@ -582,6 +582,8 @@ |
17 | |
18 | extern ZORBA_DLL_PUBLIC ZorbaErrorCode ZDDY0018_NODES_NOT_IN_SAME_COLLECTION; |
19 | |
20 | +extern ZORBA_DLL_PUBLIC ZorbaErrorCode ZDDY0019_UNDO_NOT_POSSIBLE; |
21 | + |
22 | extern ZORBA_DLL_PUBLIC ZorbaErrorCode ZDDY0020_INDEX_DOMAIN_NODE_NOT_IN_COLLECTION; |
23 | |
24 | extern ZORBA_DLL_PUBLIC ZorbaErrorCode ZDDY0021_INDEX_NOT_DECLARED; |
25 | |
26 | === modified file 'modules/com/zorba-xquery/www/modules/pregenerated/errors.xq' |
27 | --- modules/com/zorba-xquery/www/modules/pregenerated/errors.xq 2012-03-07 13:11:43 +0000 |
28 | +++ modules/com/zorba-xquery/www/modules/pregenerated/errors.xq 2012-03-08 18:55:32 +0000 |
29 | @@ -465,6 +465,10 @@ |
30 | |
31 | (:~ |
32 | :) |
33 | +declare variable $zerr:ZDDY0019 as xs:QName := fn:QName($zerr:NS, "zerr:ZDDY0019"); |
34 | + |
35 | +(:~ |
36 | +:) |
37 | declare variable $zerr:ZDDY0020 as xs:QName := fn:QName($zerr:NS, "zerr:ZDDY0020"); |
38 | |
39 | (:~ |
40 | |
41 | === modified file 'modules/com/zorba-xquery/www/modules/store/dynamic/collections/dml.xq' |
42 | --- modules/com/zorba-xquery/www/modules/store/dynamic/collections/dml.xq 2011-08-26 23:36:24 +0000 |
43 | +++ modules/com/zorba-xquery/www/modules/store/dynamic/collections/dml.xq 2012-03-08 18:55:32 +0000 |
44 | @@ -260,7 +260,7 @@ |
45 | : @return The result of this function is an empty XDM instance and a pending update |
46 | : list which, once applied, deletes the last node from the collection. |
47 | : |
48 | - : @error zerr:ZDDY0009 If available collections does not provide a mapping |
49 | + : @error zerr:ZDDY0003 If available collections does not provide a mapping |
50 | : for the expanded QName $name. |
51 | : @error zerr:ZDDY0011 if the collection doesn't contain any node. |
52 | : |
53 | @@ -278,7 +278,7 @@ |
54 | : @return The result of this function is an empty XDM instance and a pending update |
55 | : list which, once applied, deletes the last n nodes. |
56 | : |
57 | - : @error zerr:ZDDY0009 If available collections does not provide a mapping |
58 | + : @error zerr:ZDDY0003 If available collections does not provide a mapping |
59 | : for the expanded QName $name. |
60 | : @error zerr:ZDDY0011 if the collection doesn't contain the given number of nodes. |
61 | : |
62 | @@ -288,6 +288,19 @@ |
63 | $number as xs:integer) external; |
64 | |
65 | (:~ |
66 | + : The truncate function is an updating function that deletes the |
67 | + : entire contents of collection. |
68 | + : |
69 | + : @param $name The name of the collection whose content to delete |
70 | + : |
71 | + : @return The result of this function is an empty XDM instance and a pending update |
72 | + : list which, once applied, deletes the nodes. |
73 | + : |
74 | + : @error zerr:ZDDY0003 if the collection identified by $name is not available. |
75 | + :) |
76 | +declare updating function dml:truncate($name as xs:QName) external; |
77 | + |
78 | +(:~ |
79 | : The index-of function return the index of the given node in the collection. |
80 | : |
81 | : @param $node The node to retrieve the index from. |
82 | @@ -307,7 +320,7 @@ |
83 | : |
84 | : @return The sequence contained in the given collection. |
85 | : |
86 | - : @error zerr:ZDDY0009 If available collections does not provide a mapping |
87 | + : @error zerr:ZDDY0003 If available collections does not provide a mapping |
88 | : for the expanded QName $name. |
89 | : |
90 | :) |
91 | |
92 | === modified file 'modules/com/zorba-xquery/www/modules/store/static/collections/dml.xq' |
93 | --- modules/com/zorba-xquery/www/modules/store/static/collections/dml.xq 2011-10-03 09:18:49 +0000 |
94 | +++ modules/com/zorba-xquery/www/modules/store/static/collections/dml.xq 2012-03-08 18:55:32 +0000 |
95 | @@ -409,6 +409,21 @@ |
96 | $number as xs:integer) external; |
97 | |
98 | (:~ |
99 | + : The truncate function is an updating function that deletes the |
100 | + : entire contents of collection. |
101 | + : |
102 | + : @param $name The name of the collection whose content to delete |
103 | + : |
104 | + : @return The result of this function is an empty XDM instance and a pending update |
105 | + : list which, once applied, deletes the nodes. |
106 | + : |
107 | + : @error zerr:ZDDY0001 if the collection identified by $name is not declared. |
108 | + : @error zerr:ZDDY0003 if the collection identified by $name is not available. |
109 | + : |
110 | + :) |
111 | +declare updating function cdml:truncate($name as xs:QName) external; |
112 | + |
113 | +(:~ |
114 | : The index-of function that returns the position of the node in its collection. |
115 | : |
116 | : @param $node The node to retrieve the index for. |
117 | |
118 | === modified file 'src/diagnostics/diagnostic_en.xml' |
119 | --- src/diagnostics/diagnostic_en.xml 2012-03-07 14:22:29 +0000 |
120 | +++ src/diagnostics/diagnostic_en.xml 2012-03-08 18:55:32 +0000 |
121 | @@ -2021,6 +2021,10 @@ |
122 | <value>all nodes must be in same collection</value> |
123 | </diagnostic> |
124 | |
125 | + <diagnostic code="ZDDY0019" name="UNDO_NOT_POSSIBLE"> |
126 | + <value>"$1": collection $2 cannot be undone</value> |
127 | + </diagnostic> |
128 | + |
129 | <diagnostic code="ZDDY0020" name="INDEX_DOMAIN_NODE_NOT_IN_COLLECTION"> |
130 | <value>"$1": index domain expression yields nodes that are not in collection</value> |
131 | </diagnostic> |
132 | |
133 | === modified file 'src/diagnostics/pregenerated/diagnostic_list.cpp' |
134 | --- src/diagnostics/pregenerated/diagnostic_list.cpp 2012-03-07 13:11:43 +0000 |
135 | +++ src/diagnostics/pregenerated/diagnostic_list.cpp 2012-03-08 18:55:32 +0000 |
136 | @@ -852,6 +852,9 @@ |
137 | ZorbaErrorCode ZDDY0018_NODES_NOT_IN_SAME_COLLECTION( "ZDDY0018" ); |
138 | |
139 | |
140 | +ZorbaErrorCode ZDDY0019_UNDO_NOT_POSSIBLE( "ZDDY0019" ); |
141 | + |
142 | + |
143 | ZorbaErrorCode ZDDY0020_INDEX_DOMAIN_NODE_NOT_IN_COLLECTION( "ZDDY0020" ); |
144 | |
145 | |
146 | |
147 | === modified file 'src/diagnostics/pregenerated/dict_en.cpp' |
148 | --- src/diagnostics/pregenerated/dict_en.cpp 2012-03-07 14:22:29 +0000 |
149 | +++ src/diagnostics/pregenerated/dict_en.cpp 2012-03-08 18:55:32 +0000 |
150 | @@ -284,6 +284,7 @@ |
151 | { "ZDDY0016", "\"$1\": multiple attemps to create a collection in the same snapshot" }, |
152 | { "ZDDY0017", "node does not belong to any collection" }, |
153 | { "ZDDY0018", "all nodes must be in same collection" }, |
154 | + { "ZDDY0019", "\"$1\": collection $2 cannot be undone" }, |
155 | { "ZDDY0020", "\"$1\": index domain expression yields nodes that are not in collection" }, |
156 | { "ZDDY0021", "\"$1\": undeclared index" }, |
157 | { "ZDDY0022", "\"$1\": index already exists" }, |
158 | |
159 | === modified file 'src/functions/func_collections_impl.cpp' |
160 | --- src/functions/func_collections_impl.cpp 2012-02-16 12:48:17 +0000 |
161 | +++ src/functions/func_collections_impl.cpp 2012-03-08 18:55:32 +0000 |
162 | @@ -293,6 +293,21 @@ |
163 | /******************************************************************************* |
164 | |
165 | ********************************************************************************/ |
166 | +PlanIter_t zorba_store_collections_static_dml_truncate::codegen( |
167 | + CompilerCB*, |
168 | + static_context* sctx, |
169 | + const QueryLoc& loc, |
170 | + std::vector<PlanIter_t>& argv, |
171 | + expr& ann) const |
172 | +{ |
173 | + return new ZorbaTruncateCollectionIterator(sctx, loc, argv, |
174 | + getName()->getNamespace() == static_context::ZORBA_STORE_DYNAMIC_COLLECTIONS_DML_FN_NS); |
175 | +} |
176 | + |
177 | + |
178 | +/******************************************************************************* |
179 | + |
180 | +********************************************************************************/ |
181 | PlanIter_t zorba_store_collections_static_dml_delete_node_first::codegen( |
182 | CompilerCB*, |
183 | static_context* sctx, |
184 | |
185 | === modified file 'src/functions/pregenerated/func_collections.cpp' |
186 | --- src/functions/pregenerated/func_collections.cpp 2012-02-16 12:48:17 +0000 |
187 | +++ src/functions/pregenerated/func_collections.cpp 2012-03-08 18:55:32 +0000 |
188 | @@ -58,6 +58,7 @@ |
189 | |
190 | |
191 | |
192 | + |
193 | PlanIter_t zorba_store_collections_static_dml_collection_name::codegen( |
194 | CompilerCB*, |
195 | static_context* sctx, |
196 | @@ -686,6 +687,30 @@ |
197 | { |
198 | |
199 | |
200 | + DECL_WITH_KIND(sctx, zorba_store_collections_static_dml_truncate, |
201 | + (createQName("http://www.zorba-xquery.com/modules/store/static/collections/dml","","truncate"), |
202 | + GENV_TYPESYSTEM.QNAME_TYPE_ONE, |
203 | + GENV_TYPESYSTEM.EMPTY_TYPE), |
204 | + FunctionConsts::ZORBA_STORE_COLLECTIONS_STATIC_DML_TRUNCATE_1); |
205 | + |
206 | + } |
207 | + |
208 | + |
209 | + { |
210 | + |
211 | + |
212 | + DECL_WITH_KIND(sctx, zorba_store_collections_static_dml_truncate, |
213 | + (createQName("http://www.zorba-xquery.com/modules/store/dynamic/collections/dml","","truncate"), |
214 | + GENV_TYPESYSTEM.QNAME_TYPE_ONE, |
215 | + GENV_TYPESYSTEM.EMPTY_TYPE), |
216 | + FunctionConsts::ZORBA_STORE_DYNAMIC_COLLECTIONS_DML_TRUNCATE_1); |
217 | + |
218 | + } |
219 | + |
220 | + |
221 | + { |
222 | + |
223 | + |
224 | DECL_WITH_KIND(sctx, zorba_store_collections_static_dml_collection_name, |
225 | (createQName("http://www.zorba-xquery.com/modules/store/static/collections/dml","","collection-name"), |
226 | GENV_TYPESYSTEM.ANY_NODE_TYPE_ONE, |
227 | |
228 | === modified file 'src/functions/pregenerated/func_collections.h' |
229 | --- src/functions/pregenerated/func_collections.h 2012-01-11 17:30:25 +0000 |
230 | +++ src/functions/pregenerated/func_collections.h 2012-03-08 18:55:32 +0000 |
231 | @@ -434,6 +434,25 @@ |
232 | }; |
233 | |
234 | |
235 | +//zorba-store-collections-static-dml:truncate |
236 | +class zorba_store_collections_static_dml_truncate : public function |
237 | +{ |
238 | +public: |
239 | + zorba_store_collections_static_dml_truncate(const signature& sig, FunctionConsts::FunctionKind kind) |
240 | + : |
241 | + function(sig, kind) |
242 | + { |
243 | + |
244 | + } |
245 | + |
246 | + short getScriptingKind() const { return UPDATING_EXPR; } |
247 | + |
248 | + bool accessesDynCtx() const { return true; } |
249 | + |
250 | + CODEGEN_DECL(); |
251 | +}; |
252 | + |
253 | + |
254 | //zorba-store-collections-static-dml:collection-name |
255 | class zorba_store_collections_static_dml_collection_name : public function |
256 | { |
257 | |
258 | === modified file 'src/functions/pregenerated/function_enum.h' |
259 | --- src/functions/pregenerated/function_enum.h 2012-03-07 15:49:25 +0000 |
260 | +++ src/functions/pregenerated/function_enum.h 2012-03-08 18:55:32 +0000 |
261 | @@ -79,6 +79,8 @@ |
262 | ZORBA_STORE_COLLECTIONS_STATIC_DML_DELETE_NODES_LAST_2, |
263 | ZORBA_STORE_DYNAMIC_COLLECTIONS_DML_DELETE_NODE_LAST_1, |
264 | ZORBA_STORE_DYNAMIC_COLLECTIONS_DML_DELETE_NODES_LAST_2, |
265 | + ZORBA_STORE_COLLECTIONS_STATIC_DML_TRUNCATE_1, |
266 | + ZORBA_STORE_DYNAMIC_COLLECTIONS_DML_TRUNCATE_1, |
267 | ZORBA_STORE_COLLECTIONS_STATIC_DML_COLLECTION_NAME_1, |
268 | ZORBA_STORE_DYNAMIC_COLLECTIONS_DML_COLLECTION_NAME_1, |
269 | ZORBA_STORE_COLLECTIONS_STATIC_DDL_IS_AVAILABLE_COLLECTION_1, |
270 | |
271 | === modified file 'src/runtime/collections/collections_impl.cpp' |
272 | --- src/runtime/collections/collections_impl.cpp 2012-02-16 12:48:17 +0000 |
273 | +++ src/runtime/collections/collections_impl.cpp 2012-03-08 18:55:32 +0000 |
274 | @@ -1796,6 +1796,93 @@ |
275 | /******************************************************************************* |
276 | |
277 | ********************************************************************************/ |
278 | +bool ZorbaTruncateCollectionIterator::nextImpl( |
279 | + store::Item_t& result, |
280 | + PlanState& planState) const |
281 | +{ |
282 | + store::Collection_t collection; |
283 | + store::Item_t collectionName; |
284 | + std::auto_ptr<store::PUL> pul; |
285 | + |
286 | + PlanIteratorState* state; |
287 | + DEFAULT_STACK_INIT(PlanIteratorState, state, planState); |
288 | + |
289 | + consumeNext(collectionName, theChildren[0].getp(), planState); |
290 | + |
291 | + (void)getCollection( |
292 | + theSctx, collectionName, loc, theDynamicCollection, collection); |
293 | + |
294 | + // create the pul and add the primitive |
295 | + pul.reset(GENV_ITEMFACTORY->createPendingUpdateList()); |
296 | + |
297 | + pul->addTruncateCollection(&loc, collectionName, theDynamicCollection); |
298 | + |
299 | + result = pul.release(); |
300 | + STACK_PUSH( result != NULL, state); |
301 | + |
302 | + STACK_END (state); |
303 | +} |
304 | + |
305 | +/******************************************************************************* |
306 | + |
307 | +********************************************************************************/ |
308 | +const StaticallyKnownCollection* |
309 | +ZorbaTruncateCollectionIterator::getCollection( |
310 | + const static_context* aSctx, |
311 | + const store::Item_t& aName, |
312 | + const QueryLoc& aLoc, |
313 | + bool aDynamicCollection, |
314 | + store::Collection_t& coll) const |
315 | +{ |
316 | + const StaticallyKnownCollection* collectionDecl = aSctx->lookup_collection(aName); |
317 | + if (collectionDecl == 0 && !aDynamicCollection) |
318 | + { |
319 | + throw XQUERY_EXCEPTION( |
320 | + zerr::ZDDY0001_COLLECTION_NOT_DECLARED, |
321 | + ERROR_PARAMS( aName->getStringValue() ), |
322 | + ERROR_LOC( aLoc ) |
323 | + ); |
324 | + } |
325 | + |
326 | + if (!aDynamicCollection) |
327 | + { |
328 | + // checking collection update mode |
329 | + switch(collectionDecl->getUpdateProperty()) |
330 | + { |
331 | + case StaticContextConsts::decl_const: |
332 | + throw XQUERY_EXCEPTION( |
333 | + zerr::ZDDY0004_COLLECTION_CONST_UPDATE, |
334 | + ERROR_PARAMS( aName->getStringValue() ), |
335 | + ERROR_LOC( loc ) |
336 | + ); |
337 | + |
338 | + case StaticContextConsts::decl_append_only: |
339 | + throw XQUERY_EXCEPTION( |
340 | + zerr::ZDDY0005_COLLECTION_APPEND_BAD_INSERT, |
341 | + ERROR_PARAMS( aName->getStringValue() ), |
342 | + ERROR_LOC( loc ) |
343 | + ); |
344 | + default: break; |
345 | + } |
346 | + } |
347 | + |
348 | + coll = GENV_STORE.getCollection(aName, aDynamicCollection); |
349 | + |
350 | + if (coll == NULL) |
351 | + { |
352 | + throw XQUERY_EXCEPTION( |
353 | + zerr::ZDDY0003_COLLECTION_DOES_NOT_EXIST, |
354 | + ERROR_PARAMS( aName->getStringValue() ), |
355 | + ERROR_LOC( aLoc ) |
356 | + ); |
357 | + } |
358 | + |
359 | + return collectionDecl; |
360 | +} |
361 | + |
362 | +/******************************************************************************* |
363 | + |
364 | +********************************************************************************/ |
365 | bool ZorbaCollectionNameIterator::nextImpl( |
366 | store::Item_t& result, |
367 | PlanState& planState) const |
368 | |
369 | === modified file 'src/runtime/collections/pregenerated/collections.cpp' |
370 | --- src/runtime/collections/pregenerated/collections.cpp 2011-11-01 14:26:48 +0000 |
371 | +++ src/runtime/collections/pregenerated/collections.cpp 2012-03-08 18:55:32 +0000 |
372 | @@ -551,6 +551,34 @@ |
373 | // </ZorbaDeleteNodesLastIterator> |
374 | |
375 | |
376 | +// <ZorbaTruncateCollectionIterator> |
377 | +const char* ZorbaTruncateCollectionIterator::class_name_str = "ZorbaTruncateCollectionIterator"; |
378 | +ZorbaTruncateCollectionIterator::class_factory<ZorbaTruncateCollectionIterator> |
379 | +ZorbaTruncateCollectionIterator::g_class_factory; |
380 | + |
381 | +const serialization::ClassVersion |
382 | +ZorbaTruncateCollectionIterator::class_versions[] ={{ 1, 0x000905, false}}; |
383 | + |
384 | +const int ZorbaTruncateCollectionIterator::class_versions_count = |
385 | +sizeof(ZorbaTruncateCollectionIterator::class_versions)/sizeof(struct serialization::ClassVersion); |
386 | + |
387 | +void ZorbaTruncateCollectionIterator::accept(PlanIterVisitor& v) const { |
388 | + v.beginVisit(*this); |
389 | + |
390 | + std::vector<PlanIter_t>::const_iterator lIter = theChildren.begin(); |
391 | + std::vector<PlanIter_t>::const_iterator lEnd = theChildren.end(); |
392 | + for ( ; lIter != lEnd; ++lIter ){ |
393 | + (*lIter)->accept(v); |
394 | + } |
395 | + |
396 | + v.endVisit(*this); |
397 | +} |
398 | + |
399 | +ZorbaTruncateCollectionIterator::~ZorbaTruncateCollectionIterator() {} |
400 | + |
401 | +// </ZorbaTruncateCollectionIterator> |
402 | + |
403 | + |
404 | // <ZorbaCollectionNameIterator> |
405 | const char* ZorbaCollectionNameIterator::class_name_str = "ZorbaCollectionNameIterator"; |
406 | ZorbaCollectionNameIterator::class_factory<ZorbaCollectionNameIterator> |
407 | |
408 | === modified file 'src/runtime/collections/pregenerated/collections.h' |
409 | --- src/runtime/collections/pregenerated/collections.h 2011-11-01 14:26:48 +0000 |
410 | +++ src/runtime/collections/pregenerated/collections.h 2012-03-08 18:55:32 +0000 |
411 | @@ -865,6 +865,50 @@ |
412 | |
413 | /** |
414 | * |
415 | + * zorba:truncate |
416 | + * |
417 | + * Author: Zorba Team |
418 | + */ |
419 | +class ZorbaTruncateCollectionIterator : public NaryBaseIterator<ZorbaTruncateCollectionIterator, PlanIteratorState> |
420 | +{ |
421 | +protected: |
422 | + bool theDynamicCollection; //whether it's the function of the dynamic or the static collection module |
423 | +public: |
424 | + SERIALIZABLE_CLASS(ZorbaTruncateCollectionIterator); |
425 | + |
426 | + SERIALIZABLE_CLASS_CONSTRUCTOR2T(ZorbaTruncateCollectionIterator, |
427 | + NaryBaseIterator<ZorbaTruncateCollectionIterator, PlanIteratorState>); |
428 | + |
429 | + void serialize( ::zorba::serialization::Archiver& ar) |
430 | + { |
431 | + serialize_baseclass(ar, |
432 | + (NaryBaseIterator<ZorbaTruncateCollectionIterator, PlanIteratorState>*)this); |
433 | + |
434 | + ar & theDynamicCollection; |
435 | + } |
436 | + |
437 | + ZorbaTruncateCollectionIterator( |
438 | + static_context* sctx, |
439 | + const QueryLoc& loc, |
440 | + std::vector<PlanIter_t>& children, |
441 | + bool aDynamicCollection) |
442 | + : |
443 | + NaryBaseIterator<ZorbaTruncateCollectionIterator, PlanIteratorState>(sctx, loc, children), |
444 | + theDynamicCollection(aDynamicCollection) |
445 | + {} |
446 | + |
447 | + virtual ~ZorbaTruncateCollectionIterator(); |
448 | + |
449 | +public: |
450 | + const StaticallyKnownCollection* getCollection(const static_context* sctx, const store::Item_t& name, const QueryLoc& loc, bool dyn_coll, store::Collection_t& coll) const; |
451 | + void accept(PlanIterVisitor& v) const; |
452 | + |
453 | + bool nextImpl(store::Item_t& result, PlanState& aPlanState) const; |
454 | +}; |
455 | + |
456 | + |
457 | +/** |
458 | + * |
459 | * zorba:collection-name |
460 | * |
461 | * Author: Zorba Team |
462 | |
463 | === modified file 'src/runtime/core/apply_updates.cpp' |
464 | --- src/runtime/core/apply_updates.cpp 2011-08-17 18:55:07 +0000 |
465 | +++ src/runtime/core/apply_updates.cpp 2012-03-08 18:55:32 +0000 |
466 | @@ -141,12 +141,13 @@ |
467 | SchemaValidatorImpl validator(loc, sctx); |
468 | ICCheckerImpl icChecker(sctx, gdctx); |
469 | std::vector<store::Index*> indexes; |
470 | + std::vector<store::Index*> truncate_indexes; |
471 | store::ItemHandle<store::PUL> indexPul; |
472 | |
473 | // Get all the indexes that are associated with any of the collections that |
474 | // are going to be updated by this pul. Check which of those indices can be |
475 | // maintained incrementally, and pass this info back to the pul. |
476 | - pul->getIndicesToRefresh(indexes); |
477 | + pul->getIndicesToRefresh(indexes, truncate_indexes); |
478 | |
479 | ulong numIndices = (ulong)indexes.size(); |
480 | |
481 | @@ -178,6 +179,17 @@ |
482 | zorbaIndexes[i] = indexDecl; |
483 | } |
484 | |
485 | + numIndices = (ulong)truncate_indexes.size(); |
486 | + for (ulong i = 0; i < numIndices; ++i) |
487 | + { |
488 | + IndexDecl* indexDecl = sctx->lookup_index(indexes[i]->getName()); |
489 | + |
490 | + if (indexDecl->getMaintenanceMode() == IndexDecl::DOC_MAP) |
491 | + { |
492 | + pul->addIndexTruncator(indexDecl->getSourceName(0), indexes[i]); |
493 | + } |
494 | + } |
495 | + |
496 | try |
497 | { |
498 | // Apply updates |
499 | |
500 | === modified file 'src/runtime/spec/collections/collections.xml' |
501 | --- src/runtime/spec/collections/collections.xml 2012-01-11 17:30:25 +0000 |
502 | +++ src/runtime/spec/collections/collections.xml 2012-03-08 18:55:32 +0000 |
503 | @@ -924,6 +924,52 @@ |
504 | /******************************************************************************* |
505 | ********************************************************************************/ |
506 | --> |
507 | +<zorba:iterator name="ZorbaTruncateCollectionIterator" > |
508 | + |
509 | + <zorba:description author="Zorba Team"> |
510 | + zorba:truncate |
511 | + </zorba:description> |
512 | + |
513 | + <zorba:function generateCodegen="false"> |
514 | + |
515 | + <zorba:signature localname="truncate" prefix="zorba-store-collections-static-dml"> |
516 | + <zorba:param>xs:QName</zorba:param> |
517 | + <zorba:output>empty-sequence()</zorba:output> |
518 | + </zorba:signature> |
519 | + |
520 | + <zorba:signature localname="truncate" prefix="zorba-store-dynamic-collections-dml"> |
521 | + <zorba:param>xs:QName</zorba:param> |
522 | + <zorba:output>empty-sequence()</zorba:output> |
523 | + </zorba:signature> |
524 | + |
525 | + <zorba:methods> |
526 | + <zorba:getScriptingKind returnValue="UPDATING_EXPR"/> |
527 | + <zorba:accessesDynCtx returnValue="true"/> |
528 | + </zorba:methods> |
529 | + |
530 | + </zorba:function> |
531 | + |
532 | + <zorba:constructor> |
533 | + <zorba:parameter type="bool" name="aDynamicCollection" /> |
534 | + </zorba:constructor> |
535 | + |
536 | + <zorba:member type="bool" name="theDynamicCollection" |
537 | + brief="whether it's the function of the dynamic or the static collection module"/> |
538 | + |
539 | + <zorba:method const="true" name="getCollection" return="const StaticallyKnownCollection*"> |
540 | + <zorba:param type="const static_context*" name="sctx"/> |
541 | + <zorba:param type="const store::Item_t&" name="name"/> |
542 | + <zorba:param type="const QueryLoc&" name="loc"/> |
543 | + <zorba:param type="bool" name="dyn_coll"/> |
544 | + <zorba:param type="store::Collection_t&" name="coll"/> |
545 | + </zorba:method> |
546 | +</zorba:iterator> |
547 | + |
548 | + |
549 | +<!-- |
550 | +/******************************************************************************* |
551 | +********************************************************************************/ |
552 | +--> |
553 | <zorba:iterator name="ZorbaCollectionNameIterator" > |
554 | |
555 | <zorba:description author="Zorba Team"> |
556 | |
557 | === modified file 'src/runtime/visitors/pregenerated/planiter_visitor.h' |
558 | --- src/runtime/visitors/pregenerated/planiter_visitor.h 2012-03-07 15:49:25 +0000 |
559 | +++ src/runtime/visitors/pregenerated/planiter_visitor.h 2012-03-08 18:55:32 +0000 |
560 | @@ -92,6 +92,8 @@ |
561 | |
562 | class ZorbaDeleteNodesLastIterator; |
563 | |
564 | + class ZorbaTruncateCollectionIterator; |
565 | + |
566 | class ZorbaCollectionNameIterator; |
567 | |
568 | class IsAvailableCollectionIterator; |
569 | @@ -697,6 +699,9 @@ |
570 | virtual void beginVisit ( const ZorbaDeleteNodesLastIterator& ) = 0; |
571 | virtual void endVisit ( const ZorbaDeleteNodesLastIterator& ) = 0; |
572 | |
573 | + virtual void beginVisit ( const ZorbaTruncateCollectionIterator& ) = 0; |
574 | + virtual void endVisit ( const ZorbaTruncateCollectionIterator& ) = 0; |
575 | + |
576 | virtual void beginVisit ( const ZorbaCollectionNameIterator& ) = 0; |
577 | virtual void endVisit ( const ZorbaCollectionNameIterator& ) = 0; |
578 | |
579 | |
580 | === modified file 'src/runtime/visitors/pregenerated/printer_visitor.cpp' |
581 | --- src/runtime/visitors/pregenerated/printer_visitor.cpp 2012-03-07 15:49:25 +0000 |
582 | +++ src/runtime/visitors/pregenerated/printer_visitor.cpp 2012-03-08 18:55:32 +0000 |
583 | @@ -545,6 +545,20 @@ |
584 | // </ZorbaDeleteNodesLastIterator> |
585 | |
586 | |
587 | +// <ZorbaTruncateCollectionIterator> |
588 | +void PrinterVisitor::beginVisit ( const ZorbaTruncateCollectionIterator& a) { |
589 | + thePrinter.startBeginVisit("ZorbaTruncateCollectionIterator", ++theId); |
590 | + printCommons( &a, theId ); |
591 | + thePrinter.endBeginVisit( theId ); |
592 | +} |
593 | + |
594 | +void PrinterVisitor::endVisit ( const ZorbaTruncateCollectionIterator& ) { |
595 | + thePrinter.startEndVisit(); |
596 | + thePrinter.endEndVisit(); |
597 | +} |
598 | +// </ZorbaTruncateCollectionIterator> |
599 | + |
600 | + |
601 | // <ZorbaCollectionNameIterator> |
602 | void PrinterVisitor::beginVisit ( const ZorbaCollectionNameIterator& a) { |
603 | thePrinter.startBeginVisit("ZorbaCollectionNameIterator", ++theId); |
604 | |
605 | === modified file 'src/runtime/visitors/pregenerated/printer_visitor.h' |
606 | --- src/runtime/visitors/pregenerated/printer_visitor.h 2012-03-07 15:49:25 +0000 |
607 | +++ src/runtime/visitors/pregenerated/printer_visitor.h 2012-03-08 18:55:32 +0000 |
608 | @@ -140,6 +140,9 @@ |
609 | void beginVisit( const ZorbaDeleteNodesLastIterator& ); |
610 | void endVisit ( const ZorbaDeleteNodesLastIterator& ); |
611 | |
612 | + void beginVisit( const ZorbaTruncateCollectionIterator& ); |
613 | + void endVisit ( const ZorbaTruncateCollectionIterator& ); |
614 | + |
615 | void beginVisit( const ZorbaCollectionNameIterator& ); |
616 | void endVisit ( const ZorbaCollectionNameIterator& ); |
617 | |
618 | |
619 | === modified file 'src/store/api/pul.h' |
620 | --- src/store/api/pul.h 2011-10-12 20:59:49 +0000 |
621 | +++ src/store/api/pul.h 2012-03-08 18:55:32 +0000 |
622 | @@ -203,6 +203,11 @@ |
623 | bool isLast, |
624 | bool dyn_collection = false) = 0; |
625 | |
626 | + virtual void addTruncateCollection( |
627 | + const QueryLoc* aQueryLoc, |
628 | + Item_t& name, |
629 | + bool dyn_collection = false) = 0; |
630 | + |
631 | // functions to add primitives for indexes |
632 | |
633 | virtual void addCreateIndex( |
634 | @@ -281,13 +286,18 @@ |
635 | |
636 | // utils |
637 | virtual void getIndicesToRefresh( |
638 | - std::vector<Index*>& indices) = 0; |
639 | + std::vector<Index*>& indices, |
640 | + std::vector<Index*>& truncate_indices) = 0; |
641 | |
642 | virtual void addIndexEntryCreator( |
643 | const Item* collectionName, |
644 | Index* idx, |
645 | IndexEntryCreator* creator) = 0; |
646 | |
647 | + virtual void addIndexTruncator( |
648 | + const store::Item* collectionName, |
649 | + Index* idx) = 0; |
650 | + |
651 | virtual void setValidator( |
652 | SchemaValidator* validator) = 0; |
653 | |
654 | |
655 | === modified file 'src/store/api/update_consts.h' |
656 | --- src/store/api/update_consts.h 2012-01-11 17:30:25 +0000 |
657 | +++ src/store/api/update_consts.h 2012-03-08 18:55:32 +0000 |
658 | @@ -81,6 +81,7 @@ |
659 | UP_INSERT_AT_INTO_COLLECTION, |
660 | UP_REMOVE_FROM_COLLECTION, |
661 | UP_REMOVE_AT_FROM_COLLECTION, |
662 | + UP_TRUNCATE_COLLECTION, |
663 | |
664 | // index primitives |
665 | UP_CREATE_INDEX, |
666 | @@ -177,6 +178,8 @@ |
667 | return "insertAtIntoCollection"; |
668 | case UP_REMOVE_FROM_COLLECTION: |
669 | return "removeFromCollection"; |
670 | + case UP_TRUNCATE_COLLECTION: |
671 | + return "truncateCollection"; |
672 | case UP_REMOVE_AT_FROM_COLLECTION: |
673 | return "removeAtFromCollection"; |
674 | case UP_CREATE_INDEX: |
675 | |
676 | === modified file 'src/store/naive/collection.h' |
677 | --- src/store/naive/collection.h 2012-03-05 15:52:06 +0000 |
678 | +++ src/store/naive/collection.h 2012-03-08 18:55:32 +0000 |
679 | @@ -73,6 +73,8 @@ |
680 | zorba::xs_integer position, |
681 | zorba::xs_integer num) = 0; |
682 | |
683 | + virtual void removeAll() = 0; |
684 | + |
685 | virtual void adjustTreePositions() = 0; |
686 | |
687 | /***************************** ID Management ********************************/ |
688 | |
689 | === modified file 'src/store/naive/pul_primitive_factory.cpp' |
690 | --- src/store/naive/pul_primitive_factory.cpp 2012-03-07 14:22:29 +0000 |
691 | +++ src/store/naive/pul_primitive_factory.cpp 2012-03-08 18:55:32 +0000 |
692 | @@ -376,6 +376,18 @@ |
693 | return new UpdDeleteNodesFromCollection(pul, aLoc, name, nodes, isLast, dyn_collection); |
694 | } |
695 | |
696 | + |
697 | + /*************************************************************************** |
698 | + ***************************************************************************/ |
699 | + UpdTruncateCollection* |
700 | + PULPrimitiveFactory::createUpdTruncateCollection( |
701 | + CollectionPul* pul, |
702 | + const QueryLoc* aLoc, |
703 | + store::Item_t& name, |
704 | + bool dyn_collection) |
705 | + { |
706 | + return new UpdTruncateCollection(pul, aLoc, name, dyn_collection); |
707 | + } |
708 | |
709 | /*************************************************************************** |
710 | ***************************************************************************/ |
711 | |
712 | === modified file 'src/store/naive/pul_primitive_factory.h' |
713 | --- src/store/naive/pul_primitive_factory.h 2012-02-28 20:45:43 +0000 |
714 | +++ src/store/naive/pul_primitive_factory.h 2012-03-08 18:55:32 +0000 |
715 | @@ -50,6 +50,7 @@ |
716 | class UpdInsertBeforeIntoCollection; |
717 | class UpdInsertAfterIntoCollection; |
718 | class UpdDeleteNodesFromCollection; |
719 | + class UpdTruncateCollection; |
720 | class UpdCreateIndex; |
721 | class UpdDeleteIndex; |
722 | class UpdRefreshIndex; |
723 | @@ -311,6 +312,15 @@ |
724 | std::vector<store::Item_t>& nodes, |
725 | bool isLast, |
726 | bool dyn_collection = false); |
727 | + |
728 | + /*************************************************************************** |
729 | + ***************************************************************************/ |
730 | + virtual UpdTruncateCollection* |
731 | + createUpdTruncateCollection( |
732 | + CollectionPul* pul, |
733 | + const QueryLoc*, |
734 | + store::Item_t& name, |
735 | + bool dyn_collection = false); |
736 | |
737 | /*************************************************************************** |
738 | ***************************************************************************/ |
739 | |
740 | === modified file 'src/store/naive/pul_primitives.cpp' |
741 | --- src/store/naive/pul_primitives.cpp 2012-03-07 14:22:29 +0000 |
742 | +++ src/store/naive/pul_primitives.cpp 2012-03-08 18:55:32 +0000 |
743 | @@ -1276,6 +1276,31 @@ |
744 | } |
745 | |
746 | |
747 | +/******************************************************************************* |
748 | + UpdTruncateCollection |
749 | +********************************************************************************/ |
750 | +void UpdTruncateCollection::apply() |
751 | +{ |
752 | + Collection* lColl = static_cast<Collection*> |
753 | + (GET_STORE().getCollection(theName, theDynamicCollection).getp()); |
754 | + assert(lColl); |
755 | + |
756 | + lColl->removeAll(); |
757 | + theIsApplied = true; |
758 | + |
759 | +} |
760 | + |
761 | +void UpdTruncateCollection::undo() |
762 | +{ |
763 | + if (!theIsApplied) return; |
764 | + |
765 | + throw ZORBA_EXCEPTION( |
766 | + zerr::ZDDY0019_UNDO_NOT_POSSIBLE, |
767 | + ERROR_PARAMS( theName->getStringValue(), "truncate" ) |
768 | + ); |
769 | + |
770 | +} |
771 | + |
772 | |
773 | ///////////////////////////////////////////////////////////////////////////////// |
774 | // // |
775 | |
776 | === modified file 'src/store/naive/pul_primitives.h' |
777 | --- src/store/naive/pul_primitives.h 2012-02-28 20:45:43 +0000 |
778 | +++ src/store/naive/pul_primitives.h 2012-03-08 18:55:32 +0000 |
779 | @@ -1210,6 +1210,37 @@ |
780 | }; |
781 | |
782 | |
783 | +/******************************************************************************* |
784 | + |
785 | +********************************************************************************/ |
786 | +class UpdTruncateCollection: public UpdCollection |
787 | +{ |
788 | + friend class PULPrimitiveFactory; |
789 | + |
790 | +protected: |
791 | + std::vector<store::Item_t> theTrees; // needed for undo only |
792 | + |
793 | + UpdTruncateCollection( |
794 | + CollectionPul* pul, |
795 | + const QueryLoc* aLoc, |
796 | + store::Item_t& name, |
797 | + bool dyn_collection) |
798 | + : |
799 | + UpdCollection(pul, aLoc, name, dyn_collection) |
800 | + { |
801 | + } |
802 | + |
803 | +public: |
804 | + store::UpdateConsts::UpdPrimKind getKind() const |
805 | + { |
806 | + return store::UpdateConsts::UP_TRUNCATE_COLLECTION; |
807 | + } |
808 | + |
809 | + void apply(); |
810 | + void undo(); |
811 | +}; |
812 | + |
813 | + |
814 | ///////////////////////////////////////////////////////////////////////////////// |
815 | // // |
816 | // Index Primitives // |
817 | |
818 | === modified file 'src/store/naive/simple_collection.cpp' |
819 | --- src/store/naive/simple_collection.cpp 2012-03-07 14:22:29 +0000 |
820 | +++ src/store/naive/simple_collection.cpp 2012-03-08 18:55:32 +0000 |
821 | @@ -336,6 +336,17 @@ |
822 | |
823 | |
824 | /******************************************************************************* |
825 | + * Remove all the nodes from the collection |
826 | +********************************************************************************/ |
827 | +void SimpleCollection::removeAll() |
828 | +{ |
829 | + SYNC_CODE(AutoLatch lock(theLatch, Latch::WRITE);) |
830 | + |
831 | + theXmlTrees.clear(); |
832 | +} |
833 | + |
834 | + |
835 | +/******************************************************************************* |
836 | Return the node at the given position within the collection, or NULL if the |
837 | given position is >= than the number of nodes in the collection. |
838 | ********************************************************************************/ |
839 | |
840 | === modified file 'src/store/naive/simple_collection.h' |
841 | --- src/store/naive/simple_collection.h 2012-03-07 14:22:29 +0000 |
842 | +++ src/store/naive/simple_collection.h 2012-03-08 18:55:32 +0000 |
843 | @@ -41,6 +41,7 @@ |
844 | class SimpleCollection : public Collection |
845 | { |
846 | friend class CollectionIter; |
847 | + friend class UpdTruncateCollection; |
848 | |
849 | public: |
850 | class CollectionIter : public store::Iterator |
851 | @@ -124,6 +125,8 @@ |
852 | // virtual to allow extension by subclasses |
853 | virtual bool removeNode(xs_integer position); |
854 | |
855 | + virtual void removeAll(); |
856 | + |
857 | // virtual to allow extension by subclasses |
858 | virtual xs_integer removeNodes(xs_integer position, xs_integer num); |
859 | |
860 | |
861 | === modified file 'src/store/naive/simple_index.h' |
862 | --- src/store/naive/simple_index.h 2012-01-11 17:30:25 +0000 |
863 | +++ src/store/naive/simple_index.h 2012-03-08 18:55:32 +0000 |
864 | @@ -69,6 +69,8 @@ |
865 | |
866 | virtual KeyIterator_t keys() const = 0; |
867 | |
868 | + virtual void clear() = 0; |
869 | + |
870 | store::IndexCondition_t createCondition(store::IndexCondition::Kind k); |
871 | |
872 | // |
873 | |
874 | === modified file 'src/store/naive/simple_index_general.cpp' |
875 | --- src/store/naive/simple_index_general.cpp 2012-02-15 10:25:02 +0000 |
876 | +++ src/store/naive/simple_index_general.cpp 2012-03-08 18:55:32 +0000 |
877 | @@ -755,6 +755,26 @@ |
878 | } |
879 | |
880 | |
881 | +/****************************************************************************** |
882 | + |
883 | +*******************************************************************************/ |
884 | +void GeneralHashIndex::clear() |
885 | +{ |
886 | + for (ulong i = 0; i < store::XS_LAST; ++i) |
887 | + { |
888 | + if (theMaps[i] == NULL) |
889 | + continue; |
890 | + |
891 | + theMaps[i]->clear(); |
892 | + } |
893 | + |
894 | + if (isTyped()) |
895 | + { |
896 | + theSingleMap->clear(); |
897 | + } |
898 | +} |
899 | + |
900 | + |
901 | ///////////////////////////////////////////////////////////////////////////////// |
902 | // // |
903 | // GeneralHashIndex::KeyIterator // |
904 | @@ -912,6 +932,26 @@ |
905 | /****************************************************************************** |
906 | |
907 | *******************************************************************************/ |
908 | +void GeneralTreeIndex::clear() |
909 | +{ |
910 | + for (ulong i = 0; i < store::XS_LAST; ++i) |
911 | + { |
912 | + if (theMaps[i] == NULL) |
913 | + continue; |
914 | + |
915 | + theMaps[i]->clear(); |
916 | + } |
917 | + |
918 | + if (isTyped()) |
919 | + { |
920 | + theSingleMap->clear(); |
921 | + } |
922 | +} |
923 | + |
924 | + |
925 | +/****************************************************************************** |
926 | + |
927 | +*******************************************************************************/ |
928 | store::Index::KeyIterator_t GeneralTreeIndex::keys() const |
929 | { |
930 | return 0; |
931 | |
932 | === modified file 'src/store/naive/simple_index_general.h' |
933 | --- src/store/naive/simple_index_general.h 2012-02-28 20:45:43 +0000 |
934 | +++ src/store/naive/simple_index_general.h 2012-03-08 18:55:32 +0000 |
935 | @@ -238,6 +238,8 @@ |
936 | Index::KeyIterator_t keys() const; |
937 | |
938 | bool remove(const store::Item_t& key, store::Item_t& item, bool); |
939 | + |
940 | + void clear(); |
941 | }; |
942 | |
943 | |
944 | @@ -291,6 +293,8 @@ |
945 | Index::KeyIterator_t keys() const; |
946 | |
947 | bool remove(const store::Item_t& key, store::Item_t& item, bool all); |
948 | + |
949 | + void clear(); |
950 | }; |
951 | |
952 | |
953 | |
954 | === modified file 'src/store/naive/simple_pul.cpp' |
955 | --- src/store/naive/simple_pul.cpp 2012-03-07 14:22:29 +0000 |
956 | +++ src/store/naive/simple_pul.cpp 2012-03-08 18:55:32 +0000 |
957 | @@ -944,6 +944,17 @@ |
958 | } |
959 | |
960 | |
961 | +void PULImpl::addTruncateCollection( |
962 | + const QueryLoc* aQueryLoc, |
963 | + store::Item_t& name, |
964 | + bool dyn_collection) |
965 | +{ |
966 | + CollectionPul* pul = getCollectionPulByName(name.getp(),dyn_collection); |
967 | + |
968 | + pul->theTruncateCollectionList.push_back( |
969 | + GET_PUL_FACTORY().createUpdTruncateCollection(pul, aQueryLoc, name, dyn_collection)); |
970 | +} |
971 | + |
972 | /******************************************************************************* |
973 | Index primitives |
974 | ********************************************************************************/ |
975 | @@ -1157,6 +1168,11 @@ |
976 | UP_LIST_NONE); |
977 | |
978 | mergeUpdateList(thisPul, |
979 | + thisPul->theTruncateCollectionList, |
980 | + otherPul->theTruncateCollectionList, |
981 | + UP_LIST_NONE); |
982 | + |
983 | + mergeUpdateList(thisPul, |
984 | thisPul->theDeleteCollectionList, |
985 | otherPul->theDeleteCollectionList, |
986 | UP_LIST_NONE); |
987 | @@ -1502,7 +1518,9 @@ |
988 | This method is invoked by the ApplyIterator before any of the pul primitives |
989 | is applied. |
990 | ********************************************************************************/ |
991 | -void PULImpl::getIndicesToRefresh(std::vector<store::Index*>& indices) |
992 | +void PULImpl::getIndicesToRefresh( |
993 | + std::vector<store::Index*>& indices, |
994 | + std::vector<store::Index*>& truncate_indices) |
995 | { |
996 | SimpleStore* store = &GET_STORE(); |
997 | |
998 | @@ -1513,6 +1531,7 @@ |
999 | // modified/inserted/deleted collection docs, because they will be need later |
1000 | // to maintain indices. |
1001 | std::set<store::Collection*> collections; |
1002 | + std::set<store::Collection*> truncated_collections; |
1003 | |
1004 | CollectionPulMap::iterator collIte = theCollectionPuls.begin(); |
1005 | CollectionPulMap::iterator collEnd = theCollectionPuls.end(); |
1006 | @@ -1529,6 +1548,12 @@ |
1007 | |
1008 | CollectionPul* pul = collIte->second; |
1009 | |
1010 | + if (pul->theTruncateCollectionList.size() > 0) |
1011 | + { |
1012 | + truncated_collections.insert(collection); |
1013 | + continue; |
1014 | + } |
1015 | + |
1016 | NodeToUpdatesMap::iterator ite = pul->theNodeToUpdatesMap.begin(); |
1017 | NodeToUpdatesMap::iterator end = pul->theNodeToUpdatesMap.end(); |
1018 | for (; ite != end; ++ite) |
1019 | @@ -1595,6 +1620,21 @@ |
1020 | if (colIte != colEnd) |
1021 | break; |
1022 | } |
1023 | + |
1024 | + for (csize i = 0; i < numIndexSources; ++i) |
1025 | + { |
1026 | + std::set<store::Collection*>::const_iterator colIte = truncated_collections.begin(); |
1027 | + std::set<store::Collection*>::const_iterator colEnd = truncated_collections.end(); |
1028 | + |
1029 | + for (; colIte != colEnd; ++colIte) |
1030 | + { |
1031 | + if (indexSources[i]->equals((*colIte)->getName())) |
1032 | + { |
1033 | + truncate_indices.push_back(index); |
1034 | + break; |
1035 | + } |
1036 | + } |
1037 | + } |
1038 | } |
1039 | } |
1040 | |
1041 | @@ -1617,6 +1657,18 @@ |
1042 | /******************************************************************************* |
1043 | |
1044 | ********************************************************************************/ |
1045 | +void PULImpl::addIndexTruncator( |
1046 | + const store::Item* collectionName, |
1047 | + store::Index* idx) |
1048 | +{ |
1049 | + CollectionPul* pul = getCollectionPulByName(collectionName,false); |
1050 | + pul->theTruncatedIndices.push_back(static_cast<IndexImpl*>(idx)); |
1051 | +} |
1052 | + |
1053 | + |
1054 | +/******************************************************************************* |
1055 | + |
1056 | +********************************************************************************/ |
1057 | void PULImpl::setICChecker(store::ICChecker* icChecker) |
1058 | { |
1059 | theICChecker = icChecker; |
1060 | @@ -1796,6 +1848,7 @@ |
1061 | cleanList(theCreateCollectionList); |
1062 | cleanList(theInsertIntoCollectionList); |
1063 | cleanList(theDeleteFromCollectionList); |
1064 | + cleanList(theTruncateCollectionList); |
1065 | cleanList(theDeleteCollectionList); |
1066 | |
1067 | cleanIndexDeltas(theBeforeIndexDeltas); |
1068 | @@ -1822,6 +1875,7 @@ |
1069 | switchPulInPrimitivesList(theCreateCollectionList); |
1070 | switchPulInPrimitivesList(theInsertIntoCollectionList); |
1071 | switchPulInPrimitivesList(theDeleteFromCollectionList); |
1072 | + switchPulInPrimitivesList(theTruncateCollectionList); |
1073 | switchPulInPrimitivesList(theDeleteCollectionList); |
1074 | } |
1075 | |
1076 | @@ -1946,7 +2000,14 @@ |
1077 | ********************************************************************************/ |
1078 | void CollectionPul::refreshIndices() |
1079 | { |
1080 | - csize numIncrementalIndices = theIncrementalIndices.size(); |
1081 | + csize numIncrementalIndices = theTruncatedIndices.size(); |
1082 | + for (csize idx = 0; idx < numIncrementalIndices; ++idx) |
1083 | + { |
1084 | + ValueIndex* index = static_cast<ValueIndex*>(theTruncatedIndices[idx]); |
1085 | + index->clear(); |
1086 | + } |
1087 | + |
1088 | + numIncrementalIndices = theIncrementalIndices.size(); |
1089 | |
1090 | for (csize idx = 0; idx < numIncrementalIndices; ++idx) |
1091 | { |
1092 | @@ -2134,6 +2195,7 @@ |
1093 | applyList(theCreateCollectionList); |
1094 | applyList(theInsertIntoCollectionList); |
1095 | applyList(theDeleteFromCollectionList); |
1096 | + applyList(theTruncateCollectionList); |
1097 | |
1098 | // Compute the after-delta for each incrementally maintained index. |
1099 | computeIndexAfterDeltas(); |
1100 | @@ -2266,6 +2328,7 @@ |
1101 | |
1102 | try |
1103 | { |
1104 | + undoList(theTruncateCollectionList); |
1105 | undoList(theDeleteFromCollectionList); |
1106 | undoList(theInsertIntoCollectionList); |
1107 | undoList(theCreateCollectionList); |
1108 | |
1109 | === modified file 'src/store/naive/simple_pul.h' |
1110 | --- src/store/naive/simple_pul.h 2012-03-07 14:22:29 +0000 |
1111 | +++ src/store/naive/simple_pul.h 2012-03-08 18:55:32 +0000 |
1112 | @@ -183,6 +183,7 @@ |
1113 | std::vector<UpdatePrimitive*> theCreateCollectionList; |
1114 | std::vector<UpdatePrimitive*> theInsertIntoCollectionList; |
1115 | std::vector<UpdatePrimitive*> theDeleteFromCollectionList; |
1116 | + std::vector<UpdatePrimitive*> theTruncateCollectionList; |
1117 | std::vector<UpdatePrimitive*> theDeleteCollectionList; |
1118 | |
1119 | // Validate in place primitives |
1120 | @@ -194,6 +195,7 @@ |
1121 | std::vector<XmlNode*> theDeletedDocs; |
1122 | |
1123 | std::vector<IndexImpl*> theIncrementalIndices; |
1124 | + std::vector<IndexImpl*> theTruncatedIndices; |
1125 | |
1126 | std::vector<IndexEntryCreator_t> theIndexEntryCreators; |
1127 | |
1128 | @@ -465,6 +467,11 @@ |
1129 | bool isLast, |
1130 | bool dyn_collection = false); |
1131 | |
1132 | + void addTruncateCollection( |
1133 | + const QueryLoc* aQueryLoc, |
1134 | + store::Item_t& name, |
1135 | + bool dyn_collection = false); |
1136 | + |
1137 | // Index primitives |
1138 | void addCreateIndex( |
1139 | const QueryLoc* aQueryLoc, |
1140 | @@ -539,13 +546,19 @@ |
1141 | // utils |
1142 | void checkTransformUpdates(const std::vector<store::Item*>& rootNodes) const; |
1143 | |
1144 | - void getIndicesToRefresh(std::vector<store::Index*>& indices); |
1145 | + void getIndicesToRefresh( |
1146 | + std::vector<store::Index*>& indices, |
1147 | + std::vector<store::Index*>& truncate_indices); |
1148 | |
1149 | void addIndexEntryCreator( |
1150 | const store::Item* collectionName, |
1151 | store::Index* idx, |
1152 | store::IndexEntryCreator* creator); |
1153 | |
1154 | + void addIndexTruncator( |
1155 | + const store::Item* collectionName, |
1156 | + store::Index* idx); |
1157 | + |
1158 | void setValidator(store::SchemaValidator* validator); |
1159 | store::SchemaValidator* getValidator() const { return theValidator; } |
1160 | |
1161 | |
1162 | === added file 'test/rbkt/ExpQueryResults/zorba/collections/delete_nodes/truncate_001.xml.res' |
1163 | --- test/rbkt/ExpQueryResults/zorba/collections/delete_nodes/truncate_001.xml.res 1970-01-01 00:00:00 +0000 |
1164 | +++ test/rbkt/ExpQueryResults/zorba/collections/delete_nodes/truncate_001.xml.res 2012-03-08 18:55:32 +0000 |
1165 | @@ -0,0 +1,1 @@ |
1166 | +<a>1</a><a>2</a><a>3</a><a>4</a><a>5</a><a>6</a><a>7</a><a>8</a><a>9</a><a>10</a><b>1</b><b>2</b><b>3</b><b>4</b><b>5</b><b>6</b><b>7</b><b>8</b><b>9</b><b>10</b> |
1167 | |
1168 | === added file 'test/rbkt/ExpQueryResults/zorba/collections/dynamic6.xml.res' |
1169 | --- test/rbkt/ExpQueryResults/zorba/collections/dynamic6.xml.res 1970-01-01 00:00:00 +0000 |
1170 | +++ test/rbkt/ExpQueryResults/zorba/collections/dynamic6.xml.res 2012-03-08 18:55:32 +0000 |
1171 | @@ -0,0 +1,1 @@ |
1172 | +0 |
1173 | |
1174 | === added file 'test/rbkt/ExpQueryResults/zorba/index/auctions2.xml.res' |
1175 | --- test/rbkt/ExpQueryResults/zorba/index/auctions2.xml.res 1970-01-01 00:00:00 +0000 |
1176 | +++ test/rbkt/ExpQueryResults/zorba/index/auctions2.xml.res 2012-03-08 18:55:32 +0000 |
1177 | @@ -0,0 +1,1 @@ |
1178 | +<person id="person0"><city>Macon</city></person> |
1179 | |
1180 | === modified file 'test/rbkt/Queries/zorba/collections/collection_002.xqdata' |
1181 | --- test/rbkt/Queries/zorba/collections/collection_002.xqdata 2011-06-24 19:58:33 +0000 |
1182 | +++ test/rbkt/Queries/zorba/collections/collection_002.xqdata 2012-03-08 18:55:32 +0000 |
1183 | @@ -2,4 +2,6 @@ |
1184 | |
1185 | declare collection ns:collection as node()*; |
1186 | |
1187 | -declare function ns:test2() { () }; |
1188 | \ No newline at end of file |
1189 | +declare collection ns:collection2 as node()*; |
1190 | + |
1191 | +declare function ns:test2() { () }; |
1192 | |
1193 | === added file 'test/rbkt/Queries/zorba/collections/delete_nodes/truncate_001.xq' |
1194 | --- test/rbkt/Queries/zorba/collections/delete_nodes/truncate_001.xq 1970-01-01 00:00:00 +0000 |
1195 | +++ test/rbkt/Queries/zorba/collections/delete_nodes/truncate_001.xq 2012-03-08 18:55:32 +0000 |
1196 | @@ -0,0 +1,27 @@ |
1197 | +import module namespace ddl = "http://www.zorba-xquery.com/modules/store/static/collections/ddl"; |
1198 | +import module namespace dml = "http://www.zorba-xquery.com/modules/store/static/collections/dml"; |
1199 | + |
1200 | +import module namespace ns = "http://www.example.com/example" at "../collection_002.xqdata"; |
1201 | + |
1202 | +variable $contents; |
1203 | + |
1204 | +ddl:create(xs:QName("ns:collection")); |
1205 | +ddl:create(xs:QName("ns:collection2")); |
1206 | + |
1207 | +dml:insert-nodes( |
1208 | + xs:QName("ns:collection"), |
1209 | + for $i in 1 to 10 return <a>{$i}</a> |
1210 | +); |
1211 | + |
1212 | +dml:insert-nodes( |
1213 | + xs:QName("ns:collection2"), |
1214 | + for $i in 1 to 10 return <b>{$i}</b> |
1215 | +); |
1216 | + |
1217 | +$contents := (dml:collection(xs:QName("ns:collection")), dml:collection(xs:QName("ns:collection2"))); |
1218 | + |
1219 | +(dml:truncate(xs:QName("ns:collection")), dml:truncate(xs:QName("ns:collection2"))); |
1220 | + |
1221 | +$contents := ($contents, dml:collection(xs:QName("ns:collection")), dml:collection(xs:QName("ns:collection"))); |
1222 | + |
1223 | +$contents |
1224 | |
1225 | === added file 'test/rbkt/Queries/zorba/collections/dynamic6.xq' |
1226 | --- test/rbkt/Queries/zorba/collections/dynamic6.xq 1970-01-01 00:00:00 +0000 |
1227 | +++ test/rbkt/Queries/zorba/collections/dynamic6.xq 2012-03-08 18:55:32 +0000 |
1228 | @@ -0,0 +1,10 @@ |
1229 | +import module namespace ddl = "http://www.zorba-xquery.com/modules/store/dynamic/collections/ddl"; |
1230 | +import module namespace dml = "http://www.zorba-xquery.com/modules/store/dynamic/collections/dml"; |
1231 | + |
1232 | +ddl:create(xs:QName("ddl:test2"),(<center1/>,<oldlast/>)); |
1233 | + |
1234 | +dml:insert-nodes-first(xs:QName("ddl:test2"), (<c1/>,<c2/>)); |
1235 | + |
1236 | +dml:truncate(xs:QName("ddl:test2")); |
1237 | + |
1238 | +count(dml:collection(xs:QName("ddl:test2"))) |
1239 | |
1240 | === added file 'test/rbkt/Queries/zorba/index/auctions2.xq' |
1241 | --- test/rbkt/Queries/zorba/index/auctions2.xq 1970-01-01 00:00:00 +0000 |
1242 | +++ test/rbkt/Queries/zorba/index/auctions2.xq 2012-03-08 18:55:32 +0000 |
1243 | @@ -0,0 +1,25 @@ |
1244 | +import module namespace auctions = "http://www.w3.org/TestModules/auctions" at |
1245 | + "auctions_module1.xqlib"; |
1246 | + |
1247 | +import module namespace ddl = "http://www.zorba-xquery.com/modules/store/static/collections/ddl"; |
1248 | +import module namespace dml = "http://www.zorba-xquery.com/modules/store/static/collections/dml"; |
1249 | +import module namespace index_ddl = "http://www.zorba-xquery.com/modules/store/static/indexes/ddl"; |
1250 | +import module namespace index_dml = "http://www.zorba-xquery.com/modules/store/static/indexes/dml"; |
1251 | + |
1252 | +declare namespace err = "http://www.w3.org/2005/xqt-errors"; |
1253 | + |
1254 | +auctions:create-db(); |
1255 | + |
1256 | +variable $cities := (); |
1257 | + |
1258 | +$cities := for $x in auctions:probe-point-city(xs:QName("auctions:PersonCity"), "Macon") |
1259 | + return <person id = "{$x/@id}">{$x//city}</person>; |
1260 | + |
1261 | +dml:truncate(xs:QName("auctions:auctions")); |
1262 | + |
1263 | +$cities := ($cities, |
1264 | + for $x in auctions:probe-point-city(xs:QName("auctions:PersonCity"), "Macon") |
1265 | + return <person id = "{$x/@id}">{$x//city}</person>); |
1266 | + |
1267 | +$cities |
1268 | + |
- fix bug #938934 "collection dml:truncate function missing"
- fixes documentation bug: raise zerr:ZDDY0003 instead of zerr:ZDDY0009