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-2008
5  * Oracle. All rights reserved.
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  * $Id$
20  */
21 
22 #ifndef XQQUERY_HPP
23 #define XQQUERY_HPP
24 
25 #include <xqilla/framework/XQillaExport.hpp>
26 #include <vector>
27 #include <string>
28 #include <xercesc/util/XMemory.hpp>
31 #include <xqilla/runtime/LazySequenceResult.hpp>
33 
34 class DynamicContext;
35 class XQUserFunction;
36 class XQGlobalVariable;
37 class XQUserFunctionInstance;
38 class XQQuery;
39 
40 typedef std::vector<XQGlobalVariable*, XQillaAllocator<XQGlobalVariable*> > GlobalVariables;
41 typedef std::vector<XQQuery*, XQillaAllocator<XQQuery*> > ImportedModules;
42 
57 class XQILLA_API XQQuery : public XERCES_CPP_NAMESPACE_QUALIFIER XMemory
58 {
59 public:
61  ~XQQuery();
62 
64  // @{
65 
74  DynamicContext *createDynamicContext(XERCES_CPP_NAMESPACE_QUALIFIER MemoryManager *memMgr =
75  XERCES_CPP_NAMESPACE_QUALIFIER XMLPlatformUtils::fgMemoryManager) const;
76 
90  Result execute(DynamicContext* context) const;
91 
106  Result execute(const Item::Ptr &contextItem, DynamicContext *context) const;
107 
123  Result execute(const XMLCh *templateQName, DynamicContext *context) const;
124 
135  void execute(EventHandler *events, DynamicContext* context) const;
136 
148  void execute(EventHandler *events, const Item::Ptr &contextItem, DynamicContext *context) const;
149 
162  void execute(EventHandler *events, const XMLCh *templateQName, DynamicContext *context) const;
163 
183  void staticResolution();
184 
197  void staticTyping(StaticTyper *styper = 0);
198 
200 
202  // @{
203 
205  const XMLCh* getQueryText() const;
206 
208  std::string getQueryPlan() const;
209 
211 
213  // @{
214 
216  ASTNode* getQueryBody() const;
218  void setQueryBody(ASTNode* query);
219 
221  void addFunction(XQUserFunction* fnDef);
223  const UserFunctions &getFunctions() const { return m_userDefFns; }
224 
226  void addVariable(XQGlobalVariable* varDef);
228  const GlobalVariables &getVariables() const { return m_userDefVars; }
229 
231  const ImportedModules &getImportedModules() const { return m_importedModules; }
232 
234  const XMLCh* getFile() const;
236  void setFile(const XMLCh* file);
237 
238  const DynamicContext *getStaticContext() const { return m_context; }
239 
241 
243  // @{
244 
246  void setIsLibraryModule(bool bIsModule=true);
248  bool getIsLibraryModule() const;
250  void setModuleTargetNamespace(const XMLCh* uri);
252  const XMLCh* getModuleTargetNamespace() const;
254  void importModule(const XMLCh* szUri, VectorOfStrings* locations, StaticContext* context, const LocationInfo *location);
255 
257 
258 private:
260  class QueryResult : public ResultImpl
261  {
262  public:
263  QueryResult(const XQQuery *query);
264 
265  Item::Ptr nextOrTail(Result &tail, DynamicContext *context);
266 
267  private:
268  const XQQuery *_query;
269  };
270 
271 private:
273  XQQuery(const XMLCh* queryText, DynamicContext *context, bool contextOwned = false,
274  XERCES_CPP_NAMESPACE_QUALIFIER MemoryManager *memMgr =
275  XERCES_CPP_NAMESPACE_QUALIFIER XMLPlatformUtils::fgMemoryManager);
276 
277  XQQuery(const XQQuery &);
278  XQQuery &operator=(const XQQuery &);
279 
280  void executeProlog(DynamicContext *context) const;
281 
282 private:
284  XERCES_CPP_NAMESPACE_QUALIFIER MemoryManager* m_memMgr;
285 
287  DynamicContext *m_context;
288  bool m_contextOwned;
289 
290  ASTNode* m_query;
291 
292  bool m_bIsLibraryModule;
293  const XMLCh* m_szTargetNamespace;
294  const XMLCh* m_szQueryText;
295  const XMLCh* m_szCurrentFile;
296 
297  UserFunctions m_userDefFns;
298  GlobalVariables m_userDefVars;
299  ImportedModules m_importedModules;
300 
301  friend class QueryResult;
302  friend class XQilla;
303 };
304 
305 #endif
const UserFunctions & getFunctions() const
Returns a vector of all XQUserFunction objects from the query.
Definition: XQQuery.hpp:223
Definition: EventHandler.hpp:31
const GlobalVariables & getVariables() const
Returns a vector of all XQGlobalVariable objects from the query.
Definition: XQQuery.hpp:228
The parse time static context interface.
Definition: StaticContext.hpp:59
std::vector< const XMLCh *, XQillaAllocator< const XMLCh * > > VectorOfStrings
Definition: DocumentCache.hpp:37
A scoped pointer wrapper for the lazily evaluated query result.
Definition: Result.hpp:39
std::vector< XQUserFunction *, XQillaAllocator< XQUserFunction * > > UserFunctions
Definition: StaticContext.hpp:50
Encapsulates a query expression.
Definition: XQQuery.hpp:57
std::vector< XQGlobalVariable *, XQillaAllocator< XQGlobalVariable * > > GlobalVariables
Definition: XQQuery.hpp:38
std::vector< XQQuery *, XQillaAllocator< XQQuery * > > ImportedModules
Definition: XQQuery.hpp:41
The execution time dynamic context interface.
Definition: DynamicContext.hpp:39
const ImportedModules & getImportedModules() const
Returns a vector of all XQGlobalVariable objects from the query.
Definition: XQQuery.hpp:231
A class that gives records a location in the query.
Definition: LocationInfo.hpp:31
const DynamicContext * getStaticContext() const
Definition: XQQuery.hpp:238
Provides factory methods for creating XQQuery and DynamicContext objects.
Definition: XQilla.hpp:48
A lazily evaluated query result.
Definition: ResultImpl.hpp:35