[英]Strange ClassCastException error using GoogleDriveApi for android with Groovy
[英]Gremlin Groovy ClassCastException with Frames
使用与tinkerpop的帧关联的@GremlinGroovy批注时,我收到以下错误。
java.lang.ClassCastException: com.thinkaurelius.titan.graphdb.relations.CacheEdge cannot be cast to com.tinkerpop.blueprints.Vertex
at com.tinkerpop.frames.structures.FramedVertexIterable$1.next(FramedVertexIterable.java:36)
at com.tinkerpop.frames.annotations.gremlin.GremlinGroovyAnnotationHandler.processVertex(GremlinGroovyAnnotationHandler.java:75)
at com.tinkerpop.frames.annotations.gremlin.GremlinGroovyAnnotationHandler.processElement(GremlinGroovyAnnotationHandler.java:114)
at com.tinkerpop.frames.annotations.gremlin.GremlinGroovyAnnotationHandler.processElement(GremlinGroovyAnnotationHandler.java:30)
at com.tinkerpop.frames.FramedElement.invoke(FramedElement.java:83)
at com.sun.proxy.$Proxy81.getProxyCandidateEdgeFromPersonUuid(Unknown Source)
at com.company.prod.domain.Person$Impl.toImpl(Person.java:100)
....
以下行导致错误:
FooEdge fe = foo.getFooEdgeFromUuid(this.getUuid());
哪个正在调用此方法:
@GremlinGroovy("it.outE('has').filter{it.inV().has('uuid', T.eq, uuid).hasNext()}")
FooEdge getFooEdgeFromUuid(@GremlinParam("uuid") String uuid);
我还尝试了以下遍历(导致相同的错误):
@GremlinGroovy("it.out('has').has('uuid', T.eq, uuid).inE('has')")
但是,当我打开gremlin外壳来测试相同的遍历时-一切正常。 有什么想法可能导致此问题?
这并不是解决方案的答案。 除了使用@GremlinGroovy批注之外,还可以将gremlin与@JavaHandler批注一起使用。
@JavaHandler
void getFooEdgeFromUuid(String uuid);
abstract class Impl implements JavaHandlerContext<Vertex>, Foo {
public FooEdge getFooEdgeFromUuid(String uuid) {
return frameEdges(
gremlin().out("has")
.has("person-uuid", Tokens.T.eq, uuid)
.inE("has"),
FooEdge.class).iterator().next();
}
}
我认为您在这里没有适当的用法,可以在Frames上为该注释提供文档:
https://github.com/tinkerpop/frames/wiki/Gremlin-Groovy
首先,请注意:
@GremlinGroovy("it.outE('has').filter{it.inV().has('uuid', T.eq, uuid).hasNext()}")
FooEdge getFooEdgeFromUuid(@GremlinParam("uuid") String uuid);
和:
@GremlinGroovy("it.out('has').has('uuid', T.eq, uuid).inE('has')")
返回一个Iterator
所以它不是getFooEdgeFromUuid()
用,因为您不需要在getFooEdgeFromUuid()
返回某种形式的List
。 假设您知道此查询将仅且始终返回一条边的事实,那么可能要做的事情是:
@GremlinGroovy("it.out('has').has('uuid', T.eq, uuid).inE('has').next()")
我之所以说“总是”,是因为否则,您将获得NoSuchElementException
。 这样,可以正确对齐类型,您可以执行以下操作:
@GremlinGroovy("it.outE('has').filter{it.inV().has('uuid', T.eq, uuid)}")
Iterable<FooEdge> getFooEdgesFromUuid(@GremlinParam("uuid") String uuid);
当然,所有这些可能都不起作用,因为我在文档中看到了这句话:
可以使用Gremlin路径表达式作为通过GremlinGroovyModule确定顶点邻接的方法。
换句话说,使用@GremlinGroovy
可以返回框架顶点(而不是您尝试做的边)。 如果我上面建议的方法不起作用,那么使用@JavaHandler
的解决方法可能是您的最佳选择。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.