Skip to content

Commit f210af1

Browse files
author
Zhen Li
authored
Merge pull request #306 from technige/1.1-apidocs
Some API doc updates
2 parents 75f6c99 + f6861d2 commit f210af1

File tree

13 files changed

+232
-94
lines changed

13 files changed

+232
-94
lines changed

driver/src/main/java/org/neo4j/driver/v1/AuthToken.java

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,10 +19,9 @@
1919
package org.neo4j.driver.v1;
2020

2121
/**
22-
* This is a combination of a <b>Principal</b>, for instance a username,
23-
* and one or more <b>Credentials</b>, for instance a password. It is used
24-
* to authenticate with a Neo4j instance. See {@link AuthTokens}
25-
* for available types of {@link AuthToken}.
22+
* Token for holding authentication details, such as <em>user name</em> and <em>password</em>.
23+
* Such a token is required by a {@link Driver} to authenticate with a Neo4j
24+
* instance.
2625
*
2726
* @see AuthTokens
2827
* @see GraphDatabase#driver(String, AuthToken)

driver/src/main/java/org/neo4j/driver/v1/Config.java

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -493,6 +493,7 @@ private TrustStrategy( Strategy strategy, File certFile )
493493

494494
/**
495495
* Return the strategy type desired.
496+
*
496497
* @return the strategy we should use
497498
*/
498499
public Strategy strategy()
@@ -530,17 +531,15 @@ public static TrustStrategy trustCustomCertificateSignedBy( File certFile )
530531
}
531532

532533
/**
533-
*
534-
* @return
534+
* Trust strategy for certificates that can be verified through the local system store.
535535
*/
536536
public static TrustStrategy trustSystemCertificates()
537537
{
538538
return new TrustStrategy( Strategy.TRUST_SYSTEM_CA_SIGNED_CERTIFICATES );
539539
}
540540

541541
/**
542-
*
543-
* @return
542+
* Trust strategy for certificates that can be verified through the local system store.
544543
*
545544
* @since 1.1
546545
*/

driver/src/main/java/org/neo4j/driver/v1/Driver.java

Lines changed: 39 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -18,55 +18,40 @@
1818
*/
1919
package 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
*/
7156
public 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
}

driver/src/main/java/org/neo4j/driver/v1/Logger.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,9 @@
1818
*/
1919
package org.neo4j.driver.v1;
2020

21+
/**
22+
* Logs messages for driver activity.
23+
*/
2124
public interface Logger
2225
{
2326
void error( String message, Throwable cause );

driver/src/main/java/org/neo4j/driver/v1/Logging.java

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,16 @@
1818
*/
1919
package org.neo4j.driver.v1;
2020

21+
/**
22+
* Accessor for {@link Logger} instances.
23+
*/
2124
public interface Logging
2225
{
26+
/**
27+
* Obtain a {@link Logger} instance by name.
28+
*
29+
* @param name name of a {@link Logger}
30+
* @return {@link Logger} instance
31+
*/
2332
Logger getLog( String name );
2433
}

driver/src/main/java/org/neo4j/driver/v1/Record.java

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -30,13 +30,15 @@
3030
import org.neo4j.driver.v1.util.Pair;
3131

3232
/**
33-
* A record is the object you work with when reading {@link StatementResult} - results
34-
* are streams of records, where records carry the values your statement returned.
33+
* Container for Cypher result values.
34+
* <p>
35+
* Streams of records are returned from Cypher statement execution, contained
36+
* within a {@link StatementResult}.
37+
* <p>
38+
* A record is a form of ordered map and, as such, contained values can be
39+
* accessed by either positional {@link #get(int) index} or textual
40+
* {@link #get(String) key}.
3541
*
36-
* Records are made up of named, ordered {@link #fields() fields}, each field has
37-
* a key and a value, both are determined by the statement you've executed. To
38-
* access the values in your result, you can either use the field key or the field
39-
* index, meaning the position the field has in the record.
4042
* @since 1.0
4143
*/
4244
@Immutable

driver/src/main/java/org/neo4j/driver/v1/Session.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,8 @@
2121
import org.neo4j.driver.v1.util.Resource;
2222

2323
/**
24+
* Provides a context of work for database interactions.
25+
* <p>
2426
* A <em>Session</em> hosts a series of {@linkplain Transaction transactions}
2527
* carried out against a database. Within the database, all statements are
2628
* carried out within a transaction. Within application code, however, it is

driver/src/main/java/org/neo4j/driver/v1/StatementResult.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@
2828

2929

3030
/**
31-
* The result of running a statement, conceptually a stream of {@link Record records}.
31+
* The result of running a Cypher statement, conceptually a stream of {@link Record records}.
3232
*
3333
* The standard way of navigating through the result returned by the database is to
3434
* {@link #next() iterate} over it.

driver/src/main/java/org/neo4j/driver/v1/Transaction.java

Lines changed: 12 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -21,29 +21,25 @@
2121
import org.neo4j.driver.v1.util.Resource;
2222

2323
/**
24-
* Represents a transaction in the Neo4j database.
25-
*
26-
* This interface may seem surprising in that it does not have explicit "commit" or "rollback" methods.
27-
* It is designed to minimize the complexity of the code you need to write to use transactions in a safe way, ensuring
28-
* that transactions are properly rolled back even if there is an exception while the transaction is running.
29-
*
30-
* <h2>Example:</h2>
31-
*
24+
* Logical container for an atomic unit of work.
25+
* <p>
26+
* A driver Transaction object corresponds to a server transaction.
27+
* Transactions are typically wrapped in a try-with-resources block
28+
* which ensures that <code>COMMIT</code> or <code>ROLLBACK</code>
29+
* occurs correctly on close.Note that <code>ROLLBACK</code> is the
30+
* default action unless {@link #success()} is called before closing.
3231
* <pre class="docTest:TransactionDocIT#classDoc">
3332
* {@code
34-
* try( Transaction tx = session.beginTransaction() )
33+
* try(Transaction tx = session.beginTransaction())
3534
* {
36-
* tx.run( "CREATE (n)" );
35+
* tx.run("CREATE (a:Person {name: {x}})", parameters("x", "Alice"));
3736
* tx.success();
3837
* }
3938
* }
4039
* </pre>
4140
*
42-
* <h2>Important note on semantics</h2>
43-
*
44-
* Please see the section under {@link StatementRunner} for an important overview of the guarantees
45-
* the transaction gives you around when statements are executed.
46-
*
41+
* @see Session#run
42+
* @see StatementRunner
4743
* @since 1.0
4844
*/
4945
public interface Transaction extends Resource, StatementRunner
@@ -67,7 +63,7 @@ public interface Transaction extends Resource, StatementRunner
6763
* {@code
6864
* try(Transaction tx = session.beginTransaction() )
6965
* {
70-
* tx.run( "CREATE (n)" );
66+
* tx.run("CREATE (a:Person {name: {x}})", parameters("x", "Alice"));
7167
* tx.failure();
7268
* }
7369
* }

driver/src/main/java/org/neo4j/driver/v1/Value.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@
3737
import org.neo4j.driver.v1.util.Immutable;
3838

3939
/**
40-
* Represents a value from Neo4j.
40+
* A unit of data that adheres to the Neo4j type system.
4141
*
4242
* This interface describes a number of <code>isType</code> methods along with
4343
* <code>typeValue</code> methods. The first set of these correlate with types from

driver/src/main/javadoc/overview.html

Lines changed: 60 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -5,27 +5,74 @@
55
</HEAD>
66
<BODY>
77

8-
This is the reference driver implementation for <a href="http://neo4j.com">Neo4j</a>, it allows you to connect to a
9-
Neo4j server and interact with it.
10-
If you are using Java, this is generally the interface you'd use to integrate Neo4j in your application.
8+
<p>These pages document the official <a href="https://neo4j.com" target="_top">Neo4j</a> driver for Java.</p>
119

12-
<h3>Getting Connected</h3>
10+
<h3>Example</h3>
1311

14-
<p>Once you have the driver and a connector on your classpath, you can establish sessions with Neo4j.</p>
12+
<pre><code>import org.neo4j.driver.v1.*;
1513

16-
<pre><code>Driver driver = GraphDatabase.driver( "bolt://localhost:7687", AuthTokens.basic( "neo4j", "p4ssw0rd" ) );
17-
try( Session session = driver.session() )
14+
import static org.neo4j.driver.v1.Values.parameters;
15+
16+
public class SmallExample
1817
{
19-
StatementResult result = session.run( "RETURN 'hello, world!'" );
20-
while( result.hasNext() )
18+
// Driver objects are thread-safe and are typically made available application-wide.
19+
Driver driver;
20+
21+
public SmallExample(String uri, String user, String password)
22+
{
23+
driver = GraphDatabase.driver(uri, AuthTokens.basic(user, password));
24+
}
25+
26+
private void addPerson(String name)
27+
{
28+
// Sessions are lightweight and disposable connection wrappers.
29+
try (Session session = driver.session())
30+
{
31+
// Wrapping Cypher in an explicit transaction provides atomicity
32+
// and makes handling errors much easier.
33+
try (Transaction tx = session.beginTransaction())
34+
{
35+
tx.run("MERGE (a:Person {name: {x}})", parameters("x", name));
36+
tx.success(); // Mark this write as successful.
37+
}
38+
}
39+
}
40+
41+
private void printPeople(String initial)
2142
{
22-
Record record = result.next();
23-
System.out.println( record.get(0).asString() );
43+
try (Session session = driver.session())
44+
{
45+
// Auto-commit transactions are a quick and easy way to wrap a read.
46+
StatementResult result = session.run(
47+
"MATCH (a:Person) WHERE a.name STARTS WITH {x} RETURN a.name AS name",
48+
parameters("x", initial));
49+
// Each Cypher execution returns a stream of records.
50+
while (result.hasNext())
51+
{
52+
Record record = result.next();
53+
// Values can be extracted from a record by index or name.
54+
System.out.println(record.get("name").asString());
55+
}
56+
}
57+
}
58+
59+
public void close()
60+
{
61+
// Closing a driver immediately shuts down all open connections.
62+
driver.close();
63+
}
64+
65+
public static void main(String... args)
66+
{
67+
SmallExample example = new SmallExample("bolt://localhost:7687", "neo4j", "password");
68+
example.addPerson("Ada");
69+
example.addPerson("Alice");
70+
example.addPerson("Bob");
71+
example.printPeople("A");
72+
example.close();
2473
}
2574
}
2675
</code></pre>
2776

28-
Have a look at the <a href="org/neo4j/driver/v1/Driver.html" title="interface in org.neo4j"><code>Driver</code></a>class to get started.
29-
3077
</BODY>
3178
</HTML>

0 commit comments

Comments
 (0)