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 encourage sharing it 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
or Rollback
methods, or just a single operation in autocommit mode (where no begin/commit/rollback methods are used).
Initially, a transaction starts as a read transaction and only when there is a call to a method which updates the persistent graph database, it automatically becomes a write transaction. To become a write transaction it must wait until all other read transactions have finished. But a transaction can also be started as a write transaction using the BeginUpdate
method instead of Begin
.
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.