memgraph/include/database/db_accessor.hpp
Kruno Tomola Fabro 5a42e15c4a Alpha version of label indexes.
Squashed messages from 9 commits:

9.
Properties now uses PropertyFamily and contained classes.
Fetching,seting,clearing properties can be done with PropertyFamilyKey or PropertyTypeKey.
Hierarchy of newly added clases is:
Vertices -n-> PropertyFamily {name: String} <-1-n-> PropertyType {type: Property::Flags}
Edges -n-> PropertyFamily {name: String} <-1-n-> PropertyType {type: Property::Flags}

PropertyFamilyKey -> PropertyType
PropertyTypeKey -> PropertyType

PropertyType t0,t1;
let t0!=t1 be true
let t0.family==t1.family be true

then next is true
PropertyTypeKey{&t0}!=PropertyTypeKey{&t1}
PropertyFamilyKey{&t0}==PropertyFamilyKey{&t1}
PropertyFamilyKey{&t0}==PropertyTypeKey{&t1}
PropertyTypeKey{&t0}==PropertyFamilyKey{&t1}

8.
Intermedate commit.
Noticed that integration queries throw SEGFAULT.

7.
Defined interface for indexes.
Fixed three memory leaks.
Fixed integration_queries test which now passes.

6.
Commit which return Xorshift128plus to valid shape.

5.
Tmp commit.

4.
Label Index is compiling.

3.
tmp

2.
Vertex::Accessor now updates Label index.

1.
Applied changes for code review.
2016-08-18 15:34:36 +01:00

107 lines
2.9 KiB
C++

#pragma once
#include "database/db_transaction.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/border.hpp"
#include "utils/option.hpp"
namespace tx
{
class Transaction;
}
/*
* 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<const Vertex::Accessor> vertex_find(const Id &id);
// Creates new Vertex and returns filled Vertex::Accessor.
Vertex::Accessor vertex_insert();
//*******************EDGE METHODS
Option<const Edge::Accessor> 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);
//********************TYPE METHODS
const EdgeType &type_find_or_create(const std::string &name);
bool type_contains(const std::string &name);
//********************PROPERTY METHODS
// Vertices::prop_familys_t::Accessor vertex_property_family_access();
//
// auto edge_property_family_access();
PropertyFamily &vertex_property_family_get(const std::string &name);
PropertyFamily &edge_property_family_get(const std::string &name);
//********************TRANSACTION METHODS
void commit();
void abort();
private:
template <class T, class K>
friend class NonUniqueUnorderedIndex;
DbTransaction db_transaction;
};
//**********************CONVENIENT FUNCTIONS
template <class R>
bool option_fill(Option<R> &o)
{
return o.is_present() && o.get().fill();
}