All the manipulation of a database must be enclosed within a session. A
Session should be initiated from a
Database instance. This is where you can get a
Graph instance which represents the persistent graph (the graph database).
Graph instance is needed to manipulate the
Database as a graph.
Also, temporary data is associated to the
Session, thus when a
Session is closed, all the temporary data associated to that
Session is removed too.
Values instances or even session attributes are an example of temporary data.
You must take into account the fact that a
Session is exclusive for a thread, we do not at all encourage that it be shared among threads as it will definitely raise unexpected errors.
Session manages the transactions, allowing the execution of a set of graph operations as a single execution unit. A transaction encloses all the graph operations between the
Commit methods, or just a single operation in autocommit mode (where no begin/commit methods are used).
Initially, a transaction starts as a read transaction and only when a method which updates the persistent graph database is found does it automatically become a write transaction. To become a write transaction it must wait until all other read transactions have finished.
Since HelloDEX is a simple example we are going to use autocommit because we don't need more complex transactions.
For more information about DEX transactions please take a look at the
Session class in the reference documentation of your chosen DEX API.
Session sess = db.newSession(); Graph g = sess.getGraph();
Session sess = db.NewSession(); Graph g = sess.GetGraph();
Session *sess = db->NewSession(); Graph *g = sess->GetGraph();