You want to insert a new vertex into your graph database. Which method can you use?
db.addVertex()
db.createVertex()
db.createVertexType()
db.insertVertex()
db.insert()
db.add()
To create an edge two vertices which are connected by the edge must already exist.
db.addEdge(Object id, Vertex outVertex, Vertex inVertex, String label)
method the second (start vertex) and third parameter (destination vertex of the edge) are mandatory. The last parameter is the subclass of E if needed. The first parameter may be null because the id is set automatically. Can edges have properties?
Which is the correct syntax if you want to find all Students which have attended the course with @rid #20:15 and have achieved an A-grade?
db.executeSQL(new OSQLSynchQuery ("select * from Student where out = #20:15 and attends.Grade = 'A'"));
db.command(new OSQLSynchQuery (
"select out from attends where in.@rid = #20:15 and Grade = 'A' and out.@class = 'Student'"
)).execute();
db.command(new OSQLSynchQuery ("select * from Student where out = #20:15 and Grade = 'A'")).execute();
db.command("select out('Student') from attends where in.@rid = #20:15 and Grade = 'A'").execute();
db.command(<OSQLSynchQuery>).execute()
is the correct syntax. select out from attends where in.@rid = #20:15 and Grade = 'A' and out.@class = 'Student'
is the correct SQL query: Start at an edge because an edge has only one start vertex (out) and one destination vertex (in). So search for all attend edges with destination #20:15 and a Grade of 'A' which start at a Student vertex; then return these Student vertices.Which is the result of db.command().execute()?
Iterable <Vertex>
- If you query a vertex class e.g.
select * from Student
you get a result of typeIterable <Vertex>
. - If you query an edge class e.g.
select * from attends
you get a result of typeIterable <Edge>
. - If you query a function with integer results e.g.
select count(*) from Student
you get a result of typeIterable <Integer>
- If you query a vertex class e.g.
select * from Student
you get a result of typeIterable <Vertex>
. - If you query an edge class e.g.
select * from attends
you get a result of typeIterable <Edge>
. - If you query anything else e.g.
select Grade from attends
you get a result of typeIterable <Vertex>
Iterable <Edge>
. In most cases you get a result of type Iterable <Vertex>
: If you select a subclass of V you get persistent vertices, if you select anything else you get temporary vertices. Suppose you have a certain vertex in your code Vertex myVertex;
You want to get all outgoing edges from myVertex of edge type MyEdge. Which of the following code lines produce this result?
Iterable edges =myVertex.getEdges(Direction.OUT, "MyEdge");
Iterable edges =db.getEdges(myVertex, Direction.OUT, "MyEdge");
Vertex v = db.command(new OSQLSynchQuery("select outE('MyEdge') from V where @rid = ?")).execute(myVertex);
Iterable edges = (Iterable ) v.getProperty("outE");
Iterable edges = db.command(new OSQLSynchQuery("select from MyEdge where out = ?")).execute(myVertex);
db.getEdges(myVertex, Direction.OUT, "MyEdge");
is wrong. db.getEdges()
is only suitable if you want to retrieve all edges of an edge class.Attention: If you use SQL and refer to a vertex class in the FROM part you have to use
outE() or inE() with parentheses to get the connected edges. If you refer to an edge class in the FROM part you have to use in or out without parentheses to get the connected vertices.