0

我在 Neo4j 数据库上使用 Gremlin。我能够加载 tinkergraph 数据库并对其进行 gremlin 遍历,但无法加载本地数据库并对其进行遍历。

从控制台上的修补程序图中,我使用以下命令,它工作正常:

g = new TinkerGraph();
g.loadGraphXML('/db/data/graph-example-1.xml');
g.V.name    this works fine and getting the expected results.

即使从 Java 代码我也能做到。我发送相同的命令:

final String scriptURI = SERVER_ROOT_URI + "ext/GremlinPlugin/graphdb/execute_script";
WebResource resource = Client.create().resource(scriptURI);
String entity = toJsonNameValuePairCollection("script", " g = new TinkerGraph();g.loadGraphXML('/db/data/graph-example-1.xml');g.V.name");
ClientResponse response = resource.accept(MediaType.APPLICATION_JSON).type(MediaType.APPLICATION_JSON).entity(entity .post(ClientResponse.class);

但是当我尝试从我在“db/data/”创建的硬盘访问数据时,它在控制台中工作正常,但不能通过 java 代码。

控制台命令:

g = new Neo4jGraph('db/data/'); 名称

我得到了预期的输出。

但是通过 Java 代码我收到以下错误: javax.script.ScriptException: java.lang.RuntimeException: java.io.FileNotFoundException

我的Java代码是:

最终字符串 scriptURI = SERVER_ROOT_URI + "ext/GremlinPlugin/graphdb/execute_script"; WebResource 资源 = Client.create().resource(scriptURI); String entity = toJsonNameValuePairCollection("script", "g = new Neo4jGraph('db/data/');gVname"); ClientResponse response = resource.accept(MediaType.APPLICATION_JSON).type(MediaType.APPLICATION_JSON).entity(entity.post(ClientResponse.class);

4

1 回答 1

0

在 Neo4j Server 中,g 已经绑定到服务器 Neo4j 图形实例,因此您可以直接使用它(在 Gremlin 插件的 REST 调用中省略 g = new Neo4jGraph())。

最后,如果您确实需要打开一个新数据库,请确保脚本中的“db/data/”指向您想要的位置。它是一个相对路径,因此相对于服务器工作目录。也许你可以先做

dir = new File('db/data') dir.getAbsolutePath()

并返回?

于 2011-09-22T10:41:13.287 回答