use of com.orientechnologies.orient.core.db.record.OIdentifiable in project orientdb by orientechnologies.
the class OrientDeleteEdgeTest method testDeleteEdgeWhileIterate.
@Test
public void testDeleteEdgeWhileIterate() {
OrientGraph graph = new OrientGraph("memory:test_graph", "admin", "admin");
try {
graph.createEdgeType("Plays");
OrientVertex player = graph.addVertex(null);
OrientVertex team = graph.addVertex(null);
player.addEdge("plays", team);
graph.commit();
Iterator<Edge> team_edges = player.getEdges(Direction.OUT, "plays").iterator();
while (team_edges.hasNext()) {
final Edge edge = team_edges.next();
graph.removeEdge(edge);
}
ODocument docPlayer = player.getRecord();
Iterable<OIdentifiable> out = docPlayer.field("out_Plays");
Assert.assertFalse(out.iterator().hasNext());
ODocument docTeam = team.getRecord();
Iterable<OIdentifiable> in = docTeam.field("in_Plays");
Assert.assertFalse(in.iterator().hasNext());
graph.getRawGraph().getLocalCache().clear();
docPlayer = graph.getRawGraph().load(docPlayer.getIdentity());
out = docPlayer.field("out_Plays");
Assert.assertFalse(out.iterator().hasNext());
docTeam = graph.getRawGraph().load(docTeam.getIdentity());
in = docTeam.field("in_Plays");
Assert.assertFalse(in.iterator().hasNext());
} finally {
graph.drop();
}
}
use of com.orientechnologies.orient.core.db.record.OIdentifiable in project orientdb by orientechnologies.
the class OrientDeleteVertexTest method shouldDeleteEdgesWhenDeletingVertex.
@Test
public void shouldDeleteEdgesWhenDeletingVertex() {
// Create a node v1 with at least two edges
OrientGraph g = createGraph();
OrientVertex v1 = g.addVertex("class:V1");
OrientVertex v2 = g.addVertex("class:V2");
OrientVertex v22 = g.addVertex("class:V2");
g.addEdge(null, v1, v2, "edgeType1");
g.addEdge(null, v1, v22, "edgeType1");
g.shutdown();
// delete connected vertex v2
g = createGraph();
long total = g.countVertices();
g.getVertex(v2.getId()).remove();
assertEquals(total - 1, g.countVertices());
// the v1 out_edgeType1 property should not contain a reference to
// deleted node v2
// OK INSIDE THE TRANSACTION
Iterable<OrientEdge> out_edge = g.getVertex(v1.getId()).getProperty("out_edgeType1");
boolean contains = false;
for (OIdentifiable id : out_edge) if (id.equals(v2.getId()))
contains = true;
assertFalse(contains);
g.shutdown();
// the v1 node should only have one edge left
// OK
assertEquals(1, getEdgeCount(v1.getId()));
g = createGraph();
// v2 vertex sould be deleted
// OK
assertNull(g.getVertex(v2.getId()));
// the v1 out_edgeType1 property should not contain a reference to
// deleted v2
// FAILS HERE OUTSIDE OF THE TRANSACTION
out_edge = g.getVertex(v1.getId()).getProperty("out_edgeType1");
contains = false;
for (OIdentifiable id : out_edge) if (id.equals(v2.getId()))
contains = true;
assertFalse(contains);
g.shutdown();
}
use of com.orientechnologies.orient.core.db.record.OIdentifiable in project orientdb by orientechnologies.
the class OrientEdgeClassTest method testDeleteEdgeWhileIterate.
@Test
public void testDeleteEdgeWhileIterate() {
OrientGraph graph = new OrientGraph("memory:test_graph", "admin", "admin");
try {
graph.createEdgeType("Plays");
OrientVertex player = graph.addVertex(null);
OrientVertex team = graph.addVertex(null);
OrientVertex team2 = graph.addVertex(null);
player.addEdge("plays", team);
player.addEdge("PlAyS", team2);
graph.commit();
// CHECK CASE INSENSITIVE
Iterator<Edge> team_edges = player.getEdges(Direction.OUT, "pLAys").iterator();
Assert.assertTrue(team_edges.hasNext());
team_edges.next();
Assert.assertTrue(team_edges.hasNext());
team_edges.next();
// CHECK CASE SENSITIVE
team_edges = player.getEdges(Direction.OUT, "Plays").iterator();
Assert.assertTrue(team_edges.hasNext());
team_edges.next();
Assert.assertTrue(team_edges.hasNext());
team_edges.next();
ODocument docPlayer = player.getRecord();
Iterable<OIdentifiable> out = docPlayer.field("out_Plays");
Assert.assertTrue(out.iterator().hasNext());
ODocument docTeam = team.getRecord();
Iterable<OIdentifiable> in = docTeam.field("in_Plays");
Assert.assertTrue(in.iterator().hasNext());
graph.getRawGraph().getLocalCache().clear();
docPlayer = graph.getRawGraph().load(docPlayer.getIdentity());
out = docPlayer.field("out_Plays");
Assert.assertTrue(out.iterator().hasNext());
docTeam = graph.getRawGraph().load(docTeam.getIdentity());
in = docTeam.field("in_Plays");
Assert.assertTrue(in.iterator().hasNext());
} finally {
graph.drop();
}
}
use of com.orientechnologies.orient.core.db.record.OIdentifiable in project orientdb by orientechnologies.
the class OMatchStatementExecutionTest method testSimpleWhere.
@Test
public void testSimpleWhere() throws Exception {
List<ODocument> qResult = db.command(new OCommandSQL("match {class:Person, as: person, where: (name = 'n1' or name = 'n2')} return person")).execute();
assertEquals(2, qResult.size());
for (ODocument doc : qResult) {
assertTrue(doc.fieldNames().length == 1);
OIdentifiable personId = doc.field("person");
ODocument person = personId.getRecord();
String name = person.field("name");
assertTrue(name.equals("n1") || name.equals("n2"));
}
}
use of com.orientechnologies.orient.core.db.record.OIdentifiable in project orientdb by orientechnologies.
the class OMatchStatementExecutionTest method testTriangle2.
@Test
public void testTriangle2() {
StringBuilder query = new StringBuilder();
query.append("match ");
query.append("{class:TriangleV, as: friend1}");
query.append(" .out('TriangleE'){class:TriangleV, as: friend2, where: (uid = 1)}");
query.append(" .out('TriangleE'){as: friend3},");
query.append("{class:TriangleV, as: friend1}");
query.append(" .out('TriangleE'){as: friend3}");
query.append("return $patterns");
List<ODocument> result = db.command(new OCommandSQL(query.toString())).execute();
assertEquals(1, result.size());
ODocument doc = result.get(0);
ODocument friend1 = ((OIdentifiable) doc.field("friend1")).getRecord();
ODocument friend2 = ((OIdentifiable) doc.field("friend2")).getRecord();
ODocument friend3 = ((OIdentifiable) doc.field("friend3")).getRecord();
assertEquals(0, friend1.field("uid"));
assertEquals(1, friend2.field("uid"));
assertEquals(2, friend3.field("uid"));
}
Aggregations