|
1 | 1 | # Neo4j Java Driver
|
2 | 2 |
|
3 |
| -This is the first official Neo4j java driver for connecting to Neo4j-the-database via the newly designed remoting |
4 |
| -protocol BOLT. |
| 3 | +This repository holds the official Java driver for Neo4j. |
| 4 | +The API is designed to work against both single instance and clustered databases. |
5 | 5 |
|
6 |
| -For detailed information such as manual, driver API documentations, changelogs, please refer to |
7 |
| -[wiki](https://github.com/neo4j/neo4j-java-driver/wiki). |
8 | 6 |
|
9 |
| -## Java version |
| 7 | +## For Driver Users |
10 | 8 |
|
11 |
| -Starting from 1.5 driver requires Java 8 for building and at runtime. |
12 |
| -Please use 1.4 series when Java 7 is required. |
| 9 | +This section provides general information for developers who are building Neo4j-backed applications. |
| 10 | +Note that this driver is designed to be used only by Neo4j 3.0 and above and provides no HTTP capabilities. |
13 | 11 |
|
14 |
| -## Minimum viable snippet |
15 | 12 |
|
16 |
| -Add the driver to your project: |
| 13 | +### Java Runtime |
17 | 14 |
|
18 |
| - <dependencies> |
19 |
| - <dependency> |
20 |
| - <groupId>org.neo4j.driver</groupId> |
21 |
| - <artifactId>neo4j-java-driver</artifactId> |
22 |
| - <version>x.y.z</version> |
23 |
| - </dependency> |
24 |
| - </dependencies> |
| 15 | +Recent drivers require either the Java 8 or Java 9 runtime. |
| 16 | +The table below shows runtime compatiblity for the currently-supported driver versions. |
25 | 17 |
|
26 |
| -*Please check the [Releases](https://github.com/neo4j/neo4j-java-driver/releases) for the newest driver version |
27 |
| -available. |
| 18 | +| Driver Series | Java 7 | Java 8 | Java 9 | |
| 19 | +|---------------|:------:|:------:|:------:| |
| 20 | +| 1.3 | X | X | | |
| 21 | +| 1.4 | X | X | | |
| 22 | +| 1.5 | | X | X | |
| 23 | +| 1.6 | | X | X | |
28 | 24 |
|
| 25 | +The automatic module name of the driver required by Java 9 is `org.neo4j.driver`. |
29 | 26 |
|
30 |
| -Connect to a Neo4j 3.0.0+ database: |
31 | 27 |
|
32 |
| - Driver driver = GraphDatabase.driver( "bolt://localhost:7687", AuthTokens.basic( "neo4j", "neo4j" ) ); |
33 |
| - |
34 |
| - try ( Session session = driver.session() ) |
35 |
| - { |
36 |
| - StatementResult rs = session.run( "CREATE (n) RETURN n" ); |
37 |
| - } |
38 |
| - |
39 |
| - driver.close(); |
| 28 | +### The `pom.xml` file |
40 | 29 |
|
41 |
| -## Building |
| 30 | +The driver is distributed exclusively via [Maven](https://search.maven.org/). |
| 31 | +To use the driver in your Maven project, include the following within your `pom.xml` file: |
| 32 | +```xml |
| 33 | +<dependency> |
| 34 | + <groupId>org.neo4j.driver</groupId> |
| 35 | + <artifactId>neo4j-java-driver</artifactId> |
| 36 | + <version>x.y.z</version> |
| 37 | +</dependency> |
| 38 | +``` |
| 39 | +Here, `x.y.z` will need to be replaced with the appropriate driver version. |
| 40 | +It is generally recommended to use the latest driver version wherever possible. |
| 41 | +This ensures access to new features and recent bug fixes. |
| 42 | +All available versions of this driver can be found at |
| 43 | +[Maven Central](https://mvnrepository.com/artifact/org.neo4j.driver/neo4j-java-driver) or |
| 44 | +[Releases](https://github.com/neo4j/neo4j-java-driver/releases). |
| 45 | + |
| 46 | + |
| 47 | +### Example |
| 48 | + |
| 49 | +To run a simple query, the following can be used: |
| 50 | +```java |
| 51 | +Driver driver = GraphDatabase.driver( "bolt://localhost:7687", AuthTokens.basic( "neo4j", "PasSW0rd" ) ); |
| 52 | +try ( Session session = driver.session() ) |
| 53 | +{ |
| 54 | + StatementResult rs = session.run( "CREATE (n) RETURN n" ); |
| 55 | +} |
| 56 | +driver.close(); |
| 57 | +``` |
| 58 | + |
| 59 | +For full applications, a single ``Driver`` object should be created with application-wide scope and lifetime. |
| 60 | +This allows full utilization of the driver connection pool. |
| 61 | +The connection pool reduces network overhead added by sharing TCP connections between subsequent transactions. |
| 62 | +Network connections are acquired on demand from the pool when running Cypher queries, and returned back to connection pool after query execution finishes. |
| 63 | +As a result of this design, it is expensive to create and close a ``Driver`` object. |
| 64 | +``Session`` objects, on the other hand, are very cheap to use. |
| 65 | + |
| 66 | + |
| 67 | +### Thread Safety |
| 68 | + |
| 69 | +``Driver`` objects are thread-safe, but ``Session`` and ``Transaction`` objects should only be used by a single thread. |
| 70 | + |
| 71 | + |
| 72 | +### Further reading |
| 73 | +Check out our [Wiki](https://github.com/neo4j/neo4j-java-driver/wiki) for detailed and most up-to-date developer manuals, driver API documentations, changelogs, etc. |
| 74 | + |
| 75 | + |
| 76 | +### Bug Report |
| 77 | +If you encounter any bugs while using this driver, please follow the instructions in our [Contribution Guide](https://github.com/neo4j/neo4j-java-driver/blob/1.6/CONTRIBUTING.md#need-to-raise-an-issue) |
| 78 | +when raising an issue at [Issues](https://github.com/neo4j/neo4j-java-driver/issues). |
| 79 | + |
| 80 | +When reporting, please mention the versions of the driver and server, as well as the server topology (single instance, causal cluster, etc). |
| 81 | +Also include any error stacktraces and a code snippet to reproduce the error if possible, as well as anything else that you think might be helpful. |
| 82 | + |
| 83 | + |
| 84 | +## For Driver Developers |
| 85 | + |
| 86 | +This section targets users who would like to compile the driver source code on their own machine for the purpose of, for example, contributing a PR. |
| 87 | +Before contributing to this project, please take a few minutes to read our [Contribution Guide](https://github.com/neo4j/neo4j-java-driver/blob/1.6/CONTRIBUTING.md#want-to-contribute). |
| 88 | + |
| 89 | + |
| 90 | +### Java Version |
| 91 | + |
| 92 | +For the 1.5 series driver and above, source code _must_ compile on Java 8. |
| 93 | +For previous versions, the compilation requires Java 7. |
| 94 | + |
| 95 | + |
| 96 | +### Building |
42 | 97 |
|
43 | 98 | The source code here reflects the current development status of a new driver version.
|
44 |
| -If you want to use the driver in your products, please use the released driver via maven central or check out the |
45 |
| -code with git tags instead. |
| 99 | +To use the driver in a project, please use the released driver via Maven Central or check out the code with git tags of corresponding versions instead. |
| 100 | + |
46 | 101 |
|
47 |
| -### Running tests and creating a package |
| 102 | +#### Running Tests and Creating a Package |
48 | 103 |
|
49 | 104 | The driver unit tests relies on latest [`boltkit`](https://github.com/neo4j-contrib/boltkit) installed on your local machine.
|
50 |
| -If `boltkit` is not installed, then all tests that requires `boltkit` will be ignored and not be executed. |
| 105 | +If `boltkit` is not installed, then all tests that requires `boltkit` will be ignored and will not be executed. |
| 106 | + |
| 107 | +The following Maven command shows how to run all tests and build the source code: |
| 108 | +``` |
| 109 | +mvn clean install |
| 110 | +``` |
| 111 | +When running integration tests, the driver would start a Neo4j instance and a Neo4j cluster on your local machine. |
| 112 | +Your tests might fail due to |
| 113 | +* a Neo4j server instance is already running on your machine and occupying the default server ports, |
| 114 | +* a lack of persmission to download Neo4j Enterprise artifacts. |
| 115 | + |
| 116 | +To skip the integration tests, use: |
| 117 | +``` |
| 118 | +mvn clean install -DskipITs |
| 119 | +``` |
51 | 120 |
|
52 |
| -Then execute the following Maven command: |
53 | 121 |
|
54 |
| - mvn clean install |
| 122 | +#### Windows |
55 | 123 |
|
56 |
| -### Windows |
| 124 | +If you are building on windows, you will need to run the install with admin rights. |
| 125 | +This is because integration tests require admin privileges to install and start a service. |
57 | 126 |
|
58 |
| -If you are building on windows, you need to run install as admin, so that Neo4j-the-database could be installed and |
59 |
| -started for integration tests. |
|
0 commit comments