Back to index

nordugrid-arc-nox  1.1.0~rc6
XmlDatabase.cpp
Go to the documentation of this file.
00001 #ifdef HAVE_CONFIG_H
00002 #include <config.h>
00003 #endif
00004 
00005 #include "XmlDatabase.h"
00006 
00007 namespace Arc
00008 {
00009 
00010 XmlDatabase::XmlDatabase(const std::string &db_path,
00011                          const std::string &db_name)
00012 {
00013     container_ = new Arc::XmlContainer(db_path, db_name);
00014 }
00015 
00016 XmlDatabase::~XmlDatabase(void)
00017 {
00018     delete container_;
00019 }
00020 
00021 void
00022 XmlDatabase::put(const std::string &name, const std::string &content)
00023 {
00024     container_->put(name, content);
00025 }
00026 
00027 void
00028 XmlDatabase::put(const std::string &name, Arc::XMLNode &doc)
00029 {
00030     std::string content;
00031     doc.GetDoc(content);
00032     container_->put(name, content);
00033 }
00034 
00035 void
00036 XmlDatabase::get(const std::string &name, Arc::XMLNode &doc)
00037 {
00038     std::string content = container_->get(name);
00039     if (!content.empty()) {
00040         Arc::XMLNode nn(content);
00041         nn.New(doc);
00042     }
00043 }
00044 
00045 void
00046 XmlDatabase::del(const std::string &name)
00047 {
00048     container_->del(name);
00049 }
00050 
00051 Arc::XMLNodeList
00052 XmlDatabase::query(const std::string &name, const std::string &q)
00053 {
00054     Arc::XMLNode node;
00055     get(name, node);
00056     return node.XPathLookup(q, node.Namespaces());
00057 }
00058 
00059 void
00060 XmlDatabase::queryAll(const std::string &q,
00061                       std::map<std::string, Arc::XMLNodeList> &result)
00062 {
00063     std::vector<std::string> doc_names = container_->get_doc_names();
00064 
00065     for (int i = 0; i < doc_names.size(); i++) {
00066         Arc::XMLNodeList r = query(doc_names[i], q);
00067         result[doc_names[i]] = r;
00068     }
00069 }
00070 
00071 void
00072 XmlDatabase::update(const std::string &name, const std::string &query,
00073                     Arc::XMLNode &new_value)
00074 {
00075     container_->start_update();
00076     // get content
00077     // parse content to XMLNode
00078     // run query
00079     // replace query result nodes with new_value
00080     // get the new document as string
00081     // put the content back to container
00082     container_->end_update();
00083 }
00084 
00085 void
00086 XmlDatabase::checkpoint()
00087 {
00088     container_->checkpoint();
00089 }
00090 
00091 } // namespace Arc
00092