2015-12-08 04:51:55 +08:00
|
|
|
#pragma once
|
2015-10-08 06:58:29 +08:00
|
|
|
|
2016-08-25 22:29:45 +08:00
|
|
|
#include "storage/type_group_edge.hpp"
|
|
|
|
#include "storage/type_group_vertex.hpp"
|
|
|
|
|
2016-09-10 01:48:15 +08:00
|
|
|
#include "snapshot/snapshot_engine.hpp"
|
2016-08-25 22:29:45 +08:00
|
|
|
#include "storage/garbage/garbage.hpp"
|
2015-10-12 02:59:27 +08:00
|
|
|
#include "storage/graph.hpp"
|
|
|
|
#include "transactions/engine.hpp"
|
2015-10-08 06:58:29 +08:00
|
|
|
|
2016-09-08 20:25:52 +08:00
|
|
|
class Indexes;
|
|
|
|
|
2016-09-13 03:13:04 +08:00
|
|
|
// TODO: Maybe split this in another layer between Db and Dbms. Where the new
|
|
|
|
// layer would hold SnapshotEngine and his kind of concept objects. Some
|
|
|
|
// guidelines would be: retain objects which are necessary to implement querys
|
|
|
|
// in Db, the rest can be moved to the new layer.
|
2016-12-21 02:36:38 +08:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Main class which represents Database concept in code.
|
|
|
|
*/
|
2015-10-08 06:58:29 +08:00
|
|
|
class Db
|
|
|
|
{
|
|
|
|
public:
|
2015-10-12 02:59:27 +08:00
|
|
|
using sptr = std::shared_ptr<Db>;
|
2015-10-08 06:58:29 +08:00
|
|
|
|
2016-12-21 02:36:38 +08:00
|
|
|
/**
|
|
|
|
* This constructor will create a database with the name "default"
|
|
|
|
*
|
|
|
|
* NOTE: explicit is here to prevent compiler from evaluating const char *
|
|
|
|
* into a bool.
|
|
|
|
*
|
|
|
|
* @param import_snapshot will in constructor import latest snapshot
|
|
|
|
* into the db.
|
|
|
|
*/
|
2016-09-13 21:17:50 +08:00
|
|
|
explicit Db(bool import_snapshot = true);
|
2016-09-19 06:22:36 +08:00
|
|
|
|
2016-12-21 02:36:38 +08:00
|
|
|
/**
|
|
|
|
* Construct database with a custom name.
|
|
|
|
*
|
|
|
|
* @param name database name
|
|
|
|
* @param import_snapshot will in constructor import latest snapshot
|
|
|
|
* into the db.
|
|
|
|
*/
|
2016-09-13 21:17:50 +08:00
|
|
|
Db(const char *name, bool import_snapshot = true);
|
2016-09-19 06:22:36 +08:00
|
|
|
|
2016-12-21 02:36:38 +08:00
|
|
|
/**
|
|
|
|
* Construct database with a custom name.
|
|
|
|
*
|
|
|
|
* @param name database name
|
|
|
|
* @param import_snapshot will in constructor import latest snapshot
|
|
|
|
* into the db.
|
|
|
|
*/
|
2016-09-13 19:21:07 +08:00
|
|
|
Db(const std::string &name, bool import_snapshot = true);
|
2016-09-19 06:22:36 +08:00
|
|
|
|
2016-12-21 02:36:38 +08:00
|
|
|
/**
|
|
|
|
* Database object can't be copied.
|
|
|
|
*/
|
2016-08-13 06:01:39 +08:00
|
|
|
Db(const Db &db) = delete;
|
2016-08-10 16:39:02 +08:00
|
|
|
|
2016-09-13 03:13:04 +08:00
|
|
|
private:
|
2016-12-21 02:36:38 +08:00
|
|
|
/** database name */
|
2016-09-13 03:13:04 +08:00
|
|
|
const std::string name_;
|
2016-08-10 16:39:02 +08:00
|
|
|
|
2016-09-13 03:13:04 +08:00
|
|
|
public:
|
2016-12-21 02:36:38 +08:00
|
|
|
/** transaction engine related to this database */
|
2016-09-13 03:13:04 +08:00
|
|
|
tx::Engine tx_engine;
|
2016-12-21 02:36:38 +08:00
|
|
|
|
|
|
|
/** graph related to this database */
|
2016-09-13 03:13:04 +08:00
|
|
|
Graph graph;
|
2016-12-21 02:36:38 +08:00
|
|
|
|
|
|
|
/** garbage collector related to this database*/
|
2016-09-13 03:13:04 +08:00
|
|
|
Garbage garbage = {tx_engine};
|
2016-08-25 22:29:45 +08:00
|
|
|
|
2016-12-21 02:36:38 +08:00
|
|
|
/**
|
|
|
|
* snapshot engine related to this database
|
|
|
|
*
|
|
|
|
* \b IMPORTANT: has to be initialized after name
|
|
|
|
* */
|
2016-09-13 03:13:04 +08:00
|
|
|
SnapshotEngine snap_engine = {*this};
|
2016-08-25 22:29:45 +08:00
|
|
|
|
2016-12-21 02:36:38 +08:00
|
|
|
/**
|
|
|
|
* Creates Indexes for this database.
|
|
|
|
*/
|
|
|
|
Indexes indexes();
|
2016-09-13 03:13:04 +08:00
|
|
|
// TODO: Indexes should be created only once somwhere Like Db or layer
|
|
|
|
// between Db and Dbms.
|
2016-08-25 22:29:45 +08:00
|
|
|
|
2016-12-21 02:36:38 +08:00
|
|
|
/**
|
|
|
|
* Returns a name of the database.
|
|
|
|
*
|
|
|
|
* @return database name
|
|
|
|
*/
|
2016-09-13 03:13:04 +08:00
|
|
|
std::string const &name() const;
|
2015-10-08 06:58:29 +08:00
|
|
|
};
|