Search in sources :

Example 36 with Edge

use of com.tinkerpop.blueprints.Edge in project orientdb by orientechnologies.

the class BlueprintsConcurrentGraphChangesTestNoTx method assertEdgesDeletedGraph.

private void assertEdgesDeletedGraph() {
    OrientBaseGraph graph = getGraph();
    graph.setUseLightweightEdges(false);
    Assert.assertEquals(VERTEXES_COUNT, graph.countVertices("TestVertex"));
    Assert.assertEquals(0, graph.countEdges("TestEdge"));
    for (TestVertex vertex : vertexes) {
        Iterable<Vertex> vertexes = graph.command(new OSQLSynchQuery<Vertex>("select from TestVertex where uuid = '" + vertex.uuid + "'")).execute();
        Assert.assertTrue(vertexes.iterator().hasNext());
        Vertex gVertex = vertexes.iterator().next();
        OMultiCollectionIterator<Edge> outEdges = (OMultiCollectionIterator<Edge>) gVertex.getEdges(Direction.OUT);
        Assert.assertEquals(outEdges.size(), 0);
        OMultiCollectionIterator<Edge> inEdges = (OMultiCollectionIterator<Edge>) gVertex.getEdges(Direction.IN);
        Assert.assertEquals(inEdges.size(), 0);
    }
    assertGraphIsConsistent(graph);
    graph.shutdown();
}
Also used : Vertex(com.tinkerpop.blueprints.Vertex) OSQLSynchQuery(com.orientechnologies.orient.core.sql.query.OSQLSynchQuery) OMultiCollectionIterator(com.orientechnologies.common.collection.OMultiCollectionIterator) OrientBaseGraph(com.tinkerpop.blueprints.impls.orient.OrientBaseGraph) Edge(com.tinkerpop.blueprints.Edge)

Example 37 with Edge

use of com.tinkerpop.blueprints.Edge in project orientdb by orientechnologies.

the class BlueprintsTest method testSubEdge.

@Test
public void testSubEdge() {
    if (graph.getEdgeType("SubEdge") == null)
        graph.createEdgeType("SubEdge");
    if (graph.getVertexType("SubVertex") == null)
        graph.createVertexType("SubVertex");
    Vertex v1 = graph.addVertex("class:SubVertex");
    v1.setProperty("key", "subtype+subedge");
    Assert.assertEquals(((OrientVertex) v1).getRecord().getSchemaClass().getName(), "SubVertex");
    Vertex v2 = graph.addVertex("class:SubVertex");
    v2.setProperty("key", "subtype+subedge");
    Assert.assertEquals(((OrientVertex) v2).getRecord().getSchemaClass().getName(), "SubVertex");
    Edge e = graph.addEdge("class:SubEdge", v1, v2, null);
    e.setProperty("key", "subedge");
    Assert.assertEquals(((OrientEdge) e).getRecord().getSchemaClass().getName(), "SubEdge");
    graph.commit();
}
Also used : Vertex(com.tinkerpop.blueprints.Vertex) Edge(com.tinkerpop.blueprints.Edge) Test(org.junit.Test)

Example 38 with Edge

use of com.tinkerpop.blueprints.Edge in project orientdb by orientechnologies.

the class BlueprintsTest method testEdgePhysicalRemoval.

@Test
public void testEdgePhysicalRemoval() {
    graph.command(new OCommandSQL("delete from e where name = 'forceCreationOfDocument'")).execute();
    Vertex v1 = graph.addVertex(null);
    Vertex v2 = graph.addVertex(null);
    OrientEdge e = graph.addEdge(null, v1, v2, "anyLabel");
    e.setProperty("key", "forceCreationOfDocument");
    Iterable<Edge> result = graph.command(new OSQLSynchQuery<Edge>("select from e where key = 'forceCreationOfDocument'")).execute();
    Assert.assertTrue(result.iterator().hasNext());
    Assert.assertTrue(result.iterator().next() instanceof Edge);
    e.remove();
    graph.commit();
    result = graph.command(new OSQLSynchQuery<Edge>("select from e where key = 'forceCreationOfDocument'")).execute();
    Assert.assertFalse(result.iterator().hasNext());
}
Also used : OCommandSQL(com.orientechnologies.orient.core.sql.OCommandSQL) Vertex(com.tinkerpop.blueprints.Vertex) OSQLSynchQuery(com.orientechnologies.orient.core.sql.query.OSQLSynchQuery) Edge(com.tinkerpop.blueprints.Edge) Test(org.junit.Test)

Example 39 with Edge

use of com.tinkerpop.blueprints.Edge in project orientdb by orientechnologies.

the class EdgeBug method reparent.

private void reparent(Vertex child, Vertex parent) {
    OrientGraph db = new OrientGraph("memory:temp", "admin", "admin");
    OrientVertex childVertex = db.getVertex(child.getId());
    Iterable<Edge> parentEdges = childVertex.getEdges(Direction.OUT, "hasParent");
    // remove original parent edge
    for (Edge parentEdge : parentEdges) parentEdge.remove();
    // get vertex again
    childVertex = db.getVertex(childVertex.getId());
    Vertex parentVertex = db.getVertex(parent.getId());
    // add new edge to b
    childVertex.addEdge("hasParent", parentVertex);
    db.commit();
}
Also used : OrientVertex(com.tinkerpop.blueprints.impls.orient.OrientVertex) Vertex(com.tinkerpop.blueprints.Vertex) OrientGraph(com.tinkerpop.blueprints.impls.orient.OrientGraph) OrientVertex(com.tinkerpop.blueprints.impls.orient.OrientVertex) Edge(com.tinkerpop.blueprints.Edge)

Example 40 with Edge

use of com.tinkerpop.blueprints.Edge in project orientdb by orientechnologies.

the class OrientIndex method create.

private void create(final String indexName, final Class<? extends Element> indexClass, OType iKeyType) {
    this.indexClass = indexClass;
    if (iKeyType == null)
        iKeyType = OType.STRING;
    final OIndexFactory factory = OIndexes.getFactory(OClass.INDEX_TYPE.DICTIONARY.toString(), null);
    this.recordKeyValueIndex = new OIndexTxAwareOneValue(graph.getRawGraph(), (OIndex<OIdentifiable>) graph.getRawGraph().getMetadata().getIndexManager().createIndex("__@recordmap@___" + indexName, OClass.INDEX_TYPE.DICTIONARY.toString(), new OSimpleKeyIndexDefinition(factory.getLastVersion(), OType.LINK, OType.STRING), null, null, null));
    final String className;
    if (Vertex.class.isAssignableFrom(indexClass))
        className = VERTEX;
    else if (Edge.class.isAssignableFrom(indexClass))
        className = EDGE;
    else
        className = indexClass.getName();
    final ODocument metadata = new ODocument();
    metadata.field(CONFIG_CLASSNAME, className);
    metadata.field(CONFIG_RECORD_MAP_NAME, recordKeyValueIndex.getName());
    final OIndexFactory nuFactory = OIndexes.getFactory(OClass.INDEX_TYPE.NOTUNIQUE.toString(), null);
    // CREATE THE MAP
    this.underlying = new OIndexTxAwareMultiValue(graph.getRawGraph(), (OIndex<Set<OIdentifiable>>) graph.getRawGraph().getMetadata().getIndexManager().createIndex(indexName, OClass.INDEX_TYPE.NOTUNIQUE.toString(), new OSimpleKeyIndexDefinition(nuFactory.getLastVersion(), iKeyType), null, null, metadata));
}
Also used : OIndex(com.orientechnologies.orient.core.index.OIndex) OSimpleKeyIndexDefinition(com.orientechnologies.orient.core.index.OSimpleKeyIndexDefinition) OIndexTxAwareMultiValue(com.orientechnologies.orient.core.index.OIndexTxAwareMultiValue) OIndexTxAwareOneValue(com.orientechnologies.orient.core.index.OIndexTxAwareOneValue) OIndexFactory(com.orientechnologies.orient.core.index.OIndexFactory) Edge(com.tinkerpop.blueprints.Edge) OIdentifiable(com.orientechnologies.orient.core.db.record.OIdentifiable) ODocument(com.orientechnologies.orient.core.record.impl.ODocument)

Aggregations

Edge (com.tinkerpop.blueprints.Edge)214 Vertex (com.tinkerpop.blueprints.Vertex)141 Test (org.junit.Test)53 Graph (com.tinkerpop.blueprints.Graph)49 TinkerGraph (com.tinkerpop.blueprints.impls.tg.TinkerGraph)49 HashSet (java.util.HashSet)28 OrientVertex (com.tinkerpop.blueprints.impls.orient.OrientVertex)13 ArrayList (java.util.ArrayList)13 Collection (java.util.Collection)11 JSONObject (org.codehaus.jettison.json.JSONObject)11 HashMap (java.util.HashMap)10 OrientEdge (com.tinkerpop.blueprints.impls.orient.OrientEdge)9 OrientGraph (com.tinkerpop.blueprints.impls.orient.OrientGraph)9 OCommandSQL (com.orientechnologies.orient.core.sql.OCommandSQL)8 Map (java.util.Map)8 OrientBaseGraph (com.tinkerpop.blueprints.impls.orient.OrientBaseGraph)7 ODocument (com.orientechnologies.orient.core.record.impl.ODocument)6 OSQLSynchQuery (com.orientechnologies.orient.core.sql.query.OSQLSynchQuery)6 KeyIndexableGraph (com.tinkerpop.blueprints.KeyIndexableGraph)6 URI (org.openrdf.model.URI)6