Merge lp:~zorba-coders/zorba/treeidapi into lp:zorba

Proposed by Ghislain Fourny
Status: Merged
Merged at revision: 10741
Proposed branch: lp:~zorba-coders/zorba/treeidapi
Merge into: lp:zorba
Diff against target: 864 lines (+309/-53)
16 files modified
src/store/naive/CMakeLists.txt (+1/-0)
src/store/naive/atomic_items.cpp (+29/-20)
src/store/naive/atomic_items.h (+3/-2)
src/store/naive/loader_dtd.cpp (+2/-2)
src/store/naive/loader_fast.cpp (+1/-1)
src/store/naive/node_items.cpp (+7/-7)
src/store/naive/node_items.h (+11/-9)
src/store/naive/simple_collection.cpp (+12/-3)
src/store/naive/simple_collection.h (+3/-2)
src/store/naive/simple_item_factory.cpp (+2/-2)
src/store/naive/simple_item_factory.h (+1/-1)
src/store/naive/simple_store.cpp (+25/-2)
src/store/naive/simple_store.h (+18/-2)
src/store/naive/store_defs.h (+3/-0)
src/store/naive/tree_id.cpp (+81/-0)
src/store/naive/tree_id.h (+110/-0)
To merge this branch: bzr merge lp:~zorba-coders/zorba/treeidapi
Reviewer Review Type Date Requested Status
Matthias Brantner Needs Information
Till Westmann Pending
Markos Zaharioudakis Pending
Review via email: mp+93591@code.launchpad.net

Commit message

Introducing tree ID API.

Description of the change

Introducing tree ID API.

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 treeidapi-2012-02-17T15-44-01.686Z 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: 3 Pending.

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

It seems to me that the change you are proposing is adding a lot of overhead. Especially for the simple store, a ulong with simple arithmetic operations has been replaced with a class containing several virtual functions.

I propose the following alternative solution which we should consider:

- make the SimpleStore and XmlNode template classes
- introduce typedefs to keep the textual changes minimal
- the template parameters are the TreeId that should be used and a traits class providing the required operations for the TreeId
- in the simplestore,
  - the type of the TreeId would be ulong
  - the traits class would implement the basic operations very efficiently (e.g. + operator or < with ulongs)
- in some other store,
  - the type of the TreeId could be a uuid
  - the traits class would implement the operations on top of uuids

This way, the simplestore's code that is actually executed (i.e. there is no runtime overhead). Also, once this extension mechanism is in place, other dynamic extensions (e.g. factories) could be replaced also in order to avoid even more runtime overhead.

review: Needs Information

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'src/store/naive/CMakeLists.txt'
2--- src/store/naive/CMakeLists.txt 2011-06-22 17:30:15 +0000
3+++ src/store/naive/CMakeLists.txt 2012-02-17 15:26:34 +0000
4@@ -47,6 +47,7 @@
5 inmemorystore.cpp
6 inmemorystorec.cpp
7 dataguide.cpp
8+ tree_id.cpp
9 )
10
11 IF (NOT ZORBA_NO_FULL_TEXT)
12
13=== modified file 'src/store/naive/atomic_items.cpp'
14--- src/store/naive/atomic_items.cpp 2012-02-15 10:25:02 +0000
15+++ src/store/naive/atomic_items.cpp 2012-02-17 15:26:34 +0000
16@@ -40,6 +40,7 @@
17 #include "node_items.h"
18 #include "atomic_items.h"
19 #include "ordpath.h"
20+#include "tree_id.h"
21
22 #include "util/ascii_util.h"
23 #include "util/string_util.h"
24@@ -1043,12 +1044,12 @@
25 StructuralAnyUriItem::StructuralAnyUriItem(
26 zstring& encoded,
27 ulong collectionId,
28- ulong treeId,
29+ const TreeId_t& treeId,
30 store::StoreConsts::NodeKind nodeKind,
31 const OrdPath& ordPath)
32 :
33 theCollectionId(collectionId),
34- theTreeId(treeId),
35+ theTreeId(treeId->copy()),
36 theNodeKind(nodeKind),
37 theOrdPath(ordPath)
38 {
39@@ -1091,8 +1092,10 @@
40 //
41 // Decode tree id
42 //
43- theTreeId = strtoul(start, &next, 10);
44-
45+ ulong ulid = strtoul(start, &next, 10);
46+ ostringstream oss;
47+ oss << std::dec << ulid;
48+ theTreeId = GET_DEFAULT_TREE_ID_GENERATOR().fromString(oss.str());
49 if (errno != 0 || start == next)
50 throw ZORBA_EXCEPTION(zerr::ZAPI0028_INVALID_NODE_URI, ERROR_PARAMS(theValue));
51
52@@ -1144,7 +1147,7 @@
53
54 return
55 (other->theCollectionId == theCollectionId &&
56- other->theTreeId == theTreeId &&
57+ GET_DEFAULT_TREE_ID_GENERATOR().equals(other->theTreeId, theTreeId) &&
58 theOrdPath.getRelativePosition(other->theOrdPath) == OrdPath::ANCESTOR);
59 }
60 }
61@@ -1169,7 +1172,7 @@
62
63 return
64 (other->theCollectionId == theCollectionId &&
65- other->theTreeId == theTreeId &&
66+ GET_DEFAULT_TREE_ID_GENERATOR().equals(other->theTreeId, theTreeId) &&
67 other->theNodeKind != store::StoreConsts::attributeNode &&
68 theNodeKind != store::StoreConsts::attributeNode &&
69 theOrdPath.getRelativePosition2(other->theOrdPath) == OrdPath::FOLLOWING_SIBLING);
70@@ -1196,7 +1199,7 @@
71
72 return
73 (other->theCollectionId == theCollectionId &&
74- other->theTreeId == theTreeId &&
75+ GET_DEFAULT_TREE_ID_GENERATOR().equals(other->theTreeId, theTreeId) &&
76 theOrdPath.getRelativePosition(other->theOrdPath) == OrdPath::FOLLOWING);
77 }
78 }
79@@ -1220,7 +1223,7 @@
80 StructuralAnyUriItem* other = static_cast<StructuralAnyUriItem*>(aOther.getp());
81 return
82 (other->theCollectionId == theCollectionId &&
83- other->theTreeId == theTreeId &&
84+ GET_DEFAULT_TREE_ID_GENERATOR().equals(other->theTreeId, theTreeId) &&
85 other->theNodeKind != store::StoreConsts::attributeNode &&
86 theOrdPath.getRelativePosition(other->theOrdPath) == OrdPath::DESCENDANT);
87 }
88@@ -1245,7 +1248,7 @@
89 StructuralAnyUriItem* other = static_cast<StructuralAnyUriItem*>(aOther.getp());
90 return
91 (other->theCollectionId == theCollectionId &&
92- other->theTreeId == theTreeId &&
93+ GET_DEFAULT_TREE_ID_GENERATOR().equals(other->theTreeId, theTreeId) &&
94 theOrdPath.getRelativePosition(other->theOrdPath) == OrdPath::DESCENDANT);
95 }
96 }
97@@ -1269,7 +1272,7 @@
98 StructuralAnyUriItem* other = static_cast<StructuralAnyUriItem*>(aOther.getp());
99 return
100 (other->theCollectionId == theCollectionId &&
101- other->theTreeId == theTreeId &&
102+ GET_DEFAULT_TREE_ID_GENERATOR().equals(other->theTreeId, theTreeId) &&
103 other->theNodeKind != store::StoreConsts::attributeNode &&
104 theNodeKind != store::StoreConsts::attributeNode &&
105 theOrdPath.getRelativePosition2(other->theOrdPath) == OrdPath::PRECEDING_SIBLING);
106@@ -1295,7 +1298,7 @@
107 StructuralAnyUriItem* other = static_cast<StructuralAnyUriItem*>(aOther.getp());
108 return
109 (other->theCollectionId == theCollectionId &&
110- other->theTreeId == theTreeId &&
111+ GET_DEFAULT_TREE_ID_GENERATOR().equals(other->theTreeId, theTreeId) &&
112 theOrdPath.getRelativePosition(other->theOrdPath) == OrdPath::PRECEDING);
113 }
114 }
115@@ -1319,7 +1322,7 @@
116 StructuralAnyUriItem* other = static_cast<StructuralAnyUriItem*>(aOther.getp());
117 return
118 (other->theCollectionId == theCollectionId &&
119- other->theTreeId == theTreeId &&
120+ GET_DEFAULT_TREE_ID_GENERATOR().equals(other->theTreeId, theTreeId) &&
121 other->theNodeKind != store::StoreConsts::attributeNode &&
122 theOrdPath.getRelativePosition2(other->theOrdPath) == OrdPath::CHILD);
123 }
124@@ -1344,7 +1347,7 @@
125 StructuralAnyUriItem* other = static_cast<StructuralAnyUriItem*>(aOther.getp());
126 return
127 (other->theCollectionId == theCollectionId &&
128- other->theTreeId == theTreeId &&
129+ GET_DEFAULT_TREE_ID_GENERATOR().equals(other->theTreeId, theTreeId) &&
130 other->theNodeKind == store::StoreConsts::attributeNode &&
131 theOrdPath.getRelativePosition2(other->theOrdPath) == OrdPath::CHILD);
132 }
133@@ -1369,7 +1372,7 @@
134 StructuralAnyUriItem* other = static_cast<StructuralAnyUriItem*>(aOther.getp());
135 return
136 (other->theCollectionId == theCollectionId &&
137- other->theTreeId == theTreeId &&
138+ GET_DEFAULT_TREE_ID_GENERATOR().equals(other->theTreeId, theTreeId) &&
139 theOrdPath.getRelativePosition2(other->theOrdPath) == OrdPath::PARENT);
140 }
141 }
142@@ -1391,8 +1394,11 @@
143 StructuralAnyUriItem* other = static_cast<StructuralAnyUriItem*>(aOther.getp());
144 return
145 (theCollectionId > other->theCollectionId ||
146- (theCollectionId == other->theCollectionId && theTreeId > other->theTreeId) ||
147- (theCollectionId == other->theCollectionId && other->theTreeId == theTreeId && theOrdPath > other->theOrdPath));
148+ (theCollectionId == other->theCollectionId &&
149+ GET_DEFAULT_TREE_ID_GENERATOR().isBefore(other->theTreeId, theTreeId)) ||
150+ (theCollectionId == other->theCollectionId &&
151+ GET_DEFAULT_TREE_ID_GENERATOR().equals(other->theTreeId, theTreeId) &&
152+ theOrdPath > other->theOrdPath));
153 }
154 }
155
156@@ -1413,8 +1419,11 @@
157 StructuralAnyUriItem* other = static_cast<StructuralAnyUriItem*>(aOther.getp());
158 return
159 (theCollectionId < other->theCollectionId ||
160- (theCollectionId == other->theCollectionId && theTreeId < other->theTreeId) ||
161- (theCollectionId == other->theCollectionId && other->theTreeId == theTreeId && theOrdPath < other->theOrdPath));
162+ (theCollectionId == other->theCollectionId &&
163+ GET_DEFAULT_TREE_ID_GENERATOR().isBefore(theTreeId, other->theTreeId)) ||
164+ (theCollectionId == other->theCollectionId &&
165+ GET_DEFAULT_TREE_ID_GENERATOR().equals(other->theTreeId, theTreeId) &&
166+ theOrdPath < other->theOrdPath));
167 }
168 }
169
170@@ -1479,7 +1488,7 @@
171 StructuralAnyUriItem* other = static_cast<StructuralAnyUriItem*>(aOther.getp());
172
173 if (other->theCollectionId == theCollectionId &&
174- other->theTreeId == theTreeId &&
175+ GET_DEFAULT_TREE_ID_GENERATOR().equals(other->theTreeId, theTreeId) &&
176 other->theNodeKind != store::StoreConsts::attributeNode &&
177 theNodeKind != store::StoreConsts::attributeNode)
178 {
179@@ -1512,7 +1521,7 @@
180 {
181 StructuralAnyUriItem* other = static_cast<StructuralAnyUriItem*>(aOther.getp());
182 return (theCollectionId == other->theCollectionId &&
183- theTreeId == other->theTreeId);
184+ GET_DEFAULT_TREE_ID_GENERATOR().equals(other->theTreeId, theTreeId));
185 }
186 }
187
188
189=== modified file 'src/store/naive/atomic_items.h'
190--- src/store/naive/atomic_items.h 2012-01-26 19:56:14 +0000
191+++ src/store/naive/atomic_items.h 2012-02-17 15:26:34 +0000
192@@ -31,6 +31,7 @@
193 #include "store/api/xs_type_codes.h"
194 #include "store/naive/store_defs.h"
195 #include "store/naive/shared_types.h"
196+#include "tree_id.h"
197
198 #ifndef ZORBA_NO_FULL_TEXT
199 #include "store/naive/naive_ft_token_iterator.h"
200@@ -615,7 +616,7 @@
201
202 protected:
203 ulong theCollectionId;
204- ulong theTreeId;
205+ TreeId_t theTreeId;
206 store::StoreConsts::NodeKind theNodeKind;
207 OrdPath theOrdPath;
208
209@@ -630,7 +631,7 @@
210 StructuralAnyUriItem(
211 zstring& value,
212 ulong collectionId,
213- ulong treeId,
214+ const TreeId_t& treeId,
215 store::StoreConsts::NodeKind nodeKind,
216 const OrdPath& ordPath);
217
218
219=== modified file 'src/store/naive/loader_dtd.cpp'
220--- src/store/naive/loader_dtd.cpp 2012-02-15 10:25:02 +0000
221+++ src/store/naive/loader_dtd.cpp 2012-02-17 15:26:34 +0000
222@@ -124,7 +124,7 @@
223 if (docUri.empty())
224 {
225 std::ostringstream uristream;
226- uristream << "zorba://internalDocumentURI-" << theTree->getId();
227+ uristream << "zorba://internalDocumentURI-" << theTree->getId()->toString();
228 theDocUri = uristream.str();
229 }
230 else
231@@ -566,7 +566,7 @@
232 if (docUri.empty())
233 {
234 std::ostringstream uristream;
235- uristream << "zorba://internalDocumentURI-" << theTree->getId();
236+ uristream << "zorba://internalDocumentURI-" << theTree->getId()->toString();
237
238 theDocUri = uristream.str();
239 }
240
241=== modified file 'src/store/naive/loader_fast.cpp'
242--- src/store/naive/loader_fast.cpp 2012-02-15 10:25:02 +0000
243+++ src/store/naive/loader_fast.cpp 2012-02-17 15:26:34 +0000
244@@ -260,7 +260,7 @@
245 if (docUri.empty())
246 {
247 std::ostringstream uristream;
248- uristream << "zorba://internalDocumentURI-" << theTree->getId();
249+ uristream << "zorba://internalDocumentURI-" << theTree->getId()->toString();
250
251 theDocUri = uristream.str();
252 }
253
254=== modified file 'src/store/naive/node_items.cpp'
255--- src/store/naive/node_items.cpp 2012-02-15 10:25:02 +0000
256+++ src/store/naive/node_items.cpp 2012-02-17 15:26:34 +0000
257@@ -81,7 +81,7 @@
258 }
259
260
261-XmlTree::XmlTree(XmlNode* root, ulong id)
262+XmlTree::XmlTree(XmlNode* root, TreeId_t id)
263 :
264 theRefCount(0),
265 theId(id),
266@@ -1548,7 +1548,7 @@
267 theDocUri(docUri)
268 {
269 NODE_TRACE1("{\nConstructing doc node " << this << " tree = "
270- << getTree()->getId() << ":" << getTree()
271+ << getTree()->getId()->toString() << ":" << getTree()
272 << " doc uri = " << docUri);
273 }
274
275@@ -1900,7 +1900,7 @@
276
277 NODE_TRACE1("Constructed element node " << this << " parent = "
278 << std::hex << (parent ? (ulong)parent : 0) << " pos = " << pos
279- << " tree = " << getTree()->getId() << ":" << getTree()
280+ << " tree = " << getTree()->getId()->toString() << ":" << getTree()
281 << " ordpath = " << theOrdPath.show()
282 << " name = " << theName->getStringValue()
283 << " type = " << getType()->getStringValue());
284@@ -3332,7 +3332,7 @@
285
286 NODE_TRACE1("Constructed attribute node " << this << " parent = "
287 << std::hex << (parent ? (ulong)parent : 0) << " pos = " << pos
288- << " tree = " << getTree()->getId() << ":" << getTree()
289+ << " tree = " << getTree()->getId()->toString() << ":" << getTree()
290 << " ordpath = " << theOrdPath.show()
291 << " name = " << theName->getStringValue()
292 << " value = " << getStringValue());
293@@ -3714,7 +3714,7 @@
294 #else
295 NODE_TRACE1("Constructed text node " << this << " parent = "
296 << std::hex << (parent ? (ulong)parent : 0) << " pos = " << pos
297- << " tree = " << getTree()->getId() << ":" << getTree()
298+ << " tree = " << getTree()->getId()->toString() << ":" << getTree()
299 << " content = " << getText());
300 #endif
301 }
302@@ -4396,7 +4396,7 @@
303
304 NODE_TRACE1("Constructed pi node " << this << " parent = "
305 << std::hex << (parent ? (ulong)parent : 0) << " pos = " << pos
306- << " tree = " << getTree()->getId() << ":" << getTree()
307+ << " tree = " << getTree()->getId()->toString() << ":" << getTree()
308 << " ordpath = " << theOrdPath.show() << " target = " << theTarget);
309 }
310
311@@ -4521,7 +4521,7 @@
312
313 NODE_TRACE1("Constructed comment node " << this << " parent = "
314 << std::hex << (parent ? (ulong)parent : 0) << " pos = " << pos
315- << " tree = " << getTree()->getId() << ":" << getTree()
316+ << " tree = " << getTree()->getId()->toString() << ":" << getTree()
317 << " ordpath = " << theOrdPath.show() << " content = "
318 << theContent);
319 }
320
321=== modified file 'src/store/naive/node_items.h'
322--- src/store/naive/node_items.h 2012-01-26 19:56:14 +0000
323+++ src/store/naive/node_items.h 2012-02-17 15:26:34 +0000
324@@ -29,6 +29,8 @@
325 #include "store/naive/item_vector.h"
326 #include "store/naive/ordpath.h"
327 #include "store/naive/nsbindings.h" // TODO remove by introducing explicit destructors
328+#include "tree_id.h"
329+#include "simple_store.h"
330
331 // Note: whether the EMBEDED_TYPE is defined or not is done in store_defs.h
332 #ifndef EMBEDED_TYPE
333@@ -177,7 +179,7 @@
334 mutable long theRefCount;
335 SYNC_CODE(mutable RCLock theRCLock;)
336
337- ulong theId;
338+ TreeId_t theId;
339 ulong thePos;
340
341 SimpleCollection * theCollection;
342@@ -200,7 +202,7 @@
343 #endif
344
345 protected:
346- XmlTree(XmlNode* root, ulong id);
347+ XmlTree(XmlNode* root, TreeId_t id);
348
349 public:
350 XmlTree();
351@@ -215,9 +217,9 @@
352
353 SYNC_CODE(RCLock* getRCLock() const { return &theRCLock; })
354
355- void setId(ulong id) { theId = id; }
356+ void setId(TreeId_t id) { theId = id; }
357
358- ulong getId() const { return theId; }
359+ const TreeId_t& getId() const { return theId; }
360
361 ulong getCollectionId() const;
362
363@@ -512,7 +514,7 @@
364
365 XmlTree* getTree() const { return (XmlTree*)theUnion.treeRCPtr; }
366
367- ulong getTreeId() const { return getTree()->getId(); }
368+ const TreeId_t& getTreeId() const { return getTree()->getId(); }
369
370 XmlNode* getRoot() const { return getTree()->getRoot(); }
371
372@@ -1618,13 +1620,13 @@
373 {
374 if (col1 == 0)
375 {
376- ulong tree1 = this->getTreeId();
377- ulong tree2 = other->getTreeId();
378+ const TreeId_t& tree1 = this->getTreeId();
379+ const TreeId_t& tree2 = other->getTreeId();
380
381- if (tree1 < tree2)
382+ if (GET_DEFAULT_TREE_ID_GENERATOR().isBefore(tree1, tree2))
383 return -1;
384
385- if (tree1 == tree2)
386+ if (GET_DEFAULT_TREE_ID_GENERATOR().equals(tree1, tree2))
387 return compareInSameTree(this, other);
388 }
389 else
390
391=== modified file 'src/store/naive/simple_collection.cpp'
392--- src/store/naive/simple_collection.cpp 2012-02-15 10:25:02 +0000
393+++ src/store/naive/simple_collection.cpp 2012-02-17 15:26:34 +0000
394@@ -41,11 +41,11 @@
395 :
396 theName(aName),
397 theIsDynamic(aDynamicCollection),
398- theTreeCounter(1),
399 theAnnotations(aAnnotations),
400 theNodeType(aNodeType)
401 {
402 theId = GET_STORE().createCollectionId();
403+ theTreeIdGenerator = GET_STORE().getTreeIdGeneratorFactory().createTreeGenerator();
404 }
405
406 /*******************************************************************************
407@@ -54,9 +54,9 @@
408 SimpleCollection::SimpleCollection()
409 :
410 theIsDynamic(false),
411- theTreeCounter(1),
412 theNodeType(NULL)
413 {
414+ theTreeIdGenerator = GET_STORE().getTreeIdGeneratorFactory().createTreeGenerator();
415 }
416
417 /*******************************************************************************
418@@ -379,7 +379,9 @@
419 std::size_t lPosition = to_xs_unsignedInt(position);
420
421 if (lPosition < theXmlTrees.size() &&
422- BASE_NODE(theXmlTrees[lPosition])->getTreeId() == n->getTreeId())
423+ GET_DEFAULT_TREE_ID_GENERATOR().equals(
424+ BASE_NODE(theXmlTrees[lPosition])->getTreeId(),
425+ n->getTreeId()))
426 {
427 return true;
428 }
429@@ -491,6 +493,13 @@
430 activeICNames->close();
431 }
432
433+/*******************************************************************************
434+
435+********************************************************************************/
436+TreeId_t SimpleCollection::createTreeId()
437+{
438+ return theTreeIdGenerator->create();
439+}
440
441 /*******************************************************************************
442
443
444=== modified file 'src/store/naive/simple_collection.h'
445--- src/store/naive/simple_collection.h 2012-01-15 09:18:22 +0000
446+++ src/store/naive/simple_collection.h 2012-02-17 15:26:34 +0000
447@@ -20,6 +20,7 @@
448
449 #include "store/api/iterator.h"
450 #include "store/api/collection.h"
451+#include "tree_id.h"
452
453 #include "zorbautils/latch.h"
454 #include "zorbautils/checked_vector.h"
455@@ -68,7 +69,7 @@
456 checked_vector<store::Item_t> theXmlTrees;
457 bool theIsDynamic;
458
459- ulong theTreeCounter;
460+ TreeIdGenerator* theTreeIdGenerator;
461
462 const std::vector<store::Annotation_t> theAnnotations;
463 store::Item_t theNodeType;
464@@ -100,7 +101,7 @@
465 void getAnnotations(std::vector<store::Annotation_t>& annotations) const;
466
467 // virtual to allow extension by subclasses
468- virtual ulong createTreeId() { return theTreeCounter++; }
469+ virtual TreeId_t createTreeId();
470
471 store::Iterator_t getIterator();
472
473
474=== modified file 'src/store/naive/simple_item_factory.cpp'
475--- src/store/naive/simple_item_factory.cpp 2012-02-15 10:25:02 +0000
476+++ src/store/naive/simple_item_factory.cpp 2012-02-17 15:26:34 +0000
477@@ -120,7 +120,7 @@
478 bool BasicItemFactory::createStructuralAnyURI(
479 store::Item_t& result,
480 ulong collectionId,
481- ulong treeId,
482+ const TreeId_t& treeId,
483 store::StoreConsts::NodeKind nodeKind,
484 const OrdPath& ordPath)
485 {
486@@ -128,7 +128,7 @@
487 std::ostringstream stream;
488 stream << "zorba:"
489 << collectionId << "."
490- << treeId << "."
491+ << treeId->toString() << "."
492 << static_cast<int>(nodeKind) << "."
493 << ordPath.serialize();
494 zstring uri = stream.str();
495
496=== modified file 'src/store/naive/simple_item_factory.h'
497--- src/store/naive/simple_item_factory.h 2011-12-21 14:40:33 +0000
498+++ src/store/naive/simple_item_factory.h 2012-02-17 15:26:34 +0000
499@@ -91,7 +91,7 @@
500 bool createStructuralAnyURI(
501 store::Item_t& result,
502 ulong collectionId,
503- ulong treeId,
504+ const TreeId_t& treeId,
505 store::StoreConsts::NodeKind nodeKind,
506 const OrdPath& ordPath);
507
508
509=== modified file 'src/store/naive/simple_store.cpp'
510--- src/store/naive/simple_store.cpp 2012-02-15 10:25:02 +0000
511+++ src/store/naive/simple_store.cpp 2012-02-17 15:26:34 +0000
512@@ -56,6 +56,7 @@
513 #include "name_iterator.h"
514 #include "document_name_iterator.h"
515 #include "pul_primitive_factory.h"
516+#include "tree_id.h"
517
518 #include "util/cxx_util.h"
519 #include "util/uuid/uuid.h"
520@@ -102,6 +103,7 @@
521 theIteratorFactory(NULL),
522 theNodeFactory(NULL),
523 thePULFactory(NULL),
524+ theTreeIdGeneratorFactory(NULL),
525 theDocuments(CollectionSet::DEFAULT_COLLECTION_MAP_SIZE, true),
526 theCollections(0),
527 theIndices(0, NULL, CollectionSet::DEFAULT_COLLECTION_MAP_SIZE, true),
528@@ -169,6 +171,8 @@
529 theNodeFactory = createNodeFactory();
530
531 thePULFactory = createPULPrimitiveFactory();
532+
533+ theTreeIdGeneratorFactory = createTreeIdGeneratorFactory();
534
535 theTraceLevel = store::Properties::instance()->storeTraceLevel();
536
537@@ -400,6 +404,25 @@
538 /*******************************************************************************
539
540 *******************************************************************************/
541+TreeIdGeneratorFactory*
542+SimpleStore::createTreeIdGeneratorFactory() const
543+{
544+ return new ZorbaTreeIdGeneratorFactory();
545+}
546+
547+
548+/*******************************************************************************
549+
550+*******************************************************************************/
551+void
552+SimpleStore::destroyTreeIdGeneratorFactory(TreeIdGeneratorFactory* g) const
553+{
554+ delete g;
555+}
556+
557+/*******************************************************************************
558+
559+*******************************************************************************/
560 CollectionSet* SimpleStore::createCollectionSet() const
561 {
562 return new CollectionSet();
563@@ -473,10 +496,10 @@
564 /*******************************************************************************
565 create a tree id for a new tree that does not belong to any collection.
566 ********************************************************************************/
567-ulong SimpleStore::createTreeId()
568+TreeId_t SimpleStore::createTreeId()
569 {
570 SYNC_CODE(AutoMutex lock(&theTreeCounterMutex);)
571- return theTreeCounter++;
572+ return getTreeIdGeneratorFactory().getDefaultTreeIdGenerator().create();
573 }
574
575
576
577=== modified file 'src/store/naive/simple_store.h'
578--- src/store/naive/simple_store.h 2012-01-10 10:52:15 +0000
579+++ src/store/naive/simple_store.h 2012-02-17 15:26:34 +0000
580@@ -19,6 +19,7 @@
581 #include "store/naive/shared_types.h"
582 #include "store/naive/store_defs.h"
583 #include "store/naive/hashmap_nodep.h"
584+#include "tree_id.h"
585
586 #if (defined (WIN32) || defined (WINCE))
587 #include "store/naive/node_items.h"
588@@ -48,6 +49,8 @@
589 class ValueIndexSpecification;
590 }
591
592+class TreeIdGeneratorFactory;
593+
594 namespace simplestore
595 {
596
597@@ -125,6 +128,11 @@
598 theNodeToReferencesMap:
599 -----------------------
600 A hashmap that maps nodes into their references
601+
602+ theTreeIdGeneratorFactory:
603+ --------------------------
604+ An factory of ID generators (each collection can have its own in
605+ addition to the default one).
606
607 ********************************************************************************/
608 class SimpleStore : public store::Store
609@@ -173,7 +181,8 @@
610 store::IteratorFactory * theIteratorFactory;
611 NodeFactory * theNodeFactory;
612 PULPrimitiveFactory * thePULFactory;
613-
614+ TreeIdGeneratorFactory * theTreeIdGeneratorFactory;
615+
616 DocumentSet theDocuments;
617 CollectionSet* theCollections;
618 IndexSet theIndices;
619@@ -203,6 +212,9 @@
620
621 PULPrimitiveFactory& getPULFactory() const { return *thePULFactory; }
622
623+ TreeIdGeneratorFactory& getTreeIdGeneratorFactory() const
624+ { return *theTreeIdGeneratorFactory; }
625+
626 StringPool& getNamespacePool() const { return *theNamespacePool; }
627
628 QNamePool& getQNamePool() const { return *theQNamePool; }
629@@ -217,7 +229,7 @@
630
631 ulong createCollectionId();
632
633- ulong createTreeId();
634+ TreeId_t createTreeId();
635
636 store::Collection_t createCollection(
637 const store::Item_t& aName,
638@@ -414,6 +426,10 @@
639 virtual PULPrimitiveFactory* createPULPrimitiveFactory() const;
640
641 virtual void destroyPULPrimitiveFactory(PULPrimitiveFactory*) const;
642+
643+ virtual TreeIdGeneratorFactory* createTreeIdGeneratorFactory() const;
644+
645+ virtual void destroyTreeIdGeneratorFactory(TreeIdGeneratorFactory*) const;
646
647 virtual CollectionSet* createCollectionSet() const;
648
649
650=== modified file 'src/store/naive/store_defs.h'
651--- src/store/naive/store_defs.h 2012-01-10 13:54:05 +0000
652+++ src/store/naive/store_defs.h 2012-02-17 15:26:34 +0000
653@@ -38,6 +38,9 @@
654
655 #define GET_PUL_FACTORY() \
656 (GET_STORE().getPULFactory())
657+
658+#define GET_DEFAULT_TREE_ID_GENERATOR() \
659+ (GET_STORE().getTreeIdGeneratorFactory().getDefaultTreeIdGenerator())
660
661
662 #define BASE_NODE(item) (reinterpret_cast<XmlNode*>((item).getp()))
663
664=== added file 'src/store/naive/tree_id.cpp'
665--- src/store/naive/tree_id.cpp 1970-01-01 00:00:00 +0000
666+++ src/store/naive/tree_id.cpp 2012-02-17 15:26:34 +0000
667@@ -0,0 +1,81 @@
668+/*
669+ * Copyright 2006-2008 The FLWOR Foundation.
670+ *
671+ * Licensed under the Apache License, Version 2.0 (the "License");
672+ * you may not use this file except in compliance with the License.
673+ * You may obtain a copy of the License at
674+ *
675+ * http://www.apache.org/licenses/LICENSE-2.0
676+ *
677+ * Unless required by applicable law or agreed to in writing, software
678+ * distributed under the License is distributed on an "AS IS" BASIS,
679+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
680+ * See the License for the specific language governing permissions and
681+ * limitations under the License.
682+ */
683+
684+#include "tree_id.h"
685+#include <iostream>
686+#include <sstream>
687+
688+namespace zorba {
689+
690+ZorbaTreeId::ZorbaTreeId(ulong id)
691+: theId(id)
692+{};
693+
694+zstring ZorbaTreeId::toString()
695+{
696+ std::ostringstream oss;
697+ oss << std::dec << theId;
698+ return oss.str();
699+}
700+
701+TreeId* ZorbaTreeId::copy()
702+{
703+ return new ZorbaTreeId(theId);
704+}
705+
706+TreeId_t ZorbaTreeIdGenerator::create() {
707+ TreeId_t lStoreRes(new ZorbaTreeId(theNextId));
708+ ++theNextId;
709+ return lStoreRes;
710+}
711+
712+bool ZorbaTreeIdGenerator::equals(const TreeId_t& anId,
713+ const TreeId_t& anotherId) const
714+{
715+ const ZorbaTreeId* lId1 = dynamic_cast<ZorbaTreeId*>(anId.get());
716+ const ZorbaTreeId* lId2 = dynamic_cast<ZorbaTreeId*>(anotherId.get());
717+ return lId1->theId == lId2->theId;
718+}
719+
720+bool ZorbaTreeIdGenerator::isBefore(const TreeId_t& anId,
721+ const TreeId_t& anotherId) const
722+{
723+ const ZorbaTreeId* lId1 = dynamic_cast<ZorbaTreeId*>(anId.get());
724+ const ZorbaTreeId* lId2 = dynamic_cast<ZorbaTreeId*>(anotherId.get());
725+ return lId1->theId < lId2->theId;
726+}
727+
728+TreeId_t ZorbaTreeIdGenerator::fromString(const zstring& s) const
729+{
730+ std::istringstream iss(s.str());
731+ ulong lId;
732+ iss >> std::dec >> lId;
733+ TreeId_t lRes(new ZorbaTreeId(lId));
734+ return lRes;
735+}
736+
737+TreeIdGenerator* ZorbaTreeIdGeneratorFactory::createTreeGenerator()
738+{
739+ return new ZorbaTreeIdGenerator();
740+}
741+
742+TreeIdGenerator& ZorbaTreeIdGeneratorFactory::getDefaultTreeIdGenerator()
743+{
744+ static ZorbaTreeIdGenerator lSingleton;
745+ return lSingleton;
746+}
747+
748+}
749\ No newline at end of file
750
751=== added file 'src/store/naive/tree_id.h'
752--- src/store/naive/tree_id.h 1970-01-01 00:00:00 +0000
753+++ src/store/naive/tree_id.h 2012-02-17 15:26:34 +0000
754@@ -0,0 +1,110 @@
755+/*
756+ * Copyright 2006-2008 The FLWOR Foundation.
757+ *
758+ * Licensed under the Apache License, Version 2.0 (the "License");
759+ * you may not use this file except in compliance with the License.
760+ * You may obtain a copy of the License at
761+ *
762+ * http://www.apache.org/licenses/LICENSE-2.0
763+ *
764+ * Unless required by applicable law or agreed to in writing, software
765+ * distributed under the License is distributed on an "AS IS" BASIS,
766+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
767+ * See the License for the specific language governing permissions and
768+ * limitations under the License.
769+ */
770+#ifndef ZORBA_TREE_ID_H
771+#define ZORBA_TREE_ID_H
772+
773+#include "store/naive/shared_types.h"
774+#include "zorbautils/hashmap_itemh.h"
775+
776+namespace zorba {
777+
778+/*
779+This class is an abstract class for tree IDs.
780+You can convert an ID to a string, or copy it to another instance.
781+*/
782+
783+class TreeId {
784+public:
785+ virtual ~TreeId() {}
786+public:
787+ virtual zstring toString() = 0;
788+ // Caller gets pointer ownership.
789+ virtual TreeId* copy() = 0;
790+};
791+
792+/*
793+The type alias used everywhere in the program.
794+Only assign IDs with = if lvalue is taking over ownership.
795+Otherwise, copy.
796+*/
797+typedef std::auto_ptr<TreeId> TreeId_t;
798+
799+/*
800+This class is an abstract class for tree ID generation. It provides
801+a creation method, two comparison methods (= and <) as well as a way
802+to parse a string back to an ID.
803+*/
804+class TreeIdGenerator {
805+public:
806+ virtual ~TreeIdGenerator() {}
807+
808+ virtual TreeId_t create() = 0;
809+ virtual bool equals(const TreeId_t& id1, const TreeId_t& id2) const = 0;
810+ virtual bool isBefore(const TreeId_t& id1, const TreeId_t& id2) const = 0;
811+ virtual TreeId_t fromString(const zstring&) const = 0;
812+};
813+
814+/*
815+This class allows generation of independent tree ID generators (each of
816+them might have its own counter).
817+*/
818+class TreeIdGeneratorFactory {
819+public:
820+ virtual ~TreeIdGeneratorFactory() {}
821+
822+ virtual TreeIdGenerator* createTreeGenerator() = 0;
823+ virtual TreeIdGenerator& getDefaultTreeIdGenerator() = 0;
824+};
825+
826+/*
827+Zorba's implementation of tree IDs, using an unsigned long.
828+*/
829+class ZorbaTreeId : public TreeId {
830+friend class ZorbaTreeIdGenerator;
831+private:
832+ ulong theId;
833+ ZorbaTreeId(ulong idKey);
834+public:
835+ zstring toString();
836+ virtual TreeId* copy();
837+};
838+
839+/*
840+Zorba's implementation of the tree ID generator.
841+*/
842+class ZorbaTreeIdGenerator : public TreeIdGenerator {
843+private:
844+ ulong theNextId;
845+public:
846+ ZorbaTreeIdGenerator() : theNextId(1) {}
847+ virtual TreeId_t create();
848+ virtual bool equals(const TreeId_t& id1, const TreeId_t& id2) const;
849+ virtual bool isBefore(const TreeId_t& id1, const TreeId_t& id2) const;
850+ virtual TreeId_t fromString(const zstring&) const;
851+};
852+
853+/*
854+Zorba's implementation of the tree ID generator factory.
855+*/
856+class ZorbaTreeIdGeneratorFactory : public TreeIdGeneratorFactory {
857+public:
858+ virtual TreeIdGenerator* createTreeGenerator();
859+ virtual TreeIdGenerator& getDefaultTreeIdGenerator();
860+};
861+
862+}
863+
864+#endif /* ZORBA_TREE_ID_H */

Subscribers

People subscribed via source and target branches