#pragma once #include "database/db.hpp" #include "database/db_accessor.hpp" #include "storage/record_accessor.hpp" #include "storage/vertex.hpp" #include "storage/vertex_accessor.hpp" #include "storage/vertices.hpp" #include "transactions/transaction.hpp" #include "utils/iterator/iterator.hpp" #include "utils/option.hpp" /* * DbAccessor * -Guarantees that access to Vertex and Edge is possible only through * Vertex::Accessor and Edge::Accessor. * -Guarantees that changing Vertex and Edge is possible only using * Vertex::Accessor returned by vertex_insert() method and * Edge::Accessor returned by edge_insert() method. * -Offers CRUD for Vertex and Edge except iterating over all edges. * * Vertex::Accessor * By default Vertex::accessor is empty. Caller has to call fill() method * to fetch valid data and check it's return value. fill() method returns * true if there is valid data for current transaction false otherwise. * Only exception to this rule is vertex_insert() method in DbAccessor * which returns by default filled Vertex::Accessor. * * Edge::Accessor * By default Edge::accessor is empty. Caller has to call fill() method * to * fetch valid data and check it's return value. fill() method returns * true * if there is valid data for current transaction false otherwise. * Only exception to this rule is edge_insert() method in DbAccessor * which * returns by default filled Edge::Accessor. */ class DbAccessor { public: DbAccessor(Db &db); //*******************VERTEX METHODS auto vertex_access(); Option vertex_find(const Id &id); // Creates new Vertex and returns filled Vertex::Accessor. Vertex::Accessor vertex_insert(); //*******************EDGE METHODS Option edge_find(const Id &id); // Creates new Edge and returns filled Edge::Accessor. Edge::Accessor edge_insert(Vertex::Accessor const &from, Vertex::Accessor const &to); //*******************LABEL METHODS const Label &label_find_or_create(const std::string &name); bool label_contains(const std::string &name); VertexIndexRecordCollection &label_find_index(const Label &label); //********************TYPE METHODS const EdgeType &type_find_or_create(const std::string &name); bool type_contains(const std::string &name); //********************TRANSACTION METHODS void commit(); void abort(); private: DbTransaction db; }; //**********************CONVENIENT FUNCTIONS template bool option_fill(Option &o) { return o.is_present() && o.get().fill(); }