Search in sources :

Example 81 with OIdentifiable

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();
    }
}
Also used : Edge(com.tinkerpop.blueprints.Edge) OIdentifiable(com.orientechnologies.orient.core.db.record.OIdentifiable) ODocument(com.orientechnologies.orient.core.record.impl.ODocument) Test(org.junit.Test)

Example 82 with OIdentifiable

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();
}
Also used : OIdentifiable(com.orientechnologies.orient.core.db.record.OIdentifiable) Test(org.junit.Test)

Example 83 with OIdentifiable

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();
    }
}
Also used : Edge(com.tinkerpop.blueprints.Edge) OIdentifiable(com.orientechnologies.orient.core.db.record.OIdentifiable) ODocument(com.orientechnologies.orient.core.record.impl.ODocument) Test(org.junit.Test)

Example 84 with OIdentifiable

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"));
    }
}
Also used : OCommandSQL(com.orientechnologies.orient.core.sql.OCommandSQL) OIdentifiable(com.orientechnologies.orient.core.db.record.OIdentifiable) ODocument(com.orientechnologies.orient.core.record.impl.ODocument) Test(org.junit.Test)

Example 85 with OIdentifiable

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"));
}
Also used : OCommandSQL(com.orientechnologies.orient.core.sql.OCommandSQL) OIdentifiable(com.orientechnologies.orient.core.db.record.OIdentifiable) ODocument(com.orientechnologies.orient.core.record.impl.ODocument) Test(org.junit.Test)

Aggregations

OIdentifiable (com.orientechnologies.orient.core.db.record.OIdentifiable)536 ODocument (com.orientechnologies.orient.core.record.impl.ODocument)278 ORecordId (com.orientechnologies.orient.core.id.ORecordId)120 Test (org.testng.annotations.Test)104 HashSet (java.util.HashSet)89 OCommandSQL (com.orientechnologies.orient.core.sql.OCommandSQL)79 ORidBag (com.orientechnologies.orient.core.db.record.ridbag.ORidBag)70 ORID (com.orientechnologies.orient.core.id.ORID)56 OIndexCursor (com.orientechnologies.orient.core.index.OIndexCursor)47 Test (org.junit.Test)43 OClass (com.orientechnologies.orient.core.metadata.schema.OClass)42 ODatabaseDocumentTx (com.orientechnologies.orient.core.db.document.ODatabaseDocumentTx)41 ArrayList (java.util.ArrayList)39 ORecord (com.orientechnologies.orient.core.record.ORecord)35 Map (java.util.Map)31 ByteBuffer (java.nio.ByteBuffer)28 OrientVertex (com.tinkerpop.blueprints.impls.orient.OrientVertex)26 OIndexTxAwareOneValue (com.orientechnologies.orient.core.index.OIndexTxAwareOneValue)22 OSQLSynchQuery (com.orientechnologies.orient.core.sql.query.OSQLSynchQuery)22 OCommandExecutionException (com.orientechnologies.orient.core.exception.OCommandExecutionException)21