zorba-coders team mailing list archive
-
zorba-coders team
-
Mailing list archive
-
Message #00969
[Merge] lp:~fcavalieri/zorba/setsatundo into lp:zorba
Federico Cavalieri has proposed merging lp:~fcavalieri/zorba/setsatundo into lp:zorba.
Requested reviews:
Federico Cavalieri (fcavalieri)
Markos Zaharioudakis (markos-za)
For more details, see:
https://code.launchpad.net/~fcavalieri/zorba/setsatundo/+merge/79093
Implemented undo for SetElementType and SetAttributeType.
--
https://code.launchpad.net/~fcavalieri/zorba/setsatundo/+merge/79093
Your team Zorba Coders is subscribed to branch lp:zorba.
=== modified file 'ChangeLog'
--- ChangeLog 2011-10-12 09:20:36 +0000
+++ ChangeLog 2011-10-12 10:04:34 +0000
@@ -49,6 +49,7 @@
* New node-reference module. References can be obtained for any node, and
different nodes cannot have the same identifier.
* Fixed bug #872697 (segmentation fault with validation of NMTOKENS)
+ * Added undo for node revalidation
version 2.0.1
=== modified file 'src/store/naive/pul_primitives.cpp'
--- src/store/naive/pul_primitives.cpp 2011-10-12 09:20:36 +0000
+++ src/store/naive/pul_primitives.cpp 2011-10-12 10:04:34 +0000
@@ -465,12 +465,20 @@
{
ElementNode* target = ELEM_NODE(theTarget);
+ theOldTypeName=target->getType();
+ theOldHaveTypedValue=target->haveTypedValue();
+ if (theOldHaveTypedValue)
+ theOldHaveEmptyTypedValue=target->haveEmptyTypedValue();
+ theOldIsInSubstitutionGroup=target->isInSubstitutionGroup();
+
target->setType(theTypeName);
TextNode* textChild;
-
- if (target->haveTypedTypedValue(textChild))
+ theOldHaveTypedTypedValue=target->haveTypedTypedValue(textChild);
+ if (theOldHaveTypedTypedValue)
{
+ theOldHaveListTypedValue= textChild->haveListValue();
+ theOldTypedValue=textChild->getValue();
zstring textValue;
textChild->getStringValue2(textValue);
@@ -491,7 +499,7 @@
if (theHaveTypedTypedValue)
{
- TextNode* textChild = target->getUniqueTextChild();
+ textChild = target->getUniqueTextChild();
textChild->setTypedValue(theTypedValue);
if (theHaveListTypedValue)
@@ -509,8 +517,57 @@
target->setInSubstGroup();
else
target->resetInSubstGroup();
-}
-
+
+ theIsApplied=true;
+}
+
+void UpdSetElementType::undo()
+{
+ if (theIsApplied)
+ {
+ ElementNode* target = ELEM_NODE(theTarget);
+
+ target->setType(theOldTypeName);
+
+ if (theHaveTypedTypedValue)
+ {
+ TextNode* textChild = target->getUniqueTextChild();
+ textChild->revertToTextContent();
+ }
+
+ if (theOldHaveTypedValue)
+ {
+ target->setHaveTypedValue();
+
+ if (theOldHaveEmptyTypedValue)
+ target->setHaveEmptyTypedValue();
+ else
+ target->resetHaveEmptyTypedValue();
+
+ if (theOldHaveTypedTypedValue)
+ {
+ TextNode* textChild = target->getUniqueTextChild();
+
+ textChild->setTypedValue(theOldTypedValue);
+ if (theOldHaveListTypedValue)
+ textChild->setHaveListValue();
+ else
+ textChild->resetHaveListValue();
+ }
+ }
+ else
+ {
+ target->resetHaveTypedValue();
+ }
+
+ if (theOldIsInSubstitutionGroup)
+ target->setInSubstGroup();
+ else
+ target->resetInSubstGroup();
+
+ theIsApplied=false;
+ }
+}
/*******************************************************************************
@@ -570,6 +627,10 @@
{
AttributeNode* target = ATTR_NODE(theTarget);
+ theOldTypeName=target->getType();
+ theOldTypedValue.transfer(target->theTypedValue);
+ theOldHaveListValue=target->haveListValue();
+
target->setType(theTypeName);
target->theTypedValue.transfer(theTypedValue);
@@ -577,8 +638,26 @@
target->setHaveListValue();
else
target->resetHaveListValue();
-}
-
+
+ theIsApplied=true;
+}
+
+void UpdSetAttributeType::undo()
+{
+ if (theIsApplied)
+ {
+ AttributeNode* target = ATTR_NODE(theTarget);
+ target->setType(theOldTypeName);
+ target->theTypedValue.transfer(theOldTypedValue);
+
+ if (theOldHaveListValue)
+ target->setHaveListValue();
+ else
+ target->resetHaveListValue();
+
+ theIsApplied=false;
+ }
+}
/*******************************************************************************
=== modified file 'src/store/naive/pul_primitives.h'
--- src/store/naive/pul_primitives.h 2011-10-10 12:12:00 +0000
+++ src/store/naive/pul_primitives.h 2011-10-12 10:04:34 +0000
@@ -712,16 +712,24 @@
protected:
store::Item_t theTypeName;
-
store::Item_t theTypedValue;
bool theHaveTypedValue;
bool theHaveEmptyTypedValue;
bool theHaveTypedTypedValue;
bool theHaveListTypedValue;
-
bool theIsInSubstitutionGroup;
+ store::Item_t theOldTypeName;
+ store::Item_t theOldTypedValue;
+
+ bool theOldHaveTypedValue;
+ bool theOldHaveEmptyTypedValue;
+ bool theOldHaveTypedTypedValue;
+ bool theOldHaveListTypedValue;
+ bool theOldIsInSubstitutionGroup;
+
+
UpdSetElementType(
PULImpl* pul,
const QueryLoc* aLoc,
@@ -752,7 +760,7 @@
}
void apply();
- void undo() {}
+ void undo();
};
@@ -769,6 +777,10 @@
store::Item_t theTypedValue;
bool theHaveListValue;
+ store::Item_t theOldTypeName;
+ store::Item_t theOldTypedValue;
+ bool theOldHaveListValue;
+
UpdSetAttributeType(
PULImpl* pul,
const QueryLoc* aLoc,
@@ -791,7 +803,7 @@
}
void apply();
- void undo() {}
+ void undo();
};
=== modified file 'src/store/naive/simple_pul.cpp'
--- src/store/naive/simple_pul.cpp 2011-10-10 09:59:54 +0000
+++ src/store/naive/simple_pul.cpp 2011-10-12 10:04:34 +0000
@@ -2078,14 +2078,13 @@
// Revalidate the updated docs
if (thePul->theValidator != NULL && !theValidationNodes.empty())
{
- store::PUL_t validationPul =
- GET_STORE().getItemFactory()->createPendingUpdateList();
+ theValidationPul = GET_STORE().getItemFactory()->createPendingUpdateList();
- thePul->theValidator->validate(theValidationNodes, *validationPul.getp());
+ thePul->theValidator->validate(theValidationNodes, *theValidationPul.getp());
try
{
- validationPul->applyUpdates(false);
+ theValidationPul->applyUpdates(false);
}
catch (...)
{
@@ -2234,6 +2233,12 @@
undoList(theInsertIntoCollectionList);
undoList(theCreateCollectionList);
+ // Undo validation
+ if (theValidationPul)
+ {
+ undoList(static_cast<PULImpl *>(theValidationPul.getp())->theValidationList);
+ }
+
// Undo text node merging
std::vector<TextNodeMerge>::reverse_iterator rit = theMergeList.rbegin();
std::vector<TextNodeMerge>::reverse_iterator rend = theMergeList.rend();
=== modified file 'src/store/naive/simple_pul.h'
--- src/store/naive/simple_pul.h 2011-10-11 20:51:15 +0000
+++ src/store/naive/simple_pul.h 2011-10-12 10:04:34 +0000
@@ -166,6 +166,8 @@
std::set<store::Item*> theValidationNodes;
+ store::PUL_t theValidationPul;
+
bool theAdjustTreePositions;
bool theIsApplied;
=== added file 'test/rbkt/ExpQueryResults/zorba/updates/undo10.xml.res'
--- test/rbkt/ExpQueryResults/zorba/updates/undo10.xml.res 1970-01-01 00:00:00 +0000
+++ test/rbkt/ExpQueryResults/zorba/updates/undo10.xml.res 2011-10-12 10:04:34 +0000
@@ -0,0 +1,2 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<ELEM-items-a type="ItemsType-A"><ELEM-number type="positiveInteger"/></ELEM-items-a>
\ No newline at end of file
=== added file 'test/rbkt/ExpQueryResults/zorba/updates/undo8.xml.res'
--- test/rbkt/ExpQueryResults/zorba/updates/undo8.xml.res 1970-01-01 00:00:00 +0000
+++ test/rbkt/ExpQueryResults/zorba/updates/undo8.xml.res 2011-10-12 10:04:34 +0000
@@ -0,0 +1,2 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<ELEM-shiporders type="xs:anyType"><ELEM-shiporder type="xs:anyType"><ATTR-orderid type="xs:untypedAtomic"/><ELEM-orderperson type="xs:anyType"/><ELEM-shipto type="xs:anyType"><ELEM-name type="xs:anyType"/><ELEM-address type="xs:anyType"/><ELEM-city type="xs:anyType"/><ELEM-country type="xs:anyType"/></ELEM-shipto><ELEM-item type="xs:anyType"><ELEM-title type="xs:anyType"/><ELEM-note type="xs:anyType"/><ELEM-quantity type="xs:anyType"/><ELEM-price type="xs:anyType"/></ELEM-item><ELEM-item type="xs:anyType"><ELEM-title type="xs:anyType"/><ELEM-quantity type="xs:anyType"/><ELEM-price type="xs:anyType"/></ELEM-item></ELEM-shiporder></ELEM-shiporders>
\ No newline at end of file
=== added file 'test/rbkt/ExpQueryResults/zorba/updates/undo9.xml.res'
--- test/rbkt/ExpQueryResults/zorba/updates/undo9.xml.res 1970-01-01 00:00:00 +0000
+++ test/rbkt/ExpQueryResults/zorba/updates/undo9.xml.res 2011-10-12 10:04:34 +0000
@@ -0,0 +1,2 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<ELEM-shiporders type="xs:untyped"><ELEM-shiporder type="xs:untyped"><ATTR-orderid type="xs:untypedAtomic"/><ELEM-orderperson type="xs:untyped"/><ELEM-shipto type="xs:untyped"><ELEM-name type="xs:untyped"/><ELEM-address type="xs:untyped"/><ELEM-city type="xs:untyped"/><ELEM-country type="xs:untyped"/></ELEM-shipto><ELEM-item type="xs:untyped"><ELEM-title type="xs:untyped"/><ELEM-note type="xs:untyped"/><ELEM-quantity type="xs:untyped"/><ELEM-price type="xs:untyped"/></ELEM-item><ELEM-item type="xs:untyped"><ELEM-title type="xs:untyped"/><ELEM-quantity type="xs:untyped"/><ELEM-price type="xs:untyped"/></ELEM-item></ELEM-shiporder></ELEM-shiporders>
\ No newline at end of file
=== added file 'test/rbkt/Queries/zorba/updates/subst.xsd'
--- test/rbkt/Queries/zorba/updates/subst.xsd 1970-01-01 00:00:00 +0000
+++ test/rbkt/Queries/zorba/updates/subst.xsd 2011-10-12 10:04:34 +0000
@@ -0,0 +1,23 @@
+<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema"
+targetNamespace="http://www.zorba-xquery.org/schema" xmlns="http://www.zorba-xquery.org/schema"
+ elementFormDefault="qualified">
+
+ <xs:element name="items-a" type="ItemsType-A"/>
+ <xs:complexType name="ItemsType-A">
+ <xs:sequence>
+ <xs:element ref="number-a"/>
+ </xs:sequence>
+ </xs:complexType>
+
+ <xs:element name="number-a" type="xs:integer"/>
+
+ <xs:element name="number" type="xs:positiveInteger" substitutionGroup="number-a"/>
+
+ <xs:element name="items-b" type="ItemsType-B"/>
+ <xs:complexType name="ItemsType-B">
+ <xs:sequence>
+ <xs:element name="number" type="xs:string"/>
+ </xs:sequence>
+ </xs:complexType>
+
+</xs:schema>
\ No newline at end of file
=== added file 'test/rbkt/Queries/zorba/updates/undo10.xq'
--- test/rbkt/Queries/zorba/updates/undo10.xq 1970-01-01 00:00:00 +0000
+++ test/rbkt/Queries/zorba/updates/undo10.xq 2011-10-12 10:04:34 +0000
@@ -0,0 +1,34 @@
+import module namespace m = 'xqueryzorba.org/test/xqddf/ic' at '../xqddf/ic.xqlib';
+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 ic_ddl = "http://www.zorba-xquery.com/modules/store/static/integrity_constraints/ddl";
+import module namespace schema = "http://www.zorba-xquery.com/modules/schema";
+import module namespace u = "http://www.zorba-xquery.com/test/undo/utils" at "utils.xqlib";
+import schema namespace s="http://www.zorba-xquery.org/schema" at "subst.xsd";
+
+declare revalidation lax;
+
+variable $x:=
+validate{
+<items-a xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ xmlns="http://www.zorba-xquery.org/schema">
+ <number>111</number>
+</items-a>};
+
+ddl:create($m:empc);
+
+ic_ddl:activate(xs:QName("m:ic_simple"));
+
+try
+{
+(
+ rename node $x as QName("http://www.zorba-xquery.org/schema", "items-b"),
+
+ dml:insert-nodes($m:empc, <emp><salary>600</salary></emp>)
+);
+}
+catch *
+{
+}
+
+u:dump-types($x)
=== added file 'test/rbkt/Queries/zorba/updates/undo8.xq'
--- test/rbkt/Queries/zorba/updates/undo8.xq 1970-01-01 00:00:00 +0000
+++ test/rbkt/Queries/zorba/updates/undo8.xq 2011-10-12 10:04:34 +0000
@@ -0,0 +1,54 @@
+import module namespace m = 'xqueryzorba.org/test/xqddf/ic' at '../xqddf/ic.xqlib';
+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 ic_ddl = "http://www.zorba-xquery.com/modules/store/static/integrity_constraints/ddl";
+import module namespace schema = "http://www.zorba-xquery.com/modules/schema";
+import module namespace u = "http://www.zorba-xquery.com/test/undo/utils" at "utils.xqlib";
+import schema namespace s="http://www.zorba-xquery.org/schema" at "shiporder.xsd";
+
+declare revalidation lax;
+declare construction preserve;
+
+variable $x:=
+<shiporders xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ xmlns="http://www.zorba-xquery.org/schema">
+<shiporder orderid="889923">
+ <orderperson>John Smith</orderperson>
+ <shipto>
+ <name>Ola Nordmann</name>
+ <address>Langgt 23</address>
+ <city>4000 Stavanger</city>
+ <country>Norway</country>
+ </shipto>
+ <item>
+ <title>Empire Burlesque</title>
+ <note>Special Edition</note>
+ <quantity>1</quantity>
+ <price>10.90</price>
+ </item>
+ <item>
+ <title>Hide your heart</title>
+ <quantity>1</quantity>
+ <price>9.90</price>
+ </item>
+</shiporder>
+</shiporders>;
+
+
+ddl:create($m:empc);
+
+ic_ddl:activate(xs:QName("m:ic_simple"));
+
+try
+{
+(
+ insert node ($x//*:item)[1]/*:note after ($x//*:item)[last()]/*:title,
+
+ dml:insert-nodes($m:empc, <emp><salary>600</salary></emp>)
+);
+}
+catch *
+{
+}
+
+u:dump-types($x)
\ No newline at end of file
=== added file 'test/rbkt/Queries/zorba/updates/undo9.xq'
--- test/rbkt/Queries/zorba/updates/undo9.xq 1970-01-01 00:00:00 +0000
+++ test/rbkt/Queries/zorba/updates/undo9.xq 2011-10-12 10:04:34 +0000
@@ -0,0 +1,54 @@
+import module namespace m = 'xqueryzorba.org/test/xqddf/ic' at '../xqddf/ic.xqlib';
+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 ic_ddl = "http://www.zorba-xquery.com/modules/store/static/integrity_constraints/ddl";
+import module namespace schema = "http://www.zorba-xquery.com/modules/schema";
+import module namespace u = "http://www.zorba-xquery.com/test/undo/utils" at "utils.xqlib";
+import schema namespace s="http://www.zorba-xquery.org/schema" at "shiporder.xsd";
+
+declare revalidation lax;
+declare construction strip;
+
+variable $x:=
+<shiporders xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ xmlns="http://www.zorba-xquery.org/schema">
+<shiporder orderid="889923">
+ <orderperson>John Smith</orderperson>
+ <shipto>
+ <name>Ola Nordmann</name>
+ <address>Langgt 23</address>
+ <city>4000 Stavanger</city>
+ <country>Norway</country>
+ </shipto>
+ <item>
+ <title>Empire Burlesque</title>
+ <note>Special Edition</note>
+ <quantity>1</quantity>
+ <price>10.90</price>
+ </item>
+ <item>
+ <title>Hide your heart</title>
+ <quantity>1</quantity>
+ <price>9.90</price>
+ </item>
+</shiporder>
+</shiporders>;
+
+
+ddl:create($m:empc);
+
+ic_ddl:activate(xs:QName("m:ic_simple"));
+
+try
+{
+(
+ insert node ($x//*:item)[1]/*:note after ($x//*:item)[last()]/*:title,
+
+ dml:insert-nodes($m:empc, <emp><salary>600</salary></emp>)
+);
+}
+catch *
+{
+}
+
+u:dump-types($x)
\ No newline at end of file
=== added file 'test/rbkt/Queries/zorba/updates/utils.xqlib'
--- test/rbkt/Queries/zorba/updates/utils.xqlib 1970-01-01 00:00:00 +0000
+++ test/rbkt/Queries/zorba/updates/utils.xqlib 2011-10-12 10:04:34 +0000
@@ -0,0 +1,30 @@
+module namespace u = "http://www.zorba-xquery.com/test/undo/utils";
+import module namespace schema = "http://www.zorba-xquery.com/modules/schema";
+
+declare function u:dump-types($nodes as node()*) as element()*
+{
+for $node in $nodes
+return
+ if ($node instance of text()) then ()
+ else
+ (
+ element
+ {
+ if ($node instance of element()) then concat("ELEM-",string(node-name($node)))
+ else if ($node instance of attribute()) then concat("ATTR-",string(node-name($node)))
+ else if ($node instance of text()) then 'TEXT'
+ else if ($node instance of document-node()) then 'DOCU'
+ else if ($node instance of comment()) then 'COMM'
+ else if ($node instance of processing-instruction()) then 'PROC'
+ else 'unknown'
+ }
+ {
+ attribute type {schema:schema-type($node)},
+ for $attr in $node/@*
+ return u:dump-types($attr),
+ for $elem in $node/node()
+ return u:dump-types($elem)
+ }
+ )
+};
+
Follow ups
-
[Merge] lp:~fcavalieri/zorba/setsatundo into lp:zorba
From: noreply, 2011-10-12
-
[Merge] lp:~fcavalieri/zorba/setsatundo into lp:zorba
From: Zorba Build Bot, 2011-10-12
-
[Merge] lp:~fcavalieri/zorba/setsatundo into lp:zorba
From: Zorba Build Bot, 2011-10-12
-
[Merge] lp:~fcavalieri/zorba/setsatundo into lp:zorba
From: Federico Cavalieri, 2011-10-12
-
Re: [Merge] lp:~fcavalieri/zorba/setsatundo into lp:zorba
From: Federico Cavalieri, 2011-10-12
-
Re: [Merge] lp:~fcavalieri/zorba/setsatundo into lp:zorba
From: Markos Zaharioudakis, 2011-10-12
-
[Merge] lp:~fcavalieri/zorba/setsatundo into lp:zorba
From: Zorba Build Bot, 2011-10-12
-
Re: [Merge] lp:~fcavalieri/zorba/setsatundo into lp:zorba
From: Zorba Build Bot, 2011-10-12
-
[Merge] lp:~fcavalieri/zorba/setsatundo into lp:zorba
From: Zorba Build Bot, 2011-10-12
-
[Merge] lp:~fcavalieri/zorba/setsatundo into lp:zorba
From: Zorba Build Bot, 2011-10-12
-
[Merge] lp:~fcavalieri/zorba/setsatundo into lp:zorba
From: Federico Cavalieri, 2011-10-12