我正在使用带有OpenNTF Domino API的XPages应用程序来研究Graph数据建模功能。作为示例,我采用了IBM Domino随附的Teamroom。
我已经定义了一种将响应文档迁移到Grap db中的方法,但是我收到错误消息:无法对非静态方法进行静态引用
该方法如下所示:
private void migrateResponses(DFramedTransactionalGraph<DGraph> profilesGraph) {
try {
Database db = Factory.getSession().getCurrentDatabase();
View view = db.getView("responsesOnly");
DocumentCollection col = view.getAllDocuments();
System.out.println("number of docs found " + col.getCount());
for (Document response : col) {
System.out.println("form:" + response.getFormName());
System.out.println("id:" + response.getUniversalID());
org.openntf.domino.ext.Document parent = response.getParentDocument();
if (null == parent.getParentDocument()){
//has no parent document so this parent document is a MainTopic/Post
Post post = profilesGraph.addVertex(parent.getMetaversalID(), Post.class);
Response vertexResponse = profilesGraph.addVertex(response.getUniversalID(), Response.class);
vertexResponse.setSubject(response.getItemValueString("Subject"));
Post.addResponse(vertexResponse);
}
}
profilesGraph.commit();
} catch (Throwable t) {
XspOpenLogUtil.logError(t);
}
}
错误发生在以下行:
Post.addResponse(vertexResponse);
这是我的Post类的样子:
package com.wordpress.quintessens.graph.teamroom;
import org.openntf.domino.graph2.annotations.AdjacencyUnique;
import org.openntf.domino.graph2.builtin.DVertexFrame;
import com.tinkerpop.blueprints.Direction;
import com.tinkerpop.frames.Property;
import com.tinkerpop.frames.modules.typedgraph.TypeValue;
@TypeValue("post")
public interface Post extends DVertexFrame {
@Property("$$Key")
public String getKey();
@Property("subject")
public String getSubject();
@Property("subject")
public void setSubject(String n);
// real edges!
@AdjacencyUnique(label = "hasWritten", direction = Direction.OUT)
public Iterable<Profile> getAuthors();
@AdjacencyUnique(label = "hasReaction", direction = Direction.IN)
public void addResponse(Response response);
@AdjacencyUnique(label = "hasReaction", direction = Direction.IN)
public void removeResponse(Response response);
@AdjacencyUnique(label = "hasReaction", direction = Direction.IN)
public Iterable<Response> getResponses();
}
您是否有建议我应该如何修改我的代码使其起作用?
最佳答案
除非OpenNTF或TinkerPop使用提供的注释在做某种魔术,否则您将尝试在接口上调用非静态方法。您确定不想更改:
Post.addResponse(vertexResponse);
至
post.addResponse(vertexResponse);