1

私は最近 OrientDb を学ぼうとしていますが、OrientDb コンソール自体にある程度慣れてきたので、ブループリントを使用して単純な Java プログラムを作成し、グラフを作成することに取り組んでいます。いくつかの頂点とそれらの間にエッジを作成しようとしていますが、頂点は正常に作成されますが、作成メソッドを 2 回呼び出さない限り、エッジを表示できません。呼び出しの 1 つをコメントアウトすると、エッジは作成されません。スリープ時間を追加してタイミングの問題を確認しようとしましたが、何も役に立たないようです。

コンソールを使用して確認しようとしましたが、頂点は作成されていますが、エッジは表示されていません。オリエント用に 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 メソッドを 1 回呼び出したときに、クラス Friend の [スキーマ] タブにエッジが表示されないため、何か間違ったことをしているとは思いませんか? ただし、これらは 2 回目の呼び出しの後に表示されます。さらに、Person クラスで select from Person クエリを実行すると、Person クラスへの着信リンクと発信リンクも表示されます。これらの着信リンクと発信リンクは、createEdge メソッドを少なくとも 1 回呼び出した場合にのみ表示されます。

どんな助けでも大歓迎です。また、役立つ場合は、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>
4

1 に答える 1

2

ここでルーズエンドを結ぶだけです... gremlin-usersメーリングリストで回答されました:

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

ルカの応答を考慮した基本的な要約...最初に軽量エッジをオフにします。

alter database custom useLightweightEdges=false

次に、新しい OrientDB 依存関係を必ず使用してください。

<dependency>
    <groupId>com.orientechnologies</groupId>
    <artifactId>orientdb-graphdb</artifactId>
    <version>1.7-rc1</version>
</dependency>
于 2014-03-24T14:20:20.490 に答える