RecordProxy work in progres... Initial test case for VertexProxy

This commit is contained in:
Marko Budiselic 2015-12-15 23:35:09 +01:00
parent 126b95b454
commit d7ae5e69ce
9 changed files with 58 additions and 29 deletions

View File

@ -8,8 +8,7 @@
* well, only if you're editing the template file, that's ok :) * well, only if you're editing the template file, that's ok :)
*/ */
#ifndef MEMGRAPH_API_RESOURCES_INCLUDE_HPP #pragma once
#define MEMGRAPH_API_RESOURCES_INCLUDE_HPP
#include <list> #include <list>
#include <memory> #include <memory>
@ -47,5 +46,3 @@ void init(ioc::Container& container)
// insert<Node>("/node/{id:\\d+}"); // insert<Node>("/node/{id:\\d+}");
<INIT> <INIT>
} }
#endif

View File

@ -19,18 +19,21 @@ public:
auto& transaction = db->tx_engine.begin(); auto& transaction = db->tx_engine.begin();
// insert a new vertex // insert a new vertex
auto vertex = db->graph.vertices.insert(transaction); auto vertex_proxy = db->graph.vertices.insert(transaction);
// map fields // map fields
for(auto it = req.json.MemberBegin(); it != req.json.MemberEnd(); ++it) for(auto it = req.json.MemberBegin(); it != req.json.MemberEnd(); ++it)
{ {
vertex->data.props.set<String>(it->name.GetString(), it->value.GetString()); vertex_proxy.property<std::string, std::string>(
it->name.GetString(),
it->value.GetString()
);
} }
// commit the transaction // commit the transaction
transaction.commit(); transaction.commit();
return vertex; return vertex_proxy.version();
}, },
[&req, &res](Vertex* node) { [&req, &res](Vertex* node) {
return res.send(properties_to_string(node)); return res.send(properties_to_string(node));

View File

@ -1,5 +1,4 @@
#ifndef MEMGRAPH_API_RESOURCES_RELATIONSHIP_HPP #pragma once
#define MEMGRAPH_API_RESOURCES_RELATIONSHIP_HPP
#include "api/restful/resource.hpp" #include "api/restful/resource.hpp"
@ -27,5 +26,3 @@ public:
return res.send("GET /db/data/relationship"); return res.send("GET /db/data/relationship");
} }
}; };
#endif

View File

@ -1,5 +1,4 @@
#ifndef MEMGRAPH_API_RESTFUL_RESOURCE_HPP #pragma once
#define MEMGRAPH_API_RESTFUL_RESOURCE_HPP
#include "api/restful/restful_resource.hpp" #include "api/restful/restful_resource.hpp"
@ -49,5 +48,3 @@ protected:
private: private:
std::once_flag once_flag; std::once_flag once_flag;
}; };
#endif

View File

@ -1,5 +1,4 @@
#ifndef MEMGRAPH_API_RESTFUL_RESTFUL_RESOURCE_HPP #pragma once
#define MEMGRAPH_API_RESTFUL_RESTFUL_RESOURCE_HPP
#include <memory> #include <memory>
@ -155,5 +154,3 @@ public:
Restful(T& resource, sp::Speedy& app, const std::string& path) Restful(T& resource, sp::Speedy& app, const std::string& path)
: detail::Methods<T, Ms...>(resource, app, path) {} : detail::Methods<T, Ms...>(resource, app, path) {}
}; };
#endif

View File

@ -20,11 +20,6 @@ public:
value.accept(*this); value.accept(*this);
} }
void handle(Null&)
{
buffer << "NULL";
}
void handle(Bool& b) void handle(Bool& b)
{ {
buffer << (b.value() ? "true" : "false"); buffer << (b.value() ? "true" : "false");

View File

@ -2,11 +2,32 @@
#include "transactions/transaction.hpp" #include "transactions/transaction.hpp"
#include "mvcc/version_list.hpp" #include "mvcc/version_list.hpp"
#include "storage/model/properties/property.hpp"
template <class T, class Store, class Derived> template <typename T, typename Store, typename Derived>
class RecordProxy class RecordProxy
{ {
public: public:
RecordProxy(T* record, Store *store, mvcc::VersionList<T> *version_list) :
record(record), store(store), version_list(version_list)
{
}
RecordProxy(const RecordProxy& record_proxy) = delete;
RecordProxy(RecordProxy&& other) :
record(other.record), store(other.store), version_list(other.version_list)
{
other.record = nullptr;
other.store = nullptr;
other.version_list = nullptr;
}
~RecordProxy()
{
// TODO: implementation
}
Derived update(tx::Transaction& transaction) const Derived update(tx::Transaction& transaction) const
{ {
// TODO: implementation // TODO: implementation
@ -20,6 +41,24 @@ public:
transaction.commit(); transaction.commit();
} }
template<typename K>
Property* property(const K& key) const
{
return record->data.props.find(key);
}
template<typename K, typename V>
void property(const K& key, const V& value)
{
record->data.props.template set<String>(key, value);
// TODO: update the index
}
T* version()
{
return record;
}
private: private:
T* record; T* record;
Store *store; Store *store;

View File

@ -1,9 +1,10 @@
#pragma once #pragma once
#include "record_proxy.hpp" #include "record_proxy.hpp"
#include "vertices.hpp"
class Vertices;
class VertexProxy : public RecordProxy<Vertex, Vertices, VertexProxy> class VertexProxy : public RecordProxy<Vertex, Vertices, VertexProxy>
{ {
// TODO: implementation using RecordProxy::RecordProxy;
}; };

View File

@ -2,6 +2,7 @@
#include "vertex.hpp" #include "vertex.hpp"
#include "common.hpp" #include "common.hpp"
#include "vertex_proxy.hpp"
class Vertices class Vertices
{ {
@ -22,7 +23,7 @@ public:
return vertex; return vertex;
} }
Vertex* insert(tx::Transaction& transaction) VertexProxy insert(tx::Transaction& transaction)
{ {
// get next vertex id // get next vertex id
auto next = counter.next(std::memory_order_acquire); auto next = counter.next(std::memory_order_acquire);
@ -39,7 +40,9 @@ public:
auto vertex_accessor = inserted_vertex_record->second.access(transaction); auto vertex_accessor = inserted_vertex_record->second.access(transaction);
auto vertex = vertex_accessor.insert(); auto vertex = vertex_accessor.insert();
return vertex; VertexProxy vertex_proxy(vertex, this, &inserted_vertex_record->second);
return vertex_proxy;
} }
Vertex* update(tx::Transaction& transaction, const Id& id) Vertex* update(tx::Transaction& transaction, const Id& id)