Merge lp:~zorba-coders/zorba/simplestore-api into lp:zorba

Proposed by Ghislain Fourny
Status: Merged
Approved by: Markos Zaharioudakis
Approved revision: 10708
Merged at revision: 10735
Proposed branch: lp:~zorba-coders/zorba/simplestore-api
Merge into: lp:zorba
Diff against target: 4494 lines (+2001/-1775)
18 files modified
src/store/naive/CMakeLists.txt (+1/-0)
src/store/naive/atomic_items.cpp (+3/-3)
src/store/naive/inmemorystore.cpp (+2/-2)
src/store/naive/inmemorystorec.cpp (+1/-1)
src/store/naive/loader.h (+50/-58)
src/store/naive/loader_dtd.cpp (+8/-8)
src/store/naive/loader_fast.cpp (+27/-2)
src/store/naive/node_factory.h (+7/-7)
src/store/naive/node_items.cpp (+16/-16)
src/store/naive/pul_primitives.cpp (+25/-21)
src/store/naive/simple_index_value.h (+3/-3)
src/store/naive/simple_item_factory.cpp (+2/-4)
src/store/naive/simple_pul.cpp (+1/-1)
src/store/naive/simple_store.cpp (+63/-1281)
src/store/naive/simple_store.h (+47/-364)
src/store/naive/store.cpp (+1322/-0)
src/store/naive/store.h (+419/-0)
src/store/naive/store_manager_impl.h (+4/-4)
To merge this branch: bzr merge lp:~zorba-coders/zorba/simplestore-api
Reviewer Review Type Date Requested Status
Markos Zaharioudakis Approve
Matthias Brantner Approve
Review via email: mp+96360@code.launchpad.net

Commit message

Introduced SimpleStore API (separating factory, collection and treeID creation from the rest of the store).

Description of the change

Introduced SimpleStore API (separating factory, collection and treeID creation from the rest of the store).

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 simplestore-api-2012-03-07T14-29-07.412Z 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, Needs Fixing < 1, Pending < 1. Got: 1 Pending.

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

- The destroy* functions could also be pure virtual in store.h. Why aren't they?
- With the introduction of a new abstract Store class, the need for types like DocumentSet, CollectionSet, IndexSet somehow disappears because functions such as getDocument only delegate to the corresponding Set. Instead, the implementation could be directly done in the deriving store class. But this is just something to consider and not a must fix.
- Along this argument, the RefNodeMap should be moved into the SimpleStore class because it's unlikely that another store shares the same data structure.
- The counters (i.e. theUriCounter, theCollectionCounter, and theTreeCounter) could go into the SimpleStore subclass.

review: Needs Information
Revision history for this message
Ghislain Fourny (gislenius) wrote :

Hi Matthias, thanks for your comments. The pushed revisions address comments 1, 3, and 4. Comment 2 was considered but not implemented, as discussed with you over the phone.

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 simplestore-api-2012-03-12T18-02-52.82Z 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, Needs Fixing < 1, Pending < 1. Got: 1 Needs Information, 2 Pending.

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

Attempt to merge into lp:zorba failed due to conflicts:

text conflict in src/store/naive/loader.h
text conflict in src/store/naive/simple_store.cpp
text conflict in src/store/naive/simple_store.h

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

Attempt to merge into lp:zorba failed due to conflicts:

text conflict in src/store/naive/loader.h
text conflict in src/store/naive/simple_store.cpp
text conflict in src/store/naive/simple_store.h

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

Attempt to merge into lp:zorba failed due to conflicts:

text conflict in src/store/naive/loader.h
text conflict in src/store/naive/simple_store.cpp
text conflict in src/store/naive/simple_store.h

10708. By Markos Zaharioudakis

merge from trunk

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 simplestore-api-2012-03-27T01-51-30.554Z 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 'src/store/naive/CMakeLists.txt'
2--- src/store/naive/CMakeLists.txt 2012-03-26 01:31:32 +0000
3+++ src/store/naive/CMakeLists.txt 2012-03-27 01:25:22 +0000
4@@ -48,6 +48,7 @@
5 inmemorystorec.cpp
6 dataguide.cpp
7 collection.cpp
8+ store.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-03-26 01:31:32 +0000
15+++ src/store/naive/atomic_items.cpp 2012-03-27 01:25:22 +0000
16@@ -46,7 +46,7 @@
17 #include "util/utf8_util.h"
18
19 #define CREATE_XS_TYPE(aType) \
20- GET_STORE().getItemFactory()->createQName(SimpleStore::XS_URI, "xs", aType);
21+ GET_STORE().getItemFactory()->createQName(Store::XS_URI, "xs", aType);
22
23 #define CREATE_BOOLITEM(item, aValue) \
24 GET_STORE().getItemFactory()->createBoolean(item, aValue)
25@@ -735,7 +735,7 @@
26 if (ZSTREQ(getLocalName(), "id"))
27 {
28 if (ZSTREQ(getPrefix(), "xml") ||
29- ztd::equals(theNamespace, SimpleStore::XML_URI, SimpleStore::XML_URI_LEN))
30+ ztd::equals(theNamespace, Store::XML_URI, Store::XML_URI_LEN))
31 return true;
32 }
33
34@@ -748,7 +748,7 @@
35 if (ZSTREQ(getLocalName(), "base"))
36 {
37 if (ZSTREQ(getPrefix(), "xml") ||
38- ztd::equals(getNamespace(), SimpleStore::XML_URI, SimpleStore::XML_URI_LEN))
39+ ztd::equals(getNamespace(), Store::XML_URI, Store::XML_URI_LEN))
40 return true;
41 }
42
43
44=== modified file 'src/store/naive/inmemorystore.cpp'
45--- src/store/naive/inmemorystore.cpp 2012-03-26 01:31:32 +0000
46+++ src/store/naive/inmemorystore.cpp 2012-03-27 01:25:22 +0000
47@@ -34,14 +34,14 @@
48
49 void StoreManager::shutdownStore(void* store)
50 {
51- static_cast<simplestore::SimpleStore*>(store)->shutdown();
52+ static_cast<simplestore::Store*>(store)->shutdown();
53 }
54
55
56 namespace simplestore
57 {
58
59-SimpleStore* StoreManagerImpl::theStore = NULL;
60+Store* StoreManagerImpl::theStore = NULL;
61
62 }
63
64
65=== modified file 'src/store/naive/inmemorystorec.cpp'
66--- src/store/naive/inmemorystorec.cpp 2012-03-26 01:31:32 +0000
67+++ src/store/naive/inmemorystorec.cpp 2012-03-27 01:25:22 +0000
68@@ -29,6 +29,6 @@
69 void
70 shutdown_store(void* aStore)
71 {
72- static_cast<zorba::simplestore::SimpleStore*>(aStore)->shutdown();
73+ static_cast<zorba::simplestore::Store*>(aStore)->shutdown();
74 }
75 /* vim:set et sw=2 ts=2: */
76
77=== modified file 'src/store/naive/loader.h'
78--- src/store/naive/loader.h 2012-03-26 01:31:32 +0000
79+++ src/store/naive/loader.h 2012-03-27 01:25:22 +0000
80@@ -99,26 +99,17 @@
81
82 public:
83 XmlLoader(
84- BasicItemFactory* factory,
85- XQueryDiagnostics* xqueryDiagnostics,
86- const store::LoadProperties& loadProperties,
87- bool dataguide)
88- :
89- theLoadProperties(loadProperties),
90- ctxt(NULL),
91- theFactory(factory),
92- theXQueryDiagnostics(xqueryDiagnostics),
93- theTraceLevel(0),
94- theBuildDataGuide(dataguide)
95- {
96- }
97+ store::ItemFactory* factory,
98+ XQueryDiagnostics* xqueryDiagnostics,
99+ const store::LoadProperties& loadProperties,
100+ bool dataguide);
101
102- virtual ~XmlLoader() {}
103+ virtual ~XmlLoader();
104
105 virtual store::Item_t loadXml(
106- const zstring& baseUri,
107- const zstring& docUri,
108- std::istream& xmlStream) = 0;
109+ const zstring& baseUri,
110+ const zstring& docUri,
111+ std::istream& xmlStream) = 0;
112 };
113
114
115@@ -164,17 +155,17 @@
116
117 public:
118 FastXmlLoader(
119- BasicItemFactory* factory,
120- XQueryDiagnostics* xqueryDiagnostics,
121- const store::LoadProperties& loadProperties,
122- bool dataguide);
123+ store::ItemFactory* factory,
124+ XQueryDiagnostics* xqueryDiagnostics,
125+ const store::LoadProperties& loadProperties,
126+ bool dataguide);
127
128 ~FastXmlLoader();
129
130 store::Item_t loadXml(
131- const zstring& baseUri,
132- const zstring& uri,
133- std::istream& xmlStream);
134+ const zstring& baseUri,
135+ const zstring& uri,
136+ std::istream& xmlStream);
137
138 protected:
139 void abortload();
140@@ -191,31 +182,31 @@
141 static void endDocument(void * ctx);
142
143 static void startElement(
144- void * ctx,
145- const xmlChar * localname,
146- const xmlChar * prefix,
147- const xmlChar * URI,
148- int nb_namespaces,
149- const xmlChar ** namespaces,
150- int nb_attributes,
151- int nb_defaulted,
152- const xmlChar ** attributes);
153+ void * ctx,
154+ const xmlChar * localname,
155+ const xmlChar * prefix,
156+ const xmlChar * URI,
157+ int nb_namespaces,
158+ const xmlChar ** namespaces,
159+ int nb_attributes,
160+ int nb_defaulted,
161+ const xmlChar ** attributes);
162
163 static void endElement(
164- void * ctx,
165- const xmlChar * localname,
166- const xmlChar * prefix,
167- const xmlChar * URI);
168+ void * ctx,
169+ const xmlChar * localname,
170+ const xmlChar * prefix,
171+ const xmlChar * URI);
172
173 static void characters(
174- void * ctx,
175- const xmlChar * ch,
176- int len);
177+ void * ctx,
178+ const xmlChar * ch,
179+ int len);
180
181 static void cdataBlock(
182- void * ctx,
183- const xmlChar * value,
184- int len);
185+ void * ctx,
186+ const xmlChar * value,
187+ int len);
188
189 static void comment(
190 void * ctx,
191@@ -247,6 +238,7 @@
192 xmlChar *content);
193 };
194
195+
196 /*******************************************************************************
197 FragmentXmlLoader
198 *******************************************************************************/
199@@ -254,18 +246,18 @@
200 {
201 public:
202 FragmentXmlLoader(
203- BasicItemFactory* factory,
204- XQueryDiagnostics* xqueryDiagnostics,
205- const store::LoadProperties& loadProperties,
206- bool dataguide);
207+ store::ItemFactory* factory,
208+ XQueryDiagnostics* xqueryDiagnostics,
209+ const store::LoadProperties& loadProperties,
210+ bool dataguide);
211
212 ~FragmentXmlLoader();
213
214 store::Item_t loadXml(
215- const zstring& baseUri,
216- const zstring& uri,
217- std::istream& xmlStream);
218-
219+ const zstring& baseUri,
220+ const zstring& uri,
221+ std::istream& xmlStream);
222+
223 protected:
224 bool fillBuffer(FragmentIStream* theFragmentStream);
225
226@@ -356,17 +348,17 @@
227
228 public:
229 DtdXmlLoader(
230- BasicItemFactory* factory,
231- XQueryDiagnostics* xqueryDiagnostics,
232- const store::LoadProperties& loadProperties,
233- bool dataguide);
234+ store::ItemFactory* factory,
235+ XQueryDiagnostics* xqueryDiagnostics,
236+ const store::LoadProperties& loadProperties,
237+ bool dataguide);
238
239 ~DtdXmlLoader();
240
241 store::Item_t loadXml(
242- const zstring& baseUri,
243- const zstring& uri,
244- std::istream& xmlStream);
245+ const zstring& baseUri,
246+ const zstring& uri,
247+ std::istream& xmlStream);
248
249 protected:
250 void abortload();
251
252=== modified file 'src/store/naive/loader_dtd.cpp'
253--- src/store/naive/loader_dtd.cpp 2012-03-26 01:31:32 +0000
254+++ src/store/naive/loader_dtd.cpp 2012-03-27 01:25:22 +0000
255@@ -115,7 +115,7 @@
256
257 ********************************************************************************/
258 FragmentXmlLoader::FragmentXmlLoader(
259- BasicItemFactory* factory,
260+ store::ItemFactory* factory,
261 XQueryDiagnostics* xqueryDiagnostics,
262 const store::LoadProperties& loadProperties,
263 bool dataguide)
264@@ -507,7 +507,7 @@
265
266 ********************************************************************************/
267 DtdXmlLoader::DtdXmlLoader(
268- BasicItemFactory* factory,
269+ store::ItemFactory* factory,
270 XQueryDiagnostics* xqueryDiagnostics,
271 const store::LoadProperties& loadProperties,
272 bool dataguide)
273@@ -1124,7 +1124,7 @@
274 for (xmlNs *ns = node->nsDef; ns != NULL; ns = ns->next)
275 numNamespaces++;
276
277- SimpleStore& store = GET_STORE();
278+ Store& store = GET_STORE();
279 NodeFactory& nfactory = store.getNodeFactory();
280 DtdXmlLoader& loader = *(static_cast<DtdXmlLoader *>(ctx));
281 ZORBA_LOADER_CHECK_ERROR(loader);
282@@ -1291,7 +1291,7 @@
283 break;
284 case XML_ATTRIBUTE_IDREFS:
285 GET_STORE().getItemFactory()->createIDREFS(typedValue, value);
286- GET_STORE().getItemFactory()->createQName(typeName, SimpleStore::XS_URI, "xs", "IDREFS");
287+ GET_STORE().getItemFactory()->createQName(typeName, Store::XS_URI, "xs", "IDREFS");
288 attrNode->setHaveListValue();
289 break;
290 case XML_ATTRIBUTE_ENTITY:
291@@ -1300,7 +1300,7 @@
292 break;
293 case XML_ATTRIBUTE_ENTITIES:
294 GET_STORE().getItemFactory()->createENTITIES(typedValue, value);
295- GET_STORE().getItemFactory()->createQName(typeName, SimpleStore::XS_URI, "xs", "ENTITIES");
296+ GET_STORE().getItemFactory()->createQName(typeName, Store::XS_URI, "xs", "ENTITIES");
297 attrNode->setHaveListValue();
298 break;
299 case XML_ATTRIBUTE_NMTOKEN:
300@@ -1309,16 +1309,16 @@
301 break;
302 case XML_ATTRIBUTE_NMTOKENS:
303 GET_STORE().getItemFactory()->createNMTOKENS(typedValue, value);
304- GET_STORE().getItemFactory()->createQName(typeName, SimpleStore::XS_URI, "xs", "NMTOKENS");
305+ GET_STORE().getItemFactory()->createQName(typeName, Store::XS_URI, "xs", "NMTOKENS");
306 attrNode->setHaveListValue();
307 break;
308 case XML_ATTRIBUTE_NOTATION:
309 GET_STORE().getItemFactory()->createNOTATION(typedValue, value);
310- GET_STORE().getItemFactory()->createQName(typeName, SimpleStore::XS_URI, "xs", "NOTATION");
311+ GET_STORE().getItemFactory()->createQName(typeName, Store::XS_URI, "xs", "NOTATION");
312 break;
313 case XML_ATTRIBUTE_ENUMERATION:
314 GET_STORE().getItemFactory()->createUntypedAtomic(typedValue, value);
315- GET_STORE().getItemFactory()->createQName(typeName, SimpleStore::XS_URI, "xs", "anySimpleType");
316+ GET_STORE().getItemFactory()->createQName(typeName, Store::XS_URI, "xs", "anySimpleType");
317 break;
318 default:
319 std::cout << "AssertError: unknown libxml2 attribute type: " <<
320
321=== modified file 'src/store/naive/loader_fast.cpp'
322--- src/store/naive/loader_fast.cpp 2012-03-26 01:31:32 +0000
323+++ src/store/naive/loader_fast.cpp 2012-03-27 01:25:22 +0000
324@@ -70,11 +70,36 @@
325 return; \
326 } while (0);
327
328+
329+/*******************************************************************************
330+
331+********************************************************************************/
332+XmlLoader::XmlLoader(
333+ store::ItemFactory* factory,
334+ XQueryDiagnostics* xqueryDiagnostics,
335+ const store::LoadProperties& loadProperties,
336+ bool dataguide)
337+ :
338+ theLoadProperties(loadProperties),
339+ ctxt(NULL),
340+ theFactory(static_cast<BasicItemFactory*>(factory)),
341+ theXQueryDiagnostics(xqueryDiagnostics),
342+ theTraceLevel(0),
343+ theBuildDataGuide(dataguide)
344+{
345+}
346+
347+
348+XmlLoader::~XmlLoader()
349+{
350+}
351+
352+
353 /*******************************************************************************
354
355 ********************************************************************************/
356 FastXmlLoader::FastXmlLoader(
357- BasicItemFactory* factory,
358+ store::ItemFactory* factory,
359 XQueryDiagnostics* xqueryDiagnostics,
360 const store::LoadProperties& loadProperties,
361 bool dataguide)
362@@ -542,7 +567,7 @@
363 int numDefaulted,
364 const xmlChar ** attributes)
365 {
366- SimpleStore& store = GET_STORE();
367+ Store& store = GET_STORE();
368 NodeFactory& nfactory = store.getNodeFactory();
369 FastXmlLoader& loader = *(static_cast<FastXmlLoader *>(ctx));
370 ZORBA_LOADER_CHECK_ERROR(loader);
371
372=== modified file 'src/store/naive/node_factory.h'
373--- src/store/naive/node_factory.h 2012-03-26 01:31:32 +0000
374+++ src/store/naive/node_factory.h 2012-03-27 01:25:22 +0000
375@@ -41,13 +41,13 @@
376 class CommentNode;
377
378
379-/**
380- * This class implements the Abstract Factory Pattern and is responsible for
381- * creating node items of the SimpleStore. Having a factory for node items
382- * allows other stores to derive from the node items of the SimpleStore without
383- * modifying a lot of code (e.g. of the loader). The class can only be
384- * instantiated by the SimpleStore.
385- */
386+/*******************************************************************************
387+ This class implements the Abstract Factory Pattern and is responsible for
388+ creating node items of the SimpleStore. Having a factory for node items
389+ allows other stores to derive from the node items of the SimpleStore without
390+ modifying a lot of code (e.g. of the loader). The class can only be
391+ instantiated by the SimpleStore.
392+********************************************************************************/
393 class NodeFactory
394 {
395 protected:
396
397=== modified file 'src/store/naive/node_items.cpp'
398--- src/store/naive/node_items.cpp 2012-03-26 01:31:32 +0000
399+++ src/store/naive/node_items.cpp 2012-03-27 01:25:22 +0000
400@@ -1293,7 +1293,7 @@
401 lCurrent = lCurrent->getParent();
402 }
403 store::Item_t lRes;
404- GET_STORE().getItemFactory()->createInteger(lRes, lNumLevels);
405+ GET_FACTORY().createInteger(lRes, lNumLevels);
406 return lRes;
407 }
408
409@@ -1765,7 +1765,7 @@
410 {
411 zstring rch;
412 getStringValue2(rch);
413- GET_STORE().getItemFactory()->createUntypedAtomic(val, rch);
414+ GET_FACTORY().createUntypedAtomic(val, rch);
415 iter = NULL;
416 }
417
418@@ -2643,7 +2643,7 @@
419
420 if (getType()->equals(GET_STORE().XS_UNTYPED_QNAME))
421 {
422- GET_STORE().getItemFactory()->createBoolean(val, false);
423+ GET_FACTORY().createBoolean(val, false);
424 return val;
425 }
426
427@@ -2687,7 +2687,7 @@
428 }
429 }
430
431- GET_STORE().getItemFactory()->createBoolean(val, nilled);
432+ GET_FACTORY().createBoolean(val, nilled);
433 return val;
434 }
435
436@@ -3145,7 +3145,7 @@
437 {
438 ZORBA_FATAL(!absUri.empty(), "");
439
440- const SimpleStore& store = GET_STORE();
441+ const Store& store = GET_STORE();
442
443 store::Item_t qname = store.getQNamePool().insert(store.XML_URI, "xml", "base");
444 store::Item_t typeName = store.theSchemaTypeNames[store::XS_ANY_URI];
445@@ -3154,7 +3154,7 @@
446
447 if (relUri.empty())
448 {
449- GET_STORE().getItemFactory()->createAnyURI(typedValue, absUri);
450+ GET_FACTORY().createAnyURI(typedValue, absUri);
451 }
452 else
453 {
454@@ -3171,7 +3171,7 @@
455 resolvedUriString = relUri;
456 }
457
458- GET_STORE().getItemFactory()->createAnyURI(typedValue, resolvedUriString);
459+ GET_FACTORY().createAnyURI(typedValue, resolvedUriString);
460 }
461
462 checkUniqueAttr(qname.getp());
463@@ -3470,7 +3470,7 @@
464 assert(parent != NULL || rootParent == NULL);
465 ZORBA_FATAL(!isHidden(), "");
466
467- SimpleStore& store = GET_STORE();
468+ Store& store = GET_STORE();
469
470 XmlTree* tree = NULL;
471 AttributeNode* copyNode = NULL;
472@@ -3502,21 +3502,21 @@
473 {
474 zstring rch;
475 getStringValue2(rch);
476- GET_STORE().getItemFactory()->createUntypedAtomic(typedValue, rch);
477+ GET_FACTORY().createUntypedAtomic(typedValue, rch);
478 }
479 }
480
481 try
482 {
483 if (parent == NULL)
484- tree = GET_STORE().getNodeFactory().createXmlTree();
485+ tree = GET_NODE_FACTORY().createXmlTree();
486
487 else if (parent == rootParent)
488 reinterpret_cast<ElementNode*>(parent)->checkUniqueAttr(nodeName);
489
490 bool append = (rootParent != parent);
491
492- copyNode = GET_STORE().getNodeFactory().createAttributeNode(
493+ copyNode = GET_NODE_FACTORY().createAttributeNode(
494 tree,
495 static_cast<ElementNode*>(parent),
496 append,
497@@ -4150,12 +4150,12 @@
498 if (isTyped())
499 {
500 getValue()->getStringValue2(rch);
501- GET_STORE().getItemFactory()->createUntypedAtomic(val, rch);
502+ GET_FACTORY().createUntypedAtomic(val, rch);
503 }
504 else
505 {
506 rch = getText();
507- GET_STORE().getItemFactory()->createUntypedAtomic(val, rch);
508+ GET_FACTORY().createUntypedAtomic(val, rch);
509 }
510 iter = NULL;
511 }
512@@ -4434,7 +4434,7 @@
513 xs_integer lParentLevel = getParent()->getLevel()->getIntegerValue();
514
515 store::Item_t lRes;
516- GET_STORE().getItemFactory()->createInteger(lRes, ++lParentLevel);
517+ GET_FACTORY().createInteger(lRes, ++lParentLevel);
518
519 return lRes;
520 }
521@@ -4581,7 +4581,7 @@
522 void PiNode::getTypedValue(store::Item_t& val, store::Iterator_t& iter) const
523 {
524 zstring rch = theContent;
525- GET_STORE().getItemFactory()->createString(val, rch);
526+ GET_FACTORY().createString(val, rch);
527 iter = NULL;
528 }
529
530@@ -4705,7 +4705,7 @@
531 void CommentNode::getTypedValue(store::Item_t& val, store::Iterator_t& iter) const
532 {
533 zstring rch = theContent;
534- GET_STORE().getItemFactory()->createString(val, rch);
535+ GET_FACTORY().createString(val, rch);
536 iter = NULL;
537 }
538
539
540=== modified file 'src/store/naive/pul_primitives.cpp'
541--- src/store/naive/pul_primitives.cpp 2012-03-26 01:31:32 +0000
542+++ src/store/naive/pul_primitives.cpp 2012-03-27 01:25:22 +0000
543@@ -793,7 +793,7 @@
544 ********************************************************************************/
545 void UpdPut::apply()
546 {
547- SimpleStore* store = &GET_STORE();
548+ Store* store = &GET_STORE();
549
550 zstring targetUri;
551 theTargetUri->getStringValue2(targetUri);
552@@ -847,7 +847,7 @@
553
554 void UpdPut::undo()
555 {
556- SimpleStore* store = &GET_STORE();
557+ Store* store = &GET_STORE();
558
559 store->deleteDocument(theTargetUri->getStringValue());
560
561@@ -1034,9 +1034,12 @@
562 assert(lColl);
563
564 uint64_t lastPos;
565- try {
566+ try
567+ {
568 lastPos = to_xs_unsignedLong(lColl->size()) - 1;
569- } catch (std::range_error& e) {
570+ }
571+ catch (std::range_error& e)
572+ {
573 throw ZORBA_EXCEPTION(
574 zerr::ZSTR0060_RANGE_EXCEPTION,
575 ERROR_PARAMS(
576@@ -1329,7 +1332,7 @@
577
578 void UpdCreateIndex::apply()
579 {
580- SimpleStore* store = &GET_STORE();
581+ Store* store = &GET_STORE();
582
583 try
584 {
585@@ -1355,7 +1358,7 @@
586 {
587 if (theIsApplied)
588 {
589- SimpleStore* store = &GET_STORE();
590+ Store* store = &GET_STORE();
591
592 store->deleteIndex(theQName);
593 }
594@@ -1375,7 +1378,7 @@
595
596 void UpdDeleteIndex::apply()
597 {
598- SimpleStore* store = &GET_STORE();
599+ Store* store = &GET_STORE();
600
601 if ((theIndex = store->getIndex(theQName)) == NULL)
602 {
603@@ -1395,7 +1398,7 @@
604 {
605 if (theIsApplied)
606 {
607- SimpleStore* store = &GET_STORE();
608+ Store* store = &GET_STORE();
609
610 store->addIndex(theIndex);
611 }
612@@ -1425,7 +1428,7 @@
613
614 void UpdRefreshIndex::apply()
615 {
616- SimpleStore& store = GET_STORE();
617+ Store& store = GET_STORE();
618
619 if ((theIndex = store.getIndex(theQName)) == NULL)
620 {
621@@ -1445,7 +1448,7 @@
622 {
623 if (theIsApplied)
624 {
625- SimpleStore* store = &GET_STORE();
626+ Store* store = &GET_STORE();
627 store->deleteIndex(theQName);
628 store->addIndex(theIndex);
629 }
630@@ -1475,7 +1478,7 @@
631
632 void UpdActivateIC::apply()
633 {
634- SimpleStore* store = &GET_STORE();
635+ Store* store = &GET_STORE();
636 store->activateIC(theQName, theCollectionName,theIsApplied);
637 }
638
639@@ -1484,7 +1487,7 @@
640 {
641 if (theIsApplied)
642 {
643- SimpleStore* store = &GET_STORE();
644+ Store* store = &GET_STORE();
645 bool isApplied;
646 store->deactivateIC(theQName,isApplied);
647 theIsApplied=false;
648@@ -1517,7 +1520,7 @@
649
650 void UpdActivateForeignKeyIC::apply()
651 {
652- SimpleStore* store = &GET_STORE();
653+ Store* store = &GET_STORE();
654 store->activateForeignKeyIC(theQName, theFromCollectionName, theToCollectionName,theIsApplied);
655 }
656
657@@ -1526,7 +1529,7 @@
658 {
659 if (theIsApplied)
660 {
661- SimpleStore* store = &GET_STORE();
662+ Store* store = &GET_STORE();
663 bool isApplied;
664 store->deactivateIC(theQName,isApplied);
665 theIsApplied=false;
666@@ -1555,7 +1558,7 @@
667
668 void UpdDeActivateIC::apply()
669 {
670- SimpleStore* store = &GET_STORE();
671+ Store* store = &GET_STORE();
672 store::IC_t ic = store->deactivateIC(theQName,theIsApplied);
673 if (theIsApplied)
674 {
675@@ -1579,9 +1582,10 @@
676 {
677 if (theIsApplied)
678 {
679- SimpleStore* store = &GET_STORE();
680+ Store* store = &GET_STORE();
681 bool isApplied;
682- switch (theICKind) {
683+ switch (theICKind)
684+ {
685 case store::IC::ic_collection:
686 store->activateIC(theQName, theFromCollectionName,isApplied);
687 break;
688@@ -1617,7 +1621,7 @@
689
690 void UpdCreateDocument::apply()
691 {
692- SimpleStore* store = &GET_STORE();
693+ Store* store = &GET_STORE();
694
695 store->addNode(theUri->getStringValue(), theDoc);
696
697@@ -1629,7 +1633,7 @@
698 {
699 if (theIsApplied)
700 {
701- SimpleStore* store = &GET_STORE();
702+ Store* store = &GET_STORE();
703
704 store->deleteDocument(theUri->getStringValue());
705 theIsApplied = false;
706@@ -1653,7 +1657,7 @@
707
708 void UpdDeleteDocument::apply()
709 {
710- SimpleStore* store = &GET_STORE();
711+ Store* store = &GET_STORE();
712
713 zstring lUri = theUri->getStringValue();
714
715@@ -1671,7 +1675,7 @@
716 {
717 if (theIsApplied)
718 {
719- SimpleStore* store = &GET_STORE();
720+ Store* store = &GET_STORE();
721 store->addNode(theUri->getStringValue(), theDoc);
722 theIsApplied = false;
723 }
724
725=== modified file 'src/store/naive/simple_index_value.h'
726--- src/store/naive/simple_index_value.h 2012-03-26 01:31:32 +0000
727+++ src/store/naive/simple_index_value.h 2012-03-27 01:25:22 +0000
728@@ -73,7 +73,7 @@
729 *******************************************************************************/
730 class ValueIndex : public IndexImpl
731 {
732- friend class SimpleStore;
733+ friend class Store;
734
735 protected:
736 ValueIndexCompareFunction theCompFunction;
737@@ -102,7 +102,7 @@
738 *******************************************************************************/
739 class ValueHashIndex : public ValueIndex
740 {
741- friend class SimpleStore;
742+ friend class Store;
743 friend class ProbeValueHashIndexIterator;
744
745 typedef HashMap<const store::IndexKey*,
746@@ -191,7 +191,7 @@
747 ********************************************************************************/
748 class ValueTreeIndex : public ValueIndex
749 {
750- friend class SimpleStore;
751+ friend class Store;
752 friend class ProbeValueTreeIndexIterator;
753
754 typedef std::pair<const store::IndexKey*, ValueIndexValue*> IndexMapPair;
755
756=== modified file 'src/store/naive/simple_item_factory.cpp'
757--- src/store/naive/simple_item_factory.cpp 2012-03-26 01:31:32 +0000
758+++ src/store/naive/simple_item_factory.cpp 2012-03-27 01:25:22 +0000
759@@ -1163,10 +1163,8 @@
760 ElementNode* n = NULL;
761
762 if ( typeName == NULL )
763- throw ZORBA_EXCEPTION(
764- zerr::ZAPI0014_INVALID_ARGUMENT,
765- ERROR_PARAMS( "null", ZED( NotAllowedForTypeName ) )
766- );
767+ throw ZORBA_EXCEPTION(zerr::ZAPI0014_INVALID_ARGUMENT,
768+ ERROR_PARAMS("null", ZED( NotAllowedForTypeName)));
769
770 assert(parent == NULL ||
771 parent->getNodeKind() == store::StoreConsts::elementNode ||
772
773=== modified file 'src/store/naive/simple_pul.cpp'
774--- src/store/naive/simple_pul.cpp 2012-03-26 01:31:32 +0000
775+++ src/store/naive/simple_pul.cpp 2012-03-27 01:25:22 +0000
776@@ -1522,7 +1522,7 @@
777 std::vector<store::Index*>& indices,
778 std::vector<store::Index*>& truncate_indices)
779 {
780- SimpleStore* store = &GET_STORE();
781+ Store* store = &GET_STORE();
782
783 if (store->getIndices().empty())
784 return;
785
786=== modified file 'src/store/naive/simple_store.cpp'
787--- src/store/naive/simple_store.cpp 2012-03-26 01:31:32 +0000
788+++ src/store/naive/simple_store.cpp 2012-03-27 01:25:22 +0000
789@@ -15,57 +15,24 @@
790 */
791 #include "stdafx.h"
792
793-#include <iostream>
794-#include <climits>
795-#include <memory>
796-
797-#include <libxml/parser.h>
798-
799-#include "zorbautils/hashfun.h"
800-#include "zorbautils/fatal.h"
801-#include "zorbatypes/rchandle.h"
802-#include "diagnostics/xquery_diagnostics.h"
803-#include "diagnostics/assert.h"
804-#include "diagnostics/util_macros.h"
805-
806-#include "store/api/pul.h"
807-#include "store/api/xs_type_codes.h"
808-
809-#include "properties.h"
810-#include "string_pool.h"
811 #include "simple_store.h"
812-#include "simple_temp_seq.h"
813-#include "simple_lazy_temp_seq.h"
814+#include "store_defs.h"
815+
816 #include "simple_collection.h"
817 #include "simple_collection_set.h"
818-#include "simple_index.h"
819-#include "simple_index_value.h"
820-#include "simple_index_general.h"
821-#include "simple_ic.h"
822-#include "qname_pool.h"
823-#include "loader.h"
824-#include "store_defs.h"
825-#include "node_items.h"
826-#include "dataguide.h"
827-#include "node_iterators.h"
828 #include "simple_item_factory.h"
829 #include "simple_iterator_factory.h"
830-#include "query_context.h"
831-#include "item_iterator.h"
832 #include "node_factory.h"
833-#include "name_iterator.h"
834-#include "document_name_iterator.h"
835 #include "pul_primitive_factory.h"
836-
837-#include "util/cxx_util.h"
838+#include "node_items.h"
839+
840+#include "diagnostics/zorba_exception.h"
841+#include "diagnostics/diagnostic.h"
842+#include <zorba/diagnostic_list.h>
843+
844 #include "util/uuid/uuid.h"
845 #include "zorbautils/string_util.h"
846
847-#ifndef ZORBA_NO_FULL_TEXT
848-#include "runtime/full_text/default_tokenizer.h"
849-#include "runtime/full_text/stemmer.h"
850-#endif /* ZORBA_NO_FULL_TEXT */
851-
852 namespace zorba
853 {
854
855@@ -74,49 +41,14 @@
856
857 typedef rchandle<store::TempSeq> TempSeq_t;
858
859-
860-/*******************************************************************************
861- SimpleStore static data
862-********************************************************************************/
863-const ulong SimpleStore::NAMESPACE_POOL_SIZE = 128;
864-const ulong SimpleStore::DEFAULT_DOCUMENT_SET_SIZE = 32;
865-const ulong SimpleStore::DEFAULT_URI_COLLECTION_SET_SIZE = 32;
866-const ulong SimpleStore::DEFAULT_INDICES_SET_SIZE = 32;
867-const ulong SimpleStore::DEFAULT_INTEGRITY_CONSTRAINT_SET_SIZE = 32;
868-
869-const char* SimpleStore::XS_URI = "http://www.w3.org/2001/XMLSchema";
870-const char* SimpleStore::XML_URI = "http://www.w3.org/2001/XML/1998/namespace";
871-const char* SimpleStore::ZXSE_URI = "http://www.zorba-xquery.com/zorba/schema-extensions";
872-
873-const ulong SimpleStore::XML_URI_LEN = sizeof(SimpleStore::XML_URI);
874-
875-
876 /*******************************************************************************
877
878 ********************************************************************************/
879 SimpleStore::SimpleStore()
880 :
881- theNumUsers(0),
882- theUriCounter(0),
883 theCollectionCounter(1),
884 theTreeCounter(1),
885- theNamespacePool(NULL),
886- theQNamePool(NULL),
887- theItemFactory(NULL),
888- theIteratorFactory(NULL),
889- theNodeFactory(NULL),
890- thePULFactory(NULL),
891- theDocuments(DEFAULT_DOCUMENT_SET_SIZE, true),
892- theCollections(0),
893- theIndices(0, NULL, DEFAULT_INDICES_SET_SIZE, true),
894- theICs(0, NULL, DEFAULT_INTEGRITY_CONSTRAINT_SET_SIZE, true),
895- theHashMaps(0, NULL, DEFAULT_INDICES_SET_SIZE, true),
896- theTraceLevel(0),
897 theNodeToReferencesMap(128, true)
898-#ifndef ZORBA_NO_FULL_TEXT
899- , theStemmerProvider( nullptr )
900- , theTokenizerProvider( nullptr )
901-#endif /* ZORBA_NO_FULL_TEXT */
902 {
903 }
904
905@@ -135,216 +67,18 @@
906 ********************************************************************************/
907 void SimpleStore::init()
908 {
909- SYNC_CODE(AutoLock lock(getGlobalLock(), Lock::WRITE);)
910-
911- //zorba::zstring zstr("foo");
912- //zorba::zstring_p pstr;
913- //zorba::zstring_b bstr;
914-
915- if (theNumUsers == 0)
916- {
917- // This initializes the libxml2 library and checks potential ABI mismatches
918- // between the version it was compiled for and the actual shared library used.
919- // Calling its init is done here because we also want to free it at the end,
920- // i.e. when the store is shutdown
921- LIBXML_TEST_VERSION
922-
923- store::Properties::load(0, NULL);
924-
925- theUriCounter = 0;
926- theCollectionCounter = 1;
927- theTreeCounter = 1;
928-
929- theNamespacePool = new StringPool(NAMESPACE_POOL_SIZE);
930-
931- theNamespacePool->insertc("", theEmptyNs);
932- theNamespacePool->insertc(XS_URI, theXmlSchemaNs);
933-
934- theQNamePool = new QNamePool(QNamePool::MAX_CACHE_SIZE, theNamespacePool);
935-
936- // createItemFactory uses theNamespacePool and theQNamePool
937- // they have to be created before this function is called
938- theItemFactory = createItemFactory();
939-
940- initTypeNames();
941-
942- theIteratorFactory = new SimpleIteratorFactory();
943-
944- theNodeFactory = createNodeFactory();
945-
946- thePULFactory = createPULPrimitiveFactory();
947-
948- theTraceLevel = store::Properties::instance()->storeTraceLevel();
949-
950- theCollections = createCollectionSet();
951-
952- StoreManagerImpl::theStore = this;
953- }
954-
955- ++theNumUsers;
956-}
957-
958-
959-/*******************************************************************************
960-
961-********************************************************************************/
962-void SimpleStore::initTypeNames()
963-{
964- const char* ns = XS_URI;
965- BasicItemFactory* f = theItemFactory;
966-
967- theSchemaTypeNames.resize(store::XS_LAST);
968-
969- f->createQName(XS_UNTYPED_QNAME, ns, "xs", "untyped");
970-
971- f->createQName(XS_ANY_QNAME, ns, "xs", "anyType");
972-
973- f->createQName(XS_ANY_SIMPLE_QNAME, ns, "xs", "anySimpleType");
974-
975- f->createQName(theSchemaTypeNames[store::XS_ANY_ATOMIC], ns, "xs", "anyAtomicType");
976-
977- f->createQName(theSchemaTypeNames[store::XS_UNTYPED_ATOMIC], ns, "xs", "untypedAtomic");
978-
979- f->createQName(theSchemaTypeNames[store::XS_ANY_URI], ns, "xs", "anyURI");
980-
981- f->createQName(theSchemaTypeNames[store::XS_QNAME], ns, "xs", "QName");
982-
983- f->createQName(theSchemaTypeNames[store::XS_NOTATION], ns, "xs", "NOTATION");
984-
985- f->createQName(theSchemaTypeNames[store::XS_STRING], ns, "xs", "string");
986- f->createQName(theSchemaTypeNames[store::XS_NORMALIZED_STRING], ns, "xs", "normalizedString");
987- f->createQName(theSchemaTypeNames[store::XS_TOKEN], ns, "xs", "token");
988- f->createQName(theSchemaTypeNames[store::XS_NMTOKEN], ns, "xs", "NMTOKEN");
989- f->createQName(theSchemaTypeNames[store::XS_LANGUAGE], ns, "xs", "language");
990- f->createQName(theSchemaTypeNames[store::XS_NAME], ns, "xs", "Name");
991- f->createQName(theSchemaTypeNames[store::XS_NCNAME], ns, "xs", "NCName");
992- f->createQName(theSchemaTypeNames[store::XS_ID], ns, "xs", "ID");
993- f->createQName(theSchemaTypeNames[store::XS_IDREF], ns, "xs", "IDREF");
994- f->createQName(theSchemaTypeNames[store::XS_ENTITY], ns, "xs", "ENTITY");
995-
996- f->createQName(theSchemaTypeNames[store::XS_DATETIME], ns, "xs", "dateTime");
997- f->createQName(theSchemaTypeNames[store::XS_DATE], ns, "xs", "date");
998- f->createQName(theSchemaTypeNames[store::XS_TIME], ns, "xs", "time");
999- f->createQName(theSchemaTypeNames[store::XS_GYEAR_MONTH], ns, "xs", "gYearMonth");
1000- f->createQName(theSchemaTypeNames[store::XS_GYEAR], ns, "xs", "gYear");
1001- f->createQName(theSchemaTypeNames[store::XS_GMONTH_DAY], ns, "xs", "gMonthDay");
1002- f->createQName(theSchemaTypeNames[store::XS_GDAY], ns, "xs", "gDay");
1003- f->createQName(theSchemaTypeNames[store::XS_GMONTH], ns, "xs", "gMonth");
1004-
1005- f->createQName(theSchemaTypeNames[store::XS_DURATION], ns, "xs", "duration");
1006- f->createQName(theSchemaTypeNames[store::XS_DT_DURATION], ns, "xs", "dayTimeDuration");
1007- f->createQName(theSchemaTypeNames[store::XS_YM_DURATION], ns, "xs", "yearMonthDuration");
1008-
1009- f->createQName(theSchemaTypeNames[store::XS_FLOAT], ns, "xs", "float");
1010- f->createQName(theSchemaTypeNames[store::XS_DOUBLE], ns, "xs", "double");
1011- f->createQName(theSchemaTypeNames[store::XS_DECIMAL], ns, "xs", "decimal");
1012- f->createQName(theSchemaTypeNames[store::XS_INTEGER], ns, "xs", "integer");
1013- f->createQName(theSchemaTypeNames[store::XS_NON_POSITIVE_INTEGER], ns, "xs", "nonPositiveInteger");
1014- f->createQName(theSchemaTypeNames[store::XS_NON_NEGATIVE_INTEGER], ns, "xs", "nonNegativeInteger");
1015- f->createQName(theSchemaTypeNames[store::XS_NEGATIVE_INTEGER], ns, "xs", "negativeInteger");
1016- f->createQName(theSchemaTypeNames[store::XS_POSITIVE_INTEGER], ns, "xs", "positiveInteger");
1017-
1018- f->createQName(theSchemaTypeNames[store::XS_LONG], ns, "xs", "long");
1019- f->createQName(theSchemaTypeNames[store::XS_INT], ns, "xs", "int");
1020- f->createQName(theSchemaTypeNames[store::XS_SHORT], ns, "xs", "short");
1021- f->createQName(theSchemaTypeNames[store::XS_BYTE], ns, "xs", "byte");
1022- f->createQName(theSchemaTypeNames[store::XS_UNSIGNED_LONG], ns, "xs", "unsignedLong");
1023- f->createQName(theSchemaTypeNames[store::XS_UNSIGNED_INT], ns, "xs", "unsignedInt");
1024- f->createQName(theSchemaTypeNames[store::XS_UNSIGNED_SHORT], ns, "xs", "unsignedShort");
1025- f->createQName(theSchemaTypeNames[store::XS_UNSIGNED_BYTE], ns, "xs", "unsignedByte");
1026-
1027- f->createQName(theSchemaTypeNames[store::XS_BASE64BINARY], ns, "xs", "base64Binary");
1028- f->createQName(theSchemaTypeNames[store::XS_HEXBINARY], ns, "xs", "hexBinary");
1029- f->createQName(theSchemaTypeNames[store::XS_BOOLEAN], ns, "xs", "boolean");
1030-
1031- for (ulong i = 0; i < store::XS_LAST; ++i)
1032- {
1033- theSchemaTypeCodes[theSchemaTypeNames[i].getp()] =
1034- static_cast<store::SchemaTypeCode>(i);
1035- }
1036-}
1037-
1038-
1039-/*******************************************************************************
1040-
1041-********************************************************************************/
1042+ theCollectionCounter = 1;
1043+ theTreeCounter = 1;
1044+
1045+ Store::init();
1046+}
1047+
1048 void SimpleStore::shutdown(bool soft)
1049 {
1050- SYNC_CODE(AutoLock lock(getGlobalLock(), Lock::WRITE);)
1051-
1052- if (theNumUsers == 0)
1053- return;
1054-
1055- --theNumUsers;
1056-
1057- if (theNumUsers == 0 || soft == false)
1058+ Store::shutdown(soft);
1059+
1060+ if (theNumUsers == 0 || soft == false)
1061 {
1062- theIndices.clear();
1063- theICs.clear();
1064- theHashMaps.clear();
1065-
1066- if (theCollections != NULL)
1067- {
1068- theCollections->clear();
1069- destroyCollectionSet(theCollections);
1070- theCollections = NULL;
1071- }
1072-
1073- theDocuments.clear();
1074-
1075- if (thePULFactory != NULL)
1076- {
1077- destroyPULPrimitiveFactory(thePULFactory);
1078- thePULFactory = NULL;
1079- }
1080-
1081- if (theNodeFactory != NULL)
1082- {
1083- destroyNodeFactory(theNodeFactory);
1084- theNodeFactory = NULL;
1085- }
1086-
1087- if (theItemFactory != NULL)
1088- {
1089- destroyItemFactory(theItemFactory);
1090- theItemFactory = NULL;
1091- }
1092-
1093- if (theQNamePool != NULL)
1094- {
1095- csize numTypes = theSchemaTypeNames.size();
1096- for (csize i = 0; i < numTypes; ++i)
1097- theSchemaTypeNames[i] = NULL;
1098-
1099- XS_UNTYPED_QNAME = NULL;
1100- XS_ANY_QNAME = NULL;
1101- XS_ANY_SIMPLE_QNAME = NULL;
1102-
1103- delete theQNamePool;
1104- theQNamePool = NULL;
1105- }
1106-
1107- if (theNamespacePool != NULL)
1108- {
1109- theEmptyNs.~zstring();
1110- theXmlSchemaNs.~zstring();
1111-
1112- delete theNamespacePool;
1113- theNamespacePool = NULL;
1114- }
1115-
1116- if (theIteratorFactory != NULL)
1117- {
1118- delete theIteratorFactory;
1119- theIteratorFactory = NULL;
1120- }
1121-
1122- if (theNodeFactory != NULL)
1123- {
1124- delete theNodeFactory;
1125- theNodeFactory = NULL;
1126- }
1127-
1128 if (theNodeToReferencesMap.size() > 0)
1129 {
1130 NodeRefMap::iterator iter = theNodeToReferencesMap.begin();
1131@@ -370,16 +104,6 @@
1132 ZORBA_FATAL(0, theReferencesToNodeMap.size() +
1133 " node references still in the references to nodes map");
1134 }
1135-
1136- // do cleanup of the libxml2 library
1137- // however, after that, a user will have to call
1138- // LIBXML_TEST_VERSION if he wants to use libxml2
1139- // beyond the lifecycle of zorba
1140- xmlCleanupParser();
1141-
1142- theNumUsers = 0;
1143-
1144- StoreManagerImpl::theStore = NULL;
1145 }
1146 }
1147
1148@@ -388,7 +112,7 @@
1149
1150 *******************************************************************************/
1151 PULPrimitiveFactory*
1152-SimpleStore::createPULPrimitiveFactory() const
1153+SimpleStore::createPULFactory() const
1154 {
1155 return new PULPrimitiveFactory();
1156 }
1157@@ -398,11 +122,12 @@
1158
1159 *******************************************************************************/
1160 void
1161-SimpleStore::destroyPULPrimitiveFactory(PULPrimitiveFactory* f) const
1162+SimpleStore::destroyPULFactory(PULPrimitiveFactory* f) const
1163 {
1164 delete f;
1165 }
1166
1167+
1168 /*******************************************************************************
1169
1170 *******************************************************************************/
1171@@ -442,7 +167,7 @@
1172 /*******************************************************************************
1173
1174 *******************************************************************************/
1175-BasicItemFactory* SimpleStore::createItemFactory() const
1176+store::ItemFactory* SimpleStore::createItemFactory() const
1177 {
1178 return new BasicItemFactory(theNamespacePool, theQNamePool);
1179 }
1180@@ -451,18 +176,37 @@
1181 /*******************************************************************************
1182
1183 *******************************************************************************/
1184-void SimpleStore::destroyItemFactory(BasicItemFactory* f) const
1185-{
1186- delete f;
1187-}
1188-
1189-
1190-/*******************************************************************************
1191-
1192+void SimpleStore::destroyItemFactory(store::ItemFactory* f) const
1193+{
1194+ delete f;
1195+}
1196+
1197+
1198+/*******************************************************************************
1199+
1200+*******************************************************************************/
1201+store::IteratorFactory* SimpleStore::createIteratorFactory() const
1202+{
1203+ return new SimpleIteratorFactory();
1204+}
1205+
1206+
1207+/*******************************************************************************
1208+
1209+*******************************************************************************/
1210+void SimpleStore::destroyIteratorFactory(store::IteratorFactory* f) const
1211+{
1212+ delete f;
1213+}
1214+
1215+
1216+/*******************************************************************************
1217+ create a tree id for a new tree that does not belong to any collection.
1218 ********************************************************************************/
1219-store::ItemFactory* SimpleStore::getItemFactory() const
1220+ulong SimpleStore::createTreeId()
1221 {
1222- return theItemFactory;
1223+ SYNC_CODE(AutoMutex lock(&theTreeCounterMutex);)
1224+ return theTreeCounter++;
1225 }
1226
1227
1228@@ -477,457 +221,6 @@
1229
1230
1231 /*******************************************************************************
1232- create a tree id for a new tree that does not belong to any collection.
1233-********************************************************************************/
1234-ulong SimpleStore::createTreeId()
1235-{
1236- SYNC_CODE(AutoMutex lock(&theTreeCounterMutex);)
1237- return theTreeCounter++;
1238-}
1239-
1240-
1241-/*******************************************************************************
1242-
1243-********************************************************************************/
1244-XmlLoader* SimpleStore::getXmlLoader(XQueryDiagnostics* aXQueryDiagnostics,
1245- const store::LoadProperties& loadProperties)
1246-{
1247- if (loadProperties.getParseExternalParsedEntity())
1248- return new FragmentXmlLoader(theItemFactory,
1249- aXQueryDiagnostics,
1250- loadProperties,
1251- store::Properties::instance()->buildDataguide());
1252- else if (loadProperties.getDTDValidate())
1253- return new DtdXmlLoader(theItemFactory,
1254- aXQueryDiagnostics,
1255- loadProperties,
1256- store::Properties::instance()->buildDataguide());
1257- else
1258- return new FastXmlLoader(theItemFactory,
1259- aXQueryDiagnostics,
1260- loadProperties,
1261- store::Properties::instance()->buildDataguide());
1262-}
1263-
1264-
1265-/*******************************************************************************
1266- Create an index with a given URI and return an rchandle to the index object.
1267- If an index with the given URI exists already and the index we want to create
1268- is not a temporary one, raise an error.
1269-********************************************************************************/
1270-store::Index_t SimpleStore::createIndex(
1271- const store::Item_t& qname,
1272- const store::IndexSpecification& spec,
1273- store::Iterator* sourceIter)
1274-{
1275- store::Item* qname2 = const_cast<store::Item*>(qname.getp());
1276- store::Index_t index;
1277-
1278- if (!spec.theIsTemp && theIndices.get(qname.getp(), index))
1279- {
1280- throw ZORBA_EXCEPTION(zerr::ZSTR0001_INDEX_ALREADY_EXISTS,
1281- ERROR_PARAMS(qname->getStringValue()));
1282- }
1283-
1284- if (spec.theIsGeneral && spec.theIsSorted)
1285- {
1286- index = new GeneralTreeIndex(qname, spec);
1287- populateGeneralIndex(index, sourceIter, spec.getNumColumns());
1288- }
1289- else if (spec.theIsSorted)
1290- {
1291- index = new ValueTreeIndex(qname, spec);
1292- populateValueIndex(index, sourceIter, spec.getNumColumns());
1293- }
1294- else if (spec.theIsGeneral)
1295- {
1296- index = new GeneralHashIndex(qname, spec);
1297- populateGeneralIndex(index, sourceIter, spec.getNumColumns());
1298- }
1299- else
1300- {
1301- index = new ValueHashIndex(qname, spec);
1302- populateValueIndex(index, sourceIter, spec.getNumColumns());
1303- }
1304-
1305- if (!spec.theIsTemp)
1306- {
1307- theIndices.insert(qname2, index);
1308- }
1309-
1310- return index;
1311-}
1312-
1313-
1314-/*******************************************************************************
1315-
1316-********************************************************************************/
1317-void SimpleStore::populateValueIndex(
1318- const store::Index_t& aIndex,
1319- store::Iterator* aSourceIter,
1320- ulong aNumColumns)
1321-{
1322- if (!aSourceIter)
1323- return;
1324-
1325- store::Item_t domainItem;
1326- store::IndexKey* key = NULL;
1327-
1328- ValueIndex* index = static_cast<ValueIndex*>(aIndex.getp());
1329-
1330- aSourceIter->open();
1331-
1332- try
1333- {
1334- while (aSourceIter->next(domainItem))
1335- {
1336- if (domainItem->isNode() &&
1337- domainItem->getCollection() == NULL &&
1338- !index->isTemporary())
1339- {
1340- RAISE_ERROR_NO_LOC(zerr::ZDDY0020_INDEX_DOMAIN_NODE_NOT_IN_COLLECTION,
1341- ERROR_PARAMS(index->getName()->getStringValue()));
1342- }
1343-
1344- if (key == NULL)
1345- key = new store::IndexKey(aNumColumns);
1346-
1347- for (ulong i = 0; i < aNumColumns; ++i)
1348- {
1349- if (!aSourceIter->next((*key)[i]))
1350- {
1351- // The source iter is a ValueIndexEntryBuilderIterator, whose next()
1352- // method is guaranteed to return true exactly once. The result from
1353- // this single successful next() may be a NULL item.
1354- RAISE_ERROR_NO_LOC(zerr::ZXQP0003_INTERNAL_ERROR,
1355- ERROR_PARAMS(ZED(IncompleteKeyInIndexBuild)));
1356- }
1357- }
1358-
1359- index->insert(key, domainItem);
1360- }
1361- }
1362- catch(...)
1363- {
1364- if (key != NULL)
1365- delete key;
1366-
1367- aSourceIter->close();
1368- throw;
1369- }
1370-
1371- if (key != NULL)
1372- delete key;
1373-
1374- aSourceIter->close();
1375-}
1376-
1377-
1378-/*******************************************************************************
1379-
1380-********************************************************************************/
1381-void SimpleStore::populateGeneralIndex(
1382- const store::Index_t& idx,
1383- store::Iterator* sourceIter,
1384- ulong numColumns)
1385-{
1386- store::Item_t domainNode;
1387- store::Item_t firstKeyItem;
1388- store::Item_t keyItem;
1389-
1390- GeneralIndex* index = static_cast<GeneralIndex*>(idx.getp());
1391-
1392- sourceIter->open();
1393-
1394- try
1395- {
1396- if (sourceIter->next(domainNode))
1397- {
1398- bool more = true;
1399-
1400- assert(domainNode->isNode());
1401- assert(keyItem == NULL);
1402-
1403- // Compute the keys associated with the current domain node. Note: We
1404- // must check whether the domain node has more than one key, before we
1405- // do any insertions in the index.
1406- while (more)
1407- {
1408- if (domainNode->getCollection() == NULL && !index->isTemporary())
1409- {
1410- RAISE_ERROR_NO_LOC(zerr::ZDDY0020_INDEX_DOMAIN_NODE_NOT_IN_COLLECTION,
1411- ERROR_PARAMS(index->getName()->getStringValue()));
1412- }
1413-
1414- // Compute 1st key, or next domain node
1415- more = sourceIter->next(firstKeyItem);
1416-
1417- // If current node has no keys, put it in the "null" entry and continue
1418- // with the next domain node, if nay.
1419- if (!more || firstKeyItem->isNode())
1420- {
1421- index->insert(keyItem, domainNode);
1422-
1423- domainNode.transfer(firstKeyItem);
1424- continue;
1425- }
1426-
1427- // Compute 2nd key, or next domain node
1428- more = sourceIter->next(keyItem);
1429-
1430- // If current domain node has exactly 1 key, insert it in the index
1431- // and continue with next domain node, if any.
1432- if (!more || keyItem->isNode())
1433- {
1434- index->insert(firstKeyItem, domainNode);
1435-
1436- domainNode.transfer(keyItem);
1437- continue;
1438- }
1439-
1440- // Current domain node has at least 2 keys. So insert them in the index.
1441- // Note: we have to copy the domainNode rchandle because index->insert()
1442- // will transfer the given node.
1443- index->setMultiKey();
1444-
1445- store::Item_t node = domainNode;
1446- index->insert(firstKeyItem, node);
1447- node = domainNode;
1448- index->insert(keyItem, node);
1449-
1450- // Compute next keys or next domain node.
1451- while ((more = sourceIter->next(keyItem)))
1452- {
1453- if (keyItem->isNode())
1454- {
1455- domainNode.transfer(keyItem);
1456- break;
1457- }
1458-
1459- node = domainNode;
1460- index->insert(keyItem, node);
1461- }
1462- }
1463- }
1464- }
1465- catch(...)
1466- {
1467- sourceIter->close();
1468-
1469- throw;
1470- }
1471-
1472- sourceIter->close();
1473-}
1474-
1475-
1476-/*******************************************************************************
1477- Refreshes an index with a given URI and return an rchandle to the index object.
1478- If an index with the given URI exists already and the index we want to create
1479- is not a temporary one, raise an error.
1480-********************************************************************************/
1481-store::Index_t SimpleStore::refreshIndex(
1482- const store::Item_t& qname,
1483- const store::IndexSpecification& spec,
1484- store::Iterator* sourceIter)
1485-{
1486- store::Index_t index;
1487- store::Item* non_const_items = const_cast<store::Item*>(qname.getp());
1488-
1489- if (!theIndices.get(non_const_items, index))
1490- {
1491- throw ZORBA_EXCEPTION(
1492- zerr::ZSTR0002_INDEX_DOES_NOT_EXIST,
1493- ERROR_PARAMS( qname->getStringValue() )
1494- );
1495- }
1496-
1497- deleteIndex(qname);
1498-
1499- try
1500- {
1501- createIndex(qname, index->getSpecification(), sourceIter);
1502- }
1503- catch (...)
1504- {
1505- addIndex(index);
1506- throw;
1507- }
1508-
1509- return index;
1510-}
1511-
1512-/*******************************************************************************
1513-
1514-********************************************************************************/
1515-void SimpleStore::addIndex(store::Index_t& index)
1516-{
1517- if (index == NULL)
1518- return;
1519-
1520- store::Item* qname = const_cast<store::Item*>(index->getName());
1521-
1522- theIndices.insert(qname, index);
1523-}
1524-
1525-
1526-/*******************************************************************************
1527-
1528-********************************************************************************/
1529-store::Index* SimpleStore::getIndex(const store::Item* qname)
1530-{
1531- if (qname == NULL)
1532- return NULL;
1533-
1534- store::Item* qname2 = const_cast<store::Item*>(qname);
1535- store::Index_t index;
1536-
1537- if (theIndices.get(qname2, index))
1538- return index.getp();
1539-
1540- return NULL;
1541-}
1542-
1543-
1544-/*******************************************************************************
1545-
1546-********************************************************************************/
1547-void SimpleStore::deleteIndex(const store::Item* qname)
1548-{
1549- if (qname == NULL)
1550- return;
1551-
1552- store::Item* qname2 = const_cast<store::Item*>(qname);
1553-
1554- theIndices.erase(qname2);
1555-}
1556-
1557-
1558-/*******************************************************************************
1559-
1560-********************************************************************************/
1561-store::Iterator_t SimpleStore::listIndexNames()
1562-{
1563- return new NameIterator<IndexSet>(theIndices);
1564-}
1565-
1566-
1567-/*******************************************************************************
1568-
1569-********************************************************************************/
1570-store::IC_t SimpleStore::activateIC(
1571- const store::Item_t& icQName,
1572- const store::Item_t& collectionQName,
1573- bool& isApplied)
1574-{
1575- ZORBA_ASSERT(icQName != NULL);
1576-
1577- store::Item* qname = icQName.getp();
1578-
1579- store::IC_t ic;
1580-
1581- if (theICs.get(qname, ic))
1582- {
1583- return ic; // already activated => noop
1584- }
1585-
1586- ic = new ICCollectionImpl(icQName, collectionQName);
1587-
1588- theICs.insert(qname, ic);
1589-
1590- isApplied=true;
1591- return ic;
1592-}
1593-
1594-
1595-/*******************************************************************************
1596-
1597-********************************************************************************/
1598-store::IC_t SimpleStore::activateForeignKeyIC(
1599- const store::Item_t& icQName,
1600- const store::Item_t& fromCollectionQName,
1601- const store::Item_t& toCollectionQName,
1602- bool& isApplied)
1603-{
1604- ZORBA_ASSERT(icQName != NULL);
1605-
1606- store::Item* qname = const_cast<store::Item*>(icQName.getp());
1607-
1608- store::IC_t ic;
1609-
1610- if (theICs.get(qname, ic))
1611- {
1612- return ic; // already activated => noop
1613- }
1614-
1615- ic = new ICForeignKeyImpl(qname, fromCollectionQName, toCollectionQName);
1616-
1617- theICs.insert(qname, ic);
1618-
1619- isApplied=true;
1620- return ic;
1621-}
1622-
1623-
1624-store::IC_t
1625-SimpleStore::deactivateIC(const store::Item_t& icQName,
1626- bool& isApplied)
1627-{
1628- ZORBA_ASSERT(icQName != NULL);
1629-
1630- store::IC_t ic;
1631-
1632- if (!theICs.get(icQName.getp(), ic))
1633- {
1634- return ic; // already deactivated in the same PUL => noop
1635- }
1636-
1637- theICs.erase(icQName.getp());
1638- isApplied=true;
1639- return ic;
1640-}
1641-
1642-
1643-store::Iterator_t SimpleStore::listActiveICNames()
1644-{
1645- return new NameIterator<ICSet>(theICs);
1646-}
1647-
1648-
1649-store::IC* SimpleStore::getIC(const store::Item* icQName)
1650-{
1651- store::Item* qname = const_cast<store::Item*>(icQName);
1652- store::IC_t ic;
1653- theICs.get(qname, ic);
1654-
1655- return ic.getp();
1656-}
1657-
1658-
1659-/*******************************************************************************
1660-
1661-********************************************************************************/
1662-store::Index*
1663-SimpleStore::getMap(const store::Item* aQName) const
1664-{
1665- store::Item* lQName = const_cast<store::Item*>(aQName);
1666- store::Index_t lIndex;
1667- const_cast<IndexSet*>(&theHashMaps)->get(lQName, lIndex);
1668-
1669- return lIndex.getp();
1670-}
1671-
1672-
1673-/*******************************************************************************
1674-
1675-********************************************************************************/
1676-store::Iterator_t SimpleStore::listMapNames()
1677-{
1678- return new NameIterator<IndexSet>(theHashMaps);
1679-}
1680-
1681-
1682-/*******************************************************************************
1683 Create a collection with a given QName and return an rchandle to the new
1684 collection object. If a collection with the given QName exists already, raise
1685 an error.
1686@@ -963,401 +256,6 @@
1687
1688
1689 /*******************************************************************************
1690-
1691-********************************************************************************/
1692-void SimpleStore::addCollection(store::Collection_t& collection)
1693-{
1694- const store::Item* lName = collection->getName();
1695-
1696- bool inserted = theCollections->insert(lName, collection);
1697-
1698- if (!inserted)
1699- {
1700- throw ZORBA_EXCEPTION(zerr::ZSTR0008_COLLECTION_ALREADY_EXISTS,
1701- ERROR_PARAMS(lName->getStringValue()));
1702- }
1703-}
1704-
1705-
1706-/*******************************************************************************
1707- Return an rchandle to the Collection object corresponding to the given QName,
1708- or NULL if there is no collection with that QName.
1709-********************************************************************************/
1710-store::Collection_t SimpleStore::getCollection(
1711- const store::Item* aName,
1712- bool aDynamicCollection)
1713-{
1714- if (aName == NULL)
1715- return NULL;
1716-
1717- store::Collection_t collection;
1718- if (theCollections->get(aName, collection, aDynamicCollection))
1719- {
1720- return collection;
1721- }
1722- else
1723- {
1724- return NULL;
1725- }
1726-}
1727-
1728-
1729-/*******************************************************************************
1730- Delete the collection with the given QName. If there is no collection with
1731- that QName, this method is a NOOP.
1732-********************************************************************************/
1733-void SimpleStore::deleteCollection(
1734- const store::Item* aName,
1735- bool aDynamicCollection)
1736-{
1737- if (aName == NULL)
1738- return;
1739-
1740- if (!theCollections->remove(aName, aDynamicCollection))
1741- {
1742- throw ZORBA_EXCEPTION(zerr::ZSTR0009_COLLECTION_NOT_FOUND,
1743- ERROR_PARAMS(aName->getStringValue()));
1744- }
1745-}
1746-
1747-
1748-/*******************************************************************************
1749- Returns an iterator that lists the QName's of all the available collections.
1750-********************************************************************************/
1751-store::Iterator_t SimpleStore::listCollectionNames(bool aDynamicCollections)
1752-{
1753- return theCollections->names(aDynamicCollections);
1754-}
1755-
1756-
1757-/*******************************************************************************
1758-
1759-********************************************************************************/
1760-store::Item_t SimpleStore::loadDocument(
1761- const zstring& baseUri,
1762- const zstring& docUri,
1763- std::istream& stream,
1764- const store::LoadProperties& loadProperties)
1765-{
1766- zstring_b urib;
1767-
1768- if (!docUri.empty())
1769- urib.wrap_memory(docUri.data(), docUri.size());
1770-
1771- XmlNode_t root;
1772- bool found = theDocuments.get(urib, root);
1773-
1774- if (found)
1775- {
1776- return root.getp();
1777- }
1778-
1779- XQueryDiagnostics lXQueryDiagnostics;
1780- std::auto_ptr<XmlLoader> loader(getXmlLoader(&lXQueryDiagnostics, loadProperties));
1781-
1782- root = loader->loadXml(baseUri, docUri, stream);
1783-
1784- if (!lXQueryDiagnostics.errors().empty())
1785- {
1786- lXQueryDiagnostics.errors().front()->polymorphic_throw();
1787- }
1788-
1789- if (root != NULL && loadProperties.getStoreDocument())
1790- theDocuments.insert(urib, root);
1791-
1792- return root.getp();
1793-}
1794-
1795-
1796-/*******************************************************************************
1797- For lazy loading...
1798- Param stream is a heap pointer to an input stream. This is to be deallocated
1799- by Zorba.
1800-********************************************************************************/
1801-store::Item_t SimpleStore::loadDocument(
1802- const zstring& baseUri,
1803- const zstring& docUri,
1804- std::istream* stream,
1805- const store::LoadProperties& loadProperties)
1806-{
1807- store::Item_t docitem;
1808- try
1809- {
1810- //do full loading for now
1811- docitem = loadDocument(baseUri, docUri, *stream, loadProperties);
1812- delete stream;
1813- }
1814- catch(...)
1815- {
1816- delete stream;
1817- }
1818- return docitem;
1819-}
1820-
1821-
1822-/*******************************************************************************
1823- Add the given node with the given uri to the store. Essentially, this method
1824- establishes an association between a uri and a node. If the given uri is
1825- already associated to another node, the method raises an error. If the given
1826- uri is already associated to the given node, this method is a noop.
1827-********************************************************************************/
1828-void SimpleStore::addNode(const zstring& uri, const store::Item_t& node)
1829-{
1830- ZORBA_ASSERT(!uri.empty());
1831-
1832- if (node == NULL || !node->isNode())
1833- {
1834- RAISE_ERROR_NO_LOC(zerr::ZAPI0021_ITEM_TO_LOAD_IS_NOT_NODE, ERROR_PARAMS(uri));
1835- }
1836-
1837- XmlNode_t root = reinterpret_cast<XmlNode*>(node.getp());
1838-
1839- bool inserted = theDocuments.insert(uri, root);
1840-
1841- if (!inserted && node.getp() != root.getp())
1842- {
1843- RAISE_ERROR_NO_LOC(zerr::ZAPI0020_DOCUMENT_ALREADY_EXISTS, ERROR_PARAMS(uri));
1844- }
1845-
1846- ZORBA_FATAL(node.getp() == root.getp(), "");
1847-}
1848-
1849-
1850-/*******************************************************************************
1851- Return an rchandle to an iterator over the set of documents in the store
1852-********************************************************************************/
1853-store::Iterator_t SimpleStore::getDocumentNames() const
1854-{
1855- return new DocumentNameIterator<DocumentSet>(theDocuments);
1856-}
1857-
1858-
1859-/*******************************************************************************
1860- Return an rchandle to the root node of the document corresponding to the given
1861- URI, or NULL if there is no document with that URI.
1862-********************************************************************************/
1863-store::Item_t SimpleStore::getDocument(const zstring& uri)
1864-{
1865- if (uri.empty())
1866- return NULL;
1867-
1868- XmlNode_t root;
1869-
1870- bool found = theDocuments.get(uri, root);
1871-
1872- if (found)
1873- return root.getp();
1874-
1875- return NULL;
1876-}
1877-
1878-
1879-/*******************************************************************************
1880- Delete the document with the given URI. If there is no document with that
1881- URI, this method is a NOOP.
1882-********************************************************************************/
1883-void SimpleStore::deleteDocument(const zstring& uri)
1884-{
1885- if (uri.empty())
1886- return;
1887-
1888- theDocuments.erase(uri);
1889-}
1890-
1891-
1892-/*******************************************************************************
1893- Delete all the documents.
1894-********************************************************************************/
1895-void SimpleStore::deleteAllDocuments()
1896-{
1897- theDocuments.clear();
1898-}
1899-
1900-
1901-/*******************************************************************************
1902-
1903-********************************************************************************/
1904-store::Index_t
1905-SimpleStore::createHashMap(
1906- const store::Item_t& aQName,
1907- const store::IndexSpecification& aSpec)
1908-{
1909- store::Index_t lIndex;
1910-
1911- if (theHashMaps.get(aQName.getp(), lIndex))
1912- {
1913- throw ZORBA_EXCEPTION(
1914- zerr::ZSTR0001_INDEX_ALREADY_EXISTS,
1915- ERROR_PARAMS( aQName->getStringValue() )
1916- );
1917- }
1918-
1919- lIndex = new ValueHashIndex(aQName, aSpec);
1920-
1921- addHashMap(lIndex);
1922-
1923- return lIndex;
1924-}
1925-
1926-
1927-/*******************************************************************************
1928-
1929-********************************************************************************/
1930-store::Index_t
1931-SimpleStore::destroyHashMap(const store::Item_t& aQName)
1932-{
1933- store::Index_t lIndex;
1934- if (!theHashMaps.get(aQName.getp(), lIndex))
1935- {
1936- throw ZORBA_EXCEPTION(
1937- zerr::ZDDY0023_INDEX_DOES_NOT_EXIST,
1938- ERROR_PARAMS( aQName->getStringValue() )
1939- );
1940- }
1941- theHashMaps.erase(aQName.getp());
1942- return lIndex;
1943-}
1944-
1945-
1946-/*******************************************************************************
1947-
1948-********************************************************************************/
1949-store::Index_t
1950-SimpleStore::getHashMap(const store::Item_t& aQName) const
1951-{
1952- store::Index_t lIndex;
1953- if (const_cast<IndexSet*>(&theHashMaps)->get(aQName.getp(), lIndex))
1954- {
1955- return lIndex;
1956- }
1957- else
1958- {
1959- return 0;
1960- }
1961-}
1962-
1963-
1964-/*******************************************************************************
1965-
1966-********************************************************************************/
1967-void
1968-SimpleStore::addHashMap(const store::Index_t& aIndex)
1969-{
1970- store::Item* lName = aIndex->getName();
1971- store::Index_t lIndex = aIndex;
1972- theHashMaps.insert(lName, lIndex);
1973-}
1974-
1975-/*******************************************************************************
1976- Compare two nodes, based on their node id. Return -1 if node1 < node2, 0, if
1977- node1 == node2, or 1 if node1 > node2.
1978-********************************************************************************/
1979-short SimpleStore::compareNodes(store::Item* node1, store::Item* node2) const
1980-{
1981- ZORBA_FATAL(node1->isNode(), "");
1982- ZORBA_FATAL(node2->isNode(), "");
1983-
1984- if (node1 == node2)
1985- return 0;
1986-
1987- XmlNode* n1 = static_cast<XmlNode*>(node1);
1988- XmlNode* n2 = static_cast<XmlNode*>(node2);
1989-
1990- return (short)n1->compare2(n2);
1991-}
1992-
1993-
1994-/*******************************************************************************
1995- Sorts the items of the passed iterator
1996-
1997- @param iterator to sort
1998- @param ascendent true for ascendent and false for descendant
1999- @param duplicate duplicate elemination should be applied
2000- @return iterator which produces the sorted items
2001-********************************************************************************/
2002-store::Iterator_t SimpleStore::sortNodes(
2003- store::Iterator* input,
2004- bool ascendent,
2005- bool duplicateElemination,
2006- bool aAllowAtomics)
2007-{
2008- if (aAllowAtomics)
2009- return new StoreNodeSortOrAtomicIterator(input, ascendent, duplicateElemination);
2010- else
2011- return new StoreNodeSortIterator(input, ascendent, duplicateElemination);
2012-}
2013-
2014-
2015-/*******************************************************************************
2016- Create an iterator that eliminates the duplicate nodes in the set of items
2017- which is produced by the passed iterator
2018-********************************************************************************/
2019-store::Iterator_t SimpleStore::distinctNodes(
2020- store::Iterator* input,
2021- bool aAllowAtomics)
2022-{
2023- if (aAllowAtomics)
2024- return new StoreNodeDistinctOrAtomicIterator(input);
2025- else
2026- return new StoreNodeDistinctIterator(input, false);
2027-}
2028-
2029-
2030-/*******************************************************************************
2031- Create an iterator that checks for duplicate nodes in the set of nodes which
2032- is produced by the passed iterator, and raises an error if any duplicates
2033- are found. If no duplicates are found, the iterator simply passes on the
2034- input nodes to its consumer.
2035-********************************************************************************/
2036-store::Iterator_t SimpleStore::checkDistinctNodes(store::Iterator* input)
2037-{
2038- return new StoreNodeDistinctIterator(input, true);
2039-}
2040-
2041-
2042-/*******************************************************************************
2043- Computes the Structural Reference for the given node.
2044-********************************************************************************/
2045-bool SimpleStore::getStructuralInformation(
2046- store::Item_t& result,
2047- const store::Item* node)
2048-{
2049-#ifdef TEXT_ORDPATH
2050- const OrdPathNode* n = static_cast<const OrdPathNode*>(node);
2051-
2052- return theItemFactory->createStructuralAnyURI(result,
2053- n->getCollectionId(),
2054- n->getTreeId(),
2055- n->getNodeKind(),
2056- n->getOrdPath());
2057-#else
2058- if (node->getNodeKind() == store::StoreConsts::textNode)
2059- {
2060- OrdPath ordPath;
2061- const TextNode* n = static_cast<const TextNode*>(node);
2062- n->getOrdPath(ordPath);
2063-
2064- return theItemFactory->createStructuralAnyURI(result,
2065- n->getCollectionId(),
2066- n->getTreeId(),
2067- store::StoreConsts::textNode,
2068- ordPath);
2069- }
2070- else
2071- {
2072- const OrdPathNode* n = static_cast<const OrdPathNode*>(node);
2073-
2074- return theItemFactory->createStructuralAnyURI(result,
2075- n->getCollectionId(),
2076- n->getTreeId(),
2077- n->getNodeKind(),
2078- n->getOrdPath());
2079- }
2080-#endif
2081-}
2082-
2083-
2084-/*******************************************************************************
2085 Computes the reference of the given node.
2086
2087 @param node XDM node
2088@@ -1391,6 +289,18 @@
2089
2090
2091 /*******************************************************************************
2092+ Returns whether a reference has already been generated for the given node.
2093+
2094+ @param item XDM node
2095+ @return whether a reference has already been generated for the given node.
2096+********************************************************************************/
2097+bool SimpleStore::hasReference(const store::Item* node)
2098+{
2099+ return static_cast<const XmlNode*>(node)->haveReference();
2100+}
2101+
2102+
2103+/*******************************************************************************
2104 Returns the node which is identified by the given reference.
2105
2106 @param reference an xs:anyURI item
2107@@ -1420,18 +330,6 @@
2108
2109
2110 /*******************************************************************************
2111- Returns whether a reference has already been generated for the given node.
2112-
2113- @param item XDM node
2114- @return whether a reference has already been generated for the given node.
2115-********************************************************************************/
2116-bool SimpleStore::hasReference(const store::Item* node)
2117-{
2118- return static_cast<const XmlNode*>(node)->haveReference();
2119-}
2120-
2121-
2122-/*******************************************************************************
2123 Removes a node from the reference-to-nodes and nodes-to-references maps.
2124
2125 @param node XDM node
2126@@ -1461,121 +359,5 @@
2127 }
2128
2129
2130-/*******************************************************************************
2131-
2132-********************************************************************************/
2133-bool SimpleStore::getPathInfo(
2134- const store::Item* docUriItem,
2135- std::vector<const store::Item*>& contextPath,
2136- std::vector<const store::Item*>& relativePath,
2137- bool isAttrPath,
2138- bool& found,
2139- bool& unique)
2140-{
2141- zstring docUri;
2142- docUriItem->getStringValue2(docUri);
2143-
2144- XmlNode_t docRoot = BASE_NODE(getDocument(docUri));
2145-
2146- if (docRoot == NULL)
2147- return false;
2148-
2149-#ifdef DATAGUIDE
2150- GuideNode* guideRoot = docRoot->getDataGuide();
2151-
2152- if (!guideRoot)
2153- return false;
2154-
2155- guideRoot->getPathInfo(contextPath, relativePath, isAttrPath, found, unique);
2156-#endif
2157- return true;
2158-}
2159-
2160-
2161-/*******************************************************************************
2162- Creates a new TempSeq. The instance can be used, e.g. for variable bindings
2163-
2164- @param iterator The source for the XMDInstance
2165- @param lazy Hint for the store. If possible a XMDInstance should be
2166- evaluated lazily. For XQueryP it might be necassary to set
2167- this to false.
2168-********************************************************************************/
2169-TempSeq_t SimpleStore::createTempSeq(const store::Iterator_t& iterator, bool lazy)
2170-{
2171- if(lazy)
2172- {
2173- //tempSeq = new SimpleTempSeq(iterator, copyNodes);
2174- return new SimpleLazyTempSeq(iterator);
2175- }
2176- else
2177- {
2178- return new SimpleTempSeq(iterator);
2179- }
2180-}
2181-
2182-
2183-/*******************************************************************************
2184- Creates an empty TempSeq.
2185-********************************************************************************/
2186-TempSeq_t SimpleStore::createTempSeq(bool lazy)
2187-{
2188- if (lazy)
2189- {
2190- return new SimpleLazyTempSeq();
2191- }
2192- else
2193- {
2194- return new SimpleTempSeq();
2195- }
2196-}
2197-
2198-
2199-/*******************************************************************************
2200- Creates a temp seq initialized by the given vector.
2201- @param item_v - The vector to use to initialize the seq.
2202-********************************************************************************/
2203-TempSeq_t SimpleStore::createTempSeq(std::vector<store::Item_t>& items)
2204-{
2205- return new SimpleTempSeq(items);
2206-}
2207-
2208-
2209-/*******************************************************************************
2210- Creates a temp seq initialized by the given item.
2211-********************************************************************************/
2212-TempSeq_t SimpleStore::createTempSeq(store::Item_t& item)
2213-{
2214- return new SimpleTempSeq(item);
2215-}
2216-
2217-
2218-#ifndef ZORBA_NO_FULL_TEXT
2219-void SimpleStore::setStemmerProvider( internal::StemmerProvider const *p )
2220-{
2221- theStemmerProvider = p;
2222-}
2223-
2224-
2225-void SimpleStore::setTokenizerProvider( TokenizerProvider const *p )
2226-{
2227- theTokenizerProvider = p;
2228-}
2229-
2230-
2231-internal::StemmerProvider const* SimpleStore::getStemmerProvider() const
2232-{
2233- return theStemmerProvider ?
2234- theStemmerProvider : &internal::StemmerProvider::get_default();
2235-}
2236-
2237-
2238-TokenizerProvider const* SimpleStore::getTokenizerProvider() const
2239-{
2240- return theTokenizerProvider ?
2241- theTokenizerProvider : &default_tokenizer_provider();
2242-}
2243-#endif /* ZORBA_NO_FULL_TEXT */
2244-
2245-} // namespace store
2246+} // namespace simplestore
2247 } // namespace zorba
2248-/* vim:set et sw=2 ts=2: */
2249
2250=== modified file 'src/store/naive/simple_store.h'
2251--- src/store/naive/simple_store.h 2012-03-26 01:31:32 +0000
2252+++ src/store/naive/simple_store.h 2012-03-27 01:25:22 +0000
2253@@ -16,107 +16,21 @@
2254 #ifndef ZORBA_SIMPLE_STORE
2255 #define ZORBA_SIMPLE_STORE
2256
2257-#include "shared_types.h"
2258-#include "store_defs.h"
2259-#include "hashmap_nodep.h"
2260-
2261-#if (defined (WIN32) || defined (WINCE))
2262-#include "node_items.h"
2263-#include "store/api/collection.h"
2264-#include "store/api/index.h"
2265-#include "store/api/ic.h"
2266-#endif
2267-
2268-#include "store/api/store.h"
2269-
2270-#include "store/util/hashmap_stringbuf.h"
2271-
2272-#include "zorbautils/mutex.h"
2273-#include "zorbautils/lock.h"
2274-#include "zorbautils/hashmap_itemp.h"
2275-#include "zorbautils/hashmap_zstring_nonserializable.h"
2276-
2277-namespace zorba
2278-{
2279- class StoreManager;
2280-
2281-class XQueryDiagnostics;
2282-
2283-namespace store
2284-{
2285- class IteratorFactory;
2286- class ValueIndexSpecification;
2287-}
2288-
2289-namespace simplestore
2290-{
2291-
2292-class StringPool;
2293-class QNamePool;
2294-class XmlLoader;
2295-class FastXmlLoader;
2296-class Index;
2297-class BasicItemFactory;
2298-class NodeFactory;
2299-class PULPrimitiveFactory;
2300-
2301-typedef zorba::HashMapZString<XmlNode_t> DocumentSet;
2302-typedef ItemPointerHashMap<store::Index_t> IndexSet;
2303-typedef ItemPointerHashMap<store::IC_t> ICSet;
2304-
2305+#include "store.h"
2306+
2307+namespace zorba {
2308+namespace simplestore {
2309
2310
2311 /*******************************************************************************
2312- theSchemaTypeNames:
2313- -------------------
2314- Maps each enum value from SchemaTypeNames (see store/api/xs_types_enum.h) to
2315- its associated QName item.
2316-
2317- theSchemaTypeCodes:
2318- -------------------
2319
2320 theCollectionCounter:
2321 ---------------------
2322 Incremented every time a new collection is created. The current value of the
2323 counter is then assigned as the id of the new collection.
2324
2325- theNamespacePool:
2326- -----------------
2327-
2328- theQNamePool:
2329- -------------
2330-
2331- theItemFactory:
2332- ---------------
2333- Factory to create items.
2334-
2335- theIteratorFactory:
2336- -------------------
2337- Factory to create iterators.
2338-
2339- theNodeFactory:
2340- ---------------
2341- Factory to create node items.
2342-
2343- theDocuments:
2344- -------------
2345- A hashmap that for each xml tree that does not belong to any collection, maps
2346- the URI of the tree to the root node of the tree.
2347-
2348- theCollections:
2349- ---------------
2350- Container which contains the collections of the store. It includes a map that
2351- maps the qname of each collection to the collection's container object.
2352-
2353- theIndices:
2354- -----------
2355- A hashmap that for each index, maps the qname of the index to the index
2356- container object.
2357-
2358- theICs:
2359- -------
2360- A hashmap the for each integrity constraint, maps the qname of the ic to the
2361- ic's container object.
2362+ theTreeCounter:
2363+ ---------------
2364
2365 theReferencesToNodeMap:
2366 -----------------------
2367@@ -127,307 +41,76 @@
2368 A hashmap that maps nodes into their references
2369
2370 ********************************************************************************/
2371-class SimpleStore : public store::Store
2372+class SimpleStore : public Store
2373 {
2374 friend class zorba::StoreManager;
2375
2376 typedef std::map<const zstring, const store::Item*> RefNodeMap;
2377 typedef NodePointerHashMap<zstring> NodeRefMap;
2378
2379-public:
2380- static const char* XS_URI;
2381- static const char* XML_URI;
2382- static const char* ZXSE_URI;
2383-
2384- static const ulong XML_URI_LEN;
2385-
2386-protected:
2387- static const ulong NAMESPACE_POOL_SIZE;
2388- static const ulong DEFAULT_DOCUMENT_SET_SIZE;
2389- static const ulong DEFAULT_URI_COLLECTION_SET_SIZE;
2390- static const ulong DEFAULT_INDICES_SET_SIZE;
2391- static const ulong DEFAULT_INTEGRITY_CONSTRAINT_SET_SIZE;
2392-
2393-public:
2394- zstring theEmptyNs;
2395- zstring theXmlSchemaNs;
2396-
2397- std::vector<store::Item_t> theSchemaTypeNames;
2398- std::map<store::Item*, store::SchemaTypeCode> theSchemaTypeCodes;
2399- store::Item_t XS_UNTYPED_QNAME;
2400- store::Item_t XS_ANY_QNAME;
2401- store::Item_t XS_ANY_SIMPLE_QNAME;
2402-
2403-protected:
2404- ulong theNumUsers;
2405-
2406- ulong theUriCounter;
2407- SYNC_CODE(Mutex theUriCounterMutex;)
2408-
2409+private:
2410 ulong theCollectionCounter;
2411 SYNC_CODE(Mutex theCollectionCounterMutex;)
2412
2413 ulong theTreeCounter;
2414 SYNC_CODE(Mutex theTreeCounterMutex;)
2415
2416- StringPool * theNamespacePool;
2417- QNamePool * theQNamePool;
2418-
2419- BasicItemFactory * theItemFactory;
2420- store::IteratorFactory * theIteratorFactory;
2421- NodeFactory * theNodeFactory;
2422- PULPrimitiveFactory * thePULFactory;
2423-
2424- DocumentSet theDocuments;
2425- CollectionSet* theCollections;
2426- IndexSet theIndices;
2427- ICSet theICs;
2428- IndexSet theHashMaps;
2429-
2430- SYNC_CODE(Lock theGlobalLock;)
2431-
2432- long theTraceLevel;
2433-
2434 RefNodeMap theReferencesToNodeMap;
2435 NodeRefMap theNodeToReferencesMap;
2436
2437-#ifndef ZORBA_NO_FULL_TEXT
2438- internal::StemmerProvider const * theStemmerProvider;
2439- TokenizerProvider const * theTokenizerProvider;
2440-#endif /* ZORBA_NO_FULL_TEXT */
2441-
2442 public:
2443- void shutdown(bool soft = true);
2444-
2445- store::ItemFactory* getItemFactory() const;
2446-
2447- store::IteratorFactory* getIteratorFactory() const { return theIteratorFactory; }
2448-
2449- NodeFactory& getNodeFactory() const { return *theNodeFactory; }
2450-
2451- PULPrimitiveFactory& getPULFactory() const { return *thePULFactory; }
2452-
2453- StringPool& getNamespacePool() const { return *theNamespacePool; }
2454-
2455- QNamePool& getQNamePool() const { return *theQNamePool; }
2456-
2457- SYNC_CODE(Lock& getGlobalLock() { return theGlobalLock; })
2458-
2459- long getTraceLevel() const { return theTraceLevel; }
2460-
2461- XmlLoader* getXmlLoader(
2462- XQueryDiagnostics*,
2463- const store::LoadProperties& loadProperties);
2464-
2465+ ulong createTreeId();
2466+
2467 ulong createCollectionId();
2468
2469- ulong createTreeId();
2470-
2471 store::Collection_t createCollection(
2472 const store::Item_t& aName,
2473 const std::vector<store::Annotation_t>& annotations,
2474 const store::Item_t& aNodeType,
2475 bool aDynamicCollection = false);
2476
2477- void deleteCollection(
2478- const store::Item* aName,
2479- bool aDynamicCollection = false);
2480-
2481- store::Collection_t getCollection(
2482- const store::Item* aName,
2483- bool aDynamicCollection = false);
2484-
2485- void addCollection(store::Collection_t& collection);
2486-
2487- store::Iterator_t listCollectionNames(bool aDynamicCollections = false);
2488-
2489- store::Index_t createIndex(
2490- const store::Item_t& qname,
2491- const store::IndexSpecification& spec,
2492- store::Iterator* sourceIter);
2493-
2494- // needs to be virtual to allow implementation of additional stores
2495- virtual void populateValueIndex(
2496- const store::Index_t& index,
2497- store::Iterator* sourceIter,
2498- ulong numColumns);
2499-
2500- // needs to be virtual to allow implementation of additional stores
2501- virtual void populateGeneralIndex(
2502- const store::Index_t& index,
2503- store::Iterator* sourceIter,
2504- ulong numColumns);
2505-
2506- // needs to be virtual to allow implementation of additional stores
2507- virtual store::Index_t refreshIndex(
2508- const store::Item_t& qname,
2509- const store::IndexSpecification& spec,
2510- store::Iterator* sourceIter);
2511-
2512- // needs to be virtual to allow implementation of additional stores
2513- virtual const IndexSet& getIndices() const { return theIndices; }
2514-
2515- void addIndex(store::Index_t& index);
2516-
2517- store::Index* getIndex(const store::Item* qname);
2518-
2519- void deleteIndex(const store::Item* qname);
2520-
2521- store::Iterator_t listIndexNames();
2522-
2523- store::IC_t activateIC(
2524- const store::Item_t& icQName,
2525- const store::Item_t& collectionQName,
2526- bool& isApplied);
2527-
2528- store::IC_t activateForeignKeyIC(
2529- const store::Item_t& icQName,
2530- const store::Item_t& fromCollectionQName,
2531- const store::Item_t& toCollectionQName,
2532- bool& isApplied);
2533-
2534- store::IC_t deactivateIC(
2535- const store::Item_t& icQName,
2536- bool& isApplied);
2537-
2538- store::Iterator_t listActiveICNames();
2539-
2540- store::IC* getIC(const store::Item* icQName);
2541-
2542- /*****************************************************************************
2543-
2544- *****************************************************************************/
2545- virtual store::Index* getMap(const store::Item* aQName) const;
2546-
2547- virtual store::Iterator_t listMapNames();
2548-
2549- /*****************************************************************************
2550-
2551- *****************************************************************************/
2552- store::Item_t loadDocument(
2553- const zstring& baseUri,
2554- const zstring& docUri,
2555- std::istream& stream,
2556- const store::LoadProperties& loadProperties);
2557-
2558- store::Item_t loadDocument(
2559- const zstring& baseUri,
2560- const zstring& docUri,
2561- std::istream* stream,
2562- const store::LoadProperties& loadProperties);
2563-
2564- /*****************************************************************************
2565-
2566- *****************************************************************************/
2567- void addNode(const zstring& uri, const store::Item_t& node);
2568-
2569- store::Iterator_t getDocumentNames() const;
2570-
2571- store::Item_t getDocument(const zstring& uri);
2572-
2573- void deleteDocument(const zstring& uri);
2574-
2575- void deleteAllDocuments();
2576-
2577- /*****************************************************************************
2578-
2579- *****************************************************************************/
2580- store::Index_t createHashMap(
2581- const store::Item_t& aQName,
2582- const store::IndexSpecification& aSpec);
2583-
2584- store::Index_t destroyHashMap(const store::Item_t& aQName);
2585-
2586- store::Index_t getHashMap(const store::Item_t& aQName) const;
2587-
2588- void addHashMap(const store::Index_t& aMap);
2589-
2590- /*****************************************************************************
2591-
2592- *****************************************************************************/
2593- short compareNodes(store::Item* node1, store::Item* node2) const;
2594-
2595- store::Iterator_t sortNodes(
2596- store::Iterator* iterator,
2597- bool ascendent,
2598- bool duplicateElemination,
2599- bool aAllowAtomics = false);
2600-
2601- store::Iterator_t distinctNodes(store::Iterator* input, bool aAllowAtomics);
2602-
2603- store::Iterator_t checkDistinctNodes(store::Iterator* input);
2604-
2605- bool getStructuralInformation(store::Item_t& result, const store::Item* node);
2606-
2607- bool getPathInfo(
2608- const store::Item* docUri,
2609- std::vector<const store::Item*>& contextPath,
2610- std::vector<const store::Item*>& relativePath,
2611- bool isAttrPath,
2612- bool& found,
2613- bool& unique);
2614-
2615- /* ------------------------ Node Reference Management ---------------------------*/
2616-
2617- bool getNodeReference(store::Item_t& result, const store::Item* node);
2618-
2619- bool hasReference(const store::Item* node);
2620-
2621- bool getNodeByReference(store::Item_t& result, const zstring& reference);
2622-
2623- bool unregisterNode(XmlNode* node);
2624-
2625- /* ------------------------ Temp Sequence Management ---------------------------*/
2626-
2627- store::TempSeq_t createTempSeq(bool lazy);
2628-
2629- store::TempSeq_t createTempSeq(const store::Iterator_t& iterator, bool lazy);
2630-
2631- store::TempSeq_t createTempSeq(std::vector<store::Item_t>& item_v);
2632-
2633- store::TempSeq_t createTempSeq(store::Item_t& item);
2634-
2635-#ifndef ZORBA_NO_FULL_TEXT
2636- internal::StemmerProvider const* getStemmerProvider() const;
2637-
2638- void setStemmerProvider(internal::StemmerProvider const*);
2639-#endif /* ZORBA_NO_FULL_TEXT */
2640-
2641 protected:
2642 SimpleStore();
2643
2644 virtual ~SimpleStore();
2645-
2646+
2647 void init();
2648-
2649- void initTypeNames();
2650-
2651- // Functions to create/destory the node and item factories. These functions
2652- // are called from init and shutdown, respectively. Having this functionality
2653- // factorized allows others to derive from the SimpleStore and provide their
2654- // own factories.
2655-
2656- virtual NodeFactory* createNodeFactory() const;
2657-
2658- virtual void destroyNodeFactory(NodeFactory*) const;
2659-
2660- virtual BasicItemFactory* createItemFactory() const;
2661-
2662- virtual void destroyItemFactory(BasicItemFactory*) const;
2663-
2664- virtual PULPrimitiveFactory* createPULPrimitiveFactory() const;
2665-
2666- virtual void destroyPULPrimitiveFactory(PULPrimitiveFactory*) const;
2667-
2668- virtual CollectionSet* createCollectionSet() const;
2669-
2670- virtual void destroyCollectionSet(CollectionSet*) const;
2671-
2672-#ifndef ZORBA_NO_FULL_TEXT
2673- TokenizerProvider const* getTokenizerProvider() const;
2674-
2675- void setTokenizerProvider(TokenizerProvider const*);
2676-#endif /* ZORBA_NO_FULL_TEXT */
2677+
2678+ void shutdown(bool soft);
2679+
2680+ NodeFactory* createNodeFactory() const;
2681+
2682+ void destroyNodeFactory(NodeFactory*) const;
2683+
2684+ store::ItemFactory* createItemFactory() const;
2685+
2686+ void destroyItemFactory(store::ItemFactory*) const;
2687+
2688+ store::IteratorFactory* createIteratorFactory() const;
2689+
2690+ void destroyIteratorFactory(store::IteratorFactory*) const;
2691+
2692+ PULPrimitiveFactory* createPULFactory() const;
2693+
2694+ void destroyPULFactory(PULPrimitiveFactory*) const;
2695+
2696+ CollectionSet* createCollectionSet() const;
2697+
2698+ void destroyCollectionSet(CollectionSet*) const;
2699+
2700+ bool unregisterNode(XmlNode* node);
2701+
2702+ //
2703+ // Store api methods
2704+ //
2705+
2706+ bool getNodeReference(store::Item_t& result, const store::Item* node);
2707+
2708+ bool hasReference(const store::Item* node);
2709+
2710+ bool getNodeByReference(
2711+ store::Item_t& result,
2712+ const zstring& reference);
2713 };
2714
2715 } // namespace store
2716
2717=== added file 'src/store/naive/store.cpp'
2718--- src/store/naive/store.cpp 1970-01-01 00:00:00 +0000
2719+++ src/store/naive/store.cpp 2012-03-27 01:25:22 +0000
2720@@ -0,0 +1,1322 @@
2721+/*
2722+ * Copyright 2006-2008 The FLWOR Foundation.
2723+ *
2724+ * Licensed under the Apache License, Version 2.0 (the "License");
2725+ * you may not use this file except in compliance with the License.
2726+ * You may obtain a copy of the License at
2727+ *
2728+ * http://www.apache.org/licenses/LICENSE-2.0
2729+ *
2730+ * Unless required by applicable law or agreed to in writing, software
2731+ * distributed under the License is distributed on an "AS IS" BASIS,
2732+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
2733+ * See the License for the specific language governing permissions and
2734+ * limitations under the License.
2735+ */
2736+#include "stdafx.h"
2737+
2738+#include <iostream>
2739+#include <climits>
2740+#include <memory>
2741+
2742+#include <libxml/parser.h>
2743+
2744+#include "zorbautils/hashfun.h"
2745+#include "zorbautils/fatal.h"
2746+#include "zorbatypes/rchandle.h"
2747+#include "diagnostics/xquery_diagnostics.h"
2748+#include "diagnostics/assert.h"
2749+#include "diagnostics/util_macros.h"
2750+
2751+#include "store/api/pul.h"
2752+#include "store/api/xs_type_codes.h"
2753+
2754+#include "properties.h"
2755+#include "string_pool.h"
2756+#include "store.h"
2757+#include "simple_temp_seq.h"
2758+#include "simple_lazy_temp_seq.h"
2759+#include "collection.h"
2760+#include "collection_set.h"
2761+#include "simple_index.h"
2762+#include "simple_index_value.h"
2763+#include "simple_index_general.h"
2764+#include "simple_ic.h"
2765+#include "qname_pool.h"
2766+#include "loader.h"
2767+#include "store_defs.h"
2768+#include "node_items.h"
2769+#include "dataguide.h"
2770+#include "node_iterators.h"
2771+#include "simple_item_factory.h"
2772+#include "simple_iterator_factory.h"
2773+#include "query_context.h"
2774+#include "item_iterator.h"
2775+#include "node_factory.h"
2776+#include "name_iterator.h"
2777+#include "document_name_iterator.h"
2778+#include "pul_primitive_factory.h"
2779+
2780+#include "util/cxx_util.h"
2781+#include "util/uuid/uuid.h"
2782+#include "zorbautils/string_util.h"
2783+
2784+#ifndef ZORBA_NO_FULL_TEXT
2785+#include "runtime/full_text/default_tokenizer.h"
2786+#include "runtime/full_text/stemmer.h"
2787+#endif /* ZORBA_NO_FULL_TEXT */
2788+
2789+namespace zorba
2790+{
2791+
2792+namespace simplestore
2793+{
2794+
2795+typedef rchandle<store::TempSeq> TempSeq_t;
2796+
2797+
2798+/*******************************************************************************
2799+ Store static data
2800+********************************************************************************/
2801+const ulong Store::NAMESPACE_POOL_SIZE = 128;
2802+const ulong Store::DEFAULT_DOCUMENT_SET_SIZE = 32;
2803+const ulong Store::DEFAULT_URI_COLLECTION_SET_SIZE = 32;
2804+const ulong Store::DEFAULT_INDICES_SET_SIZE = 32;
2805+const ulong Store::DEFAULT_INTEGRITY_CONSTRAINT_SET_SIZE = 32;
2806+
2807+const char* Store::XS_URI = "http://www.w3.org/2001/XMLSchema";
2808+const char* Store::XML_URI = "http://www.w3.org/2001/XML/1998/namespace";
2809+const char* Store::ZXSE_URI = "http://www.zorba-xquery.com/zorba/schema-extensions";
2810+
2811+const ulong Store::XML_URI_LEN = sizeof(Store::XML_URI);
2812+
2813+
2814+/*******************************************************************************
2815+
2816+********************************************************************************/
2817+Store::Store()
2818+ :
2819+ theNumUsers(0),
2820+ theNamespacePool(NULL),
2821+ theQNamePool(NULL),
2822+ theItemFactory(NULL),
2823+ theIteratorFactory(NULL),
2824+ theNodeFactory(NULL),
2825+ thePULFactory(NULL),
2826+ theDocuments(DEFAULT_DOCUMENT_SET_SIZE, true),
2827+ theCollections(0),
2828+ theIndices(0, NULL, DEFAULT_INDICES_SET_SIZE, true),
2829+ theICs(0, NULL, DEFAULT_INTEGRITY_CONSTRAINT_SET_SIZE, true),
2830+ theHashMaps(0, NULL, DEFAULT_INDICES_SET_SIZE, true),
2831+ theTraceLevel(0)
2832+#ifndef ZORBA_NO_FULL_TEXT
2833+ , theStemmerProvider( nullptr )
2834+ , theTokenizerProvider( nullptr )
2835+#endif /* ZORBA_NO_FULL_TEXT */
2836+{
2837+}
2838+
2839+
2840+/*******************************************************************************
2841+
2842+********************************************************************************/
2843+Store::~Store()
2844+{
2845+}
2846+
2847+
2848+/*******************************************************************************
2849+
2850+********************************************************************************/
2851+void Store::init()
2852+{
2853+ SYNC_CODE(AutoLock lock(getGlobalLock(), Lock::WRITE);)
2854+
2855+ if (theNumUsers == 0)
2856+ {
2857+ // This initializes the libxml2 library and checks potential ABI mismatches
2858+ // between the version it was compiled for and the actual shared library used.
2859+ // Calling its init is done here because we also want to free it at the end,
2860+ // i.e. when the store is shutdown
2861+ LIBXML_TEST_VERSION
2862+
2863+ store::Properties::load(0, NULL);
2864+
2865+ theNamespacePool = new StringPool(NAMESPACE_POOL_SIZE);
2866+
2867+ theNamespacePool->insertc("", theEmptyNs);
2868+ theNamespacePool->insertc(XS_URI, theXmlSchemaNs);
2869+
2870+ theQNamePool = new QNamePool(QNamePool::MAX_CACHE_SIZE, theNamespacePool);
2871+
2872+ // createItemFactory uses theNamespacePool and theQNamePool
2873+ // they have to be created before this function is called
2874+ theItemFactory = createItemFactory();
2875+
2876+ initTypeNames();
2877+
2878+ theIteratorFactory = createIteratorFactory();
2879+
2880+ theNodeFactory = createNodeFactory();
2881+
2882+ thePULFactory = createPULFactory();
2883+
2884+ theTraceLevel = store::Properties::instance()->storeTraceLevel();
2885+
2886+ theCollections = createCollectionSet();
2887+
2888+ StoreManagerImpl::theStore = this;
2889+ }
2890+
2891+ ++theNumUsers;
2892+}
2893+
2894+
2895+/*******************************************************************************
2896+
2897+********************************************************************************/
2898+void Store::initTypeNames()
2899+{
2900+ const char* ns = XS_URI;
2901+ BasicItemFactory* f = static_cast<BasicItemFactory*>(theItemFactory);
2902+
2903+ theSchemaTypeNames.resize(store::XS_LAST);
2904+
2905+ f->createQName(XS_UNTYPED_QNAME, ns, "xs", "untyped");
2906+
2907+ f->createQName(XS_ANY_QNAME, ns, "xs", "anyType");
2908+
2909+ f->createQName(XS_ANY_SIMPLE_QNAME, ns, "xs", "anySimpleType");
2910+
2911+ f->createQName(theSchemaTypeNames[store::XS_ANY_ATOMIC], ns, "xs", "anyAtomicType");
2912+
2913+ f->createQName(theSchemaTypeNames[store::XS_UNTYPED_ATOMIC], ns, "xs", "untypedAtomic");
2914+
2915+ f->createQName(theSchemaTypeNames[store::XS_ANY_URI], ns, "xs", "anyURI");
2916+
2917+ f->createQName(theSchemaTypeNames[store::XS_QNAME], ns, "xs", "QName");
2918+
2919+ f->createQName(theSchemaTypeNames[store::XS_NOTATION], ns, "xs", "NOTATION");
2920+
2921+ f->createQName(theSchemaTypeNames[store::XS_STRING], ns, "xs", "string");
2922+ f->createQName(theSchemaTypeNames[store::XS_NORMALIZED_STRING], ns, "xs", "normalizedString");
2923+ f->createQName(theSchemaTypeNames[store::XS_TOKEN], ns, "xs", "token");
2924+ f->createQName(theSchemaTypeNames[store::XS_NMTOKEN], ns, "xs", "NMTOKEN");
2925+ f->createQName(theSchemaTypeNames[store::XS_LANGUAGE], ns, "xs", "language");
2926+ f->createQName(theSchemaTypeNames[store::XS_NAME], ns, "xs", "Name");
2927+ f->createQName(theSchemaTypeNames[store::XS_NCNAME], ns, "xs", "NCName");
2928+ f->createQName(theSchemaTypeNames[store::XS_ID], ns, "xs", "ID");
2929+ f->createQName(theSchemaTypeNames[store::XS_IDREF], ns, "xs", "IDREF");
2930+ f->createQName(theSchemaTypeNames[store::XS_ENTITY], ns, "xs", "ENTITY");
2931+
2932+ f->createQName(theSchemaTypeNames[store::XS_DATETIME], ns, "xs", "dateTime");
2933+ f->createQName(theSchemaTypeNames[store::XS_DATE], ns, "xs", "date");
2934+ f->createQName(theSchemaTypeNames[store::XS_TIME], ns, "xs", "time");
2935+ f->createQName(theSchemaTypeNames[store::XS_GYEAR_MONTH], ns, "xs", "gYearMonth");
2936+ f->createQName(theSchemaTypeNames[store::XS_GYEAR], ns, "xs", "gYear");
2937+ f->createQName(theSchemaTypeNames[store::XS_GMONTH_DAY], ns, "xs", "gMonthDay");
2938+ f->createQName(theSchemaTypeNames[store::XS_GDAY], ns, "xs", "gDay");
2939+ f->createQName(theSchemaTypeNames[store::XS_GMONTH], ns, "xs", "gMonth");
2940+
2941+ f->createQName(theSchemaTypeNames[store::XS_DURATION], ns, "xs", "duration");
2942+ f->createQName(theSchemaTypeNames[store::XS_DT_DURATION], ns, "xs", "dayTimeDuration");
2943+ f->createQName(theSchemaTypeNames[store::XS_YM_DURATION], ns, "xs", "yearMonthDuration");
2944+
2945+ f->createQName(theSchemaTypeNames[store::XS_FLOAT], ns, "xs", "float");
2946+ f->createQName(theSchemaTypeNames[store::XS_DOUBLE], ns, "xs", "double");
2947+ f->createQName(theSchemaTypeNames[store::XS_DECIMAL], ns, "xs", "decimal");
2948+ f->createQName(theSchemaTypeNames[store::XS_INTEGER], ns, "xs", "integer");
2949+ f->createQName(theSchemaTypeNames[store::XS_NON_POSITIVE_INTEGER], ns, "xs", "nonPositiveInteger");
2950+ f->createQName(theSchemaTypeNames[store::XS_NON_NEGATIVE_INTEGER], ns, "xs", "nonNegativeInteger");
2951+ f->createQName(theSchemaTypeNames[store::XS_NEGATIVE_INTEGER], ns, "xs", "negativeInteger");
2952+ f->createQName(theSchemaTypeNames[store::XS_POSITIVE_INTEGER], ns, "xs", "positiveInteger");
2953+
2954+ f->createQName(theSchemaTypeNames[store::XS_LONG], ns, "xs", "long");
2955+ f->createQName(theSchemaTypeNames[store::XS_INT], ns, "xs", "int");
2956+ f->createQName(theSchemaTypeNames[store::XS_SHORT], ns, "xs", "short");
2957+ f->createQName(theSchemaTypeNames[store::XS_BYTE], ns, "xs", "byte");
2958+ f->createQName(theSchemaTypeNames[store::XS_UNSIGNED_LONG], ns, "xs", "unsignedLong");
2959+ f->createQName(theSchemaTypeNames[store::XS_UNSIGNED_INT], ns, "xs", "unsignedInt");
2960+ f->createQName(theSchemaTypeNames[store::XS_UNSIGNED_SHORT], ns, "xs", "unsignedShort");
2961+ f->createQName(theSchemaTypeNames[store::XS_UNSIGNED_BYTE], ns, "xs", "unsignedByte");
2962+
2963+ f->createQName(theSchemaTypeNames[store::XS_BASE64BINARY], ns, "xs", "base64Binary");
2964+ f->createQName(theSchemaTypeNames[store::XS_HEXBINARY], ns, "xs", "hexBinary");
2965+ f->createQName(theSchemaTypeNames[store::XS_BOOLEAN], ns, "xs", "boolean");
2966+
2967+ for (ulong i = 0; i < store::XS_LAST; ++i)
2968+ {
2969+ theSchemaTypeCodes[theSchemaTypeNames[i].getp()] =
2970+ static_cast<store::SchemaTypeCode>(i);
2971+ }
2972+}
2973+
2974+/*******************************************************************************
2975+
2976+********************************************************************************/
2977+void Store::shutdown(bool soft)
2978+{
2979+ SYNC_CODE(AutoLock lock(getGlobalLock(), Lock::WRITE);)
2980+
2981+ if (theNumUsers == 0)
2982+ return;
2983+
2984+ --theNumUsers;
2985+
2986+ if (theNumUsers == 0 || soft == false)
2987+ {
2988+ theIndices.clear();
2989+ theICs.clear();
2990+ theHashMaps.clear();
2991+
2992+ if (theCollections != NULL)
2993+ {
2994+ theCollections->clear();
2995+ destroyCollectionSet(theCollections);
2996+ theCollections = NULL;
2997+ }
2998+
2999+ theDocuments.clear();
3000+
3001+ if (thePULFactory != NULL)
3002+ {
3003+ destroyPULFactory(thePULFactory);
3004+ thePULFactory = NULL;
3005+ }
3006+
3007+ if (theNodeFactory != NULL)
3008+ {
3009+ destroyNodeFactory(theNodeFactory);
3010+ theNodeFactory = NULL;
3011+ }
3012+
3013+ if (theItemFactory != NULL)
3014+ {
3015+ destroyItemFactory(theItemFactory);
3016+ theItemFactory = NULL;
3017+ }
3018+
3019+ if (theIteratorFactory != NULL)
3020+ {
3021+ destroyIteratorFactory(theIteratorFactory);
3022+ theIteratorFactory = NULL;
3023+ }
3024+
3025+ if (theQNamePool != NULL)
3026+ {
3027+ csize numTypes = theSchemaTypeNames.size();
3028+ for (csize i = 0; i < numTypes; ++i)
3029+ theSchemaTypeNames[i] = NULL;
3030+
3031+ XS_UNTYPED_QNAME = NULL;
3032+ XS_ANY_QNAME = NULL;
3033+ XS_ANY_SIMPLE_QNAME = NULL;
3034+
3035+ delete theQNamePool;
3036+ theQNamePool = NULL;
3037+ }
3038+
3039+ if (theNamespacePool != NULL)
3040+ {
3041+ theEmptyNs.~zstring();
3042+ theXmlSchemaNs.~zstring();
3043+
3044+ delete theNamespacePool;
3045+ theNamespacePool = NULL;
3046+ }
3047+
3048+ if (theIteratorFactory != NULL)
3049+ {
3050+ delete theIteratorFactory;
3051+ theIteratorFactory = NULL;
3052+ }
3053+
3054+ if (theNodeFactory != NULL)
3055+ {
3056+ delete theNodeFactory;
3057+ theNodeFactory = NULL;
3058+ }
3059+
3060+ // do cleanup of the libxml2 library
3061+ // however, after that, a user will have to call
3062+ // LIBXML_TEST_VERSION if he wants to use libxml2
3063+ // beyond the lifecycle of zorba
3064+ xmlCleanupParser();
3065+
3066+ theNumUsers = 0;
3067+
3068+ StoreManagerImpl::theStore = NULL;
3069+ }
3070+}
3071+
3072+
3073+/*******************************************************************************
3074+
3075+********************************************************************************/
3076+XmlLoader* Store::getXmlLoader(
3077+ XQueryDiagnostics* aXQueryDiagnostics,
3078+ const store::LoadProperties& loadProperties)
3079+{
3080+ if (loadProperties.getParseExternalParsedEntity())
3081+ return new FragmentXmlLoader(theItemFactory,
3082+ aXQueryDiagnostics,
3083+ loadProperties,
3084+ store::Properties::instance()->buildDataguide());
3085+
3086+ else if (loadProperties.getDTDValidate())
3087+ return new DtdXmlLoader(theItemFactory,
3088+ aXQueryDiagnostics,
3089+ loadProperties,
3090+ store::Properties::instance()->buildDataguide());
3091+ else
3092+ return new FastXmlLoader(theItemFactory,
3093+ aXQueryDiagnostics,
3094+ loadProperties,
3095+ store::Properties::instance()->buildDataguide());
3096+}
3097+
3098+
3099+/*******************************************************************************
3100+
3101+********************************************************************************/
3102+void Store::addCollection(store::Collection_t& collection)
3103+{
3104+ const store::Item* lName = collection->getName();
3105+
3106+ bool inserted = theCollections->insert(lName, collection);
3107+
3108+ if (!inserted)
3109+ {
3110+ throw ZORBA_EXCEPTION(zerr::ZSTR0008_COLLECTION_ALREADY_EXISTS,
3111+ ERROR_PARAMS(lName->getStringValue()));
3112+ }
3113+}
3114+
3115+
3116+/*******************************************************************************
3117+ Delete the collection with the given QName. If there is no collection with
3118+ that QName, this method is a NOOP.
3119+********************************************************************************/
3120+void Store::deleteCollection(
3121+ const store::Item* aName,
3122+ bool aDynamicCollection)
3123+{
3124+ if (aName == NULL)
3125+ return;
3126+
3127+ if (!theCollections->remove(aName, aDynamicCollection))
3128+ {
3129+ throw ZORBA_EXCEPTION(zerr::ZSTR0009_COLLECTION_NOT_FOUND,
3130+ ERROR_PARAMS(aName->getStringValue()));
3131+ }
3132+}
3133+
3134+
3135+/*******************************************************************************
3136+ Return an rchandle to the Collection object corresponding to the given QName,
3137+ or NULL if there is no collection with that QName.
3138+********************************************************************************/
3139+store::Collection_t Store::getCollection(
3140+ const store::Item* aName,
3141+ bool aDynamicCollection)
3142+{
3143+ if (aName == NULL)
3144+ return NULL;
3145+
3146+ store::Collection_t collection;
3147+ if (theCollections->get(aName, collection, aDynamicCollection))
3148+ {
3149+ return collection;
3150+ }
3151+ else
3152+ {
3153+ return NULL;
3154+ }
3155+}
3156+
3157+
3158+/*******************************************************************************
3159+ Returns an iterator that lists the QName's of all the available collections.
3160+********************************************************************************/
3161+store::Iterator_t Store::listCollectionNames(bool aDynamicCollections)
3162+{
3163+ return theCollections->names(aDynamicCollections);
3164+}
3165+
3166+
3167+/*******************************************************************************
3168+ Create an index with a given URI and return an rchandle to the index object.
3169+ If an index with the given URI exists already and the index we want to create
3170+ is not a temporary one, raise an error.
3171+********************************************************************************/
3172+store::Index_t Store::createIndex(
3173+ const store::Item_t& qname,
3174+ const store::IndexSpecification& spec,
3175+ store::Iterator* sourceIter)
3176+{
3177+ store::Item* qname2 = const_cast<store::Item*>(qname.getp());
3178+ store::Index_t index;
3179+
3180+ if (!spec.theIsTemp && theIndices.get(qname.getp(), index))
3181+ {
3182+ throw ZORBA_EXCEPTION(zerr::ZSTR0001_INDEX_ALREADY_EXISTS,
3183+ ERROR_PARAMS(qname->getStringValue()));
3184+ }
3185+
3186+ if (spec.theIsGeneral && spec.theIsSorted)
3187+ {
3188+ index = new GeneralTreeIndex(qname, spec);
3189+ populateGeneralIndex(index, sourceIter, spec.getNumColumns());
3190+ }
3191+ else if (spec.theIsSorted)
3192+ {
3193+ index = new ValueTreeIndex(qname, spec);
3194+ populateValueIndex(index, sourceIter, spec.getNumColumns());
3195+ }
3196+ else if (spec.theIsGeneral)
3197+ {
3198+ index = new GeneralHashIndex(qname, spec);
3199+ populateGeneralIndex(index, sourceIter, spec.getNumColumns());
3200+ }
3201+ else
3202+ {
3203+ index = new ValueHashIndex(qname, spec);
3204+ populateValueIndex(index, sourceIter, spec.getNumColumns());
3205+ }
3206+
3207+ if (!spec.theIsTemp)
3208+ {
3209+ theIndices.insert(qname2, index);
3210+ }
3211+
3212+ return index;
3213+}
3214+
3215+
3216+/*******************************************************************************
3217+
3218+********************************************************************************/
3219+void Store::populateValueIndex(
3220+ const store::Index_t& aIndex,
3221+ store::Iterator* aSourceIter,
3222+ ulong aNumColumns)
3223+{
3224+ if (!aSourceIter)
3225+ return;
3226+
3227+ store::Item_t domainItem;
3228+ store::IndexKey* key = NULL;
3229+
3230+ ValueIndex* index = static_cast<ValueIndex*>(aIndex.getp());
3231+
3232+ aSourceIter->open();
3233+
3234+ try
3235+ {
3236+ while (aSourceIter->next(domainItem))
3237+ {
3238+ if (domainItem->isNode() &&
3239+ domainItem->getCollection() == NULL &&
3240+ !index->isTemporary())
3241+ {
3242+ RAISE_ERROR_NO_LOC(zerr::ZDDY0020_INDEX_DOMAIN_NODE_NOT_IN_COLLECTION,
3243+ ERROR_PARAMS(index->getName()->getStringValue()));
3244+ }
3245+
3246+ if (key == NULL)
3247+ key = new store::IndexKey(aNumColumns);
3248+
3249+ for (ulong i = 0; i < aNumColumns; ++i)
3250+ {
3251+ if (!aSourceIter->next((*key)[i]))
3252+ {
3253+ // The source iter is a ValueIndexEntryBuilderIterator, whose next()
3254+ // method is guaranteed to return true exactly once. The result from
3255+ // this single successful next() may be a NULL item.
3256+ RAISE_ERROR_NO_LOC(zerr::ZXQP0003_INTERNAL_ERROR,
3257+ ERROR_PARAMS(ZED(IncompleteKeyInIndexBuild)));
3258+ }
3259+ }
3260+
3261+ index->insert(key, domainItem);
3262+ }
3263+ }
3264+ catch(...)
3265+ {
3266+ if (key != NULL)
3267+ delete key;
3268+
3269+ aSourceIter->close();
3270+ throw;
3271+ }
3272+
3273+ if (key != NULL)
3274+ delete key;
3275+
3276+ aSourceIter->close();
3277+}
3278+
3279+
3280+/*******************************************************************************
3281+
3282+********************************************************************************/
3283+void Store::populateGeneralIndex(
3284+ const store::Index_t& idx,
3285+ store::Iterator* sourceIter,
3286+ ulong numColumns)
3287+{
3288+ store::Item_t domainNode;
3289+ store::Item_t firstKeyItem;
3290+ store::Item_t keyItem;
3291+
3292+ GeneralIndex* index = static_cast<GeneralIndex*>(idx.getp());
3293+
3294+ sourceIter->open();
3295+
3296+ try
3297+ {
3298+ if (sourceIter->next(domainNode))
3299+ {
3300+ bool more = true;
3301+
3302+ assert(domainNode->isNode());
3303+ assert(keyItem == NULL);
3304+
3305+ // Compute the keys associated with the current domain node. Note: We
3306+ // must check whether the domain node has more than one key, before we
3307+ // do any insertions in the index.
3308+ while (more)
3309+ {
3310+ if (domainNode->getCollection() == NULL && !index->isTemporary())
3311+ {
3312+ RAISE_ERROR_NO_LOC(zerr::ZDDY0020_INDEX_DOMAIN_NODE_NOT_IN_COLLECTION,
3313+ ERROR_PARAMS(index->getName()->getStringValue()));
3314+ }
3315+
3316+ // Compute 1st key, or next domain node
3317+ more = sourceIter->next(firstKeyItem);
3318+
3319+ // If current node has no keys, put it in the "null" entry and continue
3320+ // with the next domain node, if nay.
3321+ if (!more || firstKeyItem->isNode())
3322+ {
3323+ index->insert(keyItem, domainNode);
3324+
3325+ domainNode.transfer(firstKeyItem);
3326+ continue;
3327+ }
3328+
3329+ // Compute 2nd key, or next domain node
3330+ more = sourceIter->next(keyItem);
3331+
3332+ // If current domain node has exactly 1 key, insert it in the index
3333+ // and continue with next domain node, if any.
3334+ if (!more || keyItem->isNode())
3335+ {
3336+ index->insert(firstKeyItem, domainNode);
3337+
3338+ domainNode.transfer(keyItem);
3339+ continue;
3340+ }
3341+
3342+ // Current domain node has at least 2 keys. So insert them in the index.
3343+ // Note: we have to copy the domainNode rchandle because index->insert()
3344+ // will transfer the given node.
3345+ index->setMultiKey();
3346+
3347+ store::Item_t node = domainNode;
3348+ index->insert(firstKeyItem, node);
3349+ node = domainNode;
3350+ index->insert(keyItem, node);
3351+
3352+ // Compute next keys or next domain node.
3353+ while ((more = sourceIter->next(keyItem)))
3354+ {
3355+ if (keyItem->isNode())
3356+ {
3357+ domainNode.transfer(keyItem);
3358+ break;
3359+ }
3360+
3361+ node = domainNode;
3362+ index->insert(keyItem, node);
3363+ }
3364+ }
3365+ }
3366+ }
3367+ catch(...)
3368+ {
3369+ sourceIter->close();
3370+
3371+ throw;
3372+ }
3373+
3374+ sourceIter->close();
3375+}
3376+
3377+
3378+/*******************************************************************************
3379+ Refreshes an index with a given URI and return an rchandle to the index object.
3380+ If an index with the given URI exists already and the index we want to create
3381+ is not a temporary one, raise an error.
3382+********************************************************************************/
3383+store::Index_t Store::refreshIndex(
3384+ const store::Item_t& qname,
3385+ const store::IndexSpecification& spec,
3386+ store::Iterator* sourceIter)
3387+{
3388+ store::Index_t index;
3389+ store::Item* non_const_items = const_cast<store::Item*>(qname.getp());
3390+
3391+ if (!theIndices.get(non_const_items, index))
3392+ {
3393+ throw ZORBA_EXCEPTION(
3394+ zerr::ZSTR0002_INDEX_DOES_NOT_EXIST,
3395+ ERROR_PARAMS( qname->getStringValue() )
3396+ );
3397+ }
3398+
3399+ deleteIndex(qname);
3400+
3401+ try
3402+ {
3403+ createIndex(qname, index->getSpecification(), sourceIter);
3404+ }
3405+ catch (...)
3406+ {
3407+ addIndex(index);
3408+ throw;
3409+ }
3410+
3411+ return index;
3412+}
3413+
3414+
3415+/*******************************************************************************
3416+
3417+********************************************************************************/
3418+void Store::addIndex(store::Index_t& index)
3419+{
3420+ if (index == NULL)
3421+ return;
3422+
3423+ store::Item* qname = const_cast<store::Item*>(index->getName());
3424+
3425+ theIndices.insert(qname, index);
3426+}
3427+
3428+
3429+/*******************************************************************************
3430+
3431+********************************************************************************/
3432+void Store::deleteIndex(const store::Item* qname)
3433+{
3434+ if (qname == NULL)
3435+ return;
3436+
3437+ store::Item* qname2 = const_cast<store::Item*>(qname);
3438+
3439+ theIndices.erase(qname2);
3440+}
3441+
3442+
3443+/*******************************************************************************
3444+
3445+********************************************************************************/
3446+store::Index* Store::getIndex(const store::Item* qname)
3447+{
3448+ if (qname == NULL)
3449+ return NULL;
3450+
3451+ store::Item* qname2 = const_cast<store::Item*>(qname);
3452+ store::Index_t index;
3453+
3454+ if (theIndices.get(qname2, index))
3455+ return index.getp();
3456+
3457+ return NULL;
3458+}
3459+
3460+
3461+/*******************************************************************************
3462+
3463+********************************************************************************/
3464+store::Iterator_t Store::listIndexNames()
3465+{
3466+ return new NameIterator<IndexSet>(theIndices);
3467+}
3468+
3469+
3470+/*******************************************************************************
3471+
3472+********************************************************************************/
3473+store::IC_t Store::activateIC(
3474+ const store::Item_t& icQName,
3475+ const store::Item_t& collectionQName,
3476+ bool& isApplied)
3477+{
3478+ ZORBA_ASSERT(icQName != NULL);
3479+
3480+ store::Item* qname = icQName.getp();
3481+
3482+ store::IC_t ic;
3483+
3484+ if (theICs.get(qname, ic))
3485+ {
3486+ return ic; // already activated => noop
3487+ }
3488+
3489+ ic = new ICCollectionImpl(icQName, collectionQName);
3490+
3491+ theICs.insert(qname, ic);
3492+
3493+ isApplied=true;
3494+ return ic;
3495+}
3496+
3497+
3498+/*******************************************************************************
3499+
3500+********************************************************************************/
3501+store::IC_t Store::activateForeignKeyIC(
3502+ const store::Item_t& icQName,
3503+ const store::Item_t& fromCollectionQName,
3504+ const store::Item_t& toCollectionQName,
3505+ bool& isApplied)
3506+{
3507+ ZORBA_ASSERT(icQName != NULL);
3508+
3509+ store::Item* qname = const_cast<store::Item*>(icQName.getp());
3510+
3511+ store::IC_t ic;
3512+
3513+ if (theICs.get(qname, ic))
3514+ {
3515+ return ic; // already activated => noop
3516+ }
3517+
3518+ ic = new ICForeignKeyImpl(qname, fromCollectionQName, toCollectionQName);
3519+
3520+ theICs.insert(qname, ic);
3521+
3522+ isApplied=true;
3523+ return ic;
3524+}
3525+
3526+
3527+/*******************************************************************************
3528+
3529+********************************************************************************/
3530+store::IC_t
3531+Store::deactivateIC(const store::Item_t& icQName,
3532+ bool& isApplied)
3533+{
3534+ ZORBA_ASSERT(icQName != NULL);
3535+
3536+ store::IC_t ic;
3537+
3538+ if (!theICs.get(icQName.getp(), ic))
3539+ {
3540+ return ic; // already deactivated in the same PUL => noop
3541+ }
3542+
3543+ theICs.erase(icQName.getp());
3544+ isApplied=true;
3545+ return ic;
3546+}
3547+
3548+
3549+/*******************************************************************************
3550+
3551+********************************************************************************/
3552+store::Iterator_t Store::listActiveICNames()
3553+{
3554+ return new NameIterator<ICSet>(theICs);
3555+}
3556+
3557+
3558+/*******************************************************************************
3559+
3560+********************************************************************************/
3561+store::IC* Store::getIC(const store::Item* icQName)
3562+{
3563+ store::Item* qname = const_cast<store::Item*>(icQName);
3564+ store::IC_t ic;
3565+ theICs.get(qname, ic);
3566+
3567+ return ic.getp();
3568+}
3569+
3570+
3571+/*******************************************************************************
3572+
3573+********************************************************************************/
3574+store::Index_t
3575+Store::createHashMap(
3576+ const store::Item_t& aQName,
3577+ const store::IndexSpecification& aSpec)
3578+{
3579+ store::Index_t lIndex;
3580+
3581+ if (theHashMaps.get(aQName.getp(), lIndex))
3582+ {
3583+ throw ZORBA_EXCEPTION(
3584+ zerr::ZSTR0001_INDEX_ALREADY_EXISTS,
3585+ ERROR_PARAMS( aQName->getStringValue() )
3586+ );
3587+ }
3588+
3589+ lIndex = new ValueHashIndex(aQName, aSpec);
3590+
3591+ addHashMap(lIndex);
3592+
3593+ return lIndex;
3594+}
3595+
3596+
3597+/*******************************************************************************
3598+
3599+********************************************************************************/
3600+store::Index_t
3601+Store::destroyHashMap(const store::Item_t& aQName)
3602+{
3603+ store::Index_t lIndex;
3604+ if (!theHashMaps.get(aQName.getp(), lIndex))
3605+ {
3606+ throw ZORBA_EXCEPTION(
3607+ zerr::ZDDY0023_INDEX_DOES_NOT_EXIST,
3608+ ERROR_PARAMS( aQName->getStringValue() )
3609+ );
3610+ }
3611+
3612+ theHashMaps.erase(aQName.getp());
3613+ return lIndex;
3614+}
3615+
3616+
3617+/*******************************************************************************
3618+
3619+********************************************************************************/
3620+store::Index*
3621+Store::getMap(const store::Item* aQName) const
3622+{
3623+ store::Item* lQName = const_cast<store::Item*>(aQName);
3624+
3625+ store::Index_t lIndex;
3626+ const_cast<IndexSet*>(&theHashMaps)->get(lQName, lIndex);
3627+
3628+ return lIndex.getp();
3629+}
3630+
3631+
3632+/*******************************************************************************
3633+
3634+********************************************************************************/
3635+store::Index_t
3636+Store::getHashMap(const store::Item_t& aQName) const
3637+{
3638+ store::Index_t lIndex;
3639+ if (const_cast<IndexSet*>(&theHashMaps)->get(aQName.getp(), lIndex))
3640+ {
3641+ return lIndex;
3642+ }
3643+ else
3644+ {
3645+ return 0;
3646+ }
3647+}
3648+
3649+
3650+/*******************************************************************************
3651+
3652+********************************************************************************/
3653+void
3654+Store::addHashMap(const store::Index_t& aIndex)
3655+{
3656+ store::Item* lName = aIndex->getName();
3657+ store::Index_t lIndex = aIndex;
3658+ theHashMaps.insert(lName, lIndex);
3659+}
3660+
3661+
3662+/*******************************************************************************
3663+
3664+********************************************************************************/
3665+store::Iterator_t Store::listMapNames()
3666+{
3667+ return new NameIterator<IndexSet>(theHashMaps);
3668+}
3669+
3670+
3671+
3672+/*******************************************************************************
3673+
3674+********************************************************************************/
3675+store::Item_t Store::loadDocument(
3676+ const zstring& baseUri,
3677+ const zstring& docUri,
3678+ std::istream& stream,
3679+ const store::LoadProperties& loadProperties)
3680+{
3681+ zstring_b urib;
3682+
3683+ if (!docUri.empty())
3684+ urib.wrap_memory(docUri.data(), docUri.size());
3685+
3686+ XmlNode_t root;
3687+ bool found = theDocuments.get(urib, root);
3688+
3689+ if (found)
3690+ {
3691+ return root.getp();
3692+ }
3693+
3694+ XQueryDiagnostics lXQueryDiagnostics;
3695+ std::auto_ptr<XmlLoader> loader(getXmlLoader(&lXQueryDiagnostics, loadProperties));
3696+
3697+ root = loader->loadXml(baseUri, docUri, stream);
3698+
3699+ if (!lXQueryDiagnostics.errors().empty())
3700+ {
3701+ lXQueryDiagnostics.errors().front()->polymorphic_throw();
3702+ }
3703+
3704+ if (root != NULL && loadProperties.getStoreDocument())
3705+ theDocuments.insert(urib, root);
3706+
3707+ return root.getp();
3708+}
3709+
3710+
3711+/*******************************************************************************
3712+ For lazy loading...
3713+ Param stream is a heap pointer to an input stream. This is to be deallocated
3714+ by Zorba.
3715+********************************************************************************/
3716+store::Item_t Store::loadDocument(
3717+ const zstring& baseUri,
3718+ const zstring& docUri,
3719+ std::istream* stream,
3720+ const store::LoadProperties& loadProperties)
3721+{
3722+ store::Item_t docitem;
3723+ try
3724+ {
3725+ //do full loading for now
3726+ docitem = loadDocument(baseUri, docUri, *stream, loadProperties);
3727+ delete stream;
3728+ }
3729+ catch(...)
3730+ {
3731+ delete stream;
3732+ }
3733+ return docitem;
3734+}
3735+
3736+
3737+/*******************************************************************************
3738+ Add the given node with the given uri to the store. Essentially, this method
3739+ establishes an association between a uri and a node. If the given uri is
3740+ already associated to another node, the method raises an error. If the given
3741+ uri is already associated to the given node, this method is a noop.
3742+********************************************************************************/
3743+void Store::addNode(const zstring& uri, const store::Item_t& node)
3744+{
3745+ ZORBA_ASSERT(!uri.empty());
3746+
3747+ if (node == NULL || !node->isNode())
3748+ {
3749+ RAISE_ERROR_NO_LOC(zerr::ZAPI0021_ITEM_TO_LOAD_IS_NOT_NODE, ERROR_PARAMS(uri));
3750+ }
3751+
3752+ XmlNode_t root = reinterpret_cast<XmlNode*>(node.getp());
3753+
3754+ bool inserted = theDocuments.insert(uri, root);
3755+
3756+ if (!inserted && node.getp() != root.getp())
3757+ {
3758+ RAISE_ERROR_NO_LOC(zerr::ZAPI0020_DOCUMENT_ALREADY_EXISTS, ERROR_PARAMS(uri));
3759+ }
3760+
3761+ ZORBA_FATAL(node.getp() == root.getp(), "");
3762+}
3763+
3764+
3765+/*******************************************************************************
3766+ Return an rchandle to an iterator over the set of documents in the store
3767+********************************************************************************/
3768+store::Iterator_t Store::getDocumentNames() const
3769+{
3770+ return new DocumentNameIterator<DocumentSet>(theDocuments);
3771+}
3772+
3773+
3774+/*******************************************************************************
3775+ Return an rchandle to the root node of the document corresponding to the given
3776+ URI, or NULL if there is no document with that URI.
3777+********************************************************************************/
3778+store::Item_t Store::getDocument(const zstring& uri)
3779+{
3780+ if (uri.empty())
3781+ return NULL;
3782+
3783+ XmlNode_t root;
3784+
3785+ bool found = theDocuments.get(uri, root);
3786+
3787+ if (found)
3788+ return root.getp();
3789+
3790+ return NULL;
3791+}
3792+
3793+
3794+/*******************************************************************************
3795+ Delete the document with the given URI. If there is no document with that
3796+ URI, this method is a NOOP.
3797+********************************************************************************/
3798+void Store::deleteDocument(const zstring& uri)
3799+{
3800+ if (uri.empty())
3801+ return;
3802+
3803+ theDocuments.erase(uri);
3804+}
3805+
3806+
3807+/*******************************************************************************
3808+ Delete all the documents.
3809+********************************************************************************/
3810+void Store::deleteAllDocuments()
3811+{
3812+ theDocuments.clear();
3813+}
3814+
3815+
3816+/*******************************************************************************
3817+ Compare two nodes, based on their node id. Return -1 if node1 < node2, 0, if
3818+ node1 == node2, or 1 if node1 > node2.
3819+********************************************************************************/
3820+short Store::compareNodes(store::Item* node1, store::Item* node2) const
3821+{
3822+ ZORBA_FATAL(node1->isNode(), "");
3823+ ZORBA_FATAL(node2->isNode(), "");
3824+
3825+ if (node1 == node2)
3826+ return 0;
3827+
3828+ XmlNode* n1 = static_cast<XmlNode*>(node1);
3829+ XmlNode* n2 = static_cast<XmlNode*>(node2);
3830+
3831+ return (short)n1->compare2(n2);
3832+}
3833+
3834+
3835+/*******************************************************************************
3836+ Sorts the items of the passed iterator
3837+
3838+ @param iterator to sort
3839+ @param ascendent true for ascendent and false for descendant
3840+ @param duplicate duplicate elemination should be applied
3841+ @return iterator which produces the sorted items
3842+********************************************************************************/
3843+store::Iterator_t Store::sortNodes(
3844+ store::Iterator* input,
3845+ bool ascendent,
3846+ bool duplicateElemination,
3847+ bool aAllowAtomics)
3848+{
3849+ if (aAllowAtomics)
3850+ return new StoreNodeSortOrAtomicIterator(input, ascendent, duplicateElemination);
3851+ else
3852+ return new StoreNodeSortIterator(input, ascendent, duplicateElemination);
3853+}
3854+
3855+
3856+/*******************************************************************************
3857+ Create an iterator that eliminates the duplicate nodes in the set of items
3858+ which is produced by the passed iterator
3859+********************************************************************************/
3860+store::Iterator_t Store::distinctNodes(
3861+ store::Iterator* input,
3862+ bool aAllowAtomics)
3863+{
3864+ if (aAllowAtomics)
3865+ return new StoreNodeDistinctOrAtomicIterator(input);
3866+ else
3867+ return new StoreNodeDistinctIterator(input, false);
3868+}
3869+
3870+
3871+/*******************************************************************************
3872+ Create an iterator that checks for duplicate nodes in the set of nodes which
3873+ is produced by the passed iterator, and raises an error if any duplicates
3874+ are found. If no duplicates are found, the iterator simply passes on the
3875+ input nodes to its consumer.
3876+********************************************************************************/
3877+store::Iterator_t Store::checkDistinctNodes(store::Iterator* input)
3878+{
3879+ return new StoreNodeDistinctIterator(input, true);
3880+}
3881+
3882+
3883+/*******************************************************************************
3884+ Computes the Structural Reference for the given node.
3885+********************************************************************************/
3886+bool Store::getStructuralInformation(
3887+ store::Item_t& result,
3888+ const store::Item* node)
3889+{
3890+#ifdef TEXT_ORDPATH
3891+ const OrdPathNode* n = static_cast<const OrdPathNode*>(node);
3892+
3893+ return theItemFactory->createStructuralAnyURI(result,
3894+ n->getCollectionId(),
3895+ n->getTreeId(),
3896+ n->getNodeKind(),
3897+ n->getOrdPath());
3898+#else
3899+ if (node->getNodeKind() == store::StoreConsts::textNode)
3900+ {
3901+ OrdPath ordPath;
3902+ const TextNode* n = static_cast<const TextNode*>(node);
3903+ n->getOrdPath(ordPath);
3904+
3905+ return GET_FACTORY().createStructuralAnyURI(result,
3906+ n->getCollectionId(),
3907+ n->getTreeId(),
3908+ store::StoreConsts::textNode,
3909+ ordPath);
3910+ }
3911+ else
3912+ {
3913+ const OrdPathNode* n = static_cast<const OrdPathNode*>(node);
3914+
3915+ return GET_FACTORY().createStructuralAnyURI(result,
3916+ n->getCollectionId(),
3917+ n->getTreeId(),
3918+ n->getNodeKind(),
3919+ n->getOrdPath());
3920+ }
3921+#endif
3922+}
3923+
3924+
3925+/*******************************************************************************
3926+
3927+********************************************************************************/
3928+bool Store::getPathInfo(
3929+ const store::Item* docUriItem,
3930+ std::vector<const store::Item*>& contextPath,
3931+ std::vector<const store::Item*>& relativePath,
3932+ bool isAttrPath,
3933+ bool& found,
3934+ bool& unique)
3935+{
3936+ zstring docUri;
3937+ docUriItem->getStringValue2(docUri);
3938+
3939+ XmlNode_t docRoot = BASE_NODE(getDocument(docUri));
3940+
3941+ if (docRoot == NULL)
3942+ return false;
3943+
3944+#ifdef DATAGUIDE
3945+ GuideNode* guideRoot = docRoot->getDataGuide();
3946+
3947+ if (!guideRoot)
3948+ return false;
3949+
3950+ guideRoot->getPathInfo(contextPath, relativePath, isAttrPath, found, unique);
3951+#endif
3952+ return true;
3953+}
3954+
3955+
3956+/*******************************************************************************
3957+ Creates a new TempSeq. The instance can be used, e.g. for variable bindings
3958+
3959+ @param iterator The source for the XMDInstance
3960+ @param lazy Hint for the store. If possible a XMDInstance should be
3961+ evaluated lazily. For XQueryP it might be necassary to set
3962+ this to false.
3963+********************************************************************************/
3964+TempSeq_t Store::createTempSeq(const store::Iterator_t& iterator, bool lazy)
3965+{
3966+ if(lazy)
3967+ {
3968+ //tempSeq = new SimpleTempSeq(iterator, copyNodes);
3969+ return new SimpleLazyTempSeq(iterator);
3970+ }
3971+ else
3972+ {
3973+ return new SimpleTempSeq(iterator);
3974+ }
3975+}
3976+
3977+
3978+/*******************************************************************************
3979+ Creates an empty TempSeq.
3980+********************************************************************************/
3981+TempSeq_t Store::createTempSeq(bool lazy)
3982+{
3983+ if (lazy)
3984+ {
3985+ return new SimpleLazyTempSeq();
3986+ }
3987+ else
3988+ {
3989+ return new SimpleTempSeq();
3990+ }
3991+}
3992+
3993+
3994+/*******************************************************************************
3995+ Creates a temp seq initialized by the given vector.
3996+ @param item_v - The vector to use to initialize the seq.
3997+********************************************************************************/
3998+TempSeq_t Store::createTempSeq(std::vector<store::Item_t>& items)
3999+{
4000+ return new SimpleTempSeq(items);
4001+}
4002+
4003+
4004+/*******************************************************************************
4005+ Creates a temp seq initialized by the given item.
4006+********************************************************************************/
4007+TempSeq_t Store::createTempSeq(store::Item_t& item)
4008+{
4009+ return new SimpleTempSeq(item);
4010+}
4011+
4012+
4013+#ifndef ZORBA_NO_FULL_TEXT
4014+void Store::setStemmerProvider( internal::StemmerProvider const *p )
4015+{
4016+ theStemmerProvider = p;
4017+}
4018+
4019+
4020+void Store::setTokenizerProvider( TokenizerProvider const *p )
4021+{
4022+ theTokenizerProvider = p;
4023+}
4024+
4025+
4026+internal::StemmerProvider const* Store::getStemmerProvider() const
4027+{
4028+ return theStemmerProvider ?
4029+ theStemmerProvider : &internal::StemmerProvider::get_default();
4030+}
4031+
4032+
4033+TokenizerProvider const* Store::getTokenizerProvider() const
4034+{
4035+ return theTokenizerProvider ?
4036+ theTokenizerProvider : &default_tokenizer_provider();
4037+}
4038+#endif /* ZORBA_NO_FULL_TEXT */
4039+
4040+} // namespace store
4041+} // namespace zorba
4042+/* vim:set et sw=2 ts=2: */
4043
4044=== added file 'src/store/naive/store.h'
4045--- src/store/naive/store.h 1970-01-01 00:00:00 +0000
4046+++ src/store/naive/store.h 2012-03-27 01:25:22 +0000
4047@@ -0,0 +1,419 @@
4048+/*
4049+ * Copyright 2006-2008 The FLWOR Foundation.
4050+ *
4051+ * Licensed under the Apache License, Version 2.0 (the "License");
4052+ * you may not use this file except in compliance with the License.
4053+ * You may obtain a copy of the License at
4054+ *
4055+ * http://www.apache.org/licenses/LICENSE-2.0
4056+ *
4057+ * Unless required by applicable law or agreed to in writing, software
4058+ * distributed under the License is distributed on an "AS IS" BASIS,
4059+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
4060+ * See the License for the specific language governing permissions and
4061+ * limitations under the License.
4062+ */
4063+#ifndef ZORBA_SIMPLESTORE_STORE_H
4064+#define ZORBA_SIMPLESTORE_STORE_H
4065+
4066+#include "shared_types.h"
4067+#include "store_defs.h"
4068+#include "hashmap_nodep.h"
4069+
4070+#if (defined (WIN32) || defined (WINCE))
4071+#include "node_items.h"
4072+#include "store/api/collection.h"
4073+#include "store/api/index.h"
4074+#include "store/api/ic.h"
4075+#endif
4076+
4077+#include "store/api/store.h"
4078+
4079+#include "store/util/hashmap_stringbuf.h"
4080+
4081+#include "zorbautils/mutex.h"
4082+#include "zorbautils/lock.h"
4083+#include "zorbautils/hashmap_itemp.h"
4084+#include "zorbautils/hashmap_zstring_nonserializable.h"
4085+
4086+namespace zorba
4087+{
4088+ class StoreManager;
4089+
4090+class XQueryDiagnostics;
4091+
4092+namespace store
4093+{
4094+ class IteratorFactory;
4095+ class ValueIndexSpecification;
4096+}
4097+
4098+namespace simplestore
4099+{
4100+
4101+class StringPool;
4102+class QNamePool;
4103+class XmlLoader;
4104+class FastXmlLoader;
4105+class Index;
4106+class BasicItemFactory;
4107+class NodeFactory;
4108+class PULPrimitiveFactory;
4109+
4110+typedef zorba::HashMapZString<XmlNode_t> DocumentSet;
4111+typedef ItemPointerHashMap<store::Index_t> IndexSet;
4112+typedef ItemPointerHashMap<store::IC_t> ICSet;
4113+
4114+
4115+
4116+/*******************************************************************************
4117+ theSchemaTypeNames:
4118+ -------------------
4119+ Maps each enum value from SchemaTypeNames (see store/api/xs_types_enum.h) to
4120+ its associated QName item.
4121+
4122+ theSchemaTypeCodes:
4123+ -------------------
4124+
4125+ theNamespacePool:
4126+ -----------------
4127+
4128+ theQNamePool:
4129+ -------------
4130+
4131+ theItemFactory:
4132+ ---------------
4133+ Factory to create items.
4134+
4135+ theIteratorFactory:
4136+ -------------------
4137+ Factory to create iterators.
4138+
4139+ theNodeFactory:
4140+ ---------------
4141+ Factory to create node items.
4142+
4143+ theDocuments:
4144+ -------------
4145+ A hashmap that for each xml tree that does not belong to any collection, maps
4146+ the URI of the tree to the root node of the tree.
4147+
4148+ theCollections:
4149+ ---------------
4150+ Container which contains the collections of the store. It includes a map that
4151+ maps the qname of each collection to the collection's container object.
4152+
4153+ theIndices:
4154+ -----------
4155+ A hashmap that for each index, maps the qname of the index to the index
4156+ container object.
4157+
4158+ theICs:
4159+ -------
4160+ A hashmap the for each integrity constraint, maps the qname of the ic to the
4161+ ic's container object.
4162+
4163+********************************************************************************/
4164+class Store : public zorba::store::Store
4165+{
4166+public:
4167+ static const char* XS_URI;
4168+ static const char* XML_URI;
4169+ static const char* ZXSE_URI;
4170+
4171+ static const ulong XML_URI_LEN;
4172+
4173+protected:
4174+ static const ulong NAMESPACE_POOL_SIZE;
4175+ static const ulong DEFAULT_DOCUMENT_SET_SIZE;
4176+ static const ulong DEFAULT_URI_COLLECTION_SET_SIZE;
4177+ static const ulong DEFAULT_INDICES_SET_SIZE;
4178+ static const ulong DEFAULT_INTEGRITY_CONSTRAINT_SET_SIZE;
4179+
4180+public:
4181+ zstring theEmptyNs;
4182+ zstring theXmlSchemaNs;
4183+
4184+ std::vector<store::Item_t> theSchemaTypeNames;
4185+ std::map<store::Item*, store::SchemaTypeCode> theSchemaTypeCodes;
4186+ store::Item_t XS_UNTYPED_QNAME;
4187+ store::Item_t XS_ANY_QNAME;
4188+ store::Item_t XS_ANY_SIMPLE_QNAME;
4189+
4190+protected:
4191+ ulong theNumUsers;
4192+
4193+ StringPool * theNamespacePool;
4194+ QNamePool * theQNamePool;
4195+
4196+ store::ItemFactory * theItemFactory;
4197+ store::IteratorFactory * theIteratorFactory;
4198+ NodeFactory * theNodeFactory;
4199+ PULPrimitiveFactory * thePULFactory;
4200+
4201+ DocumentSet theDocuments;
4202+ CollectionSet* theCollections;
4203+ IndexSet theIndices;
4204+ ICSet theICs;
4205+ IndexSet theHashMaps;
4206+
4207+ SYNC_CODE(Lock theGlobalLock;)
4208+
4209+ long theTraceLevel;
4210+
4211+#ifndef ZORBA_NO_FULL_TEXT
4212+ internal::StemmerProvider const * theStemmerProvider;
4213+ TokenizerProvider const * theTokenizerProvider;
4214+#endif /* ZORBA_NO_FULL_TEXT */
4215+
4216+/*----------------------- Initialization, shutdown ---------------------------*/
4217+protected:
4218+ Store();
4219+
4220+ virtual ~Store();
4221+
4222+ virtual void init();
4223+
4224+ void initTypeNames();
4225+
4226+public:
4227+ virtual void shutdown(bool soft = true);
4228+
4229+ SYNC_CODE(Lock& getGlobalLock() { return theGlobalLock; })
4230+
4231+ long getTraceLevel() const { return theTraceLevel; }
4232+
4233+ XmlLoader* getXmlLoader(
4234+ XQueryDiagnostics*,
4235+ const store::LoadProperties& loadProperties);
4236+
4237+/*------------------------------ Factories -----------------------------------*/
4238+public:
4239+ store::ItemFactory* getItemFactory() const { return theItemFactory; }
4240+
4241+ store::IteratorFactory* getIteratorFactory() const
4242+ {
4243+ return theIteratorFactory;
4244+ }
4245+
4246+ NodeFactory& getNodeFactory() const { return *theNodeFactory; }
4247+
4248+ PULPrimitiveFactory& getPULFactory() const { return *thePULFactory; }
4249+
4250+ StringPool& getNamespacePool() const { return *theNamespacePool; }
4251+
4252+ QNamePool& getQNamePool() const { return *theQNamePool; }
4253+
4254+protected:
4255+ // Functions to create/destory the node and item factories. These functions
4256+ // are called from init and shutdown, respectively. Having this functionality
4257+ // factorized allows others to derive from the SimpleStore and provide their
4258+ // own factories.
4259+
4260+ virtual NodeFactory* createNodeFactory() const = 0;
4261+
4262+ virtual void destroyNodeFactory(NodeFactory*) const = 0;
4263+
4264+ virtual store::ItemFactory* createItemFactory() const = 0;
4265+
4266+ virtual void destroyItemFactory(store::ItemFactory*) const = 0;
4267+
4268+ virtual store::IteratorFactory* createIteratorFactory() const = 0;
4269+
4270+ virtual void destroyIteratorFactory(store::IteratorFactory*) const = 0;
4271+
4272+ virtual PULPrimitiveFactory* createPULFactory() const = 0;
4273+
4274+ virtual void destroyPULFactory(PULPrimitiveFactory*) const = 0;
4275+
4276+ virtual CollectionSet* createCollectionSet() const = 0;
4277+
4278+ virtual void destroyCollectionSet(CollectionSet*) const = 0;
4279+
4280+/*---------------------------- Collections -----------------------------------*/
4281+public:
4282+ virtual ulong createCollectionId() = 0;
4283+
4284+ virtual ulong createTreeId() = 0;
4285+
4286+ virtual store::Collection_t createCollection(
4287+ const store::Item_t& aName,
4288+ const std::vector<store::Annotation_t>& annotations,
4289+ const store::Item_t& aNodeType,
4290+ bool aDynamicCollection = false) = 0;
4291+
4292+ virtual void addCollection(store::Collection_t& collection);
4293+
4294+ virtual void deleteCollection(
4295+ const store::Item* aName,
4296+ bool aDynamicCollection = false);
4297+
4298+ virtual store::Collection_t getCollection(
4299+ const store::Item* aName,
4300+ bool aDynamicCollection = false);
4301+
4302+ virtual store::Iterator_t listCollectionNames(bool aDynamicCollections = false);
4303+
4304+/*-------------------------------- Indices -----------------------------------*/
4305+public:
4306+ virtual store::Index_t createIndex(
4307+ const store::Item_t& qname,
4308+ const store::IndexSpecification& spec,
4309+ store::Iterator* sourceIter);
4310+
4311+ virtual store::Index_t refreshIndex(
4312+ const store::Item_t& qname,
4313+ const store::IndexSpecification& spec,
4314+ store::Iterator* sourceIter);
4315+
4316+ virtual void addIndex(store::Index_t& index);
4317+
4318+ virtual void deleteIndex(const store::Item* qname);
4319+
4320+ virtual store::Index* getIndex(const store::Item* qname);
4321+
4322+ virtual store::Iterator_t listIndexNames();
4323+
4324+ const IndexSet& getIndices() const { return theIndices; }
4325+
4326+protected:
4327+ virtual void populateValueIndex(
4328+ const store::Index_t& index,
4329+ store::Iterator* sourceIter,
4330+ ulong numColumns);
4331+
4332+ virtual void populateGeneralIndex(
4333+ const store::Index_t& index,
4334+ store::Iterator* sourceIter,
4335+ ulong numColumns);
4336+
4337+/*------------------------- Integrity constraints ----------------------------*/
4338+public:
4339+ virtual store::IC_t activateIC(
4340+ const store::Item_t& icQName,
4341+ const store::Item_t& collectionQName,
4342+ bool& isApplied);
4343+
4344+ virtual store::IC_t activateForeignKeyIC(
4345+ const store::Item_t& icQName,
4346+ const store::Item_t& fromCollectionQName,
4347+ const store::Item_t& toCollectionQName,
4348+ bool& isApplied);
4349+
4350+ virtual store::IC_t deactivateIC(
4351+ const store::Item_t& icQName,
4352+ bool& isApplied);
4353+
4354+ virtual store::Iterator_t listActiveICNames();
4355+
4356+ virtual store::IC* getIC(const store::Item* icQName);
4357+
4358+/*------------------------------------- Maps ---------------------------------*/
4359+public:
4360+ virtual store::Index_t createHashMap(
4361+ const store::Item_t& aQName,
4362+ const store::IndexSpecification& aSpec);
4363+
4364+ virtual store::Index_t destroyHashMap(const store::Item_t& aQName);
4365+
4366+ virtual store::Index* getMap(const store::Item* aQName) const;
4367+
4368+ virtual store::Index_t getHashMap(const store::Item_t& aQName) const;
4369+
4370+ virtual void addHashMap(const store::Index_t& aMap);
4371+
4372+ virtual store::Iterator_t listMapNames();
4373+
4374+/*-------------------------------- Documents ---------------------------------*/
4375+public:
4376+ virtual store::Item_t loadDocument(
4377+ const zstring& baseUri,
4378+ const zstring& docUri,
4379+ std::istream& stream,
4380+ const store::LoadProperties& loadProperties);
4381+
4382+ virtual store::Item_t loadDocument(
4383+ const zstring& baseUri,
4384+ const zstring& docUri,
4385+ std::istream* stream,
4386+ const store::LoadProperties& loadProperties);
4387+
4388+ virtual void addNode(const zstring& uri, const store::Item_t& node);
4389+
4390+ virtual store::Iterator_t getDocumentNames() const;
4391+
4392+ virtual store::Item_t getDocument(const zstring& uri);
4393+
4394+ virtual void deleteDocument(const zstring& uri);
4395+
4396+ virtual void deleteAllDocuments();
4397+
4398+/*----------------------------- Node operations ------------------------------*/
4399+public:
4400+ virtual short compareNodes(
4401+ store::Item* node1,
4402+ store::Item* node2) const;
4403+
4404+ virtual store::Iterator_t sortNodes(
4405+ store::Iterator* iterator,
4406+ bool ascendent,
4407+ bool duplicateElemination,
4408+ bool aAllowAtomics = false);
4409+
4410+ virtual store::Iterator_t distinctNodes(
4411+ store::Iterator* input,
4412+ bool aAllowAtomics);
4413+
4414+ virtual store::Iterator_t checkDistinctNodes(store::Iterator* input);
4415+
4416+ virtual bool getStructuralInformation(
4417+ store::Item_t& result,
4418+ const store::Item* node);
4419+
4420+ virtual bool getPathInfo(
4421+ const store::Item* docUri,
4422+ std::vector<const store::Item*>& contextPath,
4423+ std::vector<const store::Item*>& relativePath,
4424+ bool isAttrPath,
4425+ bool& found,
4426+ bool& unique);
4427+
4428+/*---------------------- Node Reference Management ---------------------------*/
4429+public:
4430+ virtual bool getNodeReference(store::Item_t& result, const store::Item* node) = 0;
4431+
4432+ virtual bool hasReference(const store::Item* node) = 0;
4433+
4434+ virtual bool getNodeByReference(store::Item_t& result, const zstring& ref) = 0;
4435+
4436+ virtual bool unregisterNode(XmlNode* node) = 0;
4437+
4438+/*----------------------- Temp Sequence Management ---------------------------*/
4439+public:
4440+ virtual store::TempSeq_t createTempSeq(bool lazy);
4441+
4442+ virtual store::TempSeq_t createTempSeq(const store::Iterator_t& iterator, bool lazy);
4443+
4444+ virtual store::TempSeq_t createTempSeq(std::vector<store::Item_t>& item_v);
4445+
4446+ virtual store::TempSeq_t createTempSeq(store::Item_t& item);
4447+
4448+/*--------------------------- Full Text Management ---------------------------*/
4449+public:
4450+#ifndef ZORBA_NO_FULL_TEXT
4451+ virtual internal::StemmerProvider const* getStemmerProvider() const;
4452+
4453+ virtual void setStemmerProvider(internal::StemmerProvider const*);
4454+
4455+protected:
4456+ virtual TokenizerProvider const* getTokenizerProvider() const;
4457+
4458+ virtual void setTokenizerProvider(TokenizerProvider const*);
4459+#endif /* ZORBA_NO_FULL_TEXT */
4460+};
4461+
4462+} // namespace simplestore
4463+} // namespace zorba
4464+
4465+#endif /* ZORBA_SIMPLESTORE_STORE_H */
4466+
4467
4468=== modified file 'src/store/naive/store_manager_impl.h'
4469--- src/store/naive/store_manager_impl.h 2012-03-26 01:31:32 +0000
4470+++ src/store/naive/store_manager_impl.h 2012-03-27 01:25:22 +0000
4471@@ -25,7 +25,7 @@
4472 namespace simplestore
4473 {
4474
4475-class SimpleStore;
4476+class Store;
4477
4478
4479 /*******************************************************************************
4480@@ -33,13 +33,13 @@
4481 ********************************************************************************/
4482 class StoreManagerImpl : public StoreManager
4483 {
4484- friend class SimpleStore;
4485+ friend class Store;
4486
4487 private:
4488- static SimpleStore * theStore;
4489+ static Store* theStore;
4490
4491 public:
4492- static SimpleStore* getStoreInternal() { return theStore; }
4493+ static Store* getStoreInternal() { return theStore; }
4494 };
4495
4496

Subscribers

People subscribed via source and target branches