问题
I'm trying to write a program that takes data and enters it into a Neo4j database. The program appears to be working well - I say that as it runs without issue and the
System.out.println(node.getProperty("Name"));
line returns the value of each node that I create. Yet when I go to the web console I do not see ANY of these nodes in the database. I'm positive I am writing it to the correct directory. Doing a ls -l
shows the db getting modified each time I run the program:
new-host-4:new_graph.db USER$ ls -l
total 504
-rw-r--r-- 1 USER wheel 11 Mar 25 00:55 active_tx_log
drwxr-xr-x 8 USER wheel 272 Mar 25 01:21 index
-rw-r--r-- 1 USER wheel 111766 Mar 25 01:21 messages.log
-rw-r--r-- 1 USER wheel 78 Mar 25 01:21 neostore
-rw-r--r-- 1 USER wheel 9 Mar 25 01:21 neostore.id
-rw-r--r-- 1 USER wheel 22 Mar 25 01:21 neostore.labeltokenstore.db
-rw-r--r-- 1 USER wheel 9 Mar 25 01:21 neostore.labeltokenstore.db.id
-rw-r--r-- 1 USER wheel 64 Mar 25 01:21 neostore.labeltokenstore.db.names
-rw-r--r-- 1 USER wheel 9 Mar 25 01:21 neostore.labeltokenstore.db.names.id
-rw-r--r-- 1 USER wheel 100 Mar 25 01:21 neostore.nodestore.db
-rw-r--r-- 1 USER wheel 41 Mar 25 01:21 neostore.nodestore.db.id
-rw-r--r-- 1 USER wheel 93 Mar 25 01:21 neostore.nodestore.db.labels
-rw-r--r-- 1 USER wheel 9 Mar 25 01:21 neostore.nodestore.db.labels.id
-rw-r--r-- 1 USER wheel 635 Mar 25 01:21 neostore.propertystore.db
-rw-r--r-- 1 USER wheel 153 Mar 25 01:21 neostore.propertystore.db.arrays
-rw-r--r-- 1 USER wheel 9 Mar 25 01:21 neostore.propertystore.db.arrays.id
-rw-r--r-- 1 USER wheel 9 Mar 25 01:21 neostore.propertystore.db.id
-rw-r--r-- 1 USER wheel 43 Mar 25 01:21 neostore.propertystore.db.index
-rw-r--r-- 1 USER wheel 9 Mar 25 01:21 neostore.propertystore.db.index.id
-rw-r--r-- 1 USER wheel 140 Mar 25 01:21 neostore.propertystore.db.index.keys
-rw-r--r-- 1 USER wheel 9 Mar 25 01:21 neostore.propertystore.db.index.keys.id
-rw-r--r-- 1 USER wheel 154 Mar 25 01:21 neostore.propertystore.db.strings
-rw-r--r-- 1 USER wheel 9 Mar 25 01:21 neostore.propertystore.db.strings.id
-rw-r--r-- 1 USER wheel 57 Mar 25 01:21 neostore.relationshipstore.db
-rw-r--r-- 1 USER wheel 9 Mar 25 01:21 neostore.relationshipstore.db.id
-rw-r--r-- 1 USER wheel 33 Mar 25 01:21 neostore.relationshiptypestore.db
-rw-r--r-- 1 USER wheel 9 Mar 25 01:21 neostore.relationshiptypestore.db.id
-rw-r--r-- 1 USER wheel 102 Mar 25 01:21 neostore.relationshiptypestore.db.names
-rw-r--r-- 1 USER wheel 9 Mar 25 01:21 neostore.relationshiptypestore.db.names.id
-rw-r--r-- 1 USER wheel 82 Mar 25 01:21 neostore.schemastore.db
-rw-r--r-- 1 USER wheel 9 Mar 25 01:21 neostore.schemastore.db.id
-rw-r--r-- 1 USER wheel 4 Mar 25 01:21 nioneo_logical.log.active
-rw-r--r-- 1 USER wheel 856 Mar 25 00:55 nioneo_logical.log.v0
-rw-r--r-- 1 USER wheel 464 Mar 25 00:57 nioneo_logical.log.v1
-rw-r--r-- 1 USER wheel 316 Mar 25 01:05 nioneo_logical.log.v2
-rw-r--r-- 1 USER wheel 316 Mar 25 01:21 nioneo_logical.log.v3
drwxr-xr-x 3 USER wheel 102 Mar 25 00:55 schema
-rw-r--r-- 1 USER wheel 0 Mar 25 00:55 store_lock
-rw-r--r-- 1 USER wheel 500 Mar 25 01:21 tm_tx_log.1
new-host-4:new_graph.db USER$ pwd
/usr/local/Cellar/neo4j/2.0.1/libexec/data/new_graph.db
Yet when I enter
START a = node(*)
RETURN a;
I get no nodes. If I run the EmbeddedNeo4j.java sample on this database those nodes show up in the database, but not these. The console config settings show the same directory

Am I missing something or is there a bug in Neo4J?
For reference the classes I am using are below. Main calls tester, which opens a stream. A Stream obtains a handle to the database and after applying rules to the input (not shown), creates entries with NeoProcessor. The attributes are printed to the console without issue, leading me to believe they have been written to the database, yet I never see them in the web console.
My main:
public class NeoTest {
public static void main( final String[] args )
{
//Our tester to test the database
Tester myTest = new Tester("Stream");
try{
myTest.fileTester("/Users/me/data/test");
myTest.end();
}
catch (IOException ex)
{
System.out.println("Cannot open file fool");
}
}
}
My tester:
public class Tester {
private Streamer myStream;
private String inputType;
public Tester(String inputType)
{
this.inputType = inputType;
if(inputType.toLowerCase().contains("Stream".toLowerCase()))
{
System.out.println("Using Stream");
// instantiate streamer
myStream = new Streamer();
//get DB going
myStream.openStream("calllog");
}
}
public void fileTester(String fileName) throws IOException
{
System.out.println("hi");
BufferedReader in = new BufferedReader(new FileReader(fileName));
while(in.ready())
{
String s = in.readLine();
myStream.streamInput(s);
}
in.close();
}
public void end()
{
if(inputType.toLowerCase().contains("Stream".toLowerCase()))
myStream.closeStream();
}
}
My Handler is:
public class NeoHandle {
private static GraphDatabaseService graphDb;
private String DB_PATH = "/usr/local/Cellar/neo4j/2.0.1/libexec/data/new_graph.db";
NeoHandle()
{
this.graphDb = new GraphDatabaseFactory().newEmbeddedDatabase( DB_PATH );
}
public GraphDatabaseService getNeoHandle()
{
return graphDb;
}
public void createDb()
{
// START SNIPPET: startDb
registerShutdownHook( graphDb );
// END SNIPPET: startDb
}
private static void registerShutdownHook( final GraphDatabaseService graphDb )
{
// Registers a shutdown hook for the Neo4j instance so that it
// shuts down nicely when the VM exits (even if you "Ctrl-C" the
// running application).
Runtime.getRuntime().addShutdownHook( new Thread()
{
@Override
public void run()
{
graphDb.shutdown();
}
} );
}
public void shutDown()
{
System.out.println();
System.out.println( "Shutting down database ..." );
// START SNIPPET: shutdownServer
graphDb.shutdown();
// END SNIPPET: shutdownServer
}
}
My streamer is:
public class Streamer {
private NeoHandle myHandle;
private String contextType;
Streamer()
{
}
public void openStream(String contextType)
{
myHandle = new NeoHandle();
myHandle.createDb();
}
public void streamInput(String dataLine)
{
LinkedList context = new LinkedList();
/*
* get database instance
* write to database
* check for errors
* report errors & success
*/
System.out.println(dataLine);
//apply rules to data (make ContextRules do this, send type and string of data)
ContextRules contextRules = new ContextRules();
context = contextRules.processContextRules("Calls", dataLine);
//write data (using linked list from contextRules)
NeoProcessor processor = new NeoProcessor(myHandle);
processor.processContextData(context);
}
public void closeStream()
{
/*
* close database instance
*/
myHandle.shutDown();
}
}
My Processor is:
public class NeoProcessor {
private NeoHandle handle;
public NeoProcessor(NeoHandle handle)
{
this.handle = handle;
}
public void processContextData(LinkedList context)
{
for(Object c : context)
{
if(c instanceof Entity)
{
Node node = addNode((Entity)c);
((Entity)c).setNode(node);
}
}
}
public Node addNode(Entity myNode)
{
//TODO - wrap in transaction
GraphDatabaseService graphDb = this.handle.getNeoHandle();
Node node;
try ( Transaction tx = graphDb.beginTx() )
{
node = graphDb.createNode();
if(myNode.hasName())
{
System.out.println("setting name");
node.setProperty("Name", myNode.getName());
System.out.println(node.getProperty("Name"));
}
}//try transaction
return node;
}
}
回答1:
I left out the tx.success()
call in NeoProcessor. As I'm wrapping this around a transaction, I have to commit the transaction.
来源:https://stackoverflow.com/questions/22626137/neo4j-data-not-showing-up-in-web-console