我最近在努力学习OrientDb现在,我有点熟悉OrientDb控制台本身,我在继续使用蓝本写一个简单的java程序来创建一个图表。 我想他们之间创建几个顶点和边,但是虽然我的顶点创建成功,我无法看到我的边缘,除非我呼吁创建方法的两倍。 如果我注释掉调用之一,没有边缘都被创建。 我试图通过增加睡眠时间检查任何时间问题,但似乎没有任何帮助。
我尝试使用控制台来检查,我看到创建的顶点而不是边缘。 我运行1.7 RC-1的东方。
这里是我试图让工作示例代码:
public class OrientPrototype {
static OrientGraph graph = new OrientGraph("remote:localhost/Tinker", "admin", "admin");
public static void main( String[] args ) {
removeAllExistingVerticesAndEdges();
createSimpleGraph();
displayAllVertices(getAllVertices("Person"), "name");
displayAllEdges(getAllEdges("Friend"));
}
private static void removeAllExistingVerticesAndEdges() {
for (Vertex v : graph.getVertices())
v.remove();
for (Edge e : graph.getEdges())
e.remove();
}
private static void createSimpleGraph() throws InterruptedException {
createPersons();
createFriendships();
//createFriendships();
}
private static void createPersons() {
String [] persons = {"John", "Jack", "Ryan"};
if (graph.getVertexType("Person") == null)
graph.createVertexType("Person");
for (int i = 0; i < persons.length; i++) {
try {
Vertex v = graph.addVertex("class:Person");
v.setProperty("name", persons[i]);
graph.commit();
}
catch (Exception e) {
graph.rollback();
System.out.println("Error while creating the persons. Had to roll back");
}
}
System.out.println("Done creating vertices...");
}
private static void createFriendships() {
if (graph.getEdgeType("Friend") == null) {
graph.createEdgeType("Friend");
graph.commit();
}
Map<String, Vertex> vertices = new HashMap<String, Vertex>();
for (Vertex v : graph.getVertices())
vertices.put(v.getProperty("name").toString(), v);
try {
graph.addEdge("class:Friend", vertices.get("John"), vertices.get("Jack"), "is friend");
graph.addEdge("class:Friend", vertices.get("Jack"), vertices.get("Ryan"), "is friend");
graph.addEdge("class:Friend", vertices.get("Ryan"), vertices.get("John"), "is friend");
graph.commit();
System.out.println("Done creating edges...");
}
catch (Exception e) {
graph.rollback();
System.out.println("Error while creating the edges between persons. Had to roll back");
}
}
private static Iterable<Vertex> getAllVertices(String classname) {
return graph.getVerticesOfClass(classname);
}
private static void displayAllVertices(Iterable<Vertex> it, String propertyName) {
System.out.println("The vertices in the graph are:");
for (Vertex v: it)
System.out.println(v + " " + v.getProperty("name"));
}
private static Iterable<Edge> getAllEdges(String classname) {
return graph.getEdgesOfClass(classname);
}
private static void displayAllEdges(Iterable<Edge> it) {
System.out.println("The edges in the graph are:");
for (Edge e: it)
System.out.println(e);
}
}
我不相信,我做错了什么,因为当我看控制台OrientDb,我没有看到任何边缘类朋友架构选项卡,当我做出createEdge方法单一通话? 这些做第二个电话后出现不过。 而且我也看到传入和传出链接到Person类,当我运行在Person类选择从人查询。 这些输入和输出链路只出现当我打电话的createEdge方法至少一次。
任何帮助是极大的赞赏。 还附上从我的Maven POM文件的依赖关系,如果它是有帮助:
<dependencies>
<dependency>
<groupId>com.tinkerpop.blueprints</groupId>
<artifactId>blueprints-orient-graph</artifactId>
<version>2.5.0-SNAPSHOT</version>
</dependency>
<dependency>
<groupId>com.tinkerpop.gremlin</groupId>
<artifactId>gremlin-java</artifactId>
<version>2.5.0-SNAPSHOT</version>
</dependency>
<dependency>
<groupId>com.orientechnologies</groupId>
<artifactId>orient-commons</artifactId>
<version>1.7-rc1</version>
</dependency>
<dependency>
<groupId>com.orientechnologies</groupId>
<artifactId>orientdb-core</artifactId>
<version>1.7-rc1</version>
</dependency>
<dependency>
<groupId>com.orientechnologies</groupId>
<artifactId>orientdb-client</artifactId>
<version>1.7-rc1</version>
</dependency>
<dependency>
<groupId>com.orientechnologies</groupId>
<artifactId>orientdb-object</artifactId>
<version>1.7-rc1</version>
</dependency>
<dependency>
<groupId>com.orientechnologies</groupId>
<artifactId>orientdb-enterprise</artifactId>
<version>1.7-rc1</version>
</dependency>
</dependencies>