matador::persistence Class Reference

Represents the persistence layer for a database and an object_store. More...

#include <persistence.hpp>

Public Types

typedef basic_table::table_ptr table_ptr
 
typedef basic_table::t_table_map t_table_map
 

Public Member Functions

 persistence (const std::string &dns)
 Creates a new persistence object.
 
template<class T >
void attach (const char *type, const char *parent=nullptr)
 
template<class T >
void attach_abstract (const char *type, const char *parent=nullptr)
 
template<class T , class S >
void attach (const char *type)
 
template<class T , class S >
void attach_abstract (const char *type)
 
void detach (const char *type)
 
template<class T >
bool exists ()
 
void create ()
 Creates all tables.
 
void drop ()
 Drops all tables.
 
void clear ()
 
t_table_map::iterator find_table (const std::string &type)
 Finds a table by its name.
 
t_table_map::iterator begin ()
 Returns the begin of the table map.
 
t_table_map::iterator end ()
 Returns the end of the table map.
 
object_storestore ()
 Return a reference to the underlying object_store.
 
const object_storestore () const
 Return a const reference to the underlying object_store.
 
connectionconn ()
 Return a reference to the underlying database connection.
 
const connectionconn () const
 Return a const reference to the underlying database connection.
 
void enable_log ()
 
void disable_log ()
 
bool is_log_enabled () const
 

Friends

template<class T , class Enabled >
class table
 
template<class T >
class persistence_observer
 
class session
 

Detailed Description

Represents the persistence layer for a database and an object_store.

This class acts as mediator between the database connection and the object_store. It attaches the object prototypes to the object_store and drops or creates the corresponding tables on the database.

It also holds a map of all created tables, checks if a table exists and is able to clear the object store.

Member Typedef Documentation

◆ t_table_map

Shortcut to map of table shared pointer

◆ table_ptr

Shortcut to the table shared pointer

Constructor & Destructor Documentation

◆ persistence()

matador::persistence::persistence ( const std::string &  dns)
explicit

Creates a new persistence object.

Creates a new persistence object for the given database connection string.

Parameters
dnsThe database connection string

Member Function Documentation

◆ attach() [1/2]

template<class T , class S >
void matador::persistence::attach ( const char *  type)

Inserts a new object prototype into the prototype tree. The prototype consists of a unique type name. To know where the new prototype is inserted into the hierarchy the type name of the parent node is also given. parameter.

Template Parameters
TThe type of the prototype node
SThe type of the parent prototype node
Parameters
typeThe unique name of the type.
Returns
Returns new inserted prototype iterator.

◆ attach() [2/2]

template<class T >
void matador::persistence::attach ( const char *  type,
const char *  parent = nullptr 
)

Inserts a new object prototype into the prototype tree. The prototype consists of a unique type name. To know where the new prototype is inserted into the hierarchy the type name of the parent node is also given.

Template Parameters
TThe type of the prototype node
Parameters
typeThe unique name of the type.
parentThe name of the parent type.
Returns
Returns new inserted prototype iterator.

◆ attach_abstract() [1/2]

template<class T , class S >
void matador::persistence::attach_abstract ( const char *  type)

Inserts a new object prototype into the prototype tree. The prototype consists of a unique type name. To know where the new prototype is inserted into the hierarchy the type name of the parent node is also given. parameter.

Template Parameters
TThe type of the prototype node
SThe type of the parent prototype node
Parameters
typeThe unique name of the type.
Returns
Returns new inserted prototype iterator.

◆ attach_abstract() [2/2]

template<class T >
void matador::persistence::attach_abstract ( const char *  type,
const char *  parent = nullptr 
)

Inserts a new object prototype into the prototype tree. The prototype consists of a unique type name. To know where the new prototype is inserted into the hierarchy the type name of the parent node is also given.

Template Parameters
TThe type of the prototype node
Parameters
typeThe unique name of the type.
parentThe name of the parent type.
Returns
Returns new inserted prototype iterator.

◆ begin()

t_table_map::iterator matador::persistence::begin ( )

Returns the begin of the table map.

Returns
The begin of the table map

◆ clear()

void matador::persistence::clear ( )

clears all objects from object store

◆ conn() [1/2]

connection & matador::persistence::conn ( )

Return a reference to the underlying database connection.

Returns
A reference to the database connection.

◆ conn() [2/2]

const connection & matador::persistence::conn ( ) const

Return a const reference to the underlying database connection.

Returns
A const reference to the database connection.

◆ create()

void matador::persistence::create ( )

Creates all tables.

Creates all tables currently attached to the persistence object.

◆ detach()

void matador::persistence::detach ( const char *  type)

Removes an object prototype from the prototype tree. All children nodes and all objects are also removed.

Parameters
typeThe name of the type to remove.

◆ disable_log()

void matador::persistence::disable_log ( )

Disable console log of sql statements

◆ drop()

void matador::persistence::drop ( )

Drops all tables.

Drops all tables currently attached to the persistence object.

◆ enable_log()

void matador::persistence::enable_log ( )

Enable console log of sql statements

◆ end()

t_table_map::iterator matador::persistence::end ( )

Returns the end of the table map.

Returns
The end of the table map

◆ exists()

template<class T >
bool matador::persistence::exists ( )
inline

Checks if the given entity as table exists

Template Parameters
Tentity type class
Returns
True if table exists

◆ find_table()

t_table_map::iterator matador::persistence::find_table ( const std::string &  type)

Finds a table by its name.

Finds a table by its name. If the name is unknown map::end is returned.

Parameters
typeThe name of the table
Returns
The iterator of the table or end

◆ is_log_enabled()

bool matador::persistence::is_log_enabled ( ) const

Returns true if logging is enabled.

Returns
True if logging is enabled

◆ store() [1/2]

object_store & matador::persistence::store ( )

Return a reference to the underlying object_store.

Returns
A reference to the object_store.

◆ store() [2/2]

const object_store & matador::persistence::store ( ) const

Return a const reference to the underlying object_store.

Returns
A const reference to the object_store.

The documentation for this class was generated from the following file:
  • matador/orm/persistence.hpp