1

我正在尝试将一些密码查询与 REST API(使用 java 绑定库)批处理在一起,以便通过网络只进行一次调用。但它似乎不尊重客户端的批处理并给出此错误:

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 版和相应的客户端库。这应该可能吗?

4

1 回答 1

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

    }
于 2013-08-22T14:21:41.250 回答