From 17c8ff11004548c1f0b9332af3ac1ba2fad066fa Mon Sep 17 00:00:00 2001 From: Adam Dickmeiss Date: Thu, 18 Dec 2014 11:23:41 +0100 Subject: [PATCH] Result set handling --- src/filter_sparql.cpp | 62 +++++++++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 60 insertions(+), 2 deletions(-) diff --git a/src/filter_sparql.cpp b/src/filter_sparql.cpp index 8900033..97af63c 100644 --- a/src/filter_sparql.cpp +++ b/src/filter_sparql.cpp @@ -38,9 +38,13 @@ namespace metaproxy_1 { class Session; class Rep; class Conf; + class FrontendSet; typedef boost::shared_ptr SessionPtr; typedef boost::shared_ptr ConfPtr; + + typedef boost::shared_ptr FrontendSetPtr; + typedef std::map FrontendSets; public: SPARQL(); ~SPARQL(); @@ -65,6 +69,15 @@ namespace metaproxy_1 { boost::mutex m_mutex; std::map m_clients; }; + class SPARQL::FrontendSet { + public: + FrontendSet(); + ~FrontendSet(); + private: + friend class Session; + Odr_int hits; + xmlDoc *doc; + }; class SPARQL::Session { public: Session(const SPARQL *); @@ -78,11 +91,23 @@ namespace metaproxy_1 { bool m_in_use; private: bool m_support_named_result_sets; + FrontendSets m_frontend_sets; const SPARQL *m_sparql; }; } } +yf::SPARQL::FrontendSet::~FrontendSet() +{ + if (doc) + xmlFreeDoc(doc); +} + +yf::SPARQL::FrontendSet::FrontendSet() +{ + doc = 0; +} + yf::SPARQL::SPARQL() : m_p(new Rep) { } @@ -257,22 +282,37 @@ Z_APDU *yf::SPARQL::Session::run_sparql(mp::Package &package, gdu->u.HTTP_Request->content_buf = path; gdu->u.HTTP_Request->content_len = strlen(path); - yaz_log(YLOG_LOG, "sparql: HTTP request\n%s", sparql_query); http_package.request() = gdu; http_package.move(); Z_GDU *gdu_resp = http_package.response().get(); + Z_APDU *apdu_res = 0; if (gdu_resp && gdu_resp->which == Z_GDU_HTTP_Response) { Z_HTTP_Response *resp = gdu_resp->u.HTTP_Response; + FrontendSetPtr fset(new FrontendSet); + + fset->doc = xmlParseMemory(resp->content_buf, resp->content_len); + if (!fset->doc) + apdu_res = odr.create_searchResponse(apdu_req, + YAZ_BIB1_TEMPORARY_SYSTEM_ERROR, + "invalid XML from backendbackend"); + else + { + apdu_res = odr.create_searchResponse(apdu_req, 0, 0); + + m_frontend_sets[apdu_req->u.searchRequest->resultSetName] = fset; + } } else { yaz_log(YLOG_LOG, "sparql: no HTTP response"); + apdu_res = odr.create_searchResponse(apdu_req, + YAZ_BIB1_TEMPORARY_SYSTEM_ERROR, + "no HTTP response from backend"); } - Z_APDU *apdu_res = odr.create_searchResponse(apdu_req, 0, 0); return apdu_res; } @@ -321,6 +361,24 @@ void yf::SPARQL::Session::handle_z(mp::Package &package, Z_APDU *apdu_req) { Z_SearchRequest *req = apdu_req->u.searchRequest; + FrontendSets::iterator fset_it = + m_frontend_sets.find(req->resultSetName); + if (fset_it != m_frontend_sets.end()) + { + // result set already exist + // if replace indicator is off: we return diagnostic if + // result set already exist. + if (*req->replaceIndicator == 0) + { + Z_APDU *apdu = + odr.create_searchResponse( + apdu_req, + YAZ_BIB1_RESULT_SET_EXISTS_AND_REPLACE_INDICATOR_OFF, + 0); + package.response() = apdu_res; + } + m_frontend_sets.erase(fset_it); + } if (req->query->which != Z_Query_type_1) { apdu_res = odr.create_searchResponse( -- 1.7.10.4