Search code examples
javagraphorientdb

OrientDB : OrientEdge vs OrientEdgeType and OrientVertex vs OrientVertexType


I was looking into OrientDB and I must say, the documentation is a bit confusing to me. There are a lot of questions that I would like to ask. As of now, can anyone please tell me what is the difference between OrientEdge and OrientEdgeType and between OrientVertex and OrientVertexType. Shall I create classes extending them ? How to use them ? How do I set properties in the edges while creating a relation ? I am creating EdgeType like this :

OrientEdgeType userFriendEdge = orientGraph.getEdgeType("FriendOf");
    if(userFriendEdge==null){
        userFriendEdge = orientGraph.createEdgeType("FriendOf");
        userFriendEdge.createProperty("gravity", OType.DOUBLE);
    }

Then I'm adding edge like this :

this.orientGraphFactory.getNoTx().addEdge(null, userVertex1, userVertex2, "FriendOf");

While this seems to create an edge, I cannot see it in the visual editor when I query the classes. Is this the correct way to do it ? Also, how will add properties to the edge like gravity ? Please help, I'm confused.


Solution

  • Edge types and vertex types are just classes, so doing

     orientGraph.createEdgeType("FriendOf");
    

    is the same as doing, in SQL

     CREATE CLASS FriendOf extends E
    

    Edges and vertices are instances of these classes.

    To create an edge and add properties, just try this:

     Edge e = vertex1.addEdge('FriendOf', vertex2);
     e.setProperty('since', 2015);
    

    I suggest you to use NoTx graph to manipulate the schema and Tx graph to create/manipulate data. Do not forget

     graph.shutdown()
    

    at the end