How to use neo4j bolt session/transaction in a procedure as plugin for neo4j server extension?

爱⌒轻易说出口 提交于 2019-12-12 03:37:29

问题


  1. How to handle multiple session in a single procedure for sample sudo code is presented below?

  2. I tried the same code below but for some reason it doesn't work in as plugin, with the neo4j/plugin...really don't know what happens. [BUT WORKS WELL WITH IN ECLIPSE]

    @Procedure("test.begin")
    public void begin() throws InterruptedException {
        Driver driver = GraphDatabase.driver("bolt://localhost/",
                Config.build().withEncryptionLevel(Config.EncryptionLevel.NONE).toConfig());
        Session session = driver.session();
    
        System.out.println("............started");
        String query ="";
        if (true) {
            try (Transaction tx = session.beginTransaction()) {
                int count = 10000;
                for (int i = 0; i < count; i++) {
                    Thread.sleep(1);   // some conversion
                     query = "create(n:Person{name:'" + i + "'})";
                    tx.run(query);
                }
                System.out.println("first innerloop");
                tx.success();
            }
        }
        if (true) {
            try (Transaction tx = session.beginTransaction()) {
                int count = 10000;
                for (int p = 0; p < count; p++) {
                    Thread.sleep(1);
                     query =  "create(n:Person{name:'" + p + "'})";;
                    tx.run(query);
                }
                System.out.println("second innerloop");
                tx.success();
            }
        }
    
        if (true) {
            try (Transaction tx = session.beginTransaction()) {
                int count = 70000;
                while (count > 0) { /// here this has 1million records
                    for (int j = 0; j < count; j++) {
                        Thread.sleep(2);
                         query =  "create(n:Person{name:'" + j + "'})";;
                        tx.run(query);
                    }
                    System.out.println("third innerloop");
                    count--;
                }
                tx.success();
            }
    
    
        }
        session.close();
        driver.close();
    }
    

来源:https://stackoverflow.com/questions/39480552/how-to-use-neo4j-bolt-session-transaction-in-a-procedure-as-plugin-for-neo4j-ser

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!