1

I am using embedded Neo4j, version 3.0.3. Following this guide, I have created Neo4j/Java code. It creates a database, adds two nodes (one for java, one for scala) and adds a relationship.

package examples;

import java.io.File;
import org.neo4j.graphdb.*;
import org.neo4j.graphdb.factory.GraphDatabaseFactory;

public class HelloWorld {
    public static void main(String[] args) {

        GraphDatabaseFactory dbFactory = new GraphDatabaseFactory();
        GraphDatabaseService db = dbFactory.newEmbeddedDatabase(new File("Test_DB"));

        try (Transaction tx = db.beginTx()) {
            Node javaNode = db.createNode(Tutorials.JAVA);
            javaNode.setProperty("TutorialID", "JAVA001");  

            Node scalaNode = db.createNode(Tutorials.SCALA);
            scalaNode.setProperty("TutorialID", "SCALA001");

            Relationship relationship = javaNode.createRelationshipTo(scalaNode, TutorialRelationships.JVM_LANGUAGES);
            relationship.setProperty("Id", "1234");
            tx.success();
        }
    }
}

enum Tutorials implements Label {
    JAVA, SCALA, SQL, NEO4J;
}

enum TutorialRelationships implements RelationshipType {
    JVM_LANGUAGES, NON_JVM_LANGUAGES;
}

I program using Eclipse, so all the libraries are imported and I can just click the 'run' button on Eclipse to get the code running, and it seems to work without any issues. Upon running the code, I now have a folder Test_DB in the ~/workspace/project_name/Test_DB directory, where project_name is the name of the overall Eclipse folder. My goal is now to visualize this database in a web browser. The guide I linked to earlier shows an example of this; the user was able to look at the nodes in the web browser (see the bottom of the webpage). Unfortunately, I am using a Linux computer with Firefox, and that tutorial was in Windows, and I can't figure out how to get the visualization.

There have been a few other questions related to this. Unfortunately, some of them (such as this one) propose using software other than the default visualization. I don't own the computer and I have to go through a roundabout process to get external code installed. To be clear what I mean, this link discusses the default Neo4j browser. This is what I would like to see.

This question here directly tackles the same issue, and in fact, it uses the exact same tutorial I used! The answer proposes changing the path in the neo4j-server.properties file. Unfortunately, that file doesn't exist, and upon further analysis, it seems like Neo4j 3.0 changed the configuration naming, which I found out by reading the answer to this similar question. There is now a file conf/neo4j.conf with this information. I entered the following information in the first few lines, keeping the other settings the default:

# The name of the database to mount
dbms.active_database=Test_DB 
# Paths of directories in the installation.
dbms.directories.data=/home/username/workspace/project_name/

This does not appear to work. Am I using these settings correctly? When I open the neo4j web browser after running ./bin/neo4j start and click on the database symbol in the left hand side, I see "Name: Test_DB", but it also says there are no nodes and no relationships in the database, and returning a match all query provides nothing. Is it possible for the browser to connect to my database so it can see the nodes (e.g., the two nodes in my Java code above)?

Or is it that I'm not using this code correctly; does the code somehow have to avoid quitting (i.e., replace tx.success() with something else?) to keep the data there?

Community
  • 1
  • 1
ComputerScientist
  • 936
  • 4
  • 12
  • 20

1 Answers1

0

Sorry about answering my own question, but I finally figured out how to do this! Here's what happens: according to the github change log for 3.0.0.RC-1:

Databases are now stored in a directory called databases under the directory specified in dbms.directories.data

So what we actually have to do is make sure our data base is in the following location:

/home/username/workspace/project_name/databases/

The issue is that when we run it in Eclipse, we get the database in the following folder:

/home/username/workspace/project_name/

Thus, the solution is to make sure the new database folder is preceded by a databases name, i.e., I would change one line to:

GraphDatabaseService db = dbFactory.newEmbeddedDatabase(new File("databases/Test_DB"));
ComputerScientist
  • 936
  • 4
  • 12
  • 20