5.4.9 Creating Vertices
To create a vertex, use these Oracle Property Graph methods:
-
OraclePropertyGraph.addVertex
: Adds a vertex instance to a graph. -
OracleVertex.setProperty
: Assigns a key-value property to a vertex. -
OraclePropertyGraph.commit
: Saves all changes to the property graph instance.
The following code fragment creates two vertices named V1
and V2
, with properties for age, name, weight, height, and sex in the opg
property graph instance. The v1
properties set the data types explicitly.
// Create vertex v1 and assign it properties as key-value pairs Vertex v1 = opg.addVertex(1l); v1.setProperty("age", Integer.valueOf(31)); v1.setProperty("name", "Alice"); v1.setProperty("weight", Float.valueOf(135.0f)); v1.setProperty("height", Double.valueOf(64.5d)); v1.setProperty("female", Boolean.TRUE); Vertex v2 = opg.addVertex(2l); v2.setProperty("age", 27); v2.setProperty("name", "Bob"); v2.setProperty("weight", Float.valueOf(156.0f)); v2.setProperty("height", Double.valueOf(69.5d)); v2.setProperty("female", Boolean.FALSE);
Parent topic: Using Java APIs for Property Graph Data