Database Reference
In-Depth Information
To run the preceding code, perform the following steps:
1. Import the following Java packages in your EmbeddedServer.java pro-
gram:
org.neo4j.graphdb.GraphDatabaseService;
org.neo4j.graphdb.factory.GraphDatabaseFactory;
2. Open the console and browse the location where you have created your Maven
project.
3. Now, execute following command to compile and create a build:
mvn clean compile install
4. Next, to run your embedded server, execute the following Maven command in the
console:
mvn exec:java
-Dexec.mainClass="neo4j.embedded.myserver.EmbeddedServer"
-Dexec.cleanupDaemonThreads=false
Let's understand the different sections of the preceding code:
GraphDatabaseService graphDb = new GraphDatabaseFactory()
.newEmbeddedDatabase("Location of Storing Neo4j Database
Files");
The preceding piece of code initializes the Neo4j database and stores the database files in
the given directory, which should be the path of the local filesystem.
//Register a Shutdown Hook
registerShutdownHook(graphDb);
The preceding statement defines a function that registers a shutdown hook for the Neo4j
database so that it shuts down nicely when the VM exits. It also ensures a clean shutdown
even if you execute Ctrl + C on the running application.
We can also configure the various database configurations using the functions provided in
GraphDatabaseBuilder . For example, the database creation code can be rewritten
as follows:
Search WWH ::




Custom Search