zorba-coders team mailing list archive
-
zorba-coders team
-
Mailing list archive
-
Message #05418
[Merge] lp:~zorba-coders/zorba/bug-938934 into lp:zorba
Matthias Brantner has proposed merging lp:~zorba-coders/zorba/bug-938934 into lp:zorba.
Requested reviews:
Matthias Brantner (matthias-brantner)
Till Westmann (tillw)
Related bugs:
Bug #938934 in Zorba: "collection dml:truncate function missing"
https://bugs.launchpad.net/zorba/+bug/938934
For more details, see:
https://code.launchpad.net/~zorba-coders/zorba/bug-938934/+merge/94897
--
https://code.launchpad.net/~zorba-coders/zorba/bug-938934/+merge/94897
Your team Zorba Coders is subscribed to branch lp:zorba.
=== modified file 'ChangeLog'
--- ChangeLog 2012-02-27 15:17:53 +0000
+++ ChangeLog 2012-02-28 02:00:28 +0000
@@ -10,6 +10,7 @@
%ann:must-copy-input-nodes to be used by the no-copy optimization.
* Caching of results for recursive functions with atomic parameter and return types.
* Added %ann:cache and %ann:no-cache to enable or disable caching of results of functions with atomic parameter and return types.
+ * Added truncate function to the collection modules for efficient deletion of all nodes in a collection.
* Fixed bug 917923 (bug in copying outer var values into the eval dynamic context)
* Fixed bug 924063 (sentence is incorrectly incremented when token characters end without sentence terminator)
* Optimization: change the implementation of the free-vars annotation and got rid
=== 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-02-28 02:00:28 +0000
@@ -260,7 +260,7 @@
: @return The result of this function is an empty XDM instance and a pending update
: list which, once applied, deletes the last node from the collection.
:
- : @error zerr:ZDDY0009 If available collections does not provide a mapping
+ : @error zerr:ZDDY0003 If available collections does not provide a mapping
: for the expanded QName $name.
: @error zerr:ZDDY0011 if the collection doesn't contain any node.
:
@@ -278,7 +278,7 @@
: @return The result of this function is an empty XDM instance and a pending update
: list which, once applied, deletes the last n nodes.
:
- : @error zerr:ZDDY0009 If available collections does not provide a mapping
+ : @error zerr:ZDDY0003 If available collections does not provide a mapping
: for the expanded QName $name.
: @error zerr:ZDDY0011 if the collection doesn't contain the given number of nodes.
:
@@ -288,6 +288,21 @@
$number as xs:integer) external;
(:~
+ : The truncate function is an updating function that deletes the
+ : entire contents of collection.
+ :
+ : @param $name The name of the collection whose content to delete
+ :
+ : @return The result of this function is an empty XDM instance and a pending update
+ : list which, once applied, deletes the nodes.
+ :
+ : @error zerr:ZDDY0003 If available collections does not provide a mapping
+ : for the expanded QName $name.
+ :
+ :)
+declare updating function cdml:truncate($name as xs:QName) external;
+
+(:~
: The index-of function return the index of the given node in the collection.
:
: @param $node The node to retrieve the index from.
@@ -307,7 +322,7 @@
:
: @return The sequence contained in the given collection.
:
- : @error zerr:ZDDY0009 If available collections does not provide a mapping
+ : @error zerr:ZDDY0003 If available collections does not provide a mapping
: for the expanded QName $name.
:
:)
=== 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-02-28 02:00:28 +0000
@@ -409,6 +409,22 @@
$number as xs:integer) external;
(:~
+ : The truncate function is an updating function that deletes the
+ : entire contents of collection.
+ :
+ : @param $name The name of the collection whose content to delete
+ :
+ : @return The result of this function is an empty XDM instance and a pending update
+ : list which, once applied, deletes the nodes.
+ :
+ : @error zerr:ZDDY0001 if the collection identified by $name is not declared.
+ : @error zerr:ZDDY0003 if the collection identified by $name is not available.
+ :
+ :)
+
+declare updating function cdml:truncate($name as xs:QName) external;
+
+(:~
: The index-of function that returns the position of the node in its collection.
:
: @param $node The node to retrieve the index for.
=== 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-02-28 02:00:28 +0000
@@ -293,6 +293,21 @@
/*******************************************************************************
********************************************************************************/
+PlanIter_t zorba_store_collections_static_dml_truncate::codegen(
+ CompilerCB*,
+ static_context* sctx,
+ const QueryLoc& loc,
+ std::vector<PlanIter_t>& argv,
+ expr& ann) const
+{
+ return new ZorbaTruncateCollectionIterator(sctx, loc, argv,
+ getName()->getNamespace() == static_context::ZORBA_STORE_DYNAMIC_COLLECTIONS_DML_FN_NS);
+}
+
+
+/*******************************************************************************
+
+********************************************************************************/
PlanIter_t zorba_store_collections_static_dml_delete_node_first::codegen(
CompilerCB*,
static_context* sctx,
=== 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-02-28 02:00:28 +0000
@@ -58,6 +58,7 @@
+
PlanIter_t zorba_store_collections_static_dml_collection_name::codegen(
CompilerCB*,
static_context* sctx,
@@ -686,6 +687,30 @@
{
+ DECL_WITH_KIND(sctx, zorba_store_collections_static_dml_truncate,
+ (createQName("http://www.zorba-xquery.com/modules/store/static/collections/dml","","truncate"),
+ GENV_TYPESYSTEM.QNAME_TYPE_ONE,
+ GENV_TYPESYSTEM.EMPTY_TYPE),
+ FunctionConsts::ZORBA_STORE_COLLECTIONS_STATIC_DML_TRUNCATE_1);
+
+ }
+
+
+ {
+
+
+ DECL_WITH_KIND(sctx, zorba_store_collections_static_dml_truncate,
+ (createQName("http://www.zorba-xquery.com/modules/store/dynamic/collections/dml","","truncate"),
+ GENV_TYPESYSTEM.QNAME_TYPE_ONE,
+ GENV_TYPESYSTEM.EMPTY_TYPE),
+ FunctionConsts::ZORBA_STORE_DYNAMIC_COLLECTIONS_DML_TRUNCATE_1);
+
+ }
+
+
+ {
+
+
DECL_WITH_KIND(sctx, zorba_store_collections_static_dml_collection_name,
(createQName("http://www.zorba-xquery.com/modules/store/static/collections/dml","","collection-name"),
GENV_TYPESYSTEM.ANY_NODE_TYPE_ONE,
=== 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-02-28 02:00:28 +0000
@@ -434,6 +434,25 @@
};
+//zorba-store-collections-static-dml:truncate
+class zorba_store_collections_static_dml_truncate : public function
+{
+public:
+ zorba_store_collections_static_dml_truncate(const signature& sig, FunctionConsts::FunctionKind kind)
+ :
+ function(sig, kind)
+ {
+
+ }
+
+ short getScriptingKind() const { return UPDATING_EXPR; }
+
+ bool accessesDynCtx() const { return true; }
+
+ CODEGEN_DECL();
+};
+
+
//zorba-store-collections-static-dml:collection-name
class zorba_store_collections_static_dml_collection_name : public function
{
=== modified file 'src/functions/pregenerated/function_enum.h'
--- src/functions/pregenerated/function_enum.h 2012-02-16 14:11:02 +0000
+++ src/functions/pregenerated/function_enum.h 2012-02-28 02:00:28 +0000
@@ -79,6 +79,8 @@
ZORBA_STORE_COLLECTIONS_STATIC_DML_DELETE_NODES_LAST_2,
ZORBA_STORE_DYNAMIC_COLLECTIONS_DML_DELETE_NODE_LAST_1,
ZORBA_STORE_DYNAMIC_COLLECTIONS_DML_DELETE_NODES_LAST_2,
+ ZORBA_STORE_COLLECTIONS_STATIC_DML_TRUNCATE_1,
+ ZORBA_STORE_DYNAMIC_COLLECTIONS_DML_TRUNCATE_1,
ZORBA_STORE_COLLECTIONS_STATIC_DML_COLLECTION_NAME_1,
ZORBA_STORE_DYNAMIC_COLLECTIONS_DML_COLLECTION_NAME_1,
ZORBA_STORE_COLLECTIONS_STATIC_DDL_IS_AVAILABLE_COLLECTION_1,
=== 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-02-28 02:00:28 +0000
@@ -1796,6 +1796,93 @@
/*******************************************************************************
********************************************************************************/
+bool ZorbaTruncateCollectionIterator::nextImpl(
+ store::Item_t& result,
+ PlanState& planState) const
+{
+ store::Collection_t collection;
+ store::Item_t collectionName;
+ std::auto_ptr<store::PUL> pul;
+
+ PlanIteratorState* state;
+ DEFAULT_STACK_INIT(PlanIteratorState, state, planState);
+
+ consumeNext(collectionName, theChildren[0].getp(), planState);
+
+ (void)getCollection(
+ theSctx, collectionName, loc, theDynamicCollection, collection);
+
+ // create the pul and add the primitive
+ pul.reset(GENV_ITEMFACTORY->createPendingUpdateList());
+
+ pul->addTruncateCollection(&loc, collectionName, theDynamicCollection);
+
+ result = pul.release();
+ STACK_PUSH( result != NULL, state);
+
+ STACK_END (state);
+}
+
+/*******************************************************************************
+
+********************************************************************************/
+const StaticallyKnownCollection*
+ZorbaTruncateCollectionIterator::getCollection(
+ const static_context* aSctx,
+ const store::Item_t& aName,
+ const QueryLoc& aLoc,
+ bool aDynamicCollection,
+ store::Collection_t& coll) const
+{
+ const StaticallyKnownCollection* collectionDecl = aSctx->lookup_collection(aName);
+ if (collectionDecl == 0 && !aDynamicCollection)
+ {
+ throw XQUERY_EXCEPTION(
+ zerr::ZDDY0001_COLLECTION_NOT_DECLARED,
+ ERROR_PARAMS( aName->getStringValue() ),
+ ERROR_LOC( aLoc )
+ );
+ }
+
+ if (!aDynamicCollection)
+ {
+ // checking collection update mode
+ switch(collectionDecl->getUpdateProperty())
+ {
+ case StaticContextConsts::decl_const:
+ throw XQUERY_EXCEPTION(
+ zerr::ZDDY0004_COLLECTION_CONST_UPDATE,
+ ERROR_PARAMS( aName->getStringValue() ),
+ ERROR_LOC( loc )
+ );
+
+ case StaticContextConsts::decl_append_only:
+ throw XQUERY_EXCEPTION(
+ zerr::ZDDY0005_COLLECTION_APPEND_BAD_INSERT,
+ ERROR_PARAMS( aName->getStringValue() ),
+ ERROR_LOC( loc )
+ );
+ default: break;
+ }
+ }
+
+ coll = GENV_STORE.getCollection(aName, aDynamicCollection);
+
+ if (coll == NULL)
+ {
+ throw XQUERY_EXCEPTION(
+ zerr::ZDDY0003_COLLECTION_DOES_NOT_EXIST,
+ ERROR_PARAMS( aName->getStringValue() ),
+ ERROR_LOC( aLoc )
+ );
+ }
+
+ return collectionDecl;
+}
+
+/*******************************************************************************
+
+********************************************************************************/
bool ZorbaCollectionNameIterator::nextImpl(
store::Item_t& result,
PlanState& planState) const
=== 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-02-28 02:00:28 +0000
@@ -551,6 +551,34 @@
// </ZorbaDeleteNodesLastIterator>
+// <ZorbaTruncateCollectionIterator>
+const char* ZorbaTruncateCollectionIterator::class_name_str = "ZorbaTruncateCollectionIterator";
+ZorbaTruncateCollectionIterator::class_factory<ZorbaTruncateCollectionIterator>
+ZorbaTruncateCollectionIterator::g_class_factory;
+
+const serialization::ClassVersion
+ZorbaTruncateCollectionIterator::class_versions[] ={{ 1, 0x000905, false}};
+
+const int ZorbaTruncateCollectionIterator::class_versions_count =
+sizeof(ZorbaTruncateCollectionIterator::class_versions)/sizeof(struct serialization::ClassVersion);
+
+void ZorbaTruncateCollectionIterator::accept(PlanIterVisitor& v) const {
+ v.beginVisit(*this);
+
+ std::vector<PlanIter_t>::const_iterator lIter = theChildren.begin();
+ std::vector<PlanIter_t>::const_iterator lEnd = theChildren.end();
+ for ( ; lIter != lEnd; ++lIter ){
+ (*lIter)->accept(v);
+ }
+
+ v.endVisit(*this);
+}
+
+ZorbaTruncateCollectionIterator::~ZorbaTruncateCollectionIterator() {}
+
+// </ZorbaTruncateCollectionIterator>
+
+
// <ZorbaCollectionNameIterator>
const char* ZorbaCollectionNameIterator::class_name_str = "ZorbaCollectionNameIterator";
ZorbaCollectionNameIterator::class_factory<ZorbaCollectionNameIterator>
=== 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-02-28 02:00:28 +0000
@@ -865,6 +865,50 @@
/**
*
+ * zorba:truncate
+ *
+ * Author: Zorba Team
+ */
+class ZorbaTruncateCollectionIterator : public NaryBaseIterator<ZorbaTruncateCollectionIterator, PlanIteratorState>
+{
+protected:
+ bool theDynamicCollection; //whether it's the function of the dynamic or the static collection module
+public:
+ SERIALIZABLE_CLASS(ZorbaTruncateCollectionIterator);
+
+ SERIALIZABLE_CLASS_CONSTRUCTOR2T(ZorbaTruncateCollectionIterator,
+ NaryBaseIterator<ZorbaTruncateCollectionIterator, PlanIteratorState>);
+
+ void serialize( ::zorba::serialization::Archiver& ar)
+ {
+ serialize_baseclass(ar,
+ (NaryBaseIterator<ZorbaTruncateCollectionIterator, PlanIteratorState>*)this);
+
+ ar & theDynamicCollection;
+ }
+
+ ZorbaTruncateCollectionIterator(
+ static_context* sctx,
+ const QueryLoc& loc,
+ std::vector<PlanIter_t>& children,
+ bool aDynamicCollection)
+ :
+ NaryBaseIterator<ZorbaTruncateCollectionIterator, PlanIteratorState>(sctx, loc, children),
+ theDynamicCollection(aDynamicCollection)
+ {}
+
+ virtual ~ZorbaTruncateCollectionIterator();
+
+public:
+ const StaticallyKnownCollection* getCollection(const static_context* sctx, const store::Item_t& name, const QueryLoc& loc, bool dyn_coll, store::Collection_t& coll) const;
+ void accept(PlanIterVisitor& v) const;
+
+ bool nextImpl(store::Item_t& result, PlanState& aPlanState) const;
+};
+
+
+/**
+ *
* zorba:collection-name
*
* Author: Zorba Team
=== 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-02-28 02:00:28 +0000
@@ -924,6 +924,52 @@
/*******************************************************************************
********************************************************************************/
-->
+<zorba:iterator name="ZorbaTruncateCollectionIterator" >
+
+ <zorba:description author="Zorba Team">
+ zorba:truncate
+ </zorba:description>
+
+ <zorba:function generateCodegen="false">
+
+ <zorba:signature localname="truncate" prefix="zorba-store-collections-static-dml">
+ <zorba:param>xs:QName</zorba:param>
+ <zorba:output>empty-sequence()</zorba:output>
+ </zorba:signature>
+
+ <zorba:signature localname="truncate" prefix="zorba-store-dynamic-collections-dml">
+ <zorba:param>xs:QName</zorba:param>
+ <zorba:output>empty-sequence()</zorba:output>
+ </zorba:signature>
+
+ <zorba:methods>
+ <zorba:getScriptingKind returnValue="UPDATING_EXPR"/>
+ <zorba:accessesDynCtx returnValue="true"/>
+ </zorba:methods>
+
+ </zorba:function>
+
+ <zorba:constructor>
+ <zorba:parameter type="bool" name="aDynamicCollection" />
+ </zorba:constructor>
+
+ <zorba:member type="bool" name="theDynamicCollection"
+ brief="whether it's the function of the dynamic or the static collection module"/>
+
+ <zorba:method const="true" name="getCollection" return="const StaticallyKnownCollection*">
+ <zorba:param type="const static_context*" name="sctx"/>
+ <zorba:param type="const store::Item_t&" name="name"/>
+ <zorba:param type="const QueryLoc&" name="loc"/>
+ <zorba:param type="bool" name="dyn_coll"/>
+ <zorba:param type="store::Collection_t&" name="coll"/>
+ </zorba:method>
+</zorba:iterator>
+
+
+<!--
+/*******************************************************************************
+********************************************************************************/
+-->
<zorba:iterator name="ZorbaCollectionNameIterator" >
<zorba:description author="Zorba Team">
=== modified file 'src/runtime/visitors/pregenerated/planiter_visitor.h'
--- src/runtime/visitors/pregenerated/planiter_visitor.h 2012-02-16 14:11:02 +0000
+++ src/runtime/visitors/pregenerated/planiter_visitor.h 2012-02-28 02:00:28 +0000
@@ -92,6 +92,8 @@
class ZorbaDeleteNodesLastIterator;
+ class ZorbaTruncateCollectionIterator;
+
class ZorbaCollectionNameIterator;
class IsAvailableCollectionIterator;
@@ -695,6 +697,9 @@
virtual void beginVisit ( const ZorbaDeleteNodesLastIterator& ) = 0;
virtual void endVisit ( const ZorbaDeleteNodesLastIterator& ) = 0;
+ virtual void beginVisit ( const ZorbaTruncateCollectionIterator& ) = 0;
+ virtual void endVisit ( const ZorbaTruncateCollectionIterator& ) = 0;
+
virtual void beginVisit ( const ZorbaCollectionNameIterator& ) = 0;
virtual void endVisit ( const ZorbaCollectionNameIterator& ) = 0;
=== modified file 'src/runtime/visitors/pregenerated/printer_visitor.cpp'
--- src/runtime/visitors/pregenerated/printer_visitor.cpp 2012-02-16 14:11:02 +0000
+++ src/runtime/visitors/pregenerated/printer_visitor.cpp 2012-02-28 02:00:28 +0000
@@ -544,6 +544,20 @@
// </ZorbaDeleteNodesLastIterator>
+// <ZorbaTruncateCollectionIterator>
+void PrinterVisitor::beginVisit ( const ZorbaTruncateCollectionIterator& a) {
+ thePrinter.startBeginVisit("ZorbaTruncateCollectionIterator", ++theId);
+ printCommons( &a, theId );
+ thePrinter.endBeginVisit( theId );
+}
+
+void PrinterVisitor::endVisit ( const ZorbaTruncateCollectionIterator& ) {
+ thePrinter.startEndVisit();
+ thePrinter.endEndVisit();
+}
+// </ZorbaTruncateCollectionIterator>
+
+
// <ZorbaCollectionNameIterator>
void PrinterVisitor::beginVisit ( const ZorbaCollectionNameIterator& a) {
thePrinter.startBeginVisit("ZorbaCollectionNameIterator", ++theId);
=== modified file 'src/runtime/visitors/pregenerated/printer_visitor.h'
--- src/runtime/visitors/pregenerated/printer_visitor.h 2012-02-16 14:11:02 +0000
+++ src/runtime/visitors/pregenerated/printer_visitor.h 2012-02-28 02:00:28 +0000
@@ -140,6 +140,9 @@
void beginVisit( const ZorbaDeleteNodesLastIterator& );
void endVisit ( const ZorbaDeleteNodesLastIterator& );
+ void beginVisit( const ZorbaTruncateCollectionIterator& );
+ void endVisit ( const ZorbaTruncateCollectionIterator& );
+
void beginVisit( const ZorbaCollectionNameIterator& );
void endVisit ( const ZorbaCollectionNameIterator& );
=== 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-02-28 02:00:28 +0000
@@ -203,6 +203,11 @@
bool isLast,
bool dyn_collection = false) = 0;
+ virtual void addTruncateCollection(
+ const QueryLoc* aQueryLoc,
+ Item_t& name,
+ bool dyn_collection = false) = 0;
+
// functions to add primitives for indexes
virtual void addCreateIndex(
=== 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-02-28 02:00:28 +0000
@@ -81,6 +81,7 @@
UP_INSERT_AT_INTO_COLLECTION,
UP_REMOVE_FROM_COLLECTION,
UP_REMOVE_AT_FROM_COLLECTION,
+ UP_TRUNCATE_COLLECTION,
// index primitives
UP_CREATE_INDEX,
@@ -177,6 +178,8 @@
return "insertAtIntoCollection";
case UP_REMOVE_FROM_COLLECTION:
return "removeFromCollection";
+ case UP_TRUNCATE_COLLECTION:
+ return "truncateCollection";
case UP_REMOVE_AT_FROM_COLLECTION:
return "removeAtFromCollection";
case UP_CREATE_INDEX:
=== modified file 'src/store/naive/pul_primitive_factory.cpp'
--- src/store/naive/pul_primitive_factory.cpp 2012-02-15 10:25:02 +0000
+++ src/store/naive/pul_primitive_factory.cpp 2012-02-28 02:00:28 +0000
@@ -377,6 +377,18 @@
return new UpdDeleteNodesFromCollection(pul, aLoc, name, nodes, isLast, dyn_collection);
}
+
+ /***************************************************************************
+ ***************************************************************************/
+ UpdTruncateCollection*
+ PULPrimitiveFactory::createUpdTruncateCollection(
+ CollectionPul* pul,
+ const QueryLoc* aLoc,
+ store::Item_t& name,
+ bool dyn_collection)
+ {
+ return new UpdTruncateCollection(pul, aLoc, name, dyn_collection);
+ }
/***************************************************************************
***************************************************************************/
=== modified file 'src/store/naive/pul_primitive_factory.h'
--- src/store/naive/pul_primitive_factory.h 2012-02-22 16:30:24 +0000
+++ src/store/naive/pul_primitive_factory.h 2012-02-28 02:00:28 +0000
@@ -50,6 +50,7 @@
class UpdInsertBeforeIntoCollection;
class UpdInsertAfterIntoCollection;
class UpdDeleteNodesFromCollection;
+ class UpdTruncateCollection;
class UpdCreateIndex;
class UpdDeleteIndex;
class UpdRefreshIndex;
@@ -311,6 +312,15 @@
std::vector<store::Item_t>& nodes,
bool isLast,
bool dyn_collection = false);
+
+ /***************************************************************************
+ ***************************************************************************/
+ virtual UpdTruncateCollection*
+ createUpdTruncateCollection(
+ CollectionPul* pul,
+ const QueryLoc*,
+ store::Item_t& name,
+ bool dyn_collection = false);
/***************************************************************************
***************************************************************************/
=== modified file 'src/store/naive/pul_primitives.cpp'
--- src/store/naive/pul_primitives.cpp 2012-02-15 10:25:02 +0000
+++ src/store/naive/pul_primitives.cpp 2012-02-28 02:00:28 +0000
@@ -1276,6 +1276,36 @@
}
+/*******************************************************************************
+ UpdTruncateCollection
+********************************************************************************/
+void UpdTruncateCollection::apply()
+{
+ SimpleCollection* lColl = static_cast<SimpleCollection*>
+ (GET_STORE().getCollection(theName, theDynamicCollection).getp());
+ assert(lColl);
+
+ lColl->theXmlTrees.swap(theTrees);
+
+ theIsApplied = true;
+
+}
+
+void UpdTruncateCollection::undo()
+{
+ if (!theIsApplied) return;
+
+ SimpleCollection* lColl = static_cast<SimpleCollection*>
+ (GET_STORE().getCollection(theName, theDynamicCollection).getp());
+ assert(lColl);
+
+ lColl->theXmlTrees.clear();
+
+ theTrees.swap(lColl->theXmlTrees);
+
+ theIsApplied = false;
+}
+
/////////////////////////////////////////////////////////////////////////////////
// //
=== modified file 'src/store/naive/pul_primitives.h'
--- src/store/naive/pul_primitives.h 2012-02-22 16:30:24 +0000
+++ src/store/naive/pul_primitives.h 2012-02-28 02:00:28 +0000
@@ -1210,6 +1210,37 @@
};
+/*******************************************************************************
+
+********************************************************************************/
+class UpdTruncateCollection: public UpdCollection
+{
+ friend class PULPrimitiveFactory;
+
+protected:
+ std::vector<store::Item_t> theTrees;
+
+ UpdTruncateCollection(
+ CollectionPul* pul,
+ const QueryLoc* aLoc,
+ store::Item_t& name,
+ bool dyn_collection)
+ :
+ UpdCollection(pul, aLoc, name, dyn_collection)
+ {
+ }
+
+public:
+ store::UpdateConsts::UpdPrimKind getKind() const
+ {
+ return store::UpdateConsts::UP_TRUNCATE_COLLECTION;
+ }
+
+ void apply();
+ void undo();
+};
+
+
/////////////////////////////////////////////////////////////////////////////////
// //
// Index Primitives //
=== modified file 'src/store/naive/simple_collection.h'
--- src/store/naive/simple_collection.h 2012-02-22 16:30:24 +0000
+++ src/store/naive/simple_collection.h 2012-02-28 02:00:28 +0000
@@ -40,6 +40,7 @@
class SimpleCollection : public store::Collection
{
friend class CollectionIter;
+ friend class UpdTruncateCollection;
public:
class CollectionIter : public store::Iterator
=== modified file 'src/store/naive/simple_pul.cpp'
--- src/store/naive/simple_pul.cpp 2012-02-15 10:25:02 +0000
+++ src/store/naive/simple_pul.cpp 2012-02-28 02:00:28 +0000
@@ -944,6 +944,17 @@
}
+void PULImpl::addTruncateCollection(
+ const QueryLoc* aQueryLoc,
+ store::Item_t& name,
+ bool dyn_collection)
+{
+ CollectionPul* pul = getCollectionPulByName(name.getp(),dyn_collection);
+
+ pul->theTruncateCollectionList.push_back(
+ GET_PUL_FACTORY().createUpdTruncateCollection(pul, aQueryLoc, name, dyn_collection));
+}
+
/*******************************************************************************
Index primitives
********************************************************************************/
@@ -1157,6 +1168,11 @@
UP_LIST_NONE);
mergeUpdateList(thisPul,
+ thisPul->theTruncateCollectionList,
+ otherPul->theTruncateCollectionList,
+ UP_LIST_NONE);
+
+ mergeUpdateList(thisPul,
thisPul->theDeleteCollectionList,
otherPul->theDeleteCollectionList,
UP_LIST_NONE);
@@ -1795,6 +1811,7 @@
cleanList(theCreateCollectionList);
cleanList(theInsertIntoCollectionList);
cleanList(theDeleteFromCollectionList);
+ cleanList(theTruncateCollectionList);
cleanList(theDeleteCollectionList);
cleanIndexDeltas(theBeforeIndexDeltas);
@@ -1821,6 +1838,7 @@
switchPulInPrimitivesList(theCreateCollectionList);
switchPulInPrimitivesList(theInsertIntoCollectionList);
switchPulInPrimitivesList(theDeleteFromCollectionList);
+ switchPulInPrimitivesList(theTruncateCollectionList);
switchPulInPrimitivesList(theDeleteCollectionList);
}
@@ -2133,6 +2151,7 @@
applyList(theCreateCollectionList);
applyList(theInsertIntoCollectionList);
applyList(theDeleteFromCollectionList);
+ applyList(theTruncateCollectionList);
// Compute the after-delta for each incrementally maintained index.
computeIndexAfterDeltas();
@@ -2265,6 +2284,7 @@
try
{
+ undoList(theTruncateCollectionList);
undoList(theDeleteFromCollectionList);
undoList(theInsertIntoCollectionList);
undoList(theCreateCollectionList);
=== modified file 'src/store/naive/simple_pul.h'
--- src/store/naive/simple_pul.h 2012-02-22 16:30:24 +0000
+++ src/store/naive/simple_pul.h 2012-02-28 02:00:28 +0000
@@ -183,6 +183,7 @@
std::vector<UpdatePrimitive*> theCreateCollectionList;
std::vector<UpdatePrimitive*> theInsertIntoCollectionList;
std::vector<UpdatePrimitive*> theDeleteFromCollectionList;
+ std::vector<UpdatePrimitive*> theTruncateCollectionList;
std::vector<UpdatePrimitive*> theDeleteCollectionList;
// Validate in place primitives
@@ -465,6 +466,11 @@
bool isLast,
bool dyn_collection = false);
+ void addTruncateCollection(
+ const QueryLoc* aQueryLoc,
+ store::Item_t& name,
+ bool dyn_collection = false);
+
// Index primitives
void addCreateIndex(
const QueryLoc* aQueryLoc,
=== 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-02-28 02:00:28 +0000
@@ -0,0 +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>
=== 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-02-28 02:00:28 +0000
@@ -0,0 +1,1 @@
+0
=== 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-02-28 02:00:28 +0000
@@ -0,0 +1,21 @@
+import module namespace ddl = "http://www.zorba-xquery.com/modules/store/static/collections/ddl";
+import module namespace dml = "http://www.zorba-xquery.com/modules/store/static/collections/dml";
+
+import module namespace ns = "http://www.example.com/example" at "../collection_002.xqdata";
+
+variable $contents;
+
+ddl:create(xs:QName("ns:collection"));
+
+dml:insert-nodes(
+ xs:QName("ns:collection"),
+ for $i in 1 to 10 return <a>{$i}</a>
+);
+
+$contents := dml:collection(xs:QName("ns:collection"));
+
+dml:truncate(xs:QName("ns:collection"));
+
+$contents := ($contents, dml:collection(xs:QName("ns:collection")));
+
+$contents
=== 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-02-28 02:00:28 +0000
@@ -0,0 +1,10 @@
+import module namespace ddl = "http://www.zorba-xquery.com/modules/store/dynamic/collections/ddl";
+import module namespace dml = "http://www.zorba-xquery.com/modules/store/dynamic/collections/dml";
+
+ddl:create(xs:QName("ddl:test2"),(<center1/>,<oldlast/>));
+
+dml:insert-nodes-first(xs:QName("ddl:test2"), (<c1/>,<c2/>));
+
+dml:truncate(xs:QName("ddl:test2"));
+
+count(dml:collection(xs:QName("ddl:test2")))
Follow ups
-
Re: [Merge] lp:~zorba-coders/zorba/bug-938934 into lp:zorba
From: Matthias Brantner, 2012-03-08
-
Re: [Merge] lp:~zorba-coders/zorba/bug-938934 into lp:zorba
From: Markos Zaharioudakis, 2012-02-28
-
Re: [Merge] lp:~zorba-coders/zorba/bug-938934 into lp:zorba
From: Markos Zaharioudakis, 2012-02-28
-
Re: [Merge] lp:~zorba-coders/zorba/bug-938934 into lp:zorba
From: Markos Zaharioudakis, 2012-02-28
-
Re: [Merge] lp:~zorba-coders/zorba/bug-938934 into lp:zorba
From: Matthias Brantner, 2012-02-28
-
[Merge] lp:~zorba-coders/zorba/bug-938934 into lp:zorba
From: Zorba Build Bot, 2012-02-28
-
Re: [Merge] lp:~zorba-coders/zorba/bug-938934 into lp:zorba
From: Zorba Build Bot, 2012-02-28
-
[Merge] lp:~zorba-coders/zorba/bug-938934 into lp:zorba
From: Zorba Build Bot, 2012-02-28
-
[Merge] lp:~zorba-coders/zorba/bug-938934 into lp:zorba
From: Zorba Build Bot, 2012-02-28
-
[Merge] lp:~zorba-coders/zorba/bug-938934 into lp:zorba
From: Matthias Brantner, 2012-02-28
-
[Merge] lp:~zorba-coders/zorba/bug-938934 into lp:zorba
From: Matthias Brantner, 2012-02-28
-
Re: [Merge] lp:~zorba-coders/zorba/bug-938934 into lp:zorba
From: Matthias Brantner, 2012-02-28