Merge lp:~fcavalieri/zorba/setsatundo into lp:zorba

Proposed by Federico Cavalieri
Status: Merged
Approved by: Federico Cavalieri
Approved revision: 10481
Merged at revision: 10513
Proposed branch: lp:~fcavalieri/zorba/setsatundo
Merge into: lp:zorba
Diff against target: 502 lines (+315/-15)
13 files modified
ChangeLog (+1/-0)
src/store/naive/pul_primitives.cpp (+86/-7)
src/store/naive/pul_primitives.h (+16/-4)
src/store/naive/simple_pul.cpp (+9/-4)
src/store/naive/simple_pul.h (+2/-0)
test/rbkt/ExpQueryResults/zorba/updates/undo10.xml.res (+2/-0)
test/rbkt/ExpQueryResults/zorba/updates/undo8.xml.res (+2/-0)
test/rbkt/ExpQueryResults/zorba/updates/undo9.xml.res (+2/-0)
test/rbkt/Queries/zorba/updates/subst.xsd (+23/-0)
test/rbkt/Queries/zorba/updates/undo10.xq (+34/-0)
test/rbkt/Queries/zorba/updates/undo8.xq (+54/-0)
test/rbkt/Queries/zorba/updates/undo9.xq (+54/-0)
test/rbkt/Queries/zorba/updates/utils.xqlib (+30/-0)
To merge this branch: bzr merge lp:~fcavalieri/zorba/setsatundo
Reviewer Review Type Date Requested Status
Federico Cavalieri Approve
Markos Zaharioudakis Approve
Review via email: mp+79093@code.launchpad.net

Commit message

Implemented undo for SetElementType and SetAttributeType.

Description of the change

Implemented undo for SetElementType and SetAttributeType.

To post a comment you must log in.
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 setsatundo-2011-10-12T10-10-16.743Z 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
Markos Zaharioudakis (markos-za) :
review: Approve
Revision history for this message
Federico Cavalieri (fcavalieri) :
review: Approve
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 setsatundo-2011-10-12T14-51-59.701Z is finished. The final status was:

All tests succeeded!

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'ChangeLog'
2--- ChangeLog 2011-10-12 09:20:36 +0000
3+++ ChangeLog 2011-10-12 10:04:34 +0000
4@@ -49,6 +49,7 @@
5 * New node-reference module. References can be obtained for any node, and
6 different nodes cannot have the same identifier.
7 * Fixed bug #872697 (segmentation fault with validation of NMTOKENS)
8+ * Added undo for node revalidation
9
10 version 2.0.1
11
12
13=== modified file 'src/store/naive/pul_primitives.cpp'
14--- src/store/naive/pul_primitives.cpp 2011-10-12 09:20:36 +0000
15+++ src/store/naive/pul_primitives.cpp 2011-10-12 10:04:34 +0000
16@@ -465,12 +465,20 @@
17 {
18 ElementNode* target = ELEM_NODE(theTarget);
19
20+ theOldTypeName=target->getType();
21+ theOldHaveTypedValue=target->haveTypedValue();
22+ if (theOldHaveTypedValue)
23+ theOldHaveEmptyTypedValue=target->haveEmptyTypedValue();
24+ theOldIsInSubstitutionGroup=target->isInSubstitutionGroup();
25+
26 target->setType(theTypeName);
27
28 TextNode* textChild;
29-
30- if (target->haveTypedTypedValue(textChild))
31+ theOldHaveTypedTypedValue=target->haveTypedTypedValue(textChild);
32+ if (theOldHaveTypedTypedValue)
33 {
34+ theOldHaveListTypedValue= textChild->haveListValue();
35+ theOldTypedValue=textChild->getValue();
36 zstring textValue;
37 textChild->getStringValue2(textValue);
38
39@@ -491,7 +499,7 @@
40
41 if (theHaveTypedTypedValue)
42 {
43- TextNode* textChild = target->getUniqueTextChild();
44+ textChild = target->getUniqueTextChild();
45
46 textChild->setTypedValue(theTypedValue);
47 if (theHaveListTypedValue)
48@@ -509,8 +517,57 @@
49 target->setInSubstGroup();
50 else
51 target->resetInSubstGroup();
52-}
53-
54+
55+ theIsApplied=true;
56+}
57+
58+void UpdSetElementType::undo()
59+{
60+ if (theIsApplied)
61+ {
62+ ElementNode* target = ELEM_NODE(theTarget);
63+
64+ target->setType(theOldTypeName);
65+
66+ if (theHaveTypedTypedValue)
67+ {
68+ TextNode* textChild = target->getUniqueTextChild();
69+ textChild->revertToTextContent();
70+ }
71+
72+ if (theOldHaveTypedValue)
73+ {
74+ target->setHaveTypedValue();
75+
76+ if (theOldHaveEmptyTypedValue)
77+ target->setHaveEmptyTypedValue();
78+ else
79+ target->resetHaveEmptyTypedValue();
80+
81+ if (theOldHaveTypedTypedValue)
82+ {
83+ TextNode* textChild = target->getUniqueTextChild();
84+
85+ textChild->setTypedValue(theOldTypedValue);
86+ if (theOldHaveListTypedValue)
87+ textChild->setHaveListValue();
88+ else
89+ textChild->resetHaveListValue();
90+ }
91+ }
92+ else
93+ {
94+ target->resetHaveTypedValue();
95+ }
96+
97+ if (theOldIsInSubstitutionGroup)
98+ target->setInSubstGroup();
99+ else
100+ target->resetInSubstGroup();
101+
102+ theIsApplied=false;
103+ }
104+}
105
106 /*******************************************************************************
107
108@@ -570,6 +627,10 @@
109 {
110 AttributeNode* target = ATTR_NODE(theTarget);
111
112+ theOldTypeName=target->getType();
113+ theOldTypedValue.transfer(target->theTypedValue);
114+ theOldHaveListValue=target->haveListValue();
115+
116 target->setType(theTypeName);
117 target->theTypedValue.transfer(theTypedValue);
118
119@@ -577,8 +638,26 @@
120 target->setHaveListValue();
121 else
122 target->resetHaveListValue();
123-}
124-
125+
126+ theIsApplied=true;
127+}
128+
129+void UpdSetAttributeType::undo()
130+{
131+ if (theIsApplied)
132+ {
133+ AttributeNode* target = ATTR_NODE(theTarget);
134+ target->setType(theOldTypeName);
135+ target->theTypedValue.transfer(theOldTypedValue);
136+
137+ if (theOldHaveListValue)
138+ target->setHaveListValue();
139+ else
140+ target->resetHaveListValue();
141+
142+ theIsApplied=false;
143+ }
144+}
145
146 /*******************************************************************************
147
148
149=== modified file 'src/store/naive/pul_primitives.h'
150--- src/store/naive/pul_primitives.h 2011-10-10 12:12:00 +0000
151+++ src/store/naive/pul_primitives.h 2011-10-12 10:04:34 +0000
152@@ -712,16 +712,24 @@
153
154 protected:
155 store::Item_t theTypeName;
156-
157 store::Item_t theTypedValue;
158
159 bool theHaveTypedValue;
160 bool theHaveEmptyTypedValue;
161 bool theHaveTypedTypedValue;
162 bool theHaveListTypedValue;
163-
164 bool theIsInSubstitutionGroup;
165
166+ store::Item_t theOldTypeName;
167+ store::Item_t theOldTypedValue;
168+
169+ bool theOldHaveTypedValue;
170+ bool theOldHaveEmptyTypedValue;
171+ bool theOldHaveTypedTypedValue;
172+ bool theOldHaveListTypedValue;
173+ bool theOldIsInSubstitutionGroup;
174+
175+
176 UpdSetElementType(
177 PULImpl* pul,
178 const QueryLoc* aLoc,
179@@ -752,7 +760,7 @@
180 }
181
182 void apply();
183- void undo() {}
184+ void undo();
185 };
186
187
188@@ -769,6 +777,10 @@
189 store::Item_t theTypedValue;
190 bool theHaveListValue;
191
192+ store::Item_t theOldTypeName;
193+ store::Item_t theOldTypedValue;
194+ bool theOldHaveListValue;
195+
196 UpdSetAttributeType(
197 PULImpl* pul,
198 const QueryLoc* aLoc,
199@@ -791,7 +803,7 @@
200 }
201
202 void apply();
203- void undo() {}
204+ void undo();
205 };
206
207
208
209=== modified file 'src/store/naive/simple_pul.cpp'
210--- src/store/naive/simple_pul.cpp 2011-10-10 09:59:54 +0000
211+++ src/store/naive/simple_pul.cpp 2011-10-12 10:04:34 +0000
212@@ -2078,14 +2078,13 @@
213 // Revalidate the updated docs
214 if (thePul->theValidator != NULL && !theValidationNodes.empty())
215 {
216- store::PUL_t validationPul =
217- GET_STORE().getItemFactory()->createPendingUpdateList();
218+ theValidationPul = GET_STORE().getItemFactory()->createPendingUpdateList();
219
220- thePul->theValidator->validate(theValidationNodes, *validationPul.getp());
221+ thePul->theValidator->validate(theValidationNodes, *theValidationPul.getp());
222
223 try
224 {
225- validationPul->applyUpdates(false);
226+ theValidationPul->applyUpdates(false);
227 }
228 catch (...)
229 {
230@@ -2234,6 +2233,12 @@
231 undoList(theInsertIntoCollectionList);
232 undoList(theCreateCollectionList);
233
234+ // Undo validation
235+ if (theValidationPul)
236+ {
237+ undoList(static_cast<PULImpl *>(theValidationPul.getp())->theValidationList);
238+ }
239+
240 // Undo text node merging
241 std::vector<TextNodeMerge>::reverse_iterator rit = theMergeList.rbegin();
242 std::vector<TextNodeMerge>::reverse_iterator rend = theMergeList.rend();
243
244=== modified file 'src/store/naive/simple_pul.h'
245--- src/store/naive/simple_pul.h 2011-10-11 20:51:15 +0000
246+++ src/store/naive/simple_pul.h 2011-10-12 10:04:34 +0000
247@@ -166,6 +166,8 @@
248
249 std::set<store::Item*> theValidationNodes;
250
251+ store::PUL_t theValidationPul;
252+
253 bool theAdjustTreePositions;
254
255 bool theIsApplied;
256
257=== added file 'test/rbkt/ExpQueryResults/zorba/updates/undo10.xml.res'
258--- test/rbkt/ExpQueryResults/zorba/updates/undo10.xml.res 1970-01-01 00:00:00 +0000
259+++ test/rbkt/ExpQueryResults/zorba/updates/undo10.xml.res 2011-10-12 10:04:34 +0000
260@@ -0,0 +1,2 @@
261+<?xml version="1.0" encoding="UTF-8"?>
262+<ELEM-items-a type="ItemsType-A"><ELEM-number type="positiveInteger"/></ELEM-items-a>
263\ No newline at end of file
264
265=== added file 'test/rbkt/ExpQueryResults/zorba/updates/undo8.xml.res'
266--- test/rbkt/ExpQueryResults/zorba/updates/undo8.xml.res 1970-01-01 00:00:00 +0000
267+++ test/rbkt/ExpQueryResults/zorba/updates/undo8.xml.res 2011-10-12 10:04:34 +0000
268@@ -0,0 +1,2 @@
269+<?xml version="1.0" encoding="UTF-8"?>
270+<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>
271\ No newline at end of file
272
273=== added file 'test/rbkt/ExpQueryResults/zorba/updates/undo9.xml.res'
274--- test/rbkt/ExpQueryResults/zorba/updates/undo9.xml.res 1970-01-01 00:00:00 +0000
275+++ test/rbkt/ExpQueryResults/zorba/updates/undo9.xml.res 2011-10-12 10:04:34 +0000
276@@ -0,0 +1,2 @@
277+<?xml version="1.0" encoding="UTF-8"?>
278+<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>
279\ No newline at end of file
280
281=== added file 'test/rbkt/Queries/zorba/updates/subst.xsd'
282--- test/rbkt/Queries/zorba/updates/subst.xsd 1970-01-01 00:00:00 +0000
283+++ test/rbkt/Queries/zorba/updates/subst.xsd 2011-10-12 10:04:34 +0000
284@@ -0,0 +1,23 @@
285+<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema"
286+targetNamespace="http://www.zorba-xquery.org/schema" xmlns="http://www.zorba-xquery.org/schema"
287+ elementFormDefault="qualified">
288+
289+ <xs:element name="items-a" type="ItemsType-A"/>
290+ <xs:complexType name="ItemsType-A">
291+ <xs:sequence>
292+ <xs:element ref="number-a"/>
293+ </xs:sequence>
294+ </xs:complexType>
295+
296+ <xs:element name="number-a" type="xs:integer"/>
297+
298+ <xs:element name="number" type="xs:positiveInteger" substitutionGroup="number-a"/>
299+
300+ <xs:element name="items-b" type="ItemsType-B"/>
301+ <xs:complexType name="ItemsType-B">
302+ <xs:sequence>
303+ <xs:element name="number" type="xs:string"/>
304+ </xs:sequence>
305+ </xs:complexType>
306+
307+</xs:schema>
308\ No newline at end of file
309
310=== added file 'test/rbkt/Queries/zorba/updates/undo10.xq'
311--- test/rbkt/Queries/zorba/updates/undo10.xq 1970-01-01 00:00:00 +0000
312+++ test/rbkt/Queries/zorba/updates/undo10.xq 2011-10-12 10:04:34 +0000
313@@ -0,0 +1,34 @@
314+import module namespace m = 'xqueryzorba.org/test/xqddf/ic' at '../xqddf/ic.xqlib';
315+import module namespace ddl = "http://www.zorba-xquery.com/modules/store/static/collections/ddl";
316+import module namespace dml = "http://www.zorba-xquery.com/modules/store/static/collections/dml";
317+import module namespace ic_ddl = "http://www.zorba-xquery.com/modules/store/static/integrity_constraints/ddl";
318+import module namespace schema = "http://www.zorba-xquery.com/modules/schema";
319+import module namespace u = "http://www.zorba-xquery.com/test/undo/utils" at "utils.xqlib";
320+import schema namespace s="http://www.zorba-xquery.org/schema" at "subst.xsd";
321+
322+declare revalidation lax;
323+
324+variable $x:=
325+validate{
326+<items-a xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
327+ xmlns="http://www.zorba-xquery.org/schema">
328+ <number>111</number>
329+</items-a>};
330+
331+ddl:create($m:empc);
332+
333+ic_ddl:activate(xs:QName("m:ic_simple"));
334+
335+try
336+{
337+(
338+ rename node $x as QName("http://www.zorba-xquery.org/schema", "items-b"),
339+
340+ dml:insert-nodes($m:empc, <emp><salary>600</salary></emp>)
341+);
342+}
343+catch *
344+{
345+}
346+
347+u:dump-types($x)
348
349=== added file 'test/rbkt/Queries/zorba/updates/undo8.xq'
350--- test/rbkt/Queries/zorba/updates/undo8.xq 1970-01-01 00:00:00 +0000
351+++ test/rbkt/Queries/zorba/updates/undo8.xq 2011-10-12 10:04:34 +0000
352@@ -0,0 +1,54 @@
353+import module namespace m = 'xqueryzorba.org/test/xqddf/ic' at '../xqddf/ic.xqlib';
354+import module namespace ddl = "http://www.zorba-xquery.com/modules/store/static/collections/ddl";
355+import module namespace dml = "http://www.zorba-xquery.com/modules/store/static/collections/dml";
356+import module namespace ic_ddl = "http://www.zorba-xquery.com/modules/store/static/integrity_constraints/ddl";
357+import module namespace schema = "http://www.zorba-xquery.com/modules/schema";
358+import module namespace u = "http://www.zorba-xquery.com/test/undo/utils" at "utils.xqlib";
359+import schema namespace s="http://www.zorba-xquery.org/schema" at "shiporder.xsd";
360+
361+declare revalidation lax;
362+declare construction preserve;
363+
364+variable $x:=
365+<shiporders xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
366+ xmlns="http://www.zorba-xquery.org/schema">
367+<shiporder orderid="889923">
368+ <orderperson>John Smith</orderperson>
369+ <shipto>
370+ <name>Ola Nordmann</name>
371+ <address>Langgt 23</address>
372+ <city>4000 Stavanger</city>
373+ <country>Norway</country>
374+ </shipto>
375+ <item>
376+ <title>Empire Burlesque</title>
377+ <note>Special Edition</note>
378+ <quantity>1</quantity>
379+ <price>10.90</price>
380+ </item>
381+ <item>
382+ <title>Hide your heart</title>
383+ <quantity>1</quantity>
384+ <price>9.90</price>
385+ </item>
386+</shiporder>
387+</shiporders>;
388+
389+
390+ddl:create($m:empc);
391+
392+ic_ddl:activate(xs:QName("m:ic_simple"));
393+
394+try
395+{
396+(
397+ insert node ($x//*:item)[1]/*:note after ($x//*:item)[last()]/*:title,
398+
399+ dml:insert-nodes($m:empc, <emp><salary>600</salary></emp>)
400+);
401+}
402+catch *
403+{
404+}
405+
406+u:dump-types($x)
407\ No newline at end of file
408
409=== added file 'test/rbkt/Queries/zorba/updates/undo9.xq'
410--- test/rbkt/Queries/zorba/updates/undo9.xq 1970-01-01 00:00:00 +0000
411+++ test/rbkt/Queries/zorba/updates/undo9.xq 2011-10-12 10:04:34 +0000
412@@ -0,0 +1,54 @@
413+import module namespace m = 'xqueryzorba.org/test/xqddf/ic' at '../xqddf/ic.xqlib';
414+import module namespace ddl = "http://www.zorba-xquery.com/modules/store/static/collections/ddl";
415+import module namespace dml = "http://www.zorba-xquery.com/modules/store/static/collections/dml";
416+import module namespace ic_ddl = "http://www.zorba-xquery.com/modules/store/static/integrity_constraints/ddl";
417+import module namespace schema = "http://www.zorba-xquery.com/modules/schema";
418+import module namespace u = "http://www.zorba-xquery.com/test/undo/utils" at "utils.xqlib";
419+import schema namespace s="http://www.zorba-xquery.org/schema" at "shiporder.xsd";
420+
421+declare revalidation lax;
422+declare construction strip;
423+
424+variable $x:=
425+<shiporders xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
426+ xmlns="http://www.zorba-xquery.org/schema">
427+<shiporder orderid="889923">
428+ <orderperson>John Smith</orderperson>
429+ <shipto>
430+ <name>Ola Nordmann</name>
431+ <address>Langgt 23</address>
432+ <city>4000 Stavanger</city>
433+ <country>Norway</country>
434+ </shipto>
435+ <item>
436+ <title>Empire Burlesque</title>
437+ <note>Special Edition</note>
438+ <quantity>1</quantity>
439+ <price>10.90</price>
440+ </item>
441+ <item>
442+ <title>Hide your heart</title>
443+ <quantity>1</quantity>
444+ <price>9.90</price>
445+ </item>
446+</shiporder>
447+</shiporders>;
448+
449+
450+ddl:create($m:empc);
451+
452+ic_ddl:activate(xs:QName("m:ic_simple"));
453+
454+try
455+{
456+(
457+ insert node ($x//*:item)[1]/*:note after ($x//*:item)[last()]/*:title,
458+
459+ dml:insert-nodes($m:empc, <emp><salary>600</salary></emp>)
460+);
461+}
462+catch *
463+{
464+}
465+
466+u:dump-types($x)
467\ No newline at end of file
468
469=== added file 'test/rbkt/Queries/zorba/updates/utils.xqlib'
470--- test/rbkt/Queries/zorba/updates/utils.xqlib 1970-01-01 00:00:00 +0000
471+++ test/rbkt/Queries/zorba/updates/utils.xqlib 2011-10-12 10:04:34 +0000
472@@ -0,0 +1,30 @@
473+module namespace u = "http://www.zorba-xquery.com/test/undo/utils";
474+import module namespace schema = "http://www.zorba-xquery.com/modules/schema";
475+
476+declare function u:dump-types($nodes as node()*) as element()*
477+{
478+for $node in $nodes
479+return
480+ if ($node instance of text()) then ()
481+ else
482+ (
483+ element
484+ {
485+ if ($node instance of element()) then concat("ELEM-",string(node-name($node)))
486+ else if ($node instance of attribute()) then concat("ATTR-",string(node-name($node)))
487+ else if ($node instance of text()) then 'TEXT'
488+ else if ($node instance of document-node()) then 'DOCU'
489+ else if ($node instance of comment()) then 'COMM'
490+ else if ($node instance of processing-instruction()) then 'PROC'
491+ else 'unknown'
492+ }
493+ {
494+ attribute type {schema:schema-type($node)},
495+ for $attr in $node/@*
496+ return u:dump-types($attr),
497+ for $elem in $node/node()
498+ return u:dump-types($elem)
499+ }
500+ )
501+};
502+

Subscribers

People subscribed via source and target branches