Merge lp:~zorba-coders/zorba/bug-938934 into lp:zorba

Proposed by Matthias Brantner
Status: Superseded
Proposed branch: lp:~zorba-coders/zorba/bug-938934
Merge into: lp:zorba
Diff against target: 1160 lines (+624/-9)
34 files modified
ChangeLog (+1/-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/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/pul_primitive_factory.cpp (+12/-0)
src/store/naive/pul_primitive_factory.h (+10/-0)
src/store/naive/pul_primitives.cpp (+30/-0)
src/store/naive/pul_primitives.h (+31/-0)
src/store/naive/simple_collection.h (+1/-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
Reviewer Review Type Date Requested Status
Markos Zaharioudakis Needs Fixing
Matthias Brantner Approve
Till Westmann Pending
Review via email: mp+94897@code.launchpad.net

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

To post a comment you must log in.
Revision history for this message
Matthias Brantner (matthias-brantner) wrote :

- fix bug #938934 "collection dml:truncate function missing"
- fixes documentation bug: raise zerr:ZDDY0003 instead of zerr:ZDDY0009

Revision history for this message
Zorba Build Bot (zorba-buildbot) wrote :
Revision history for this message
Zorba Build Bot (zorba-buildbot) wrote :

Validation queue job bug-938934-2012-02-28T02-03-09.189Z is finished. The final status was:

All tests succeeded!

Revision history for this message
Zorba Build Bot (zorba-buildbot) wrote :

Voting does not meet specified criteria. Required: Approve > 1, Disapprove < 1. Got: 2 Pending.

Revision history for this message
Matthias Brantner (matthias-brantner) :
review: Approve
Revision history for this message
Markos Zaharioudakis (markos-za) :
review: Approve
Revision history for this message
Markos Zaharioudakis (markos-za) wrote :

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.

review: Needs Fixing
Revision history for this message
Markos Zaharioudakis (markos-za) wrote :

Another bug: the UpdTruncateCollection::apply() method does not work if there are multiple truncate primitives in the same PUL.

lp:~zorba-coders/zorba/bug-938934 updated
10682. By Matthias Brantner

clear functions for indexes

10683. By Matthias Brantner

index management if a collection is truncated

10684. By Matthias Brantner

extended test for two truncate primitives in one PUL

Revision history for this message
Matthias Brantner (matthias-brantner) wrote :

- 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)

lp:~zorba-coders/zorba/bug-938934 updated
10685. By Matthias Brantner

added truncate function decl for dynamic collections

10686. By Matthias Brantner

merge

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

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
=== modified file 'ChangeLog'
--- ChangeLog 2012-03-07 15:49:25 +0000
+++ ChangeLog 2012-03-08 01:45:23 +0000
@@ -10,6 +10,7 @@
10 %ann:must-copy-input-nodes to be used by the no-copy optimization.10 %ann:must-copy-input-nodes to be used by the no-copy optimization.
11 * Caching of results for recursive functions with atomic parameter and return types.11 * Caching of results for recursive functions with atomic parameter and return types.
12 * Added %ann:cache and %ann:no-cache to enable or disable caching of results of functions with atomic parameter and return types.12 * Added %ann:cache and %ann:no-cache to enable or disable caching of results of functions with atomic parameter and return types.
13 * Added truncate function to the collection modules for efficient deletion of all nodes in a collection.
13 * Fixed bug 917923 (bug in copying outer var values into the eval dynamic context)14 * Fixed bug 917923 (bug in copying outer var values into the eval dynamic context)
14 * Fixed bug 867509 (Can not handle largest xs:unsignedLong values)15 * Fixed bug 867509 (Can not handle largest xs:unsignedLong values)
15 * Fixed bug 924063 (sentence is incorrectly incremented when token characters end without sentence terminator)16 * Fixed bug 924063 (sentence is incorrectly incremented when token characters end without sentence terminator)
1617
=== modified file 'modules/com/zorba-xquery/www/modules/store/dynamic/collections/dml.xq'
--- modules/com/zorba-xquery/www/modules/store/dynamic/collections/dml.xq 2011-08-26 23:36:24 +0000
+++ modules/com/zorba-xquery/www/modules/store/dynamic/collections/dml.xq 2012-03-08 01:45:23 +0000
@@ -260,7 +260,7 @@
260 : @return The result of this function is an empty XDM instance and a pending update260 : @return The result of this function is an empty XDM instance and a pending update
261 : list which, once applied, deletes the last node from the collection.261 : list which, once applied, deletes the last node from the collection.
262 :262 :
263 : @error zerr:ZDDY0009 If available collections does not provide a mapping263 : @error zerr:ZDDY0003 If available collections does not provide a mapping
264 : for the expanded QName $name.264 : for the expanded QName $name.
265 : @error zerr:ZDDY0011 if the collection doesn't contain any node.265 : @error zerr:ZDDY0011 if the collection doesn't contain any node.
266 :266 :
@@ -278,7 +278,7 @@
278 : @return The result of this function is an empty XDM instance and a pending update278 : @return The result of this function is an empty XDM instance and a pending update
279 : list which, once applied, deletes the last n nodes.279 : list which, once applied, deletes the last n nodes.
280 :280 :
281 : @error zerr:ZDDY0009 If available collections does not provide a mapping281 : @error zerr:ZDDY0003 If available collections does not provide a mapping
282 : for the expanded QName $name.282 : for the expanded QName $name.
283 : @error zerr:ZDDY0011 if the collection doesn't contain the given number of nodes.283 : @error zerr:ZDDY0011 if the collection doesn't contain the given number of nodes.
284 :284 :
@@ -288,6 +288,19 @@
288 $number as xs:integer) external;288 $number as xs:integer) external;
289289
290(:~290(:~
291 : The truncate function is an updating function that deletes the
292 : entire contents of collection.
293 :
294 : @param $name The name of the collection whose content to delete
295 :
296 : @return The result of this function is an empty XDM instance and a pending update
297 : list which, once applied, deletes the nodes.
298 :
299 : @error zerr:ZDDY0003 if the collection identified by $name is not available.
300 :)
301declare updating function dml:truncate($name as xs:QName) external;
302
303(:~
291 : The index-of function return the index of the given node in the collection.304 : The index-of function return the index of the given node in the collection.
292 :305 :
293 : @param $node The node to retrieve the index from.306 : @param $node The node to retrieve the index from.
@@ -307,7 +320,7 @@
307 :320 :
308 : @return The sequence contained in the given collection.321 : @return The sequence contained in the given collection.
309 :322 :
310 : @error zerr:ZDDY0009 If available collections does not provide a mapping323 : @error zerr:ZDDY0003 If available collections does not provide a mapping
311 : for the expanded QName $name.324 : for the expanded QName $name.
312 :325 :
313 :)326 :)
314327
=== modified file 'modules/com/zorba-xquery/www/modules/store/static/collections/dml.xq'
--- modules/com/zorba-xquery/www/modules/store/static/collections/dml.xq 2011-10-03 09:18:49 +0000
+++ modules/com/zorba-xquery/www/modules/store/static/collections/dml.xq 2012-03-08 01:45:23 +0000
@@ -409,6 +409,21 @@
409 $number as xs:integer) external;409 $number as xs:integer) external;
410410
411(:~411(:~
412 : The truncate function is an updating function that deletes the
413 : entire contents of collection.
414 :
415 : @param $name The name of the collection whose content to delete
416 :
417 : @return The result of this function is an empty XDM instance and a pending update
418 : list which, once applied, deletes the nodes.
419 :
420 : @error zerr:ZDDY0001 if the collection identified by $name is not declared.
421 : @error zerr:ZDDY0003 if the collection identified by $name is not available.
422 :
423 :)
424declare updating function cdml:truncate($name as xs:QName) external;
425
426(:~
412 : The index-of function that returns the position of the node in its collection.427 : The index-of function that returns the position of the node in its collection.
413 :428 :
414 : @param $node The node to retrieve the index for.429 : @param $node The node to retrieve the index for.
415430
=== modified file 'src/functions/func_collections_impl.cpp'
--- src/functions/func_collections_impl.cpp 2012-02-16 12:48:17 +0000
+++ src/functions/func_collections_impl.cpp 2012-03-08 01:45:23 +0000
@@ -293,6 +293,21 @@
293/*******************************************************************************293/*******************************************************************************
294294
295********************************************************************************/295********************************************************************************/
296PlanIter_t zorba_store_collections_static_dml_truncate::codegen(
297 CompilerCB*,
298 static_context* sctx,
299 const QueryLoc& loc,
300 std::vector<PlanIter_t>& argv,
301 expr& ann) const
302{
303 return new ZorbaTruncateCollectionIterator(sctx, loc, argv,
304 getName()->getNamespace() == static_context::ZORBA_STORE_DYNAMIC_COLLECTIONS_DML_FN_NS);
305}
306
307
308/*******************************************************************************
309
310********************************************************************************/
296PlanIter_t zorba_store_collections_static_dml_delete_node_first::codegen(311PlanIter_t zorba_store_collections_static_dml_delete_node_first::codegen(
297 CompilerCB*,312 CompilerCB*,
298 static_context* sctx,313 static_context* sctx,
299314
=== modified file 'src/functions/pregenerated/func_collections.cpp'
--- src/functions/pregenerated/func_collections.cpp 2012-02-16 12:48:17 +0000
+++ src/functions/pregenerated/func_collections.cpp 2012-03-08 01:45:23 +0000
@@ -58,6 +58,7 @@
5858
5959
6060
61
61PlanIter_t zorba_store_collections_static_dml_collection_name::codegen(62PlanIter_t zorba_store_collections_static_dml_collection_name::codegen(
62 CompilerCB*,63 CompilerCB*,
63 static_context* sctx,64 static_context* sctx,
@@ -686,6 +687,30 @@
686 {687 {
687 688
688689
690 DECL_WITH_KIND(sctx, zorba_store_collections_static_dml_truncate,
691 (createQName("http://www.zorba-xquery.com/modules/store/static/collections/dml","","truncate"),
692 GENV_TYPESYSTEM.QNAME_TYPE_ONE,
693 GENV_TYPESYSTEM.EMPTY_TYPE),
694 FunctionConsts::ZORBA_STORE_COLLECTIONS_STATIC_DML_TRUNCATE_1);
695
696 }
697
698
699 {
700
701
702 DECL_WITH_KIND(sctx, zorba_store_collections_static_dml_truncate,
703 (createQName("http://www.zorba-xquery.com/modules/store/dynamic/collections/dml","","truncate"),
704 GENV_TYPESYSTEM.QNAME_TYPE_ONE,
705 GENV_TYPESYSTEM.EMPTY_TYPE),
706 FunctionConsts::ZORBA_STORE_DYNAMIC_COLLECTIONS_DML_TRUNCATE_1);
707
708 }
709
710
711 {
712
713
689 DECL_WITH_KIND(sctx, zorba_store_collections_static_dml_collection_name,714 DECL_WITH_KIND(sctx, zorba_store_collections_static_dml_collection_name,
690 (createQName("http://www.zorba-xquery.com/modules/store/static/collections/dml","","collection-name"), 715 (createQName("http://www.zorba-xquery.com/modules/store/static/collections/dml","","collection-name"),
691 GENV_TYPESYSTEM.ANY_NODE_TYPE_ONE, 716 GENV_TYPESYSTEM.ANY_NODE_TYPE_ONE,
692717
=== modified file 'src/functions/pregenerated/func_collections.h'
--- src/functions/pregenerated/func_collections.h 2012-01-11 17:30:25 +0000
+++ src/functions/pregenerated/func_collections.h 2012-03-08 01:45:23 +0000
@@ -434,6 +434,25 @@
434};434};
435435
436436
437//zorba-store-collections-static-dml:truncate
438class zorba_store_collections_static_dml_truncate : public function
439{
440public:
441 zorba_store_collections_static_dml_truncate(const signature& sig, FunctionConsts::FunctionKind kind)
442 :
443 function(sig, kind)
444 {
445
446 }
447
448 short getScriptingKind() const { return UPDATING_EXPR; }
449
450 bool accessesDynCtx() const { return true; }
451
452 CODEGEN_DECL();
453};
454
455
437//zorba-store-collections-static-dml:collection-name456//zorba-store-collections-static-dml:collection-name
438class zorba_store_collections_static_dml_collection_name : public function457class zorba_store_collections_static_dml_collection_name : public function
439{458{
440459
=== modified file 'src/functions/pregenerated/function_enum.h'
--- src/functions/pregenerated/function_enum.h 2012-03-07 15:49:25 +0000
+++ src/functions/pregenerated/function_enum.h 2012-03-08 01:45:23 +0000
@@ -79,6 +79,8 @@
79 ZORBA_STORE_COLLECTIONS_STATIC_DML_DELETE_NODES_LAST_2,79 ZORBA_STORE_COLLECTIONS_STATIC_DML_DELETE_NODES_LAST_2,
80 ZORBA_STORE_DYNAMIC_COLLECTIONS_DML_DELETE_NODE_LAST_1,80 ZORBA_STORE_DYNAMIC_COLLECTIONS_DML_DELETE_NODE_LAST_1,
81 ZORBA_STORE_DYNAMIC_COLLECTIONS_DML_DELETE_NODES_LAST_2,81 ZORBA_STORE_DYNAMIC_COLLECTIONS_DML_DELETE_NODES_LAST_2,
82 ZORBA_STORE_COLLECTIONS_STATIC_DML_TRUNCATE_1,
83 ZORBA_STORE_DYNAMIC_COLLECTIONS_DML_TRUNCATE_1,
82 ZORBA_STORE_COLLECTIONS_STATIC_DML_COLLECTION_NAME_1,84 ZORBA_STORE_COLLECTIONS_STATIC_DML_COLLECTION_NAME_1,
83 ZORBA_STORE_DYNAMIC_COLLECTIONS_DML_COLLECTION_NAME_1,85 ZORBA_STORE_DYNAMIC_COLLECTIONS_DML_COLLECTION_NAME_1,
84 ZORBA_STORE_COLLECTIONS_STATIC_DDL_IS_AVAILABLE_COLLECTION_1,86 ZORBA_STORE_COLLECTIONS_STATIC_DDL_IS_AVAILABLE_COLLECTION_1,
8587
=== modified file 'src/runtime/collections/collections_impl.cpp'
--- src/runtime/collections/collections_impl.cpp 2012-02-16 12:48:17 +0000
+++ src/runtime/collections/collections_impl.cpp 2012-03-08 01:45:23 +0000
@@ -1796,6 +1796,93 @@
1796/*******************************************************************************1796/*******************************************************************************
17971797
1798********************************************************************************/1798********************************************************************************/
1799bool ZorbaTruncateCollectionIterator::nextImpl(
1800 store::Item_t& result,
1801 PlanState& planState) const
1802{
1803 store::Collection_t collection;
1804 store::Item_t collectionName;
1805 std::auto_ptr<store::PUL> pul;
1806
1807 PlanIteratorState* state;
1808 DEFAULT_STACK_INIT(PlanIteratorState, state, planState);
1809
1810 consumeNext(collectionName, theChildren[0].getp(), planState);
1811
1812 (void)getCollection(
1813 theSctx, collectionName, loc, theDynamicCollection, collection);
1814
1815 // create the pul and add the primitive
1816 pul.reset(GENV_ITEMFACTORY->createPendingUpdateList());
1817
1818 pul->addTruncateCollection(&loc, collectionName, theDynamicCollection);
1819
1820 result = pul.release();
1821 STACK_PUSH( result != NULL, state);
1822
1823 STACK_END (state);
1824}
1825
1826/*******************************************************************************
1827
1828********************************************************************************/
1829const StaticallyKnownCollection*
1830ZorbaTruncateCollectionIterator::getCollection(
1831 const static_context* aSctx,
1832 const store::Item_t& aName,
1833 const QueryLoc& aLoc,
1834 bool aDynamicCollection,
1835 store::Collection_t& coll) const
1836{
1837 const StaticallyKnownCollection* collectionDecl = aSctx->lookup_collection(aName);
1838 if (collectionDecl == 0 && !aDynamicCollection)
1839 {
1840 throw XQUERY_EXCEPTION(
1841 zerr::ZDDY0001_COLLECTION_NOT_DECLARED,
1842 ERROR_PARAMS( aName->getStringValue() ),
1843 ERROR_LOC( aLoc )
1844 );
1845 }
1846
1847 if (!aDynamicCollection)
1848 {
1849 // checking collection update mode
1850 switch(collectionDecl->getUpdateProperty())
1851 {
1852 case StaticContextConsts::decl_const:
1853 throw XQUERY_EXCEPTION(
1854 zerr::ZDDY0004_COLLECTION_CONST_UPDATE,
1855 ERROR_PARAMS( aName->getStringValue() ),
1856 ERROR_LOC( loc )
1857 );
1858
1859 case StaticContextConsts::decl_append_only:
1860 throw XQUERY_EXCEPTION(
1861 zerr::ZDDY0005_COLLECTION_APPEND_BAD_INSERT,
1862 ERROR_PARAMS( aName->getStringValue() ),
1863 ERROR_LOC( loc )
1864 );
1865 default: break;
1866 }
1867 }
1868
1869 coll = GENV_STORE.getCollection(aName, aDynamicCollection);
1870
1871 if (coll == NULL)
1872 {
1873 throw XQUERY_EXCEPTION(
1874 zerr::ZDDY0003_COLLECTION_DOES_NOT_EXIST,
1875 ERROR_PARAMS( aName->getStringValue() ),
1876 ERROR_LOC( aLoc )
1877 );
1878 }
1879
1880 return collectionDecl;
1881}
1882
1883/*******************************************************************************
1884
1885********************************************************************************/
1799bool ZorbaCollectionNameIterator::nextImpl(1886bool ZorbaCollectionNameIterator::nextImpl(
1800 store::Item_t& result,1887 store::Item_t& result,
1801 PlanState& planState) const1888 PlanState& planState) const
18021889
=== modified file 'src/runtime/collections/pregenerated/collections.cpp'
--- src/runtime/collections/pregenerated/collections.cpp 2011-11-01 14:26:48 +0000
+++ src/runtime/collections/pregenerated/collections.cpp 2012-03-08 01:45:23 +0000
@@ -551,6 +551,34 @@
551// </ZorbaDeleteNodesLastIterator>551// </ZorbaDeleteNodesLastIterator>
552552
553553
554// <ZorbaTruncateCollectionIterator>
555const char* ZorbaTruncateCollectionIterator::class_name_str = "ZorbaTruncateCollectionIterator";
556ZorbaTruncateCollectionIterator::class_factory<ZorbaTruncateCollectionIterator>
557ZorbaTruncateCollectionIterator::g_class_factory;
558
559const serialization::ClassVersion
560ZorbaTruncateCollectionIterator::class_versions[] ={{ 1, 0x000905, false}};
561
562const int ZorbaTruncateCollectionIterator::class_versions_count =
563sizeof(ZorbaTruncateCollectionIterator::class_versions)/sizeof(struct serialization::ClassVersion);
564
565void ZorbaTruncateCollectionIterator::accept(PlanIterVisitor& v) const {
566 v.beginVisit(*this);
567
568 std::vector<PlanIter_t>::const_iterator lIter = theChildren.begin();
569 std::vector<PlanIter_t>::const_iterator lEnd = theChildren.end();
570 for ( ; lIter != lEnd; ++lIter ){
571 (*lIter)->accept(v);
572 }
573
574 v.endVisit(*this);
575}
576
577ZorbaTruncateCollectionIterator::~ZorbaTruncateCollectionIterator() {}
578
579// </ZorbaTruncateCollectionIterator>
580
581
554// <ZorbaCollectionNameIterator>582// <ZorbaCollectionNameIterator>
555const char* ZorbaCollectionNameIterator::class_name_str = "ZorbaCollectionNameIterator";583const char* ZorbaCollectionNameIterator::class_name_str = "ZorbaCollectionNameIterator";
556ZorbaCollectionNameIterator::class_factory<ZorbaCollectionNameIterator>584ZorbaCollectionNameIterator::class_factory<ZorbaCollectionNameIterator>
557585
=== modified file 'src/runtime/collections/pregenerated/collections.h'
--- src/runtime/collections/pregenerated/collections.h 2011-11-01 14:26:48 +0000
+++ src/runtime/collections/pregenerated/collections.h 2012-03-08 01:45:23 +0000
@@ -865,6 +865,50 @@
865865
866/**866/**
867 * 867 *
868 * zorba:truncate
869 *
870 * Author: Zorba Team
871 */
872class ZorbaTruncateCollectionIterator : public NaryBaseIterator<ZorbaTruncateCollectionIterator, PlanIteratorState>
873{
874protected:
875 bool theDynamicCollection; //whether it's the function of the dynamic or the static collection module
876public:
877 SERIALIZABLE_CLASS(ZorbaTruncateCollectionIterator);
878
879 SERIALIZABLE_CLASS_CONSTRUCTOR2T(ZorbaTruncateCollectionIterator,
880 NaryBaseIterator<ZorbaTruncateCollectionIterator, PlanIteratorState>);
881
882 void serialize( ::zorba::serialization::Archiver& ar)
883 {
884 serialize_baseclass(ar,
885 (NaryBaseIterator<ZorbaTruncateCollectionIterator, PlanIteratorState>*)this);
886
887 ar & theDynamicCollection;
888 }
889
890 ZorbaTruncateCollectionIterator(
891 static_context* sctx,
892 const QueryLoc& loc,
893 std::vector<PlanIter_t>& children,
894 bool aDynamicCollection)
895 :
896 NaryBaseIterator<ZorbaTruncateCollectionIterator, PlanIteratorState>(sctx, loc, children),
897 theDynamicCollection(aDynamicCollection)
898 {}
899
900 virtual ~ZorbaTruncateCollectionIterator();
901
902public:
903 const StaticallyKnownCollection* getCollection(const static_context* sctx, const store::Item_t& name, const QueryLoc& loc, bool dyn_coll, store::Collection_t& coll) const;
904 void accept(PlanIterVisitor& v) const;
905
906 bool nextImpl(store::Item_t& result, PlanState& aPlanState) const;
907};
908
909
910/**
911 *
868 * zorba:collection-name912 * zorba:collection-name
869 * 913 *
870 * Author: Zorba Team914 * Author: Zorba Team
871915
=== modified file 'src/runtime/core/apply_updates.cpp'
--- src/runtime/core/apply_updates.cpp 2011-08-17 18:55:07 +0000
+++ src/runtime/core/apply_updates.cpp 2012-03-08 01:45:23 +0000
@@ -141,12 +141,13 @@
141 SchemaValidatorImpl validator(loc, sctx);141 SchemaValidatorImpl validator(loc, sctx);
142 ICCheckerImpl icChecker(sctx, gdctx);142 ICCheckerImpl icChecker(sctx, gdctx);
143 std::vector<store::Index*> indexes;143 std::vector<store::Index*> indexes;
144 std::vector<store::Index*> truncate_indexes;
144 store::ItemHandle<store::PUL> indexPul;145 store::ItemHandle<store::PUL> indexPul;
145146
146 // Get all the indexes that are associated with any of the collections that147 // Get all the indexes that are associated with any of the collections that
147 // are going to be updated by this pul. Check which of those indices can be148 // are going to be updated by this pul. Check which of those indices can be
148 // maintained incrementally, and pass this info back to the pul.149 // maintained incrementally, and pass this info back to the pul.
149 pul->getIndicesToRefresh(indexes);150 pul->getIndicesToRefresh(indexes, truncate_indexes);
150151
151 ulong numIndices = (ulong)indexes.size();152 ulong numIndices = (ulong)indexes.size();
152153
@@ -178,6 +179,17 @@
178 zorbaIndexes[i] = indexDecl;179 zorbaIndexes[i] = indexDecl;
179 }180 }
180181
182 numIndices = (ulong)truncate_indexes.size();
183 for (ulong i = 0; i < numIndices; ++i)
184 {
185 IndexDecl* indexDecl = sctx->lookup_index(indexes[i]->getName());
186
187 if (indexDecl->getMaintenanceMode() == IndexDecl::DOC_MAP)
188 {
189 pul->addIndexTruncator(indexDecl->getSourceName(0), indexes[i]);
190 }
191 }
192
181 try 193 try
182 {194 {
183 // Apply updates195 // Apply updates
184196
=== modified file 'src/runtime/spec/collections/collections.xml'
--- src/runtime/spec/collections/collections.xml 2012-01-11 17:30:25 +0000
+++ src/runtime/spec/collections/collections.xml 2012-03-08 01:45:23 +0000
@@ -924,6 +924,52 @@
924/*******************************************************************************924/*******************************************************************************
925********************************************************************************/925********************************************************************************/
926-->926-->
927<zorba:iterator name="ZorbaTruncateCollectionIterator" >
928
929 <zorba:description author="Zorba Team">
930 zorba:truncate
931 </zorba:description>
932
933 <zorba:function generateCodegen="false">
934
935 <zorba:signature localname="truncate" prefix="zorba-store-collections-static-dml">
936 <zorba:param>xs:QName</zorba:param>
937 <zorba:output>empty-sequence()</zorba:output>
938 </zorba:signature>
939
940 <zorba:signature localname="truncate" prefix="zorba-store-dynamic-collections-dml">
941 <zorba:param>xs:QName</zorba:param>
942 <zorba:output>empty-sequence()</zorba:output>
943 </zorba:signature>
944
945 <zorba:methods>
946 <zorba:getScriptingKind returnValue="UPDATING_EXPR"/>
947 <zorba:accessesDynCtx returnValue="true"/>
948 </zorba:methods>
949
950 </zorba:function>
951
952 <zorba:constructor>
953 <zorba:parameter type="bool" name="aDynamicCollection" />
954 </zorba:constructor>
955
956 <zorba:member type="bool" name="theDynamicCollection"
957 brief="whether it's the function of the dynamic or the static collection module"/>
958
959 <zorba:method const="true" name="getCollection" return="const StaticallyKnownCollection*">
960 <zorba:param type="const static_context*" name="sctx"/>
961 <zorba:param type="const store::Item_t&amp;" name="name"/>
962 <zorba:param type="const QueryLoc&amp;" name="loc"/>
963 <zorba:param type="bool" name="dyn_coll"/>
964 <zorba:param type="store::Collection_t&amp;" name="coll"/>
965 </zorba:method>
966</zorba:iterator>
967
968
969<!--
970/*******************************************************************************
971********************************************************************************/
972-->
927<zorba:iterator name="ZorbaCollectionNameIterator" >973<zorba:iterator name="ZorbaCollectionNameIterator" >
928974
929 <zorba:description author="Zorba Team">975 <zorba:description author="Zorba Team">
930976
=== modified file 'src/runtime/visitors/pregenerated/planiter_visitor.h'
--- src/runtime/visitors/pregenerated/planiter_visitor.h 2012-03-07 15:49:25 +0000
+++ src/runtime/visitors/pregenerated/planiter_visitor.h 2012-03-08 01:45:23 +0000
@@ -92,6 +92,8 @@
9292
93 class ZorbaDeleteNodesLastIterator;93 class ZorbaDeleteNodesLastIterator;
9494
95 class ZorbaTruncateCollectionIterator;
96
95 class ZorbaCollectionNameIterator;97 class ZorbaCollectionNameIterator;
9698
97 class IsAvailableCollectionIterator;99 class IsAvailableCollectionIterator;
@@ -697,6 +699,9 @@
697 virtual void beginVisit ( const ZorbaDeleteNodesLastIterator& ) = 0;699 virtual void beginVisit ( const ZorbaDeleteNodesLastIterator& ) = 0;
698 virtual void endVisit ( const ZorbaDeleteNodesLastIterator& ) = 0;700 virtual void endVisit ( const ZorbaDeleteNodesLastIterator& ) = 0;
699701
702 virtual void beginVisit ( const ZorbaTruncateCollectionIterator& ) = 0;
703 virtual void endVisit ( const ZorbaTruncateCollectionIterator& ) = 0;
704
700 virtual void beginVisit ( const ZorbaCollectionNameIterator& ) = 0;705 virtual void beginVisit ( const ZorbaCollectionNameIterator& ) = 0;
701 virtual void endVisit ( const ZorbaCollectionNameIterator& ) = 0;706 virtual void endVisit ( const ZorbaCollectionNameIterator& ) = 0;
702707
703708
=== modified file 'src/runtime/visitors/pregenerated/printer_visitor.cpp'
--- src/runtime/visitors/pregenerated/printer_visitor.cpp 2012-03-07 15:49:25 +0000
+++ src/runtime/visitors/pregenerated/printer_visitor.cpp 2012-03-08 01:45:23 +0000
@@ -545,6 +545,20 @@
545// </ZorbaDeleteNodesLastIterator>545// </ZorbaDeleteNodesLastIterator>
546546
547547
548// <ZorbaTruncateCollectionIterator>
549void PrinterVisitor::beginVisit ( const ZorbaTruncateCollectionIterator& a) {
550 thePrinter.startBeginVisit("ZorbaTruncateCollectionIterator", ++theId);
551 printCommons( &a, theId );
552 thePrinter.endBeginVisit( theId );
553}
554
555void PrinterVisitor::endVisit ( const ZorbaTruncateCollectionIterator& ) {
556 thePrinter.startEndVisit();
557 thePrinter.endEndVisit();
558}
559// </ZorbaTruncateCollectionIterator>
560
561
548// <ZorbaCollectionNameIterator>562// <ZorbaCollectionNameIterator>
549void PrinterVisitor::beginVisit ( const ZorbaCollectionNameIterator& a) {563void PrinterVisitor::beginVisit ( const ZorbaCollectionNameIterator& a) {
550 thePrinter.startBeginVisit("ZorbaCollectionNameIterator", ++theId);564 thePrinter.startBeginVisit("ZorbaCollectionNameIterator", ++theId);
551565
=== modified file 'src/runtime/visitors/pregenerated/printer_visitor.h'
--- src/runtime/visitors/pregenerated/printer_visitor.h 2012-03-07 15:49:25 +0000
+++ src/runtime/visitors/pregenerated/printer_visitor.h 2012-03-08 01:45:23 +0000
@@ -140,6 +140,9 @@
140 void beginVisit( const ZorbaDeleteNodesLastIterator& );140 void beginVisit( const ZorbaDeleteNodesLastIterator& );
141 void endVisit ( const ZorbaDeleteNodesLastIterator& );141 void endVisit ( const ZorbaDeleteNodesLastIterator& );
142142
143 void beginVisit( const ZorbaTruncateCollectionIterator& );
144 void endVisit ( const ZorbaTruncateCollectionIterator& );
145
143 void beginVisit( const ZorbaCollectionNameIterator& );146 void beginVisit( const ZorbaCollectionNameIterator& );
144 void endVisit ( const ZorbaCollectionNameIterator& );147 void endVisit ( const ZorbaCollectionNameIterator& );
145148
146149
=== modified file 'src/store/api/pul.h'
--- src/store/api/pul.h 2011-10-12 20:59:49 +0000
+++ src/store/api/pul.h 2012-03-08 01:45:23 +0000
@@ -203,6 +203,11 @@
203 bool isLast,203 bool isLast,
204 bool dyn_collection = false) = 0;204 bool dyn_collection = false) = 0;
205205
206 virtual void addTruncateCollection(
207 const QueryLoc* aQueryLoc,
208 Item_t& name,
209 bool dyn_collection = false) = 0;
210
206 // functions to add primitives for indexes211 // functions to add primitives for indexes
207212
208 virtual void addCreateIndex(213 virtual void addCreateIndex(
@@ -281,13 +286,18 @@
281286
282 // utils287 // utils
283 virtual void getIndicesToRefresh(288 virtual void getIndicesToRefresh(
284 std::vector<Index*>& indices) = 0;289 std::vector<Index*>& indices,
290 std::vector<Index*>& truncate_indices) = 0;
285291
286 virtual void addIndexEntryCreator(292 virtual void addIndexEntryCreator(
287 const Item* collectionName, 293 const Item* collectionName,
288 Index* idx,294 Index* idx,
289 IndexEntryCreator* creator) = 0;295 IndexEntryCreator* creator) = 0;
290296
297 virtual void addIndexTruncator(
298 const store::Item* collectionName,
299 Index* idx) = 0;
300
291 virtual void setValidator(301 virtual void setValidator(
292 SchemaValidator* validator) = 0;302 SchemaValidator* validator) = 0;
293303
294304
=== modified file 'src/store/api/update_consts.h'
--- src/store/api/update_consts.h 2012-01-11 17:30:25 +0000
+++ src/store/api/update_consts.h 2012-03-08 01:45:23 +0000
@@ -81,6 +81,7 @@
81 UP_INSERT_AT_INTO_COLLECTION,81 UP_INSERT_AT_INTO_COLLECTION,
82 UP_REMOVE_FROM_COLLECTION,82 UP_REMOVE_FROM_COLLECTION,
83 UP_REMOVE_AT_FROM_COLLECTION,83 UP_REMOVE_AT_FROM_COLLECTION,
84 UP_TRUNCATE_COLLECTION,
8485
85 // index primitives86 // index primitives
86 UP_CREATE_INDEX,87 UP_CREATE_INDEX,
@@ -177,6 +178,8 @@
177 return "insertAtIntoCollection";178 return "insertAtIntoCollection";
178 case UP_REMOVE_FROM_COLLECTION:179 case UP_REMOVE_FROM_COLLECTION:
179 return "removeFromCollection";180 return "removeFromCollection";
181 case UP_TRUNCATE_COLLECTION:
182 return "truncateCollection";
180 case UP_REMOVE_AT_FROM_COLLECTION:183 case UP_REMOVE_AT_FROM_COLLECTION:
181 return "removeAtFromCollection";184 return "removeAtFromCollection";
182 case UP_CREATE_INDEX:185 case UP_CREATE_INDEX:
183186
=== modified file 'src/store/naive/pul_primitive_factory.cpp'
--- src/store/naive/pul_primitive_factory.cpp 2012-03-07 14:22:29 +0000
+++ src/store/naive/pul_primitive_factory.cpp 2012-03-08 01:45:23 +0000
@@ -376,6 +376,18 @@
376 return new UpdDeleteNodesFromCollection(pul, aLoc, name, nodes, isLast, dyn_collection);376 return new UpdDeleteNodesFromCollection(pul, aLoc, name, nodes, isLast, dyn_collection);
377 }377 }
378378
379
380 /***************************************************************************
381 ***************************************************************************/
382 UpdTruncateCollection*
383 PULPrimitiveFactory::createUpdTruncateCollection(
384 CollectionPul* pul,
385 const QueryLoc* aLoc,
386 store::Item_t& name,
387 bool dyn_collection)
388 {
389 return new UpdTruncateCollection(pul, aLoc, name, dyn_collection);
390 }
379 391
380 /***************************************************************************392 /***************************************************************************
381 ***************************************************************************/393 ***************************************************************************/
382394
=== modified file 'src/store/naive/pul_primitive_factory.h'
--- src/store/naive/pul_primitive_factory.h 2012-02-28 20:45:43 +0000
+++ src/store/naive/pul_primitive_factory.h 2012-03-08 01:45:23 +0000
@@ -50,6 +50,7 @@
50 class UpdInsertBeforeIntoCollection;50 class UpdInsertBeforeIntoCollection;
51 class UpdInsertAfterIntoCollection;51 class UpdInsertAfterIntoCollection;
52 class UpdDeleteNodesFromCollection;52 class UpdDeleteNodesFromCollection;
53 class UpdTruncateCollection;
53 class UpdCreateIndex;54 class UpdCreateIndex;
54 class UpdDeleteIndex;55 class UpdDeleteIndex;
55 class UpdRefreshIndex;56 class UpdRefreshIndex;
@@ -311,6 +312,15 @@
311 std::vector<store::Item_t>& nodes,312 std::vector<store::Item_t>& nodes,
312 bool isLast,313 bool isLast,
313 bool dyn_collection = false);314 bool dyn_collection = false);
315
316 /***************************************************************************
317 ***************************************************************************/
318 virtual UpdTruncateCollection*
319 createUpdTruncateCollection(
320 CollectionPul* pul,
321 const QueryLoc*,
322 store::Item_t& name,
323 bool dyn_collection = false);
314 324
315 /***************************************************************************325 /***************************************************************************
316 ***************************************************************************/326 ***************************************************************************/
317327
=== modified file 'src/store/naive/pul_primitives.cpp'
--- src/store/naive/pul_primitives.cpp 2012-03-07 14:22:29 +0000
+++ src/store/naive/pul_primitives.cpp 2012-03-08 01:45:23 +0000
@@ -1276,6 +1276,36 @@
1276}1276}
12771277
12781278
1279/*******************************************************************************
1280 UpdTruncateCollection
1281********************************************************************************/
1282void UpdTruncateCollection::apply()
1283{
1284 SimpleCollection* lColl = static_cast<SimpleCollection*>
1285 (GET_STORE().getCollection(theName, theDynamicCollection).getp());
1286 assert(lColl);
1287
1288 lColl->theXmlTrees.swap(theTrees);
1289
1290 theIsApplied = true;
1291
1292}
1293
1294void UpdTruncateCollection::undo()
1295{
1296 if (!theIsApplied) return;
1297
1298 SimpleCollection* lColl = static_cast<SimpleCollection*>
1299 (GET_STORE().getCollection(theName, theDynamicCollection).getp());
1300 assert(lColl);
1301
1302 lColl->theXmlTrees.clear();
1303
1304 theTrees.swap(lColl->theXmlTrees);
1305
1306 theIsApplied = false;
1307}
1308
12791309
1280/////////////////////////////////////////////////////////////////////////////////1310/////////////////////////////////////////////////////////////////////////////////
1281// //1311// //
12821312
=== modified file 'src/store/naive/pul_primitives.h'
--- src/store/naive/pul_primitives.h 2012-02-28 20:45:43 +0000
+++ src/store/naive/pul_primitives.h 2012-03-08 01:45:23 +0000
@@ -1210,6 +1210,37 @@
1210};1210};
12111211
12121212
1213/*******************************************************************************
1214
1215********************************************************************************/
1216class UpdTruncateCollection: public UpdCollection
1217{
1218 friend class PULPrimitiveFactory;
1219
1220protected:
1221 std::vector<store::Item_t> theTrees; // needed for undo only
1222
1223 UpdTruncateCollection(
1224 CollectionPul* pul,
1225 const QueryLoc* aLoc,
1226 store::Item_t& name,
1227 bool dyn_collection)
1228 :
1229 UpdCollection(pul, aLoc, name, dyn_collection)
1230 {
1231 }
1232
1233public:
1234 store::UpdateConsts::UpdPrimKind getKind() const
1235 {
1236 return store::UpdateConsts::UP_TRUNCATE_COLLECTION;
1237 }
1238
1239 void apply();
1240 void undo();
1241};
1242
1243
1213/////////////////////////////////////////////////////////////////////////////////1244/////////////////////////////////////////////////////////////////////////////////
1214// //1245// //
1215// Index Primitives //1246// Index Primitives //
12161247
=== modified file 'src/store/naive/simple_collection.h'
--- src/store/naive/simple_collection.h 2012-03-07 14:22:29 +0000
+++ src/store/naive/simple_collection.h 2012-03-08 01:45:23 +0000
@@ -41,6 +41,7 @@
41class SimpleCollection : public Collection41class SimpleCollection : public Collection
42{42{
43 friend class CollectionIter;43 friend class CollectionIter;
44 friend class UpdTruncateCollection;
4445
45public:46public:
46 class CollectionIter : public store::Iterator47 class CollectionIter : public store::Iterator
4748
=== modified file 'src/store/naive/simple_index.h'
--- src/store/naive/simple_index.h 2012-01-11 17:30:25 +0000
+++ src/store/naive/simple_index.h 2012-03-08 01:45:23 +0000
@@ -69,6 +69,8 @@
6969
70 virtual KeyIterator_t keys() const = 0;70 virtual KeyIterator_t keys() const = 0;
7171
72 virtual void clear() = 0;
73
72 store::IndexCondition_t createCondition(store::IndexCondition::Kind k);74 store::IndexCondition_t createCondition(store::IndexCondition::Kind k);
7375
74 //76 //
7577
=== modified file 'src/store/naive/simple_index_general.cpp'
--- src/store/naive/simple_index_general.cpp 2012-02-15 10:25:02 +0000
+++ src/store/naive/simple_index_general.cpp 2012-03-08 01:45:23 +0000
@@ -755,6 +755,26 @@
755}755}
756756
757757
758/******************************************************************************
759
760*******************************************************************************/
761void GeneralHashIndex::clear()
762{
763 for (ulong i = 0; i < store::XS_LAST; ++i)
764 {
765 if (theMaps[i] == NULL)
766 continue;
767
768 theMaps[i]->clear();
769 }
770
771 if (isTyped())
772 {
773 theSingleMap->clear();
774 }
775}
776
777
758/////////////////////////////////////////////////////////////////////////////////778/////////////////////////////////////////////////////////////////////////////////
759// //779// //
760// GeneralHashIndex::KeyIterator //780// GeneralHashIndex::KeyIterator //
@@ -912,6 +932,26 @@
912/******************************************************************************932/******************************************************************************
913933
914*******************************************************************************/934*******************************************************************************/
935void GeneralTreeIndex::clear()
936{
937 for (ulong i = 0; i < store::XS_LAST; ++i)
938 {
939 if (theMaps[i] == NULL)
940 continue;
941
942 theMaps[i]->clear();
943 }
944
945 if (isTyped())
946 {
947 theSingleMap->clear();
948 }
949}
950
951
952/******************************************************************************
953
954*******************************************************************************/
915store::Index::KeyIterator_t GeneralTreeIndex::keys() const955store::Index::KeyIterator_t GeneralTreeIndex::keys() const
916{956{
917 return 0;957 return 0;
918958
=== modified file 'src/store/naive/simple_index_general.h'
--- src/store/naive/simple_index_general.h 2012-02-28 20:45:43 +0000
+++ src/store/naive/simple_index_general.h 2012-03-08 01:45:23 +0000
@@ -238,6 +238,8 @@
238 Index::KeyIterator_t keys() const;238 Index::KeyIterator_t keys() const;
239239
240 bool remove(const store::Item_t& key, store::Item_t& item, bool);240 bool remove(const store::Item_t& key, store::Item_t& item, bool);
241
242 void clear();
241};243};
242244
243245
@@ -291,6 +293,8 @@
291 Index::KeyIterator_t keys() const;293 Index::KeyIterator_t keys() const;
292294
293 bool remove(const store::Item_t& key, store::Item_t& item, bool all);295 bool remove(const store::Item_t& key, store::Item_t& item, bool all);
296
297 void clear();
294};298};
295299
296300
297301
=== modified file 'src/store/naive/simple_pul.cpp'
--- src/store/naive/simple_pul.cpp 2012-03-07 14:22:29 +0000
+++ src/store/naive/simple_pul.cpp 2012-03-08 01:45:23 +0000
@@ -944,6 +944,17 @@
944}944}
945945
946946
947void PULImpl::addTruncateCollection(
948 const QueryLoc* aQueryLoc,
949 store::Item_t& name,
950 bool dyn_collection)
951{
952 CollectionPul* pul = getCollectionPulByName(name.getp(),dyn_collection);
953
954 pul->theTruncateCollectionList.push_back(
955 GET_PUL_FACTORY().createUpdTruncateCollection(pul, aQueryLoc, name, dyn_collection));
956}
957
947/*******************************************************************************958/*******************************************************************************
948 Index primitives959 Index primitives
949********************************************************************************/960********************************************************************************/
@@ -1157,6 +1168,11 @@
1157 UP_LIST_NONE);1168 UP_LIST_NONE);
11581169
1159 mergeUpdateList(thisPul,1170 mergeUpdateList(thisPul,
1171 thisPul->theTruncateCollectionList,
1172 otherPul->theTruncateCollectionList,
1173 UP_LIST_NONE);
1174
1175 mergeUpdateList(thisPul,
1160 thisPul->theDeleteCollectionList,1176 thisPul->theDeleteCollectionList,
1161 otherPul->theDeleteCollectionList,1177 otherPul->theDeleteCollectionList,
1162 UP_LIST_NONE);1178 UP_LIST_NONE);
@@ -1502,7 +1518,9 @@
1502 This method is invoked by the ApplyIterator before any of the pul primitives1518 This method is invoked by the ApplyIterator before any of the pul primitives
1503 is applied.1519 is applied.
1504********************************************************************************/1520********************************************************************************/
1505void PULImpl::getIndicesToRefresh(std::vector<store::Index*>& indices)1521void PULImpl::getIndicesToRefresh(
1522 std::vector<store::Index*>& indices,
1523 std::vector<store::Index*>& truncate_indices)
1506{1524{
1507 SimpleStore* store = &GET_STORE();1525 SimpleStore* store = &GET_STORE();
15081526
@@ -1513,6 +1531,7 @@
1513 // modified/inserted/deleted collection docs, because they will be need later1531 // modified/inserted/deleted collection docs, because they will be need later
1514 // to maintain indices.1532 // to maintain indices.
1515 std::set<store::Collection*> collections;1533 std::set<store::Collection*> collections;
1534 std::set<store::Collection*> truncated_collections;
15161535
1517 CollectionPulMap::iterator collIte = theCollectionPuls.begin();1536 CollectionPulMap::iterator collIte = theCollectionPuls.begin();
1518 CollectionPulMap::iterator collEnd = theCollectionPuls.end();1537 CollectionPulMap::iterator collEnd = theCollectionPuls.end();
@@ -1529,6 +1548,12 @@
15291548
1530 CollectionPul* pul = collIte->second;1549 CollectionPul* pul = collIte->second;
15311550
1551 if (pul->theTruncateCollectionList.size() > 0)
1552 {
1553 truncated_collections.insert(collection);
1554 continue;
1555 }
1556
1532 NodeToUpdatesMap::iterator ite = pul->theNodeToUpdatesMap.begin();1557 NodeToUpdatesMap::iterator ite = pul->theNodeToUpdatesMap.begin();
1533 NodeToUpdatesMap::iterator end = pul->theNodeToUpdatesMap.end();1558 NodeToUpdatesMap::iterator end = pul->theNodeToUpdatesMap.end();
1534 for (; ite != end; ++ite)1559 for (; ite != end; ++ite)
@@ -1595,6 +1620,21 @@
1595 if (colIte != colEnd)1620 if (colIte != colEnd)
1596 break;1621 break;
1597 }1622 }
1623
1624 for (csize i = 0; i < numIndexSources; ++i)
1625 {
1626 std::set<store::Collection*>::const_iterator colIte = truncated_collections.begin();
1627 std::set<store::Collection*>::const_iterator colEnd = truncated_collections.end();
1628
1629 for (; colIte != colEnd; ++colIte)
1630 {
1631 if (indexSources[i]->equals((*colIte)->getName()))
1632 {
1633 truncate_indices.push_back(index);
1634 break;
1635 }
1636 }
1637 }
1598 }1638 }
1599}1639}
16001640
@@ -1617,6 +1657,18 @@
1617/*******************************************************************************1657/*******************************************************************************
16181658
1619********************************************************************************/1659********************************************************************************/
1660void PULImpl::addIndexTruncator(
1661 const store::Item* collectionName,
1662 store::Index* idx)
1663{
1664 CollectionPul* pul = getCollectionPulByName(collectionName,false);
1665 pul->theTruncatedIndices.push_back(static_cast<IndexImpl*>(idx));
1666}
1667
1668
1669/*******************************************************************************
1670
1671********************************************************************************/
1620void PULImpl::setICChecker(store::ICChecker* icChecker)1672void PULImpl::setICChecker(store::ICChecker* icChecker)
1621{1673{
1622 theICChecker = icChecker;1674 theICChecker = icChecker;
@@ -1796,6 +1848,7 @@
1796 cleanList(theCreateCollectionList);1848 cleanList(theCreateCollectionList);
1797 cleanList(theInsertIntoCollectionList);1849 cleanList(theInsertIntoCollectionList);
1798 cleanList(theDeleteFromCollectionList);1850 cleanList(theDeleteFromCollectionList);
1851 cleanList(theTruncateCollectionList);
1799 cleanList(theDeleteCollectionList);1852 cleanList(theDeleteCollectionList);
18001853
1801 cleanIndexDeltas(theBeforeIndexDeltas);1854 cleanIndexDeltas(theBeforeIndexDeltas);
@@ -1822,6 +1875,7 @@
1822 switchPulInPrimitivesList(theCreateCollectionList);1875 switchPulInPrimitivesList(theCreateCollectionList);
1823 switchPulInPrimitivesList(theInsertIntoCollectionList);1876 switchPulInPrimitivesList(theInsertIntoCollectionList);
1824 switchPulInPrimitivesList(theDeleteFromCollectionList);1877 switchPulInPrimitivesList(theDeleteFromCollectionList);
1878 switchPulInPrimitivesList(theTruncateCollectionList);
1825 switchPulInPrimitivesList(theDeleteCollectionList);1879 switchPulInPrimitivesList(theDeleteCollectionList);
1826}1880}
18271881
@@ -1946,7 +2000,14 @@
1946********************************************************************************/2000********************************************************************************/
1947void CollectionPul::refreshIndices()2001void CollectionPul::refreshIndices()
1948{2002{
1949 csize numIncrementalIndices = theIncrementalIndices.size();2003 csize numIncrementalIndices = theTruncatedIndices.size();
2004 for (csize idx = 0; idx < numIncrementalIndices; ++idx)
2005 {
2006 ValueIndex* index = static_cast<ValueIndex*>(theTruncatedIndices[idx]);
2007 index->clear();
2008 }
2009
2010 numIncrementalIndices = theIncrementalIndices.size();
19502011
1951 for (csize idx = 0; idx < numIncrementalIndices; ++idx)2012 for (csize idx = 0; idx < numIncrementalIndices; ++idx)
1952 {2013 {
@@ -2134,6 +2195,7 @@
2134 applyList(theCreateCollectionList);2195 applyList(theCreateCollectionList);
2135 applyList(theInsertIntoCollectionList);2196 applyList(theInsertIntoCollectionList);
2136 applyList(theDeleteFromCollectionList);2197 applyList(theDeleteFromCollectionList);
2198 applyList(theTruncateCollectionList);
21372199
2138 // Compute the after-delta for each incrementally maintained index.2200 // Compute the after-delta for each incrementally maintained index.
2139 computeIndexAfterDeltas();2201 computeIndexAfterDeltas();
@@ -2266,6 +2328,7 @@
22662328
2267 try2329 try
2268 {2330 {
2331 undoList(theTruncateCollectionList);
2269 undoList(theDeleteFromCollectionList);2332 undoList(theDeleteFromCollectionList);
2270 undoList(theInsertIntoCollectionList);2333 undoList(theInsertIntoCollectionList);
2271 undoList(theCreateCollectionList);2334 undoList(theCreateCollectionList);
22722335
=== modified file 'src/store/naive/simple_pul.h'
--- src/store/naive/simple_pul.h 2012-03-07 14:22:29 +0000
+++ src/store/naive/simple_pul.h 2012-03-08 01:45:23 +0000
@@ -183,6 +183,7 @@
183 std::vector<UpdatePrimitive*> theCreateCollectionList;183 std::vector<UpdatePrimitive*> theCreateCollectionList;
184 std::vector<UpdatePrimitive*> theInsertIntoCollectionList;184 std::vector<UpdatePrimitive*> theInsertIntoCollectionList;
185 std::vector<UpdatePrimitive*> theDeleteFromCollectionList;185 std::vector<UpdatePrimitive*> theDeleteFromCollectionList;
186 std::vector<UpdatePrimitive*> theTruncateCollectionList;
186 std::vector<UpdatePrimitive*> theDeleteCollectionList;187 std::vector<UpdatePrimitive*> theDeleteCollectionList;
187188
188 // Validate in place primitives189 // Validate in place primitives
@@ -194,6 +195,7 @@
194 std::vector<XmlNode*> theDeletedDocs;195 std::vector<XmlNode*> theDeletedDocs;
195196
196 std::vector<IndexImpl*> theIncrementalIndices;197 std::vector<IndexImpl*> theIncrementalIndices;
198 std::vector<IndexImpl*> theTruncatedIndices;
197199
198 std::vector<IndexEntryCreator_t> theIndexEntryCreators;200 std::vector<IndexEntryCreator_t> theIndexEntryCreators;
199201
@@ -465,6 +467,11 @@
465 bool isLast,467 bool isLast,
466 bool dyn_collection = false);468 bool dyn_collection = false);
467469
470 void addTruncateCollection(
471 const QueryLoc* aQueryLoc,
472 store::Item_t& name,
473 bool dyn_collection = false);
474
468 // Index primitives475 // Index primitives
469 void addCreateIndex(476 void addCreateIndex(
470 const QueryLoc* aQueryLoc,477 const QueryLoc* aQueryLoc,
@@ -539,13 +546,19 @@
539 // utils546 // utils
540 void checkTransformUpdates(const std::vector<store::Item*>& rootNodes) const;547 void checkTransformUpdates(const std::vector<store::Item*>& rootNodes) const;
541548
542 void getIndicesToRefresh(std::vector<store::Index*>& indices);549 void getIndicesToRefresh(
550 std::vector<store::Index*>& indices,
551 std::vector<store::Index*>& truncate_indices);
543552
544 void addIndexEntryCreator(553 void addIndexEntryCreator(
545 const store::Item* collectionName,554 const store::Item* collectionName,
546 store::Index* idx,555 store::Index* idx,
547 store::IndexEntryCreator* creator);556 store::IndexEntryCreator* creator);
548557
558 void addIndexTruncator(
559 const store::Item* collectionName,
560 store::Index* idx);
561
549 void setValidator(store::SchemaValidator* validator);562 void setValidator(store::SchemaValidator* validator);
550 store::SchemaValidator* getValidator() const { return theValidator; }563 store::SchemaValidator* getValidator() const { return theValidator; }
551564
552565
=== added file 'test/rbkt/ExpQueryResults/zorba/collections/delete_nodes/truncate_001.xml.res'
--- test/rbkt/ExpQueryResults/zorba/collections/delete_nodes/truncate_001.xml.res 1970-01-01 00:00:00 +0000
+++ test/rbkt/ExpQueryResults/zorba/collections/delete_nodes/truncate_001.xml.res 2012-03-08 01:45:23 +0000
@@ -0,0 +1,1 @@
1<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>
02
=== added file 'test/rbkt/ExpQueryResults/zorba/collections/dynamic6.xml.res'
--- test/rbkt/ExpQueryResults/zorba/collections/dynamic6.xml.res 1970-01-01 00:00:00 +0000
+++ test/rbkt/ExpQueryResults/zorba/collections/dynamic6.xml.res 2012-03-08 01:45:23 +0000
@@ -0,0 +1,1 @@
10
02
=== added file 'test/rbkt/ExpQueryResults/zorba/index/auctions2.xml.res'
--- test/rbkt/ExpQueryResults/zorba/index/auctions2.xml.res 1970-01-01 00:00:00 +0000
+++ test/rbkt/ExpQueryResults/zorba/index/auctions2.xml.res 2012-03-08 01:45:23 +0000
@@ -0,0 +1,1 @@
1<person id="person0"><city>Macon</city></person>
02
=== modified file 'test/rbkt/Queries/zorba/collections/collection_002.xqdata'
--- test/rbkt/Queries/zorba/collections/collection_002.xqdata 2011-06-24 19:58:33 +0000
+++ test/rbkt/Queries/zorba/collections/collection_002.xqdata 2012-03-08 01:45:23 +0000
@@ -2,4 +2,6 @@
22
3declare collection ns:collection as node()*;3declare collection ns:collection as node()*;
44
5declare function ns:test2() { () };
6\ No newline at end of file5\ No newline at end of file
6declare collection ns:collection2 as node()*;
7
8declare function ns:test2() { () };
79
=== added file 'test/rbkt/Queries/zorba/collections/delete_nodes/truncate_001.xq'
--- test/rbkt/Queries/zorba/collections/delete_nodes/truncate_001.xq 1970-01-01 00:00:00 +0000
+++ test/rbkt/Queries/zorba/collections/delete_nodes/truncate_001.xq 2012-03-08 01:45:23 +0000
@@ -0,0 +1,27 @@
1import module namespace ddl = "http://www.zorba-xquery.com/modules/store/static/collections/ddl";
2import module namespace dml = "http://www.zorba-xquery.com/modules/store/static/collections/dml";
3
4import module namespace ns = "http://www.example.com/example" at "../collection_002.xqdata";
5
6variable $contents;
7
8ddl:create(xs:QName("ns:collection"));
9ddl:create(xs:QName("ns:collection2"));
10
11dml:insert-nodes(
12 xs:QName("ns:collection"),
13 for $i in 1 to 10 return <a>{$i}</a>
14);
15
16dml:insert-nodes(
17 xs:QName("ns:collection2"),
18 for $i in 1 to 10 return <b>{$i}</b>
19);
20
21$contents := (dml:collection(xs:QName("ns:collection")), dml:collection(xs:QName("ns:collection2")));
22
23(dml:truncate(xs:QName("ns:collection")), dml:truncate(xs:QName("ns:collection2")));
24
25$contents := ($contents, dml:collection(xs:QName("ns:collection")), dml:collection(xs:QName("ns:collection")));
26
27$contents
028
=== added file 'test/rbkt/Queries/zorba/collections/dynamic6.xq'
--- test/rbkt/Queries/zorba/collections/dynamic6.xq 1970-01-01 00:00:00 +0000
+++ test/rbkt/Queries/zorba/collections/dynamic6.xq 2012-03-08 01:45:23 +0000
@@ -0,0 +1,10 @@
1import module namespace ddl = "http://www.zorba-xquery.com/modules/store/dynamic/collections/ddl";
2import module namespace dml = "http://www.zorba-xquery.com/modules/store/dynamic/collections/dml";
3
4ddl:create(xs:QName("ddl:test2"),(<center1/>,<oldlast/>));
5
6dml:insert-nodes-first(xs:QName("ddl:test2"), (<c1/>,<c2/>));
7
8dml:truncate(xs:QName("ddl:test2"));
9
10count(dml:collection(xs:QName("ddl:test2")))
011
=== added file 'test/rbkt/Queries/zorba/index/auctions2.xq'
--- test/rbkt/Queries/zorba/index/auctions2.xq 1970-01-01 00:00:00 +0000
+++ test/rbkt/Queries/zorba/index/auctions2.xq 2012-03-08 01:45:23 +0000
@@ -0,0 +1,25 @@
1import module namespace auctions = "http://www.w3.org/TestModules/auctions" at
2 "auctions_module1.xqlib";
3
4import module namespace ddl = "http://www.zorba-xquery.com/modules/store/static/collections/ddl";
5import module namespace dml = "http://www.zorba-xquery.com/modules/store/static/collections/dml";
6import module namespace index_ddl = "http://www.zorba-xquery.com/modules/store/static/indexes/ddl";
7import module namespace index_dml = "http://www.zorba-xquery.com/modules/store/static/indexes/dml";
8
9declare namespace err = "http://www.w3.org/2005/xqt-errors";
10
11auctions:create-db();
12
13variable $cities := ();
14
15$cities := for $x in auctions:probe-point-city(xs:QName("auctions:PersonCity"), "Macon")
16 return <person id = "{$x/@id}">{$x//city}</person>;
17
18dml:truncate(xs:QName("auctions:auctions"));
19
20$cities := ($cities,
21 for $x in auctions:probe-point-city(xs:QName("auctions:PersonCity"), "Macon")
22 return <person id = "{$x/@id}">{$x//city}</person>);
23
24$cities
25

Subscribers

People subscribed via source and target branches