18
18
*/
19
19
package org .neo4j .driver .v1 ;
20
20
21
- import java .net .URI ;
22
-
23
21
/**
24
- * A Neo4j database driver, through which you can create {@link Session sessions} to run statements against the database.
22
+ * Accessor for a specific Neo4j graph database.
25
23
* <p>
26
- * An example:
27
- * <pre class="doctest:DriverDocIT#exampleUsage">
28
- * {@code
29
- * // Create a driver with default configuration
30
- * Driver driver = GraphDatabase.driver( "bolt://localhost:7687" );
31
- *
32
- * // Establish a session
33
- * Session session = driver.session();
34
- *
35
- * // Running a simple statement can be done like this
36
- * session.run( "CREATE (n {name:'Bob'})" );
37
- *
38
- * // Or, run multiple statements together in an atomic transaction:
39
- * try( Transaction tx = session.beginTransaction() )
40
- * {
41
- * tx.run( "CREATE (n {name:'Alice'})" );
42
- * tx.run( "CREATE (n {name:'Tina'})" );
43
- * tx.success();
44
- * }
45
- *
46
- * // Retrieve results
47
- * StatementResult result = session.run( "MATCH (n) RETURN n.name" );
48
- * List<String> names = new LinkedList<>();
49
- * while( result.hasNext() )
50
- * {
51
- * names.add( result.next().get("n.name").asString() );
52
- * }
53
- *
54
- * // Sessions are pooled, to avoid the overhead of creating new connections - this means
55
- * // it is very important to close your session when you are done with it, otherwise you will
56
- * // run out of sessions.
57
- * session.close();
58
- *
59
- * // And, to clean up resources, always close the driver when your application is done
60
- * driver.close();
61
- * }
62
- * </pre>
24
+ * Driver implementations are typically thread-safe, act as a template
25
+ * for {@link Session} creation and host a connection pool. All configuration
26
+ * and authentication settings are held immutably by the Driver. Should
27
+ * different settings be required, a new Driver instance should be created.
63
28
* <p>
29
+ * A driver maintains a connection pool for each remote Neo4j server. Therefore
30
+ * the most efficient way to make use of a Driver is to use the same instance
31
+ * across the application.
32
+ * <p>
33
+ * To construct a new Driver, use one of the
34
+ * {@link GraphDatabase#driver(String, AuthToken) GraphDatabase.driver} methods.
35
+ * The <a href="https://tools.ietf.org/html/rfc3986">URI</a> passed to
36
+ * this method determines the type of Driver created.
37
+ * <br>
38
+ * <table border="1" cellpadding="4" style="border-collapse: collapse">
39
+ * <thead>
40
+ * <tr><th>URI Scheme</th><th>Driver</th></tr>
41
+ * </thead>
42
+ * <tbody>
43
+ * <tr>
44
+ * <td><code>bolt</code></td>
45
+ * <td>Direct driver: connects directly to the host and port specified in the URI.</td>
46
+ * </tr>
47
+ * <tr>
48
+ * <td><code>bolt+routing</code></td>
49
+ * <td>Routing driver: can automatically discover members of a Causal Cluster and route {@link Session sessions} based on {@link AccessMode}.</td>
50
+ * </tr>
51
+ * </tbody>
52
+ * </table>
64
53
*
65
- * A driver maintains a connection pool for each Neo4j instance. For resource efficiency reasons you are encouraged
66
- * to use the same driver instance across your application. You can control the connection pooling behavior when you
67
- * create the driver using the {@link Config} you pass into {@link GraphDatabase#driver(URI, Config)}.
68
- *
69
- * @since 1.0
54
+ * @since 1.0 (<em>bolt+routing</em> URIs since 1.1)
70
55
*/
71
56
public interface Driver extends AutoCloseable
72
57
{
@@ -78,17 +63,22 @@ public interface Driver extends AutoCloseable
78
63
boolean isEncrypted ();
79
64
80
65
/**
81
- * Establish a session
66
+ * Create a new general purpose {@link Session}.
82
67
*
83
- * @return a session that could be used to run {@link Session#run(String) a statement} or
84
- * {@link Session#beginTransaction() a transaction }.
68
+ * @return a new {@link Session} object.
85
69
*/
86
70
Session session ();
87
71
72
+ /**
73
+ * Create a new {@link Session} for a specific type of work.
74
+ *
75
+ * @param mode the type of access required by units of work in this session, e.g. {@link AccessMode#READ read access}.
76
+ * @return a new {@link Session} object.
77
+ */
88
78
Session session (AccessMode mode );
89
79
90
80
/**
91
- * Close all the resources assigned to this driver
81
+ * Close all the resources assigned to this driver, including any open connections.
92
82
*/
93
83
void close ();
94
84
}
0 commit comments