1818 */
1919package org .neo4j .driver .v1 ;
2020
21- import java .net .URI ;
22-
2321/**
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.
2523 * <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.
6328 * <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>
6453 *
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)
7055 */
7156public interface Driver extends AutoCloseable
7257{
@@ -78,17 +63,22 @@ public interface Driver extends AutoCloseable
7863 boolean isEncrypted ();
7964
8065 /**
81- * Establish a session
66+ * Create a new general purpose {@link Session}.
8267 *
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.
8569 */
8670 Session session ();
8771
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+ */
8878 Session session (AccessMode mode );
8979
9080 /**
91- * Close all the resources assigned to this driver
81+ * Close all the resources assigned to this driver, including any open connections.
9282 */
9383 void close ();
9484}
0 commit comments