Neo4j 2.0.1 を実行しています。2.0.1 の空間プラグインと一緒に。2.0.1 用の JDBC ドライバーと一緒に。単純なポイント レイヤーと、空間クエリを実行するためのインデックスを作成しました。ブラウザに次のクエリを入力すると、それぞれのノードが返されます。
START n=node:geom('withinDistance:[15.0,60.0, 200.0]') RETURN n
このクエリを送信するために、サーブレットにメソッドを作成しました。
//connect to database
try {
if(connection == null || connection.isClosed())
{
Class.forName("org.neo4j.jdbc.Driver"); // load jdbc driver
connection = DriverManager.getConnection("jdbc:neo4j://localhost:7474");
}
} catch (SQLException e) {
System.out.println("could not connect do DB: <br>" + e.getCause()
+ "<br>" + e.getMessage());
} catch (ClassNotFoundException e) {
System.out.println("Could not load JDBC DRIVER");
e.printStackTrace();
}
次に、サーバーにリクエストを送信しようとしています:
@Path("findRange")
@GET
@Produces(MediaType.TEXT_HTML)
public String findRange(@QueryParam("lat") double lat,
@QueryParam("lon") double lon,
@QueryParam("d") double distance)
{
connectToDbIfNecessary();
try(PreparedStatement p = connection.prepareStatement(FIND_WITHIN_RANGE))
{
p.setObject(1, lat);
p.setObject(2, lon);
p.setObject(3, distance);
ResultSet rs = p.executeQuery();
return getServerResponse(rs);
} catch (SQLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
return "failure during geospatial query:\n"+e.getErrorCode()+"<br>\n"+e.getMessage()+"<br>"+e.getCause();
}
}
私が送信する準備済みステートメントは次のとおりです。
private static final String FIND_WITHIN_RANGE = "START n=node:geom('withinDistance:[{1},{2}, {3}]') RETURN n";
Tomcat 7.0.53 でこれを実行すると、次の例外が発生します。
地理空間クエリ中の失敗: 0 クエリの実行中にエラーが発生しました START n=node:geom('withinDistance:[{1},{2}, {3}]') RETURN n with params {3=1.0E8, 2=60.5, 1= 14.9} java.lang.RuntimeException: cypher ステートメントの実行中にエラーが発生しました [{code=Neo.DatabaseError.Statement.ExecutionFailure, message=null, stackTrace=java.lang.NullPointerException at org.neo4j.gis.spatial.indexprovider.LayerNodeIndex .query(LayerNodeIndex.java:249) at org.neo4j.gis.spatial.indexprovider.LayerNodeIndex.query(LayerNodeIndex.java:293) at org.neo4j.cypher.internal.spi.v2_0.TransactionBoundExecutionContext$NodeOperations.indexQuery(TransactionBoundExecutionContext .scala:166) org.neo4j.cypher.internal.compiler.v2_0.spi.DelegatingOperations.indexQuery(DelegatingQueryContext.scala:113) で org.neo4j.cypher.internal.compiler.v2_0.spi.ExceptionTranslatingQueryContext$ExceptionTranslatingOperations.org$neo4j$cypher$internal$compiler$v2_0$spi$ExceptionTranslatingQueryContext$ExceptionTranslatingOperations$$super$indexQuery(ExceptionTranslatingQueryContext.scala:142) at org.neo4j.cypher.internal.compiler.v2_0.spi.ExceptionTranslatingQueryContext$ ExceptionTranslatingOperations$$anonfun$indexQuery$1.apply(ExceptionTranslatingQueryContext.scala:142) で org.neo4j.cypher.internal.compiler.v2_0.spi.ExceptionTranslatingQueryContext$ExceptionTranslatingOperations$$anonfun$indexQuery$1.apply(ExceptionTranslatingQueryContext.scala:142) でorg.neo4j.cypher.internal.compiler.v2_0.spi.ExceptionTranslatingQueryContext.org$neo4j$cypher$internal$compiler$v2_0$spi$ExceptionTranslatingQueryContext$$translateException(ExceptionTranslatingQueryContext.scala:149) at org.neo4j.cypher.internal.compiler.v2_0.spi.ExceptionTranslatingQueryContext$ExceptionTranslatingOperations.indexQuery(ExceptionTranslatingQueryContext.scala:142) at org.neo4j.cypher.internal.compiler.v2_0.spi.DelegatingOperations.indexQuery(DelegatingQueryContext.scala:113) at org.neo4j. cypher.internal.compiler.v2_0.executionplan.builders.EntityProducerFactory$$anonfun$2$$anonfun$applyOrElse$2.apply(EntityProducerFactory.scala:66) at org.neo4j.cypher.internal.compiler.v2_0.executionplan.builders.EntityProducerFactory $$anonfun$2$$anonfun$applyOrElse$2.apply(EntityProducerFactory.scala:64) org.neo4j.cypher.internal.compiler.v2_0.executionplan.builders.EntityProducerFactory$$anon$1.apply(EntityProducerFactory.scala:35) org.neo4j.cypher.internal.compiler.v2_0.executionplan.builders.EntityProducerFactory$$anon$1.apply(EntityProducerFactory.scala:34) at org.neo4j.cypher.internal.compiler.v2_0.pipes.StartPipe$$anonfun$internalCreateResults$1.apply(StartPipe.scala:34) at org.neo4j.cypher.internal.compiler.v2_0.pipes. StartPipe$$anonfun$internalCreateResults$1.apply(StartPipe.scala:33) at scala.collection.Iterator$$anon$13.hasNext(Iterator.scala:371) at org.neo4j.cypher.internal.compiler.v2_0.ClosingIterator$ $anonfun$hasNext$1.apply$mcZ$sp(ClosingIterator.scala:38) at org.neo4j.cypher.internal.compiler.v2_0.ClosingIterator$$anonfun$hasNext$1.apply(ClosingIterator.scala:37) at org.neo4j.cypher.internal.compiler.v2_0. neo4j.cypher.internal.compiler.v2_0.ClosingIterator$$anonfun$hasNext$1.apply(ClosingIterator.scala:37) at org.neo4j.cypher.internal.compiler.v2_0.ClosingIterator.failIfThrows(ClosingIterator.scala:91) at org.neo4j.cypher.internal.compiler.v2_0.ClosingIterator.hasNext(ClosingIterator.scala:37) org.neo4j.cypher.internal.compiler.v2_0.PipeExecutionResult.hasNext(PipeExecutionResult.scala:166) で scala.collection.Iterator$$anon$11.hasNext(Iterator.scala:327) で scala.collection .convert.Wrappers$IteratorWrapper.hasNext(Wrappers.scala:29) at org.neo4j.cypher.internal.compiler.v2_0.PipeExecutionResult$$anon$1.hasNext(PipeExecutionResult.scala:74) at org.neo4j.server.rest .transactional.ExecutionResultSerializer.writeRows(ExecutionResultSerializer.java:291) org.neo4j.server.rest.transactional.ExecutionResultSerializer.statementResult(ExecutionResultSerializer.java:103) org.neo4j.server.rest.transactional.TransactionHandle.executeStatements(TransactionHandle) .java:251) の org.neo4j.server.rest.transactional.TransactionHandle.commit(TransactionHandle.java:189) の org.neo4j.server.rest.transactional.TransactionHandle.commit(TransactionHandle.java:109) at org.neo4j.server.rest.web.TransactionalService$2.write(TransactionalService.java:198) at com.sun.jersey.core.impl.provider.entity.StreamingOutputProvider com.sun.jersey.core.impl.provider.entity.StreamingOutputProvider.writeTo(StreamingOutputProvider.java:57) の .writeTo(StreamingOutputProvider.java:71) com.sun.jersey.spi.container.ContainerResponse.write(ContainerResponse) の.java:306) com.sun.jersey.server.impl.application.WebApplicationImpl._handleRequest(WebApplicationImpl.java:1437) com.sun.jersey.server.impl.application.WebApplicationImpl.handleRequest(WebApplicationImpl.java:1349) ) com.sun.jersey.server.impl.application.WebApplicationImpl.handleRequest(WebApplicationImpl.java:1339) で、com.sun.jersey.spi.container.servlet.WebComponent で。service(WebComponent.java:416) at com.sun.jersey.spi.container.servlet.ServletContainer.service(ServletContainer.java:537) at com.sun.jersey.spi.container.servlet.ServletContainer.service(ServletContainer. java:699) で javax.servlet.http.HttpServlet.service(HttpServlet.java:848) で org.eclipse.jetty.servlet.ServletHolder.handle(ServletHolder.java:698) で org.eclipse.jetty.servlet.ServletHandler org.eclipse.jetty.servlet.ServletHandler$CachedChain.doFilter(ServletHandler.java の org.neo4j.server.rest.security.SecurityFilter.doFilter(SecurityFilter.java:112) の $CachedChain.doFilter(ServletHandler.java:1506) :1477) org.eclipse.jetty.servlet.ServletHandler.doHandle(ServletHandler.java:503) で org.eclipse.jetty.server.session.SessionHandler.doHandle(SessionHandler.java:211) で org.eclipse.jetty. server.handler.org.eclipse.jetty.servlet.ServletHandler.doScope(ServletHandler.java:432) の ContextHandler.doHandle(ContextHandler.java:1096) org.eclipse.jetty.server.session.SessionHandler.doScope(SessionHandler.java:175) のorg.eclipse.jetty.server.handler.ContextHandler.doScope(ContextHandler.java:1030) で org.eclipse.jetty.server.handler.ScopedHandler.handle(ScopedHandler.java:136) で org.eclipse.jetty.server .handler.HandlerList.handle(HandlerList.java:52) の org.eclipse.jetty.server.handler.HandlerWrapper.handle(HandlerWrapper.java:97) の org.eclipse.jetty.server.Server.handle(Server.java) :445) org.eclipse.jetty.server.HttpChannel.handle(HttpChannel.java:268) で org.eclipse.jetty.server.HttpConnection.onFillable(HttpConnection.java:229) で org.eclipse.jetty.io. AbstractConnection$ReadCallback.run(AbstractConnection.java:358) org.eclipse.jetty.util.thread.QueuedThreadPool.runJob(QueuedThreadPool.java:601) で org.eclipse.jetty.util.thread.QueuedThreadPool$3.run(QueuedThreadPool.java:532) で java.lang. Thread.run(Thread.java:722) }]
ドキュメントで指定された URL に http リクエストを手動で送信してクエリを実行すると、例外が発生しません。この例外が発生する理由がわかりません。誰かが私を正しい方向に向けることができますか?
編集: インデックス クエリをパラメーター化できないようです。ただし、Stefan Armbruster の提案どおりに実行すると、新しい例外が発生します (これは、0.12 空間実装でさらに問題になる可能性があります)。
地理空間クエリ中の失敗: 0 クエリの実行中にエラーが発生しました START n=node:geom({1}) RETURN n with params {1='withinDistance:[14.9,60.5,1.0E8]'} java.lang.RuntimeException: cypher ステートメントの実行中にエラーが発生しました(s) [{code=Neo.DatabaseError.Statement.ExecutionFailure, message=only within, withinDistance および bbox が実装されています., stackTrace=java.lang.UnsupportedOperationException: within, withinDistance および bbox のみが実装されています. org.neo4j.gis.spatial.indexprovider.LayerNodeIndex.query(LayerNodeIndex.java:281) で org.neo4j.gis.spatial.indexprovider.LayerNodeIndex.query(LayerNodeIndex.java:293) で org.neo4j.cypher.internal .spi.v2_0.TransactionBoundExecutionContext$NodeOperations.indexQuery(TransactionBoundExecutionContext.scala:166) at org.neo4j.cypher.internal.compiler.v2_0.spi.DelegatingOperations.indexQuery(DelegatingQueryContext.scala:
この問題は、2013 年半ばのこの問題に似ているようです。