2016-03-01 54 views
0

以下参考文档here有更新节点插入Neo4JRequest上弹簧数据的Neo4j 4.1.0.M1

final CloseableHttpClient httpClient = HttpClients.createDefault(); 

@Bean 
ApplicationListener<AfterSaveEvent> afterSaveEventApplicationListener() { 
return new ApplicationListener<AfterSaveEvent>() { 
    @Override 
    public void onApplicationEvent(AfterSaveEvent event) { 
     Neo4jRequest<String> neo4jRequest = new DefaultRequest(httpClient); 
     if(event.getEntity() instanceof Person) { 
      Person person = (Person) event.getEntity(); 
      //Construct the JSON statements 
      neo4jRequest.execute(endpoint,json); 
      } 
     } 
    }; 
} 

后空间索引代码中的问题SI: 其中是Neo4JRequest接口? 它似乎从封装中消失,没有为什么和如何留下任何痕迹。

有没有人有索引更新相同的问题?

感谢

回答

2

不幸的是,在文档这一部分并没有更新的4.1 M1。 以下是在SDN 4.1中的操作方法(请参阅https://github.com/spring-projects/spring-data-neo4j/issues/332

@Bean 
    ApplicationListener<AfterSaveEvent> afterSaveEventApplicationListener() { 
     return new ApplicationListener<AfterSaveEvent>() { 
      @Override 
      public void onApplicationEvent(AfterSaveEvent event) { 

       if(event.getEntity() instanceof Person) { 
        Person person = (Person) event.getEntity(); 
        String json = "construct the JSON"; 

        HttpPost httpPost = new HttpPost(Components.driver().getConfiguration().getURI() + "/db/data/index/node/" + indexName); 

        try { 
         httpPost.setEntity(new StringEntity(json.toString())); 
         HttpRequest.execute(httpClient, httpPost, Components.driver().getConfiguration().getCredentials()); 
        } catch (Exception e) { 
         //handle this 
        } 

       } 
      } 
     }; 
    }