SourceForge.net Logo
XQQuery.hpp
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2001, 2008,
3  * DecisionSoft Limited. All rights reserved.
4  * Copyright (c) 2004, 2018 Oracle and/or its affiliates. All rights reserved.
5  *
6  *
7  * Licensed under the Apache License, Version 2.0 (the "License");
8  * you may not use this file except in compliance with the License.
9  * You may obtain a copy of the License at
10  *
11  * http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing, software
14  * distributed under the License is distributed on an "AS IS" BASIS,
15  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16  * See the License for the specific language governing permissions and
17  * limitations under the License.
18  */
19 
20 #ifndef XQQUERY_HPP
21 #define XQQUERY_HPP
22 
23 #include <xqilla/framework/XQillaExport.hpp>
24 #include <vector>
25 #include <string>
26 #include <xercesc/util/XMemory.hpp>
30 
31 #include <xercesc/util/RefHashTableOf.hpp>
32 
33 class DynamicContext;
34 class XQUserFunction;
35 class XQGlobalVariable;
36 class XQQuery;
37 class DelayedModule;
38 class DelayedFuncFactory;
39 class StaticTyper;
40 
41 typedef std::vector<XQGlobalVariable*, XQillaAllocator<XQGlobalVariable*> > GlobalVariables;
42 typedef std::vector<XQQuery*, XQillaAllocator<XQQuery*> > ImportedModules;
43 typedef std::vector<DelayedFuncFactory*, XQillaAllocator<DelayedFuncFactory*> > DelayedFunctions;
44 
45 typedef XERCES_CPP_NAMESPACE_QUALIFIER RefHashTableOf<XQQuery> ModuleMap;
46 
47 class XQILLA_API ModuleCache : public XERCES_CPP_NAMESPACE_QUALIFIER XMemory
48 {
49 public:
50  ModuleCache(XERCES_CPP_NAMESPACE_QUALIFIER MemoryManager *mm);
51 
52  void put(XQQuery *module);
53  XQQuery *getByURI(const XMLCh *uri) const;
54  XQQuery *getByNamespace(const XMLCh *ns) const;
55 
59 };
60 
75 class XQILLA_API XQQuery : public XERCES_CPP_NAMESPACE_QUALIFIER XMemory
76 {
77 public:
79  ~XQQuery();
80 
82  // @{
83 
92  DynamicContext *createDynamicContext(XERCES_CPP_NAMESPACE_QUALIFIER MemoryManager *memMgr =
93  XERCES_CPP_NAMESPACE_QUALIFIER XMLPlatformUtils::fgMemoryManager) const;
94 
108  Result execute(DynamicContext* context) const;
109 
124  Result execute(const Item::Ptr &contextItem, DynamicContext *context) const;
125 
141  Result execute(const XMLCh *templateQName, DynamicContext *context) const;
142 
153  void execute(EventHandler *events, DynamicContext* context) const;
154 
166  void execute(EventHandler *events, const Item::Ptr &contextItem, DynamicContext *context) const;
167 
180  void execute(EventHandler *events, const XMLCh *templateQName, DynamicContext *context) const;
181 
201  void staticResolution();
202 
215  void staticTyping(StaticTyper *styper = 0);
216  bool staticTypingOnce(StaticTyper *styper = 0);
217 
219 
221  // @{
222 
224  const XMLCh* getQueryText() const { return m_szQueryText; }
225  void setQueryText(const XMLCh *v);
226 
228  std::string getQueryPlan() const;
229 
231 
233  // @{
234 
236  ASTNode* getQueryBody() const;
238  void setQueryBody(ASTNode* query);
239 
241  void addFunction(XQUserFunction* fnDef);
243  const UserFunctions &getFunctions() const { return m_userDefFns; }
244 
247  void addDelayedFunction(const XMLCh *uri, const XMLCh *name, size_t numArgs,
248  const XMLCh *functionDeclaration, bool isPrivate = false,
249  int line = 1, int column = 1);
250  void addDelayedFunction(const XMLCh *uri, const XMLCh *name, size_t numArgs,
251  const char *functionDeclaration, bool isPrivate = false,
252  int line = 1, int column = 1);
254  const DelayedFunctions &getDelayedFunctions() const { return m_delayedFunctions; }
255 
257  void addVariable(XQGlobalVariable* varDef);
259  const GlobalVariables &getVariables() const { return m_userDefVars; }
260 
262  const ImportedModules &getImportedModules() const { return m_importedModules; }
263 
264  ModuleCache *getModuleCache() const { return m_moduleCache; }
265  bool isModuleCacheOwned() const { return m_moduleCacheOwned; }
266 
268  const XMLCh* getFile() const { return m_szCurrentFile; }
269 
271  void setFile(const XMLCh* file);
272 
273  bool getVersion3() const { return m_version3; }
274  void setVersion3(bool v) { m_version3 = v; }
275 
276  const DynamicContext *getStaticContext() const { return m_context; }
277 
278  XQQuery *getNext() const { return m_next; }
279  void setNext(XQQuery *n) { m_next = n; }
280 
282 
284  // @{
285 
287  void setIsLibraryModule(bool bIsModule=true);
289  bool getIsLibraryModule() const;
291  void setModuleTargetNamespace(const XMLCh* uri);
293  const XMLCh* getModuleTargetNamespace() const;
295  void importModule(const XMLCh* szUri, VectorOfStrings* locations, const LocationInfo *location);
296  void importModule(XQQuery *module);
297 
298  XQQuery *findModuleForVariable(const XMLCh *uri, const XMLCh *name);
299  XQQuery *findModuleForFunction(const XMLCh *uri, const XMLCh *name, int numArgs);
300 
302 
303 private:
305  XQQuery(DynamicContext *context, bool contextOwned, ModuleCache *moduleCache,
306  XERCES_CPP_NAMESPACE_QUALIFIER MemoryManager *memMgr);
307 
308  XQQuery(const XQQuery &);
309  XQQuery &operator=(const XQQuery &);
310 
311  XQQuery *parseModule(const XMLCh *ns, const XMLCh *at, const LocationInfo *location) const;
312  void executeProlog(DynamicContext *context) const;
313 
314 private:
316  XERCES_CPP_NAMESPACE_QUALIFIER MemoryManager* m_memMgr;
317 
319  DynamicContext *m_context;
320  bool m_contextOwned;
321 
322  ASTNode* m_query;
323 
324  bool m_bIsLibraryModule;
325  const XMLCh* m_szTargetNamespace;
326  const XMLCh* m_szQueryText;
327  const XMLCh* m_szCurrentFile;
328 
329  UserFunctions m_userDefFns;
330  DelayedFunctions m_delayedFunctions;
331  GlobalVariables m_userDefVars;
332  ImportedModules m_importedModules;
333 
334  ModuleCache *m_moduleCache;
335  bool m_moduleCacheOwned;
336 
337  bool m_version3;
338 
339  enum { BEFORE, DURING, AFTER } m_staticTyped;
340 
341  // The next module with the same target namespace
342  XQQuery *m_next;
343 
344  friend class QueryResult;
345  friend class XQilla;
346  friend class DelayedModule;
347 };
348 
349 #endif
bool getVersion3() const
Definition: XQQuery.hpp:273
const UserFunctions & getFunctions() const
Returns a vector of all XQUserFunction objects from the query.
Definition: XQQuery.hpp:243
Definition: XQQuery.hpp:47
Definition: EventHandler.hpp:29
const GlobalVariables & getVariables() const
Returns a vector of all XQGlobalVariable objects from the query.
Definition: XQQuery.hpp:259
const DelayedFunctions & getDelayedFunctions() const
Returns a vector of all XQUserFunction objects from the query.
Definition: XQQuery.hpp:254
void setNext(XQQuery *n)
Definition: XQQuery.hpp:279
std::vector< const XMLCh *, XQillaAllocator< const XMLCh * > > VectorOfStrings
Definition: DocumentCache.hpp:35
A scoped pointer wrapper for the lazily evaluated query result.
Definition: Result.hpp:37
ModuleMap byNamespace_
Definition: XQQuery.hpp:57
std::vector< XQUserFunction *, XQillaAllocator< XQUserFunction * > > UserFunctions
Definition: StaticContext.hpp:48
const XMLCh * getFile() const
Returns the name of the file that this query was parsed from.
Definition: XQQuery.hpp:268
bool isModuleCacheOwned() const
Definition: XQQuery.hpp:265
Encapsulates a query expression.
Definition: XQQuery.hpp:75
ImportedModules ordered_
Definition: XQQuery.hpp:58
std::vector< DelayedFuncFactory *, XQillaAllocator< DelayedFuncFactory * > > DelayedFunctions
Definition: XQQuery.hpp:43
std::vector< XQGlobalVariable *, XQillaAllocator< XQGlobalVariable * > > GlobalVariables
Definition: XQQuery.hpp:39
void setVersion3(bool v)
Definition: XQQuery.hpp:274
xercesc::RefHashTableOf< XQQuery > ModuleMap
Definition: XQQuery.hpp:45
ModuleMap byURI_
Definition: XQQuery.hpp:56
std::vector< XQQuery *, XQillaAllocator< XQQuery * > > ImportedModules
Definition: XQQuery.hpp:42
The execution time dynamic context interface.
Definition: DynamicContext.hpp:38
const ImportedModules & getImportedModules() const
Returns a vector of all XQGlobalVariable objects from the query.
Definition: XQQuery.hpp:262
ModuleCache * getModuleCache() const
Definition: XQQuery.hpp:264
A class that gives records a location in the query.
Definition: LocationInfo.hpp:29
const DynamicContext * getStaticContext() const
Definition: XQQuery.hpp:276
Provides factory methods for creating XQQuery and DynamicContext objects.
Definition: XQilla.hpp:52
const XMLCh * getQueryText() const
Returns the expression that was parsed to create this XQQuery object.
Definition: XQQuery.hpp:224
XQQuery * getNext() const
Definition: XQQuery.hpp:278