Search in sources :

Example 76 with OrientGraph

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

the class EdgeIndexingTest method testOutLinksUniquenessThree.

/**
   * Test that "out_vertex" has edges to only single "in_vertex" but we may have several edges to single "in_vertex".
   */
@Test
public void testOutLinksUniquenessThree() {
    final String url = "memory:" + this.getClass().getSimpleName();
    OrientGraph graph = new OrientGraph(url, "admin", "admin", false);
    graph.drop();
    graph = new OrientGraph(url, "admin", "admin", false);
    graph.setUseLightweightEdges(true);
    graph.createEdgeType("link");
    OClass inVertexType = graph.createVertexType("IndexedInVertex");
    inVertexType.createProperty("in_link", OType.LINKBAG);
    inVertexType.createIndex("uniqueLinkIndex", "unique", "in_link");
    graph.setAutoStartTx(true);
    Vertex vertexOutOne = graph.addVertex(null);
    Vertex vertexInOne = graph.addVertex("class:IndexedInVertex");
    Vertex vertexInTwo = graph.addVertex("class:IndexedInVertex");
    vertexOutOne.addEdge("link", vertexInOne);
    vertexOutOne.addEdge("link", vertexInTwo);
    try {
        graph.commit();
        Assert.fail();
    // in vertex can be linked by only one out vertex.
    } catch (ORecordDuplicatedException e) {
    }
    graph.drop();
}
Also used : Vertex(com.tinkerpop.blueprints.Vertex) OrientGraph(com.tinkerpop.blueprints.impls.orient.OrientGraph) ORecordDuplicatedException(com.orientechnologies.orient.core.storage.ORecordDuplicatedException) OClass(com.orientechnologies.orient.core.metadata.schema.OClass) Test(org.junit.Test)

Example 77 with OrientGraph

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

the class EdgeIndexingTest method testOutLinksUniquenessTwo.

/**
   * Test that "in_vertex" has edges to only single "out_vertex" but we may have several edges to single "out_vertex".
   */
@Test
public void testOutLinksUniquenessTwo() {
    final String url = "memory:" + this.getClass().getSimpleName();
    OrientGraph graph = new OrientGraph(url);
    graph.drop();
    graph = new OrientGraph(url);
    graph.setUseLightweightEdges(true);
    graph.createEdgeType("link");
    graph.setAutoStartTx(false);
    OClass outVertexType = graph.createVertexType("IndexedOutVertex");
    outVertexType.createProperty("out_link", OType.LINKBAG);
    outVertexType.createIndex("uniqueLinkIndex", "unique", "out_link");
    graph.setAutoStartTx(true);
    Vertex vertexOutOne = graph.addVertex("class:IndexedOutVertex");
    Vertex vertexInOne = graph.addVertex(null);
    Vertex vertexInTwo = graph.addVertex(null);
    vertexOutOne.addEdge("link", vertexInOne);
    vertexOutOne.addEdge("link", vertexInTwo);
    Vertex vertexOutTwo = graph.addVertex("class:IndexedOutVertex");
    vertexOutTwo.addEdge("link", vertexInTwo);
    try {
        graph.commit();
        // in vertex can be linked by only one out vertex.
        Assert.fail();
    } catch (ORecordDuplicatedException e) {
    }
    graph.drop();
}
Also used : Vertex(com.tinkerpop.blueprints.Vertex) OrientGraph(com.tinkerpop.blueprints.impls.orient.OrientGraph) ORecordDuplicatedException(com.orientechnologies.orient.core.storage.ORecordDuplicatedException) OClass(com.orientechnologies.orient.core.metadata.schema.OClass) Test(org.junit.Test)

Example 78 with OrientGraph

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

the class EdgeSaveShouldNotReinsertVerticesTest method test.

@Test
public void test() {
    final OrientGraph graph = factory.getTx();
    graph.createVertexType("Person").createProperty("name", OType.STRING).createIndex(OClass.INDEX_TYPE.UNIQUE_HASH_INDEX);
    graph.begin();
    final OrientVertex v1 = graph.addVertex("class:Person", "name", "1");
    final OrientVertex v2 = graph.addVertex("class:Person", "name", "2");
    v1.setProperty("name", "2");
    v2.setProperty("name", "1");
    // At this point v1 and v2 are considered new, not updated, by internals of ODirtyManager, during the save of created edge
    // they got reinserted into indexes and storage (?).
    v1.addEdge("edge", v2);
    v1.setProperty("name", "1");
    v2.setProperty("name", "2");
    graph.commit();
    graph.shutdown();
}
Also used : OrientGraph(com.tinkerpop.blueprints.impls.orient.OrientGraph) OrientVertex(com.tinkerpop.blueprints.impls.orient.OrientVertex) Test(org.junit.Test)

Example 79 with OrientGraph

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

the class GraphFunctionsTest method before.

@BeforeClass
public static void before() {
    graph = new OrientGraph(DB_URL);
    if (graph.getEdgeType("SubEdge") == null)
        graph.createEdgeType("SubEdge");
    if (graph.getVertexType("SubVertex") == null)
        graph.createVertexType("SubVertex");
    v1 = graph.addVertex("class:SubVertex");
    v2 = graph.addVertex("class:SubVertex");
    v3 = graph.addVertex(null);
    e1 = graph.addEdge("class:SubEdge", v1, v2, null);
    e2 = graph.addEdge(null, v1, v3, "contains");
    graph.commit();
}
Also used : OrientGraph(com.tinkerpop.blueprints.impls.orient.OrientGraph) BeforeClass(org.junit.BeforeClass)

Example 80 with OrientGraph

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

the class OrderedEdgesGraphTest method testReplacePosition.

@Test
public void testReplacePosition() {
    OrientVertex loadedPerson;
    List<ODocument> edges;
    try {
        loadedPerson = graph.getVertex(mainPerson.getId());
        graph.setUseLightweightEdges(true);
        int i = 1;
        edges = loadedPerson.getRecord().field("out_Knows");
        ODocument edge10 = edges.remove(9);
        edges.add(edge10);
    } finally {
        graph.shutdown();
    }
    graph = new OrientGraph(DB_URL);
    try {
        graph.setUseLightweightEdges(true);
        loadedPerson = graph.getVertex(mainPerson.getId());
        edges = loadedPerson.getRecord().field("out_Knows");
        assertEquals(graph.getVertex(edges.get(9)).getProperty("index"), 11);
        assertEquals(graph.getVertex(edges.get(99)).getProperty("index"), 10);
    } finally {
        graph.shutdown();
    }
}
Also used : OrientGraph(com.tinkerpop.blueprints.impls.orient.OrientGraph) OrientVertex(com.tinkerpop.blueprints.impls.orient.OrientVertex) ODocument(com.orientechnologies.orient.core.record.impl.ODocument) Test(org.junit.Test)

Aggregations

OrientGraph (com.tinkerpop.blueprints.impls.orient.OrientGraph)94 OrientVertex (com.tinkerpop.blueprints.impls.orient.OrientVertex)43 Test (org.junit.Test)33 Vertex (com.tinkerpop.blueprints.Vertex)22 OrientBaseGraph (com.tinkerpop.blueprints.impls.orient.OrientBaseGraph)19 ODocument (com.orientechnologies.orient.core.record.impl.ODocument)18 OCommandSQL (com.orientechnologies.orient.core.sql.OCommandSQL)13 OSQLSynchQuery (com.orientechnologies.orient.core.sql.query.OSQLSynchQuery)13 OrientVertexType (com.tinkerpop.blueprints.impls.orient.OrientVertexType)12 Edge (com.tinkerpop.blueprints.Edge)8 OClass (com.orientechnologies.orient.core.metadata.schema.OClass)7 OrientEdge (com.tinkerpop.blueprints.impls.orient.OrientEdge)7 OrientGraphFactory (com.tinkerpop.blueprints.impls.orient.OrientGraphFactory)7 OConcurrentModificationException (com.orientechnologies.orient.core.exception.OConcurrentModificationException)6 Test (org.testng.annotations.Test)6 OIdentifiable (com.orientechnologies.orient.core.db.record.OIdentifiable)5 OrientGraphNoTx (com.tinkerpop.blueprints.impls.orient.OrientGraphNoTx)5 Before (org.junit.Before)5 BeforeClass (org.junit.BeforeClass)5 ORecordDuplicatedException (com.orientechnologies.orient.core.storage.ORecordDuplicatedException)4