如何在一个过程中使用neo4j bolt会话/事务作为neo4j服务器扩展的插件?

时间:2016-09-13 23:48:13

标签: neo4j

  1. 如何在单个程序中处理样本sudo代码的多个会话如下所示?

  2. 我尝试了下面相同的代码,但出于某种原因,它并没有作为插件工作,使用neo4j /插件......真的不知道会发生什么。 [但在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();
    }
    

0 个答案:

没有答案