Search in sources :

Example 6 with OrientEdge

use of com.tinkerpop.blueprints.impls.orient.OrientEdge in project orientdb by orientechnologies.

the class OSQLFunctionIn method fetchFromIndex.

private Object fetchFromIndex(OrientBaseGraph graph, OIdentifiable iFrom, Iterable<OIdentifiable> iTo, String[] iEdgeTypes) {
    String edgeClassName = null;
    if (iEdgeTypes == null) {
        edgeClassName = "E";
    } else if (iEdgeTypes.length == 1) {
        edgeClassName = iEdgeTypes[0];
    } else {
        return null;
    }
    OClass edgeClass = graph.getRawGraph().getMetadata().getSchema().getClass(edgeClassName);
    if (edgeClass == null) {
        return null;
    }
    Set<OIndex<?>> indexes = edgeClass.getInvolvedIndexes("in", "out");
    if (indexes == null || indexes.size() == 0) {
        return null;
    }
    OIndex index = indexes.iterator().next();
    OMultiCollectionIterator<OrientVertex> result = new OMultiCollectionIterator<OrientVertex>();
    for (OIdentifiable to : iTo) {
        OCompositeKey key = new OCompositeKey(iFrom, to);
        Object indexResult = index.get(key);
        if (indexResult instanceof OIdentifiable) {
            indexResult = Collections.singleton(indexResult);
        }
        Set<OIdentifiable> identities = new HashSet<OIdentifiable>();
        for (OIdentifiable edge : ((Iterable<OrientEdge>) indexResult)) {
            identities.add((OIdentifiable) ((ODocument) edge.getRecord()).rawField("in"));
        }
        result.add(identities);
    }
    return result;
}
Also used : OIndex(com.orientechnologies.orient.core.index.OIndex) OrientVertex(com.tinkerpop.blueprints.impls.orient.OrientVertex) OIdentifiable(com.orientechnologies.orient.core.db.record.OIdentifiable) OrientEdge(com.tinkerpop.blueprints.impls.orient.OrientEdge) OMultiCollectionIterator(com.orientechnologies.common.collection.OMultiCollectionIterator) OClass(com.orientechnologies.orient.core.metadata.schema.OClass) OCompositeKey(com.orientechnologies.orient.core.index.OCompositeKey) HashSet(java.util.HashSet) ODocument(com.orientechnologies.orient.core.record.impl.ODocument)

Example 7 with OrientEdge

use of com.tinkerpop.blueprints.impls.orient.OrientEdge in project orientdb by orientechnologies.

the class TestFailOperationOnRemovedElement method testPropertyTypeRemovedEdge.

@Test(expected = ORecordNotFoundException.class)
public void testPropertyTypeRemovedEdge() {
    OrientVertex v = grap.addVertex(null);
    OrientVertex v1 = grap.addVertex(null);
    OrientEdge e = (OrientEdge) v.addEdge("test", v1);
    grap.commit();
    e.remove();
    e.setProperty("test", "test", OType.STRING);
}
Also used : OrientVertex(com.tinkerpop.blueprints.impls.orient.OrientVertex) OrientEdge(com.tinkerpop.blueprints.impls.orient.OrientEdge) Test(org.junit.Test)

Example 8 with OrientEdge

use of com.tinkerpop.blueprints.impls.orient.OrientEdge in project orientdb by orientechnologies.

the class OrientdbEdgeTest method testEdges.

@Test
public void testEdges() throws Exception {
    OrientGraphFactory factory = getGraphFactory();
    OrientBaseGraph g = factory.getNoTx();
    try {
        try {
            g.createEdgeType("some-label");
        } catch (OSchemaException ex) {
            if (!ex.getMessage().contains("exists"))
                throw (ex);
            g.command(new OCommandSQL("delete edge some-label")).execute();
        }
        try {
            g.createVertexType("some-v-label");
        } catch (OSchemaException ex) {
            if (!ex.getMessage().contains("exists"))
                throw (ex);
            g.command(new OCommandSQL("delete vertex some-v-label")).execute();
        }
    } finally {
        g.shutdown();
    }
    OrientGraph t = factory.getTx();
    try {
        Vertex v1 = t.addVertex("class:some-v-label");
        Vertex v2 = t.addVertex("class:some-v-label");
        v1.setProperty("_id", "v1");
        v2.setProperty("_id", "v2");
        OrientEdge edge = t.addEdge(null, v1, v2, "some-label");
        edge.setProperty("some", "thing");
        t.commit();
        t.shutdown();
        t = factory.getTx();
        assertEquals(2, t.countVertices("some-v-label"));
        assertEquals(1, t.countEdges());
        assertNotNull(t.getVertices("_id", "v1").iterator().next());
        assertNotNull(t.getVertices("_id", "v2").iterator().next());
        t.commit();
        t.shutdown();
        t = factory.getTx();
        // works
        assertEquals(1, t.getVertices("_id", "v1").iterator().next().query().labels("some-label").count());
        // NoSuchElementException
        assertNotNull(t.getVertices("_id", "v1").iterator().next().query().labels("some-label").edges().iterator().next());
        t.commit();
    } finally {
        t.shutdown();
    }
}
Also used : OCommandSQL(com.orientechnologies.orient.core.sql.OCommandSQL) Vertex(com.tinkerpop.blueprints.Vertex) OrientGraph(com.tinkerpop.blueprints.impls.orient.OrientGraph) OrientGraphFactory(com.tinkerpop.blueprints.impls.orient.OrientGraphFactory) OrientBaseGraph(com.tinkerpop.blueprints.impls.orient.OrientBaseGraph) OSchemaException(com.orientechnologies.orient.core.exception.OSchemaException) OrientEdge(com.tinkerpop.blueprints.impls.orient.OrientEdge) Test(org.junit.Test)

Example 9 with OrientEdge

use of com.tinkerpop.blueprints.impls.orient.OrientEdge in project orientdb by orientechnologies.

the class GraphDatabaseTest method testDeleteOfVerticesAndEdgesWithDeleteCommandAndUnsafe.

public void testDeleteOfVerticesAndEdgesWithDeleteCommandAndUnsafe() {
    Iterable<OIdentifiable> deletedVertices = database.command(new OCommandSQL("delete from GraphVehicle return before limit 1 unsafe")).execute();
    Assert.assertTrue(deletedVertices.iterator().hasNext());
    OrientVertex v = (OrientVertex) deletedVertices.iterator().next();
    Integer confirmDeleted = database.command(new OCommandSQL("delete from " + v.getIdentity() + " unsafe")).execute();
    Assert.assertFalse(deletedVertices.iterator().hasNext());
    Assert.assertEquals(confirmDeleted.intValue(), 0);
    Iterable<Edge> edges = v.getEdges(Direction.BOTH);
    for (Edge e : edges) {
        Integer deletedEdges = database.command(new OCommandSQL("delete from " + ((OrientEdge) e).getIdentity() + " unsafe")).execute();
        Assert.assertEquals(deletedEdges.intValue(), 1);
    }
}
Also used : OCommandSQL(com.orientechnologies.orient.core.sql.OCommandSQL) OrientVertex(com.tinkerpop.blueprints.impls.orient.OrientVertex) OIdentifiable(com.orientechnologies.orient.core.db.record.OIdentifiable) OrientEdge(com.tinkerpop.blueprints.impls.orient.OrientEdge) Edge(com.tinkerpop.blueprints.Edge)

Example 10 with OrientEdge

use of com.tinkerpop.blueprints.impls.orient.OrientEdge in project orientdb by orientechnologies.

the class GraphDatabaseTest method testNewVertexAndEdgesWithFieldsInOneShoot.

public void testNewVertexAndEdgesWithFieldsInOneShoot() throws IOException {
    OrientVertex vertexA = database.addVertex(null, "field1", "value1", "field2", "value2");
    Map<String, Object> map = new HashMap<String, Object>();
    map.put("field1", "value1");
    map.put("field2", "value2");
    OrientVertex vertexB = database.addVertex(null, map);
    OrientEdge edgeC = database.addEdge(null, vertexA, vertexB, "E");
    edgeC.setProperty("edgeF1", "edgeV2");
    database.commit();
    Assert.assertEquals(vertexA.getProperty("field1"), "value1");
    Assert.assertEquals(vertexA.getProperty("field2"), "value2");
    Assert.assertEquals(vertexB.getProperty("field1"), "value1");
    Assert.assertEquals(vertexB.getProperty("field2"), "value2");
    Assert.assertEquals(edgeC.getProperty("edgeF1"), "edgeV2");
}
Also used : HashMap(java.util.HashMap) OrientVertex(com.tinkerpop.blueprints.impls.orient.OrientVertex) OrientEdge(com.tinkerpop.blueprints.impls.orient.OrientEdge)

Aggregations

OrientEdge (com.tinkerpop.blueprints.impls.orient.OrientEdge)32 OrientVertex (com.tinkerpop.blueprints.impls.orient.OrientVertex)26 Test (org.junit.Test)17 ODocument (com.orientechnologies.orient.core.record.impl.ODocument)12 OIdentifiable (com.orientechnologies.orient.core.db.record.OIdentifiable)9 OCommandSQL (com.orientechnologies.orient.core.sql.OCommandSQL)9 OrientGraph (com.tinkerpop.blueprints.impls.orient.OrientGraph)6 Edge (com.tinkerpop.blueprints.Edge)5 HashSet (java.util.HashSet)5 OClass (com.orientechnologies.orient.core.metadata.schema.OClass)4 OrientBaseGraph (com.tinkerpop.blueprints.impls.orient.OrientBaseGraph)4 HashMap (java.util.HashMap)4 OrientGraphNoTx (com.tinkerpop.blueprints.impls.orient.OrientGraphNoTx)3 OMultiCollectionIterator (com.orientechnologies.common.collection.OMultiCollectionIterator)2 ODatabaseDocumentTx (com.orientechnologies.orient.core.db.document.ODatabaseDocumentTx)2 OCommandExecutionException (com.orientechnologies.orient.core.exception.OCommandExecutionException)2 OCompositeKey (com.orientechnologies.orient.core.index.OCompositeKey)2 OIndex (com.orientechnologies.orient.core.index.OIndex)2 OImmutableClass (com.orientechnologies.orient.core.metadata.schema.OImmutableClass)2 ODirtyManager (com.orientechnologies.orient.core.record.impl.ODirtyManager)2