Java Neo4j数据未显示在web控制台中
我正试图编写一个程序,将数据输入Neo4j数据库。该计划似乎运行良好-我说,因为它运行没有问题和Java Neo4j数据未显示在web控制台中,java,neo4j,Java,Neo4j,我正试图编写一个程序,将数据输入Neo4j数据库。该计划似乎运行良好-我说,因为它运行没有问题和 System.out.println(node.getProperty("Name")); 第行返回我创建的每个节点的值。然而,当我转到web控制台时,在数据库中看不到任何这些节点。我肯定我正在把它写到正确的目录。执行ls-l显示每次运行程序时db都会被修改: new-host-4:new_graph.db USER$ ls -l total 504 -rw-r--r-- 1 USER whe
System.out.println(node.getProperty("Name"));
第行返回我创建的每个节点的值。然而,当我转到web控制台时,在数据库中看不到任何这些节点。我肯定我正在把它写到正确的目录。执行ls-l
显示每次运行程序时db都会被修改:
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
然而当我进去的时候
START a=node(*)
返回a代码>
我没有节点。如果我在这个数据库上运行EmbeddedNeo4j.java示例,那么这些节点将显示在数据库中,而不是这些节点。控制台配置设置显示相同的目录
我是否遗漏了什么,或者Neo4J中是否存在错误
下面是我使用的课程,仅供参考。Main调用tester,它打开一个流。流获得数据库的句柄,并在将规则应用于输入(未显示)后,使用NeoProcessor创建条目。属性被毫无问题地打印到控制台,这让我相信它们已经写入数据库,但我从未在web控制台中看到它们
我的主要意见是:
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");
}
}
}
我的测试人员:
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();
}
}
我的经纪人是:
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
}
}
我的拖缆是:
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();
}
}
我的处理器是:
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;
}
}
我遗漏了NeoProcessor中的tx.success()
调用。当我将其包装在一个事务中时,我必须提交该事务。UGGGG,在这里输入所有这些之后,我发现了问题所在。我漏掉了tx.success();在NeoProcessor类方法addNode中的事务结束时调用。我将回答这个问题,因为我认为把这个问题保留在这里比删除它更好,因为它可以(?)作为其他人的一个例子?