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 mobile objects which may be at the position with @rid #20:15 and a score of 5?
db.executeSQL(new OSQLSynchQuery ("select * from MobileObject where out = #20:15 and PROB_IS_AT.Score = 5"));
db.command(new OSQLSynchQuery (
"select out from PROB_IS_AT where in.@rid = #20:15 and Score = 5 and out.@class = 'MobileObject'"
)).execute();
db.command(new OSQLSynchQuery ("select * from MobileObject where out = #20:15 and Score = 5")).execute();
db.command("select out('MobileObject) from PROB_IS_AT where in.@rid = #20:15 and Score = 5").execute();
db.command(<OSQLSynchQuery>).execute()
is the correct syntax. select out from PROB_IS_AT where in.@rid = #20:15 and Score = 5 and out.@class = 'MobileObject'
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 PROB_IS_AT edges with destination #20:15 and a Score of 5 or more which start at a MobileObject vertex; then return these MobileObject vertices.Which is the result of db.command().execute()?
Iterable <Vertex>
- If you query a vertex class e.g.
select * from MobileObject
you get a result of typeIterable <Vertex>
. - If you query an edge class e.g.
select * from PROB_IS_AT
you get a result of typeIterable <Edge>
. - If you query a function with integer results e.g.
select count(*) from MobileObject
you get a result of typeIterable <Integer>
- If you query a vertex class e.g.
select * from MobileObject
you get a result of typeIterable <Vertex>
. - If you query an edge class e.g.
select * from PROB_IS_AT
you get a result of typeIterable <Edge>
. - If you query anything else e.g.
select Score from PROB_IS_AT
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 persistend 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 parantheses to get the connected edges. If you refer to an edge class in the FROM part you have to use in or out without parantheses to get the connected vertices.