由RestCypherQueryEngine生成的批处理密码查询

时间:2013-08-01 18:33:57

标签: neo4j cypher

我正在尝试使用REST API(使用java绑定库)将一些cypher查询批处理,以便只通过线路进行一次调用。但它似乎不尊重客户端的批处理并给出了这个错误:

java.lang.RuntimeException: Error reading as JSON ''
    at org.neo4j.rest.graphdb.util.JsonHelper.readJson(JsonHelper.java:57)
    at org.neo4j.rest.graphdb.util.JsonHelper.jsonToSingleValue(JsonHelper.java:62)
    at org.neo4j.rest.graphdb.RequestResult.toEntity(RequestResult.java:114)
    at org.neo4j.rest.graphdb.RequestResult.toMap(RequestResult.java:123)
    at org.neo4j.rest.graphdb.batch.RecordingRestRequest.toMap(RecordingRestRequest.java:138)
    at org.neo4j.rest.graphdb.ExecutingRestAPI.query(ExecutingRestAPI.java:489)
    at org.neo4j.rest.graphdb.ExecutingRestAPI.query(ExecutingRestAPI.java:509)
    at org.neo4j.rest.graphdb.RestAPIFacade.query(RestAPIFacade.java:233)
    at org.neo4j.rest.graphdb.query.RestCypherQueryEngine.query(RestCypherQueryEngine.java:50)
    ...
Caused by: java.io.EOFException: No content to map to Object due to end of input
    at org.codehaus.jackson.map.ObjectMapper._initForReading(ObjectMapper.java:2766)
    at org.codehaus.jackson.map.ObjectMapper._readMapAndClose(ObjectMapper.java:2709)
    at org.codehaus.jackson.map.ObjectMapper.readValue(ObjectMapper.java:1854)
    at org.neo4j.rest.graphdb.util.JsonHelper.readJson(JsonHelper.java:55)
    ... 41 more

这就是我试图批处理它们的方式:

graphDatabaseService.getRestAPI().executeBatch(new BatchCallback<Void>() {
            @Override
            public Void recordBatch(RestAPI batchRestApi) {
                String query =  "CREATE accounts=({userId:{userId}})-[r:OWNS]->({facebookId:{facebookId}})";
                graphDatabaseService.getQueryEngine().query(query, map("userId", 1, "facebookId", "1"));
                graphDatabaseService.getQueryEngine().query(query, map("userId", 2, "facebookId", "2"));
                graphDatabaseService.getQueryEngine().query(query, map("userId", 3, "facebookId", "3"));


                return null;
            }
        });

我正在使用noe4j版本1.9和相应的客户端库。这可能吗?

1 个答案:

答案 0 :(得分:0)

以下是适用于您的批处理的JUnit示例代码。这里没有使用字符串模板,而是在RestAPI对象上使用本机方法:

public static final DynamicRelationshipType OWNS = DynamicRelationshipType.withName("OWNS");

@Autowired
private SpringRestGraphDatabase             graphDatabaseService;

@Test
public void batchTest()
    {

    Assert.assertNotNull(this.graphDatabaseService);

    this.graphDatabaseService.getRestAPI().executeBatch(new BatchCallback<Void>()
        {
            @Override
            public Void recordBatch(RestAPI batchRestApi)
                {
                for (int counter = 1; counter <= 3; counter++)
                    {
                    RestNode userId = batchRestApi.createNode(map("userId", Integer.valueOf(counter)));
                    RestNode facebookId = batchRestApi.createNode(map("facebookId", Integer.valueOf(counter).toString()));
                    batchRestApi.createRelationship(userId, facebookId, OWNS, map());
                    }
                return null;
                }
        });

    }