1
1
/**
2
2
* Copyright (c) 2002-2016 "Neo Technology,"
3
3
* Network Engine for Objects in Lund AB [http://neotechnology.com]
4
- *
4
+ * <p>
5
5
* This file is part of Neo4j.
6
- *
6
+ * <p>
7
7
* Licensed under the Apache License, Version 2.0 (the "License");
8
8
* you may not use this file except in compliance with the License.
9
9
* You may obtain a copy of the License at
10
- *
11
- * http://www.apache.org/licenses/LICENSE-2.0
12
- *
10
+ * <p>
11
+ * http://www.apache.org/licenses/LICENSE-2.0
12
+ * <p>
13
13
* Unless required by applicable law or agreed to in writing, software
14
14
* distributed under the License is distributed on an "AS IS" BASIS,
15
15
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16
16
* See the License for the specific language governing permissions and
17
17
* limitations under the License.
18
18
*/
19
+
19
20
package org .neo4j .driver .v1 ;
20
21
21
22
import org .neo4j .driver .v1 .util .Resource ;
22
23
23
24
/**
24
- * A live session with a Neo4j instance.
25
+ * A <em>Session</em> hosts a series of {@linkplain Transaction transactions}
26
+ * carried out against a database. Within the database, all statements are
27
+ * carried out within a transaction. Within application code, however, it is
28
+ * not always necessary to explicitly {@link #beginTransaction() begin a
29
+ * transaction}. If a statement is {@link #run} directly against a {@link
30
+ * Session}, the server will automatically <code>BEGIN</code> and
31
+ * <code>COMMIT</code> that statement within its own transaction. This type
32
+ * of transaction is known as an <em>autocommit transaction</em>.
25
33
* <p>
26
- * Sessions serve two purposes. For one, they are an optimization. By keeping state on the database side, we can
27
- * avoid re-transmitting certain metadata over and over.
34
+ * Explicit transactions allow multiple statements to be committed as part of
35
+ * a single atomic operation and can be rolled back if necessary. They can also
36
+ * be used to ensure <em>causal consistency</em>, meaning that an application
37
+ * can run a series of queries on different members of a cluster, while
38
+ * ensuring that each query sees the state of graph at least as up-to-date as
39
+ * the graph seen by the previous query. For more on causal consistency, see
40
+ * the Neo4j clustering manual.
28
41
* <p>
29
- * Sessions also serve a role in transaction isolation and ordering semantics. Neo4j requires
30
- * "sticky sessions", meaning all requests within one session must always go to the same Neo4j instance.
42
+ * Typically, a session will wrap a TCP connection. Such a connection will be
43
+ * acquired from a connection pool and released back there when the session is
44
+ * destroyed. One connection can therefore be adopted by many sessions,
45
+ * although by only one at a time. Application code should never need to deal
46
+ * directly with connection management.
31
47
* <p>
32
- * Session objects are not thread safe, if you want to run concurrent operations against the database,
33
- * simply create multiple sessions objects.
34
- *
35
- * <h2>Important note on semantics</h2>
36
- *
37
- * Please see the section under {@link StatementRunner} for an important overview of the guarantees
38
- * the session gives you around when statements are executed .
48
+ * A session inherits its destination address and permissions from its
49
+ * underlying connection. This means that one session may only ever target one
50
+ * machine within a cluster and does not support re-authentication. To achieve
51
+ * otherwise requires creation of a separate session.
52
+ * <p>
53
+ * Similarly, multiple sessions should be used when working with concurrency;
54
+ * session implementations are generally not thread safe .
39
55
*
40
56
* @since 1.0
41
57
*/
@@ -44,20 +60,25 @@ public interface Session extends Resource, StatementRunner
44
60
String LOG_NAME = "session" ;
45
61
46
62
/**
47
- * Begin a new transaction in this session. A session can have at most one transaction running at a time, if you
48
- * want to run multiple concurrent transactions, you should use multiple concurrent sessions.
49
- * <p>
50
- * All data operations in Neo4j are transactional. However, for convenience we provide a {@link #run(String)}
51
- * method directly on this session interface as well. When you use that method, your statement automatically gets
52
- * wrapped in a transaction.
53
- * <p>
54
- * If you want to run multiple statements in the same transaction, you should wrap them in a transaction using this
55
- * method.
63
+ * Begin a new <em>explicit {@linkplain Transaction transaction}</em>. At
64
+ * most one transaction may exist in a session at any point in time. To
65
+ * maintain multiple concurrent transactions, use multiple concurrent
66
+ * sessions.
56
67
*
57
- * @return a new transaction
68
+ * @return a new {@link Transaction}
58
69
*/
59
70
Transaction beginTransaction ();
60
71
72
+ /**
73
+ * Begin a new <em>explicit {@linkplain Transaction transaction}</em>,
74
+ * requiring that the server hosting is at least as up-to-date as the
75
+ * transaction referenced by the supplied <em>bookmark</em>.
76
+ *
77
+ * @param bookmark a reference to a previous transaction
78
+ * @return a new {@link Transaction}
79
+ */
80
+ Transaction beginTransaction ( String bookmark );
81
+
61
82
/**
62
83
* Reset the current session. This sends an immediate RESET signal to the server which both interrupts
63
84
* any statement that is currently executing and ignores any subsequently queued statements. Following
0 commit comments