How to add a property to the Vertex class by Graph API in OrientDB?

时间:2018-02-03 09:34:13

标签: java graph orientdb

I am new in OrientDB. I wanted to create Vertex with Graph API. And after creating it I wanted to add some properties (fields) to the Vertex class, like name type of String, pId type integer, salary type of double. But unfortunately I couldn't find information about it in the documentation. Here is what I have done so far.

OrientGraphNoTx graph = new OrientGraphFactory("remote:localhost/people",
        "user", "password").getNoTx();

if (graph.getVertexType("Person") == null) {

    graph.createVertexType("Person");
}

Here is I am just creating Vertex if it not exists.

In SQL it could done like this:

CREATE CLASS Person EXTENDS V;
CREATE PROPERTY Person.name STRING
CREATE PROPERTY Person.pId INTEGER
CREATE PROPERTY Person.salary DOUBLE

But I want to do it by Graph API. There are methods like graph.addVertexProperty() or graph.createVertexProperty().

1 个答案:

答案 0 :(得分:1)

This could be done by:

if (graph.getVertexType("Person") == null) {

    graph.createVertexType("Person");

    OrientVertexType person = graph.getVertexType("Person");
    person.createProperty("pId", OType.INTEGER);
    person.createProperty("name", OType.STRING);
    person.createProperty("salary", OType.DOUBLE);
}