我想在一个实现 VertexFrame 的类上添加简单的 getter 和 setter,为此我使用了 JavaHandlers。对于那些方法,我不想与数据库进行任何交互。不幸的是,没有像 @Ignore 这样的东西,所以我没有意外的注释异常。当我在代理上设置一些东西并在它通过反射后立即执行获取时,什么都没有存储。可能是我不应该使用 JavaHandlers 而是其他东西。顺便说一句 manager.frame 返回 Java 动态代理对象(java.lang.reflect.Proxy)。这是失败的测试:
package com.tests.testbed;
import org.springframework.util.Assert;
import com.tinkerpop.blueprints.Vertex;
import com.tinkerpop.blueprints.impls.tg.TinkerGraph;
import com.tinkerpop.blueprints.impls.tg.TinkerGraphFactory;
import com.tinkerpop.frames.FramedGraph;
import com.tinkerpop.frames.FramedGraphFactory;
import com.tinkerpop.frames.modules.javahandler.JavaHandlerModule;
public class testProxy {
public static void main(String args[]){
TinkerGraph graph = TinkerGraphFactory.createTinkerGraph();
FramedGraphFactory framedFactory = new FramedGraphFactory(new JavaHandlerModule());
FramedGraph<TinkerGraph> manager = framedFactory.create(graph);
Vertex vertex = manager.getVertex(1);
IVert vert = manager.frame(vertex, IVert.class);
int testVal = 231;
vert.setTestVar(231);
Assert.state(vert.getTestVar() != testVal, "int was not stored!");
}
}
---------------------
package com.tests.testbed;
import com.tinkerpop.frames.Property;
import com.tinkerpop.frames.VertexFrame;
import com.tinkerpop.frames.modules.javahandler.JavaHandler;
import com.tinkerpop.frames.modules.javahandler.JavaHandlerClass;
@JavaHandlerClass(Vert.class)
public interface IVert extends VertexFrame {
@Property("id")
public int getId();
@Property("id")
public void setId(int id);
@JavaHandler
public void setTestVar(int testVar);
@JavaHandler
public int getTestVar();
}
--------------------
package com.tests.testbed;
import com.tinkerpop.blueprints.Vertex;
import com.tinkerpop.blueprints.impls.tg.TinkerGraph;
import com.tinkerpop.blueprints.impls.tg.TinkerGraphFactory;
public class Vert implements IVert {
private Vertex vertex;
private int id;
private int testVar;
public void setTestVar(int testVar){
this.testVar = testVar;
}
public int getTestVar(){
return this.testVar;
}
@Override
public Vertex asVertex() {
if (this.vertex == null){
TinkerGraph graph = TinkerGraphFactory.createTinkerGraph();
Vertex v = graph.getVertex(this.getId());
this.vertex = v;
}
return this.vertex;
}
@Override
public int getId() {
return this.id;
}
@Override
public void setId(int id) {
this.id = id;
}
}
非常感谢。PS我已经将此添加为一个问题,以防它是一个错误:https ://github.com/tinkerpop/frames/issues/109 我尝试获取 TargetObject 但我不能。请让我知道是否有任何解决方案可以添加可以保留在代理上的非数据库数据。