diff options
author | jsdelfino <jsdelfino@13f79535-47bb-0310-9956-ffa450edef68> | 2013-01-03 07:41:14 +0000 |
---|---|---|
committer | jsdelfino <jsdelfino@13f79535-47bb-0310-9956-ffa450edef68> | 2013-01-03 07:41:14 +0000 |
commit | 9e1b9e73145e00ea591bd1e0e9777625bad66dc9 (patch) | |
tree | c6563988970251cba763364bcddd33ac7fe23970 /sca-cpp/trunk/components/filedb/filedb.hpp | |
parent | 157ca678dee75e7881a0198425d0c8328f0bee04 (diff) |
Add support for HTTP patch and application of patch scripts to server and data store components.
git-svn-id: http://svn.us.apache.org/repos/asf/tuscany@1428192 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'sca-cpp/trunk/components/filedb/filedb.hpp')
-rw-r--r-- | sca-cpp/trunk/components/filedb/filedb.hpp | 27 |
1 files changed, 26 insertions, 1 deletions
diff --git a/sca-cpp/trunk/components/filedb/filedb.hpp b/sca-cpp/trunk/components/filedb/filedb.hpp index 2855cebfc6..41dde88bef 100644 --- a/sca-cpp/trunk/components/filedb/filedb.hpp +++ b/sca-cpp/trunk/components/filedb/filedb.hpp @@ -82,6 +82,7 @@ private: friend const failable<value> read(istream& is, const string& format); friend const failable<bool> post(const value& key, const value& val, const FileDB& db); friend const failable<bool> put(const value& key, const value& val, const FileDB& db); + friend const failable<bool> patch(const value& key, const value& val, const FileDB& db); friend const failable<value> get(const value& key, const FileDB& db); friend const failable<bool> del(const value& key, const FileDB& db); }; @@ -208,6 +209,30 @@ const failable<bool> put(const value& key, const value& val, const FileDB& db) { } /** + * Patch an item in the database. If the item doesn't exist it is added. + */ +const failable<bool> patch(const value& key, const value& val, const FileDB& db) { + debug(key, "filedb::patch::key"); + debug(val, "filedb::patch::value"); + debug(db.name, "filedb::patch::dbname"); + + if (isList(key)) + mkdirs(key, db.name); + const string fn = filename(key, db.name); + debug(fn, "filedb::patch::filename"); + ofstream os(fn); + if (os.fail()) { + ostringstream os; + os << "Couldn't patch file database entry: " << key; + return mkfailure<bool>(str(os)); + } + const failable<bool> r = write(val, os, db.format); + + debug(r, "filedb::patch::result"); + return r; +} + +/** * Get an item from the database. */ const failable<value> get(const value& key, const FileDB& db) { @@ -241,7 +266,7 @@ const failable<bool> del(const value& key, const FileDB& db) { if (rc == -1) { ostringstream os; os << "Couldn't delete file database entry: " << key; - return mkfailure<bool>(str(os)); + return errno == ENOENT? mkfailure<bool>(str(os), 404, false) : mkfailure<bool>(str(os)); } debug(true, "filedb::delete::result"); |