public interface Session extends org.neo4j.driver.v1.util.Resource, StatementRunner
Sessions serve two purposes. For one, they are an optimization. By keeping state on the database side, we can avoid re-transmitting certain metadata over and over.
Sessions also serve a role in transaction isolation and ordering semantics. Neo4j requires "sticky sessions", meaning all requests within one session must always go to the same Neo4j instance.
Session objects are not thread safe, if you want to run concurrent operations against the database, simply create multiple sessions objects.
StatementRunner
for an important overview of the guarantees
the session gives you around when statements are executed.Modifier and Type | Method and Description |
---|---|
Transaction |
beginTransaction()
Begin a new transaction in this session.
|
void |
close()
Signal that you are done using this session.
|
run, run, run, run, run, typeSystem
Transaction beginTransaction()
All data operations in Neo4j are transactional. However, for convenience we provide a StatementRunner.run(String)
method directly on this session interface as well. When you use that method, your statement automatically gets
wrapped in a transaction.
If you want to run multiple statements in the same transaction, you should wrap them in a transaction using this method.
void close()
Driver
.
When this method returns, all outstanding statements in the session are guaranteed to
have completed, meaning any writes you performed are guaranteed to be durably stored.close
in interface AutoCloseable
close
in interface org.neo4j.driver.v1.util.Resource
Copyright © 2016. All rights reserved.