~zorba-coders/zorba/bug1151967

« back to all changes in this revision

Viewing changes to modules/zorba-query/zorba-query.xq.src/zorba-query.cpp

  • Committer: Paul J. Lucas
  • Date: 2013-08-15 00:14:17 UTC
  • mfrom: (11597 lp_zorba)
  • mto: This revision was merged to the branch mainline in revision 11598.
  • Revision ID: paul@lucasmail.org-20130815001417-g22x9plxc8fv73zd
MergeĀ fromĀ trunk.

Show diffs side-by-side

added added

removed removed

Lines of Context:
13
13
#include <zorba/util/uuid.h>
14
14
#include <vector>
15
15
 
16
 
#include "xqxq.h"
 
16
#include "zorba-query.h"
17
17
 
18
 
namespace zorba { namespace xqxq {
 
18
namespace zorba { namespace zorbaquery {
19
19
 
20
20
/*******************************************************************************
21
21
 
22
22
********************************************************************************/
23
23
zorba::ExternalFunction*
24
 
XQXQModule::getExternalFunction(const zorba::String& localName)
 
24
ZorbaQueryModule::getExternalFunction(const zorba::String& localName)
25
25
{
26
26
  FuncMap_t::iterator lIte = theFunctions.find(localName);
27
27
    
102
102
/*******************************************************************************
103
103
 
104
104
********************************************************************************/
105
 
void XQXQModule::destroy() 
 
105
void ZorbaQueryModule::destroy() 
106
106
{
107
107
  delete this;
108
108
}
111
111
/*******************************************************************************
112
112
 
113
113
********************************************************************************/
114
 
XQXQModule::~XQXQModule()
 
114
ZorbaQueryModule::~ZorbaQueryModule()
115
115
{
116
116
  for (FuncMap_t::const_iterator lIter = theFunctions.begin();
117
117
       lIter != theFunctions.end(); ++lIter) 
229
229
/*******************************************************************************
230
230
 
231
231
********************************************************************************/
232
 
void XQXQFunction::throwError(const char *err_localname, const std::string& aErrorMessage)
 
232
void ZorbaQueryFunction::throwError(const char *err_localname, const std::string& aErrorMessage)
233
233
{
234
 
  String errNS(XQXQ_MODULE_NAMESPACE);
 
234
  String errNS(ZORBA_QUERY_MODULE_NAMESPACE);
235
235
  String errName(err_localname);
236
 
  Item errQName = XQXQModule::getItemFactory()->createQName(errNS, errName);
 
236
  Item errQName = ZorbaQueryModule::getItemFactory()->createQName(errNS, errName);
237
237
  String errDescription(aErrorMessage);
238
238
  throw USER_EXCEPTION(errQName, errDescription);
239
239
}
242
242
/*******************************************************************************
243
243
 
244
244
********************************************************************************/
245
 
XQXQFunction::XQXQFunction(const XQXQModule* aModule)
 
245
ZorbaQueryFunction::ZorbaQueryFunction(const ZorbaQueryModule* aModule)
246
246
  :
247
247
  theModule(aModule)
248
248
{
253
253
/*******************************************************************************
254
254
 
255
255
********************************************************************************/
256
 
XQXQFunction::~XQXQFunction()
 
256
ZorbaQueryFunction::~ZorbaQueryFunction()
257
257
{
258
258
}
259
259
 
261
261
/*******************************************************************************
262
262
 
263
263
********************************************************************************/
264
 
String XQXQFunction::getURI() const 
 
264
String ZorbaQueryFunction::getURI() const 
265
265
{
266
266
  return theModule->getURI();
267
267
}
270
270
/*******************************************************************************
271
271
 
272
272
********************************************************************************/
273
 
String XQXQFunction::getOneStringArgument(const Arguments_t& aArgs, int aPos) const
 
273
String ZorbaQueryFunction::getOneStringArgument(const Arguments_t& aArgs, int aPos) const
274
274
{
275
275
  Item lItem;
276
276
  Iterator_t args_iter = aArgs[aPos]->getIterator();
285
285
/*******************************************************************************
286
286
 
287
287
********************************************************************************/
288
 
Item XQXQFunction::getItemArgument(const Arguments_t& aArgs, int aPos) const
 
288
Item ZorbaQueryFunction::getItemArgument(const Arguments_t& aArgs, int aPos) const
289
289
{
290
290
  Item lItem;
291
291
  Iterator_t args_iter = aArgs[aPos]->getIterator();
300
300
/*******************************************************************************
301
301
 
302
302
********************************************************************************/
303
 
Iterator_t XQXQFunction::getIterArgument(const Arguments_t& aArgs, int aPos) const
 
303
Iterator_t ZorbaQueryFunction::getIterArgument(const Arguments_t& aArgs, int aPos) const
304
304
{
305
305
  Iterator_t args_iter = aArgs[aPos]->getIterator();
306
306
  return args_iter;
310
310
/*******************************************************************************
311
311
 
312
312
********************************************************************************/
313
 
XQuery_t XQXQFunction::getQuery(
 
313
XQuery_t ZorbaQueryFunction::getQuery(
314
314
    const zorba::DynamicContext* aDctx,
315
315
    const zorba::String& aIdent) const
316
316
{
317
317
  QueryMap* lQueryMap;
318
318
 
319
319
  if (!(lQueryMap =
320
 
        dynamic_cast<QueryMap*>(aDctx->getExternalFunctionParameter("xqxqQueryMap"))))
 
320
        dynamic_cast<QueryMap*>(aDctx->getExternalFunctionParameter("zqQueryMap"))))
321
321
  {
322
 
    throwError("NoQueryMatch", "No query with the given identifier was found");
 
322
    throwError("NO_QUERY_MATCH", "No query with the given identifier was found");
323
323
  }
324
324
  
325
325
  XQuery_t lQuery;
326
326
  if (!(lQuery = lQueryMap->getQuery(aIdent)))
327
 
    throwError("NoQueryMatch", "No query with the given identifier was found");
 
327
    throwError("NO_QUERY_MATCH", "No query with the given identifier was found");
328
328
  
329
329
  return lQuery;
330
330
}
333
333
/*******************************************************************************
334
334
 
335
335
********************************************************************************/
336
 
void  XQXQURIMapper::mapURI(
 
336
void  ZorbaQueryURIMapper::mapURI(
337
337
    String aUri,
338
338
    EntityData const* aEntityData,
339
339
    std::vector<String>& oUris)
355
355
  //construct the arguments for the url resolver
356
356
  std::vector<ItemSequence_t> lArgs;
357
357
  ItemSequence_t lSeq0 = new SingletonItemSequence(theFunction);
358
 
  ItemSequence_t lSeq1 = new SingletonItemSequence(XQXQModule::getItemFactory()->createString(aUri));
359
 
  ItemSequence_t lSeq2 = new SingletonItemSequence(XQXQModule::getItemFactory()->createString(lDataKind));
 
358
  ItemSequence_t lSeq1 = new SingletonItemSequence(ZorbaQueryModule::getItemFactory()->createString(aUri));
 
359
  ItemSequence_t lSeq2 = new SingletonItemSequence(ZorbaQueryModule::getItemFactory()->createString(lDataKind));
360
360
  lArgs.push_back(lSeq0);
361
361
  lArgs.push_back(lSeq1);
362
362
  lArgs.push_back(lSeq2);
363
363
 
364
364
  //invoke the HOF helper function using the arguments generated
365
 
  Item lHofHelper = XQXQModule::getItemFactory()->
366
 
  createQName("http://www.zorba-xquery.com/modules/xqxq", "xqxq", "hof-invoker");
 
365
  Item lHofHelper = ZorbaQueryModule::getItemFactory()->
 
366
  createQName("http://zorba.io/modules/zorba-query", "zq", "hof-invoker");
367
367
 
368
368
  ItemSequence_t lResult = theCtx->invoke(lHofHelper, lArgs);
369
369
  
384
384
/*******************************************************************************
385
385
 
386
386
********************************************************************************/
387
 
Resource* XQXQURLResolver::resolveURL(
 
387
Resource* ZorbaQueryURLResolver::resolveURL(
388
388
    const String& aUrl,
389
389
    EntityData const* aEntityData)
390
390
405
405
  //construct the arguments for the url resolver
406
406
  std::vector<ItemSequence_t> lArgs;
407
407
  ItemSequence_t lSeq0 = new SingletonItemSequence(theFunction);
408
 
  ItemSequence_t lSeq1 = new SingletonItemSequence(XQXQModule::getItemFactory()->createString(aUrl));
409
 
  ItemSequence_t lSeq2 = new SingletonItemSequence(XQXQModule::getItemFactory()->createString(lDataKind));
 
408
  ItemSequence_t lSeq1 = new SingletonItemSequence(ZorbaQueryModule::getItemFactory()->createString(aUrl));
 
409
  ItemSequence_t lSeq2 = new SingletonItemSequence(ZorbaQueryModule::getItemFactory()->createString(lDataKind));
410
410
  lArgs.push_back(lSeq0);
411
411
  lArgs.push_back(lSeq1);
412
412
  lArgs.push_back(lSeq2);
413
413
  
414
414
  //invoke the HOF helper function using the arguments generated
415
 
  Item lHofHelper = XQXQModule::getItemFactory()->
416
 
  createQName("http://www.zorba-xquery.com/modules/xqxq", "xqxq", "hof-invoker");
 
415
  Item lHofHelper = ZorbaQueryModule::getItemFactory()->
 
416
  createQName("http://zorba.io/modules/zorba-query", "zq", "hof-invoker");
417
417
 
418
418
  ItemSequence_t lResult = theCtx->invoke(lHofHelper, lArgs);
419
419
 
459
459
  StaticContext_t lSctxChild = aSctx->createChildContext();
460
460
   
461
461
  QueryMap* lQueryMap;
462
 
  if (!(lQueryMap = dynamic_cast<QueryMap*>(lDynCtx->getExternalFunctionParameter("xqxqQueryMap"))))
 
462
  if (!(lQueryMap = dynamic_cast<QueryMap*>(lDynCtx->getExternalFunctionParameter("zqQueryMap"))))
463
463
  {
464
464
    lQueryMap = new QueryMap();
465
 
    lDynCtx->addExternalFunctionParameter("xqxqQueryMap", lQueryMap);     
 
465
    lDynCtx->addExternalFunctionParameter("zqQueryMap", lQueryMap);     
466
466
  }
467
467
 
468
468
  Zorba* lZorba = Zorba::getInstance(0);
473
473
    
474
474
  StaticContext_t ltempSctx = lZorba->createStaticContext();
475
475
 
476
 
  std::auto_ptr<XQXQURLResolver> lResolver;
477
 
  std::auto_ptr<XQXQURIMapper> lMapper;
 
476
  std::auto_ptr<ZorbaQueryURLResolver> lResolver;
 
477
  std::auto_ptr<ZorbaQueryURIMapper> lMapper;
478
478
 
479
479
  if ( aArgs.size() > 2 )
480
480
  {
481
481
    Item lMapperFunctionItem = getItemArgument(aArgs, 2);
482
482
    if (!lMapperFunctionItem.isNull())
483
483
    {
484
 
      lMapper.reset(new XQXQURIMapper(lMapperFunctionItem, lSctxChild));
 
484
      lMapper.reset(new ZorbaQueryURIMapper(lMapperFunctionItem, lSctxChild));
485
485
      ltempSctx->registerURIMapper(lMapper.get());
486
486
    }
487
487
  }
491
491
    Item lResolverFunctionItem = getItemArgument(aArgs, 1);
492
492
    if (!lResolverFunctionItem.isNull())
493
493
    {
494
 
      lResolver.reset(new XQXQURLResolver(lResolverFunctionItem, lSctxChild));
 
494
      lResolver.reset(new ZorbaQueryURLResolver(lResolverFunctionItem, lSctxChild));
495
495
      ltempSctx->registerURLResolver(lResolver.get());
496
496
    }  
497
497
  }
505
505
  {
506
506
    lQuery = NULL;
507
507
    std::ostringstream err;
508
 
    err << "The query compiled using xqxq:prepare-main-module raised an error at"
 
508
    err << "The query compiled using zq:prepare-main-module raised an error at"
509
509
        << " file " << xe.source_uri() << " line " << xe.source_line()
510
510
        << " column " << xe.source_column() << ": " << xe.what();
511
511
    // << " -- Query string : " << std::endl << lQueryString;
512
512
 
513
 
    Item errQName = XQXQModule::getItemFactory()->createQName(
 
513
    Item errQName = ZorbaQueryModule::getItemFactory()->createQName(
514
514
                                xe.diagnostic().qname().ns(),
515
515
                                xe.diagnostic().qname().localname());
516
516
    throw USER_EXCEPTION(errQName, err.str());
519
519
  {
520
520
    lQuery = NULL;
521
521
    std::ostringstream err;
522
 
    err << "The query compiled using xqxq:prepare-main-module raised an error: "
 
522
    err << "The query compiled using zq:prepare-main-module raised an error: "
523
523
        << e.what();
524
524
 
525
 
    Item errQName = XQXQModule::getItemFactory()->
 
525
    Item errQName = ZorbaQueryModule::getItemFactory()->
526
526
    createQName(e.diagnostic().qname().ns(), e.diagnostic().qname().localname());
527
527
 
528
528
    throw USER_EXCEPTION(errQName, err.str());
538
538
  
539
539
  lQueryMap->storeQuery(lStrUUID, lQuery, lMapper.release(), lResolver.release());
540
540
  
541
 
  return ItemSequence_t(new SingletonItemSequence(XQXQModule::getItemFactory()->createAnyURI(lStrUUID)));
 
541
  return ItemSequence_t(new SingletonItemSequence(ZorbaQueryModule::getItemFactory()->createAnyURI(lStrUUID)));
542
542
}
543
543
    
544
544
    
563
563
  catch (XQueryException& xe)
564
564
  {
565
565
    std::ostringstream err;
566
 
    err << "The query compiled using xqxq:prepare-library-module raised an error at"
 
566
    err << "The query compiled using zq:prepare-library-module raised an error at"
567
567
        << " line " << xe.source_line() << " column " << xe.source_column()
568
568
        << ": " << xe.what();
569
569
 
570
 
    Item errQName = XQXQModule::getItemFactory()->
 
570
    Item errQName = ZorbaQueryModule::getItemFactory()->
571
571
    createQName(xe.diagnostic().qname().ns(), xe.diagnostic().qname().localname());
572
572
 
573
573
    throw USER_EXCEPTION(errQName, err.str());
575
575
  catch (ZorbaException& e)
576
576
  {
577
577
    std::ostringstream err;
578
 
    err << "The query compiled using xqxq:prepare-main-query raised an error: "
 
578
    err << "The query compiled using zq:prepare-main-query raised an error: "
579
579
        << e.what();
580
580
 
581
 
      Item errQName = XQXQModule::getItemFactory()->
 
581
      Item errQName = ZorbaQueryModule::getItemFactory()->
582
582
      createQName(e.diagnostic().qname().ns(), e.diagnostic().qname().localname());
583
583
 
584
584
      throw USER_EXCEPTION(errQName, err.str());
595
595
    const zorba::StaticContext* aSctx,
596
596
    const zorba::DynamicContext* aDctx) const 
597
597
{
598
 
  String lQueryID = XQXQFunction::getOneStringArgument(aArgs, 0);
 
598
  String lQueryID = ZorbaQueryFunction::getOneStringArgument(aArgs, 0);
599
599
 
600
600
  XQuery_t lQuery = getQuery(aDctx, lQueryID);
601
601
 
602
602
  bool lIsContextItemBound = lQuery->getDynamicContext()->isBoundContextItem();
603
603
 
604
604
  return ItemSequence_t(new SingletonItemSequence(
605
 
          XQXQModule::getItemFactory()->createBoolean(lIsContextItemBound)));
 
605
          ZorbaQueryModule::getItemFactory()->createBoolean(lIsContextItemBound)));
606
606
}
607
607
 
608
608
 
614
614
    const zorba::StaticContext* aSctx,
615
615
    const zorba::DynamicContext* aDctx) const 
616
616
{
617
 
  String lQueryID = XQXQFunction::getOneStringArgument(aArgs, 0);
 
617
  String lQueryID = ZorbaQueryFunction::getOneStringArgument(aArgs, 0);
618
618
  
619
619
  XQuery_t lQuery = getQuery(aDctx, lQueryID);
620
620
 
621
 
  Item lVarQName = XQXQFunction::getItemArgument(aArgs, 1);
 
621
  Item lVarQName = ZorbaQueryFunction::getItemArgument(aArgs, 1);
622
622
  bool lIsBoundVariable = false;
623
623
 
624
624
  try
628
628
  catch (ZorbaException& ze)
629
629
  {
630
630
    if (ze.diagnostic() == zerr::ZAPI0011_VARIABLE_NOT_DECLARED)
631
 
      XQXQFunction::throwError("UndeclaredVariable", ze.what());  
 
631
      ZorbaQueryFunction::throwError("UNDECLARED_VARIABLE", ze.what());  
632
632
    throw; // should not happen
633
633
  }
634
 
  return ItemSequence_t(new SingletonItemSequence(XQXQModule::getItemFactory()->createBoolean(lIsBoundVariable)));
 
634
  return ItemSequence_t(new SingletonItemSequence(ZorbaQueryModule::getItemFactory()->createBoolean(lIsBoundVariable)));
635
635
}
636
636
 
637
637
 
643
643
    const zorba::StaticContext* aSctx,
644
644
    const zorba::DynamicContext* aDctx) const 
645
645
{  
646
 
  String lQueryID = XQXQFunction::getOneStringArgument(aArgs, 0);
 
646
  String lQueryID = ZorbaQueryFunction::getOneStringArgument(aArgs, 0);
647
647
 
648
648
  XQuery_t lQuery = getQuery(aDctx, lQueryID);
649
649
    
669
669
    const zorba::StaticContext* aSctx,
670
670
    const zorba::DynamicContext* aDctx) const 
671
671
{
672
 
  String lQueryID = XQXQFunction::getOneStringArgument(aArgs, 0);
 
672
  String lQueryID = ZorbaQueryFunction::getOneStringArgument(aArgs, 0);
673
673
  
674
674
  XQuery_t lQuery = getQuery(aDctx, lQueryID);
675
675
 
676
 
  return ItemSequence_t(new SingletonItemSequence(XQXQModule::getItemFactory()->createBoolean(lQuery->isUpdating())));
 
676
  return ItemSequence_t(new SingletonItemSequence(ZorbaQueryModule::getItemFactory()->createBoolean(lQuery->isUpdating())));
677
677
}
678
678
 
679
679
 
685
685
    const zorba::StaticContext* aSctx,
686
686
    const zorba::DynamicContext* aDctx) const 
687
687
{
688
 
  String lQueryID = XQXQFunction::getOneStringArgument(aArgs, 0);
 
688
  String lQueryID = ZorbaQueryFunction::getOneStringArgument(aArgs, 0);
689
689
  
690
690
  XQuery_t lQuery = getQuery(aDctx, lQueryID);
691
691
 
692
 
  return ItemSequence_t(new SingletonItemSequence(XQXQModule::getItemFactory()->createBoolean(lQuery->isSequential())));
 
692
  return ItemSequence_t(new SingletonItemSequence(ZorbaQueryModule::getItemFactory()->createBoolean(lQuery->isSequential())));
693
693
}
694
694
 
695
695
 
701
701
    const zorba::StaticContext* aSctx,
702
702
    const zorba::DynamicContext* aDctx) const 
703
703
{
704
 
  String lQueryID = XQXQFunction::getOneStringArgument(aArgs,0);
 
704
  String lQueryID = ZorbaQueryFunction::getOneStringArgument(aArgs,0);
705
705
  
706
706
  XQuery_t lQuery = getQuery(aDctx, lQueryID);
707
707
 
708
708
  // shouldn't raise errors
709
 
  Item lItemContext = XQXQFunction::getItemArgument(aArgs, 1);
 
709
  Item lItemContext = ZorbaQueryFunction::getItemArgument(aArgs, 1);
710
710
  lQuery->getDynamicContext()->setContextItem(lItemContext);
711
711
 
712
712
  return ItemSequence_t(new EmptySequence());
721
721
    const zorba::StaticContext* aSctx,
722
722
    const zorba::DynamicContext* aDctx) const 
723
723
{
724
 
  XQXQFunction::throwError("ImplementationError", "This function is not implemented yet");
 
724
  ZorbaQueryFunction::throwError("ImplementationError", "This function is not implemented yet");
725
725
 
726
726
  return ItemSequence_t(new EmptySequence());
727
727
}
735
735
    const zorba::StaticContext* aSctx,
736
736
    const zorba::DynamicContext* aDctx) const 
737
737
{
738
 
  XQXQFunction::throwError("ImplementationError", "This function is not implemented yet");
 
738
  ZorbaQueryFunction::throwError("ImplementationError", "This function is not implemented yet");
739
739
 
740
740
  return ItemSequence_t(new EmptySequence());
741
741
}
749
749
    const zorba::StaticContext* aSctx,
750
750
    const zorba::DynamicContext* aDctx) const 
751
751
{
752
 
  String lQueryID = XQXQFunction::getOneStringArgument(aArgs,0);
 
752
  String lQueryID = ZorbaQueryFunction::getOneStringArgument(aArgs,0);
753
753
  
754
754
  XQuery_t lQuery = getQuery(aDctx, lQueryID);
755
755
    
756
 
  Item lVarQName = XQXQFunction::getItemArgument(aArgs, 1); 
 
756
  Item lVarQName = ZorbaQueryFunction::getItemArgument(aArgs, 1); 
757
757
 
758
 
  Iterator_t lVarValue = XQXQFunction::getIterArgument(aArgs, 2); 
 
758
  Iterator_t lVarValue = ZorbaQueryFunction::getIterArgument(aArgs, 2); 
759
759
 
760
760
  if (!lQuery->getDynamicContext()->setVariable(lVarQName.getNamespace(),
761
761
                                                lVarQName.getLocalName(),
765
765
    lMsg << "{" << lVarQName.getNamespace() << "}" << lVarQName.getLocalName()
766
766
         << ": undefined variable";
767
767
 
768
 
    throwError("UndeclaredVariable", lMsg.str());
 
768
    throwError("UNDECLARED_VARIABLE", lMsg.str());
769
769
  }
770
770
 
771
771
  return ItemSequence_t(new EmptySequence());
785
785
  {
786
786
    std::ostringstream err;
787
787
    err << "The query " << "(" << theQueryID
788
 
        << ") evaluated using xqxq:evaluate raised an error at"
 
788
        << ") evaluated using zq:evaluate raised an error at"
789
789
        << " line " << xe.source_line() << " column "
790
790
        << xe.source_column() << ": " << xe.what();
791
791
 
792
 
    Item errQName = XQXQModule::getItemFactory()->
 
792
    Item errQName = ZorbaQueryModule::getItemFactory()->
793
793
    createQName(xe.diagnostic().qname().ns(), xe.diagnostic().qname().localname());
794
794
 
795
795
    throw USER_EXCEPTION(errQName, err.str());
798
798
  {
799
799
    std::ostringstream err;
800
800
    err << "The query " << "(" << theQueryID
801
 
        << ") evaluated using xqxq:evaluate raised an error at"
 
801
        << ") evaluated using zq:evaluate raised an error at"
802
802
        << e.what();
803
803
 
804
 
    Item errQName = XQXQModule::getItemFactory()->
 
804
    Item errQName = ZorbaQueryModule::getItemFactory()->
805
805
    createQName(e.diagnostic().qname().ns(), e.diagnostic().qname().localname());
806
806
 
807
807
    throw USER_EXCEPTION(errQName, err.str());
817
817
    const zorba::StaticContext* aSctx,
818
818
    const zorba::DynamicContext* aDctx) const 
819
819
{
820
 
  String lQueryID = XQXQFunction::getOneStringArgument(aArgs,0);
 
820
  String lQueryID = ZorbaQueryFunction::getOneStringArgument(aArgs,0);
821
821
 
822
822
  XQuery_t lQuery = getQuery(aDctx, lQueryID);
823
823
 
824
824
  if (lQuery->isUpdating())
825
825
  {
826
 
    throwError("QueryIsUpdating", "Executing Query shouldn't be updating.");
 
826
    throwError("QUERY_IS_UPDATING", "Executing Query shouldn't be updating.");
827
827
  }
828
828
     
829
829
  if (lQuery->isSequential())
830
830
  {
831
 
    throwError("QueryIsSequential", "Executing Query shouldn't be sequential.");
 
831
    throwError("QUERY_IS_SEQUENTIAL", "Executing Query shouldn't be sequential.");
832
832
  }
833
833
      
834
834
  Iterator_t lIterQuery = lQuery->iterator();
845
845
    const zorba::StaticContext* aSctx,
846
846
    const zorba::DynamicContext* aDctx) const 
847
847
{
848
 
  String lQueryID = XQXQFunction::getOneStringArgument(aArgs,0);
 
848
  String lQueryID = ZorbaQueryFunction::getOneStringArgument(aArgs,0);
849
849
  
850
850
  XQuery_t lQuery = getQuery(aDctx, lQueryID);
851
851
    
852
852
  if (lQuery->isSequential())
853
853
  {
854
 
    throwError("QueryIsSequential", "Executing Query shouldn't be sequential.");   
 
854
    throwError("QUERY_IS_SEQUENTIAL", "Executing Query shouldn't be sequential.");   
855
855
  }
856
856
 
857
857
  if(!lQuery->isUpdating())
858
858
  {
859
 
    throwError("QueryNotUpdating", "Executing Query should be updating.") ; 
 
859
    throwError("QUERY_NOT_UPDATING", "Executing Query should be updating.") ; 
860
860
  }
861
861
  
862
862
  Iterator_t lIterQuery = lQuery->iterator();
872
872
    const zorba::StaticContext* aSctx,
873
873
    const zorba::DynamicContext* aDctx) const 
874
874
{
875
 
  String lQueryID = XQXQFunction::getOneStringArgument(aArgs, 0);
 
875
  String lQueryID = ZorbaQueryFunction::getOneStringArgument(aArgs, 0);
876
876
  
877
877
  XQuery_t lQuery = getQuery(aDctx, lQueryID);
878
878
 
879
879
  if(lQuery->isUpdating())
880
880
  {
881
 
    throwError("QueryIsUpdating", "Executing Query shouldn't be updating.");
 
881
    throwError("QUERY_IS_UPDATING", "Executing Query shouldn't be updating.");
882
882
  }
883
883
 
884
884
  if(!lQuery->isSequential())
885
885
  {
886
 
    throwError("QueryNotSequential", "Executing Query should be sequential.");    
 
886
    throwError("QUERY_NOT_SEQUENTIAL", "Executing Query should be sequential.");    
887
887
  }
888
888
 
889
889
  Iterator_t lIterQuery = lQuery->iterator();
899
899
    const zorba::StaticContext* aSctx,
900
900
    const zorba::DynamicContext* aDctx) const 
901
901
{
902
 
  String lQueryID = XQXQFunction::getOneStringArgument(aArgs,0);
 
902
  String lQueryID = ZorbaQueryFunction::getOneStringArgument(aArgs,0);
903
903
 
904
904
  QueryMap* lQueryMap;
905
 
  if (!(lQueryMap= dynamic_cast<QueryMap*>(aDctx->getExternalFunctionParameter("xqxqQueryMap"))))
 
905
  if (!(lQueryMap= dynamic_cast<QueryMap*>(aDctx->getExternalFunctionParameter("zqQueryMap"))))
906
906
  {
907
 
    throwError("NoQueryMatch", "String identifying query does not exists.");
 
907
    throwError("NO_QUERY_MATCH", "String identifying query does not exists.");
908
908
  }
909
909
 
910
910
  if (!lQueryMap->deleteQuery(lQueryID))
911
911
  {
912
 
    throwError("NoQueryMatch","String identifying query does not exists.");
 
912
    throwError("NO_QUERY_MATCH","String identifying query does not exists.");
913
913
  }
914
914
      
915
915
  return ItemSequence_t(new EmptySequence());
924
924
    const zorba::StaticContext* aSctx,
925
925
    const zorba::DynamicContext* aDctx) const 
926
926
{
927
 
  String lQueryID = XQXQFunction::getOneStringArgument(aArgs,0);
 
927
  String lQueryID = ZorbaQueryFunction::getOneStringArgument(aArgs,0);
928
928
 
929
929
  QueryMap* lQueryMap;
930
 
  if (!(lQueryMap= dynamic_cast<QueryMap*>(aDctx->getExternalFunctionParameter("xqxqQueryMap"))))
 
930
  if (!(lQueryMap= dynamic_cast<QueryMap*>(aDctx->getExternalFunctionParameter("zqQueryMap"))))
931
931
  {
932
 
    throwError("NoQueryMatch", "String identifying query does not exists.");
 
932
    throwError("NO_QUERY_MATCH", "String identifying query does not exists.");
933
933
  }
934
934
 
935
935
  XQuery_t lQuery = getQuery(aDctx, lQueryID);
936
936
 
937
 
  Item lVarQName = XQXQFunction::getItemArgument(aArgs, 1);
 
937
  Item lVarQName = ZorbaQueryFunction::getItemArgument(aArgs, 1);
938
938
  bool lIsBoundVariable = false;
939
939
 
940
940
  zorba::DynamicContext* lCtx = lQuery->getDynamicContext();
947
947
  catch (ZorbaException& ze)
948
948
  {
949
949
    if (ze.diagnostic() == zerr::ZAPI0011_VARIABLE_NOT_DECLARED)
950
 
      XQXQFunction::throwError("UndeclaredVariable", ze.what());  
 
950
      ZorbaQueryFunction::throwError("UNDECLARED_VARIABLE", ze.what());  
951
951
    throw; // should not happen
952
952
  }
953
953
 
955
955
  {
956
956
    std::ostringstream lMsg;
957
957
    lMsg << lLocal << ": variable not bound";
958
 
    XQXQFunction::throwError("UnboundVariable", lMsg.str());  
 
958
    ZorbaQueryFunction::throwError("UNBOUND_VARIABLE", lMsg.str());  
959
959
  }
960
960
 
961
961
  zorba::Iterator_t lIterator;
981
981
    const zorba::StaticContext* aSctx,
982
982
    const zorba::DynamicContext* aDctx) const 
983
983
{
984
 
  String lQueryID = XQXQFunction::getOneStringArgument(aArgs,0);
 
984
  String lQueryID = ZorbaQueryFunction::getOneStringArgument(aArgs,0);
985
985
 
986
986
  QueryMap* lQueryMap;
987
 
  if (!(lQueryMap = dynamic_cast<QueryMap*>(aDctx->getExternalFunctionParameter("xqxqQueryMap"))))
 
987
  if (!(lQueryMap = dynamic_cast<QueryMap*>(aDctx->getExternalFunctionParameter("zqQueryMap"))))
988
988
  {
989
 
    throwError("NoQueryMatch", "String identifying query does not exists.");
 
989
    throwError("NO_QUERY_MATCH", "String identifying query does not exists.");
990
990
  }
991
991
 
992
992
  XQuery_t lQuery = getQuery(aDctx, lQueryID);
995
995
  lExcPlan.reset(new std::stringstream());
996
996
  if (!lQuery->saveExecutionPlan(*lExcPlan.get()))
997
997
  {
998
 
    throwError("QueryPlanError", "FAILED getting query execution plan.");
 
998
    throwError("NO_QUERY_PLAN", "FAILED getting query execution plan.");
999
999
  }
1000
1000
  
1001
 
  return ItemSequence_t(new SingletonItemSequence(XQXQModule::getItemFactory()->createStreamableBase64Binary(*lExcPlan.release(), &streamReleaser)));
 
1001
  return ItemSequence_t(new SingletonItemSequence(ZorbaQueryModule::getItemFactory()->createStreamableBase64Binary(*lExcPlan.release(), &streamReleaser)));
1002
1002
}
1003
1003
 
1004
1004
 
1010
1010
    const zorba::StaticContext* aSctx,
1011
1011
    const zorba::DynamicContext* aDctx) const 
1012
1012
{
1013
 
  Item lQueryPlanItem = XQXQFunction::getItemArgument(aArgs,0);
 
1013
  Item lQueryPlanItem = ZorbaQueryFunction::getItemArgument(aArgs,0);
1014
1014
  std::istream& lQueryPlanStream = lQueryPlanItem.getStream();
1015
1015
 
1016
1016
  DynamicContext* lDynCtx = const_cast<DynamicContext*>(aDctx);
1017
1017
  StaticContext_t lSctxChild = aSctx->createChildContext();
1018
1018
   
1019
1019
  QueryMap* lQueryMap;
1020
 
  if (!(lQueryMap = dynamic_cast<QueryMap*>(lDynCtx->getExternalFunctionParameter("xqxqQueryMap"))))
 
1020
  if (!(lQueryMap = dynamic_cast<QueryMap*>(lDynCtx->getExternalFunctionParameter("zqQueryMap"))))
1021
1021
  {
1022
1022
    lQueryMap = new QueryMap();
1023
 
    lDynCtx->addExternalFunctionParameter("xqxqQueryMap", lQueryMap);     
 
1023
    lDynCtx->addExternalFunctionParameter("zqQueryMap", lQueryMap);     
1024
1024
  }
1025
1025
 
1026
1026
  Zorba* lZorba = Zorba::getInstance(0);
1027
1027
  XQuery_t lQuery;
1028
1028
  
1029
 
  std::auto_ptr<XQXQURLResolver> lResolver;
1030
 
  std::auto_ptr<XQXQURIMapper> lMapper;
 
1029
  std::auto_ptr<ZorbaQueryURLResolver> lResolver;
 
1030
  std::auto_ptr<ZorbaQueryURIMapper> lMapper;
1031
1031
  try
1032
1032
  {
1033
1033
    lQuery = lZorba->createQuery();
1038
1038
      Item lMapperFunctionItem = getItemArgument(aArgs, 2);
1039
1039
      if (!lMapperFunctionItem.isNull())
1040
1040
      {
1041
 
        lMapper.reset(new XQXQURIMapper(lMapperFunctionItem, lSctxChild));
 
1041
        lMapper.reset(new ZorbaQueryURIMapper(lMapperFunctionItem, lSctxChild));
1042
1042
        lPlanSer.add_URIMapper(lMapper.get());
1043
1043
      }
1044
1044
 
1045
1045
      Item lResolverFunctionItem = getItemArgument(aArgs, 1);
1046
1046
      if (!lResolverFunctionItem.isNull())
1047
1047
      {
1048
 
        lResolver.reset(new XQXQURLResolver(lResolverFunctionItem, lSctxChild));
 
1048
        lResolver.reset(new ZorbaQueryURLResolver(lResolverFunctionItem, lSctxChild));
1049
1049
        lPlanSer.add_URLResolver(lResolver.get());
1050
1050
      }
1051
1051
 
1063
1063
    err << "The query loaded from the query plan raised an error at"
1064
1064
      << " file" << xe.source_uri() << " line" << xe.source_line()
1065
1065
      << " column" << xe.source_column() << ": " << xe.what();
1066
 
    Item errQName = XQXQModule::getItemFactory()->createQName(
 
1066
    Item errQName = ZorbaQueryModule::getItemFactory()->createQName(
1067
1067
      xe.diagnostic().qname().ns(),
1068
1068
      xe.diagnostic().qname().localname());
1069
1069
    throw USER_EXCEPTION(errQName, err.str());
1076
1076
      err << "The query loaded from the query plan raised an error: failed to load pre-compiled query: document, collection, or module resolver required but not given.";
1077
1077
    else
1078
1078
      err << "The query loaded from the query plan raised an error: "<< ze.what();
1079
 
    Item errQName = XQXQModule::getItemFactory()->createQName(
 
1079
    Item errQName = ZorbaQueryModule::getItemFactory()->createQName(
1080
1080
      ze.diagnostic().qname().ns(),
1081
1081
      ze.diagnostic().qname().localname());
1082
1082
    throw USER_EXCEPTION(errQName, err.str());
1091
1091
  String lStrUUID = lStream.str();
1092
1092
 
1093
1093
  lQueryMap->storeQuery(lStrUUID, lQuery, lMapper.release(), lResolver.release());
1094
 
  return ItemSequence_t(new SingletonItemSequence(XQXQModule::getItemFactory()->createAnyURI(lStrUUID)));
 
1094
  return ItemSequence_t(new SingletonItemSequence(ZorbaQueryModule::getItemFactory()->createAnyURI(lStrUUID)));
1095
1095
}
1096
1096
 
1097
 
}/*namespace xqxq*/ }/*namespace zorba*/
 
1097
}/*namespace zorbaquery*/ }/*namespace zorba*/
1098
1098
 
1099
1099
#ifdef WIN32
1100
1100
#  define DLL_EXPORT __declspec(dllexport)
1103
1103
#endif
1104
1104
 
1105
1105
extern "C" DLL_EXPORT zorba::ExternalModule* createModule() {
1106
 
  return new zorba::xqxq::XQXQModule();
 
1106
  return new zorba::zorbaquery::ZorbaQueryModule();
1107
1107
}