Neo4j 数据未显示在 Web 控制台中 [英] Neo4j data not showing up in web console

查看:44
本文介绍了Neo4j 数据未显示在 Web 控制台中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试编写一个程序来获取数据并将其输入到 Neo4j 数据库中.该程序似乎运行良好 - 我说它运行没有问题并且

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"));

行返回我创建的每个节点的值.然而,当我进入 Web 控制台时,我在数据库中看不到任何这些节点.我很确定我正在将它写入正确的目录.执行 ls -l 显示每次运行程序时数据库都被修改:

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

然而当我进入START a = node(*)返回一个;

我没有节点.如果我在这个数据库上运行 EmbeddedNeo4j.java 示例,这些节点会出现在数据库中,但不会出现在这些节点中.控制台配置设置显示相同的目录

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

我是否遗漏了什么或 Neo4J 中是否存在错误?

Am I missing something or is there a bug in Neo4J?

作为参考,我正在使用的类如下.Main 调用 tester,它打开一个流.Stream 获取数据库的句柄,并在对输入(未显示)应用规则后,使用 NeoProcessor 创建条目.属性打印到控制台没有问题,这让我相信它们已写入数据库,但我从未在 Web 控制台中看到它们.

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.

我的主要内容:

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() 调用.当我围绕一个事务进行包装时,我必须提交事务.

I left out the tx.success() call in NeoProcessor. As I'm wrapping this around a transaction, I have to commit the transaction.

这篇关于Neo4j 数据未显示在 Web 控制台中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆