~ubuntu-branches/ubuntu/trusty/nordugrid-arc/trusty-proposed

« back to all changes in this revision

Viewing changes to src/hed/libs/dbxml/XmlDatabase.cpp

  • Committer: Package Import Robot
  • Author(s): Mattias Ellert
  • Date: 2013-05-08 13:48:03 UTC
  • mfrom: (1.1.7)
  • Revision ID: package-import@ubuntu.com-20130508134803-mrhc5w4d5y7ubyj4
Tags: 3.0.1-1
3.0.1 Release

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
#ifdef HAVE_CONFIG_H
2
 
#include <config.h>
3
 
#endif
4
 
 
5
 
#include "XmlDatabase.h"
6
 
 
7
 
namespace Arc
8
 
{
9
 
 
10
 
XmlDatabase::XmlDatabase(const std::string &db_path,
11
 
                         const std::string &db_name)
12
 
{
13
 
    container_ = new Arc::XmlContainer(db_path, db_name);
14
 
}
15
 
 
16
 
XmlDatabase::~XmlDatabase(void)
17
 
{
18
 
    delete container_;
19
 
}
20
 
 
21
 
void
22
 
XmlDatabase::put(const std::string &name, const std::string &content)
23
 
{
24
 
    container_->put(name, content);
25
 
}
26
 
 
27
 
void
28
 
XmlDatabase::put(const std::string &name, Arc::XMLNode &doc)
29
 
{
30
 
    std::string content;
31
 
    doc.GetDoc(content);
32
 
    container_->put(name, content);
33
 
}
34
 
 
35
 
void
36
 
XmlDatabase::get(const std::string &name, Arc::XMLNode &doc)
37
 
{
38
 
    std::string content = container_->get(name);
39
 
    if (!content.empty()) {
40
 
        Arc::XMLNode nn(content);
41
 
        nn.New(doc);
42
 
    }
43
 
}
44
 
 
45
 
void
46
 
XmlDatabase::del(const std::string &name)
47
 
{
48
 
    container_->del(name);
49
 
}
50
 
 
51
 
Arc::XMLNodeList
52
 
XmlDatabase::query(const std::string &name, const std::string &q)
53
 
{
54
 
    Arc::XMLNode node;
55
 
    get(name, node);
56
 
    return node.XPathLookup(q, node.Namespaces());
57
 
}
58
 
 
59
 
void
60
 
XmlDatabase::queryAll(const std::string &q,
61
 
                      std::map<std::string, Arc::XMLNodeList> &result)
62
 
{
63
 
    std::vector<std::string> doc_names = container_->get_doc_names();
64
 
 
65
 
    for (int i = 0; i < doc_names.size(); i++) {
66
 
        Arc::XMLNodeList r = query(doc_names[i], q);
67
 
        result[doc_names[i]] = r;
68
 
    }
69
 
}
70
 
 
71
 
void
72
 
XmlDatabase::update(const std::string& /* name */, const std::string& /* query */,
73
 
                    Arc::XMLNode& /* new_value */)
74
 
{
75
 
    container_->start_update();
76
 
    // get content
77
 
    // parse content to XMLNode
78
 
    // run query
79
 
    // replace query result nodes with new_value
80
 
    // get the new document as string
81
 
    // put the content back to container
82
 
    container_->end_update();
83
 
}
84
 
 
85
 
void
86
 
XmlDatabase::checkpoint()
87
 
{
88
 
    container_->checkpoint();
89
 
}
90
 
 
91
 
} // namespace Arc
92