Sessions and transactions

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).

The 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. Objects or 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.

A 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 Session Begin and 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 HelloSparksee is a simple example we are going to use autocommit because we don't need more complex transactions.

For more information about Sparksee transactions please take a look at the Session class in the reference documentation of your chosen Sparksee API.

[Java]
Session sess = db.newSession();
Graph g = sess.getGraph();
[C#]
Session sess = db.NewSession();
Graph g = sess.GetGraph();
[C++]
Session *sess = db->NewSession();
Graph *g = sess->GetGraph();
[Python]
sess = db.new_session()
graph = sess.get_graph()
Back to Index