代码之家  ›  专栏  ›  技术社区  ›  Rohit

使用Blueprints/Tinkerpop在OrientDb中创建边缘时出现问题

  •  1
  • Rohit  · 技术社区  · 12 年前

    我最近正在尝试学习OrientDb,现在我对OrientDb控制台本身有些熟悉,我开始使用Blueprints编写一个简单的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方法时,在类Friend的Schema选项卡中没有看到任何Edges?然而,在第二次调用后,这些确实会出现。此外,当我对Person类运行select from 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>
    
    1 回复  |  直到 12 年前
        1
  •  2
  •   stephen mallette    12 年前

    只是把松散的一端绑在这里。。。在gremlin用户邮件列表中回答:

    https://groups.google.com/forum/#!topic/gremlin-users/xUNeuJkPyUo

    Luca给出的基本总结。。。首先关闭轻质边:

    alter database custom useLightweightEdges=false
    

    然后确保使用更新的OrientDB依赖项:

    <dependency>
        <groupId>com.orientechnologies</groupId>
        <artifactId>orientdb-graphdb</artifactId>
        <version>1.7-rc1</version>
    </dependency>