Juan Zacarias has proposed merging lp:~zorba-coders/zorba/xqxq_changes into 
lp:zorba/xqxq-module with lp:~zorba-coders/zorba/api_changes as a prerequisite.

Requested reviews:
  Markos Zaharioudakis (markos-za)
  Matthias Brantner (matthias-brantner)

For more details, see:
https://code.launchpad.net/~zorba-coders/zorba/xqxq_changes/+merge/83818

Modified error message for EvaluateIterator
changed evaluate-updating to an updating function
queryMap now uses String instead of std::string
removed some unnecesary static contexts
fixed prepare-library-module
changed isBoundContextItem to use new api function
changed isBoundExternalVariable to use function from dynamicContext instead of 
XQuery_t
removed static ItemFactory
Included new class EvaluateIterator under EvaluateItemSequence to catch errors
-- 
https://code.launchpad.net/~zorba-coders/zorba/xqxq_changes/+merge/83818
Your team Zorba Coders is subscribed to branch 
lp:~zorba-coders/zorba/api_changes.
=== modified file 'src/xqxq.xq'
--- src/xqxq.xq	2011-11-23 21:27:48 +0000
+++ src/xqxq.xq	2011-11-29 17:33:29 +0000
@@ -198,7 +198,7 @@
  :   given query or applying its updates.
  :
  :)
-declare function xqxq:evaluate-updating($query-key as xs:anyURI) external;
+declare updating function xqxq:evaluate-updating($query-key as xs:anyURI) external;
 
 (:~ 
  : Evaluates the given prepared query and returns the result

=== modified file 'src/xqxq.xq.src/xqxq.cpp'
--- src/xqxq.xq.src/xqxq.cpp	2011-11-23 21:27:48 +0000
+++ src/xqxq.xq.src/xqxq.cpp	2011-11-29 17:33:29 +0000
@@ -4,6 +4,7 @@
 #include <zorba/empty_sequence.h>
 #include <zorba/store_manager.h>
 #include <zorba/user_exception.h>
+#include <zorba/uri_resolvers.h>
 #include <zorba/vector_item_sequence.h>
 #include <zorba/serializer.h>
 #include <zorba/xquery.h>
@@ -18,8 +19,6 @@
 
   /*******************************************************************************************
   *******************************************************************************************/
-  
-  ItemFactory* XQXQModule::theFactory = 0;
 
   zorba::ExternalFunction*
     XQXQModule::getExternalFunction(const zorba::String& localName)
@@ -193,15 +192,14 @@
     QueryMap::storeQuery(const String& aKeyName, XQuery_t aQuery)
   {
     std::pair<QueryMap_t::iterator,bool> ret;
-    ret = queryMap->insert(std::pair<std::string, XQuery_t>(aKeyName.c_str(), aQuery));
-    
+    ret = queryMap->insert(std::pair<String, XQuery_t>(aKeyName, aQuery));
     return ret.second;
   }
 
   XQuery_t
     QueryMap::getQuery(const String& aKeyName)
   {
-    QueryMap::QueryMap_t::iterator lIter = queryMap->find(aKeyName.c_str());
+    QueryMap::QueryMap_t::iterator lIter = queryMap->find(aKeyName);
 
     if(lIter == queryMap->end())
       return NULL;
@@ -214,7 +212,7 @@
   bool
     QueryMap::deleteQuery(const String& aKeyName)
   {
-    QueryMap::QueryMap_t::iterator lIter = queryMap->find(aKeyName.c_str());
+    QueryMap::QueryMap_t::iterator lIter = queryMap->find(aKeyName);
 
     if(lIter == queryMap->end())
       return false;
@@ -247,13 +245,11 @@
 
     String lQueryString = getOneStringArgument(aArgs, 0); 
     
-    StaticContext_t lStaticContext = lZorba->createStaticContext();
-
     XQuery_t lQuery;
     
     try
     {
-      lQuery = lZorba->compileQuery(lQueryString, lStaticContext);
+      lQuery = lZorba->compileQuery(lQueryString);
     }
     catch (ZorbaException& e)
     {
@@ -300,12 +296,13 @@
   {
     Zorba *lZorba = Zorba::getInstance(0);
     String lQueryString = getOneStringArgument(aArgs, 0);     
+ 
     Zorba_CompilerHints_t hints;
-    StaticContext_t lStaticContext =  lZorba->createStaticContext();
     hints.lib_module = true;
+
     try
     {
-      lStaticContext->loadProlog(lQueryString, hints);
+      lZorba->compileQuery(lQueryString, hints);
     }
     catch(ZorbaException& e)
     {
@@ -317,10 +314,6 @@
       );
       throw USER_EXCEPTION(errQName, err.str());
     }
-    catch(...)
-    {
-      XQXQFunction::throwError("LibraryModuleError", "LibraryModule does not compile.");
-    }
     return ItemSequence_t(new EmptySequence());
   }
 
@@ -337,20 +330,14 @@
 
     XQuery_t lQuery = getQuery(aDctx, lQueryID);
 
-    Item lContextItem;
-
-    //Remove try when bug ##### in launchpad is solved
     bool lIsContextItemBound;
     try
     {
-      lIsContextItemBound = lQuery->getDynamicContext()->getContextItem(lContextItem);
+      lIsContextItemBound = lQuery->getDynamicContext()->isBoundContextItem();
     }
     catch (ZorbaException& ze)
     {
-      if (!strcmp("XPDY0002",ze.diagnostic().qname().localname()))
-        lIsContextItemBound = false;
-      else
-        XQXQFunction::throwError(ze.diagnostic().qname().localname(), ze.diagnostic().message()); 
+      XQXQFunction::throwError(ze.diagnostic().qname().localname(), ze.diagnostic().message()); 
     }
     return ItemSequence_t(new SingletonItemSequence(XQXQModule::getItemFactory()->createBoolean(lIsContextItemBound)));
   }
@@ -372,14 +359,11 @@
 
     try
     {
-      lIsBoundVariable = lQuery->isBoundExternalVariable(lVarQName.getNamespace(),lVarQName.getLocalName());
+      lIsBoundVariable = lQuery->getDynamicContext()->isBoundExternalVariable(lVarQName.getNamespace(),lVarQName.getLocalName());
     }
     catch (ZorbaException& ze)
     {
-      if (!strcmp("XPDY0002",ze.diagnostic().qname().localname()))
-        lIsBoundVariable = false;
-      else
-        XQXQFunction::throwError(ze.diagnostic().qname().localname(), ze.diagnostic().message());  
+      XQXQFunction::throwError(ze.diagnostic().qname().localname(), ze.diagnostic().message());  
     }
     return ItemSequence_t(new SingletonItemSequence(XQXQModule::getItemFactory()->createBoolean(lIsBoundVariable)));
   
@@ -509,6 +493,29 @@
 
   /*******************************************************************************************
   *******************************************************************************************/
+  bool
+    EvaluateItemSequence::EvaluateIterator::next(Item& aItem)
+  {
+    try
+    {
+      return theIterator->next(aItem);
+    }
+    catch (ZorbaException& e)
+    {
+      const zorba::Diagnostic& d = e.diagnostic();
+      std::ostringstream message;
+      message << e;
+      std::string msg = message.str().substr(message.str().find(")")+1);
+
+      std::ostringstream err;
+      err << "The query evaluated using xqxq:evaluate raised an error as follows" << " \"(" << theQueryID << ")" << msg << ":" << d.message() << "\"";
+      Item errQName = XQXQModule::getItemFactory()->createQName(d.qname().ns(), d.qname().localname());
+      throw USER_EXCEPTION(errQName, err.str());
+    }
+  }
+
+  /*******************************************************************************************
+  *******************************************************************************************/
   zorba::ItemSequence_t
     EvaluateFunction::evaluate(
       const Arguments_t& aArgs,
@@ -531,7 +538,8 @@
     }
       
     Iterator_t lIterQuery = lQuery->iterator();
-    return ItemSequence_t(new EvaluateItemSequence(lIterQuery));
+
+    return ItemSequence_t(new EvaluateItemSequence(lIterQuery, lQueryID));
   }
 
   /*******************************************************************************************
@@ -557,7 +565,7 @@
     }
     
     Iterator_t lIterQuery = lQuery->iterator();
-    return ItemSequence_t(new EvaluateItemSequence(lIterQuery));
+    return ItemSequence_t(new EvaluateItemSequence(lIterQuery, lQueryID));
 }
 
   /*******************************************************************************************
@@ -583,7 +591,7 @@
     }
 
     Iterator_t lIterQuery = lQuery->iterator();
-    return ItemSequence_t(new EvaluateItemSequence(lIterQuery));
+    return ItemSequence_t(new EvaluateItemSequence(lIterQuery, lQueryID));
   }
 
   /*******************************************************************************************

=== modified file 'src/xqxq.xq.src/xqxq.h'
--- src/xqxq.xq.src/xqxq.h	2011-11-23 21:27:48 +0000
+++ src/xqxq.xq.src/xqxq.h	2011-11-29 17:33:29 +0000
@@ -15,9 +15,6 @@
   
 
   class XQXQModule : public ExternalModule {
-		private:
-      static ItemFactory* theFactory;
-
     protected:
       class ltstr
       {
@@ -47,21 +44,16 @@
       static ItemFactory*
         getItemFactory()
       {
-        if(!theFactory)
-        {
-          theFactory = Zorba::getInstance(0)->getItemFactory();
-        }
-
-        return theFactory;
+        return Zorba::getInstance(0)->getItemFactory();
       }
 
   };
 
   class QueryMap : public ExternalFunctionParameter{
     private:
-      typedef std::map<std::string, XQuery_t> QueryMap_t;
+      typedef std::map<String, XQuery_t> QueryMap_t;
       QueryMap_t* queryMap;
-    
+
     public:
       QueryMap();
       bool 
@@ -300,17 +292,59 @@
   class EvaluateItemSequence : public ItemSequence
   {
   protected:
-    Iterator_t theIter;
+
+    class EvaluateIterator : public Iterator
+    {
+      protected:
+        Iterator_t theIterator;
+
+        String theQueryID;
+
+      public:
+        EvaluateIterator(Iterator_t& aIter, String aQueryID)
+          : theIterator(aIter), theQueryID(aQueryID)
+        {
+        }
+
+        virtual ~EvaluateIterator(){}
+
+        virtual void
+          open()
+        {
+          theIterator->open();
+        }
+
+        virtual bool
+          next(Item& aItem);
+
+        virtual void 
+          close()
+        {
+          theIterator->close();
+        }
+
+        virtual bool
+          isOpen() const
+        {
+          return theIterator->isOpen();
+        }
+
+    };
+
+    typedef zorba::SmartPtr<EvaluateIterator> EvaluateIterator_t;
+    EvaluateIterator_t theIter; 
 
   public:
-    EvaluateItemSequence(Iterator_t& aIter)
-      : theIter(aIter)
-    {}
+    EvaluateItemSequence(Iterator_t& aIter, String& aQueryID)
+      :theIter (new EvaluateIterator(aIter, aQueryID))
+    {
+      
+    }
 
     virtual ~EvaluateItemSequence() {}
 
     Iterator_t
-    getIterator() { return theIter; }
+      getIterator() { return theIter.get(); }
   };
 
   class EvaluateFunction : public XQXQFunction{

-- 
Mailing list: https://launchpad.net/~zorba-coders
Post to     : zorba-coders@lists.launchpad.net
Unsubscribe : https://launchpad.net/~zorba-coders
More help   : https://help.launchpad.net/ListHelp

Reply via email to