Search in sources :

Example 16 with OrientGraph

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

the class EdgeIndexingTest method testOutLinksUniquenessFour.

/**
   * Test that "out_vertex" has singe and only single edge to "in_vertex". This only possible if edges are not lightweight edges.
   */
@Test
public void testOutLinksUniquenessFour() {
    final String url = "memory:" + this.getClass().getSimpleName();
    OrientGraph graph = new OrientGraph(url, "admin", "admin", false);
    graph.drop();
    graph = new OrientGraph(url, "admin", "admin", false);
    OClass edgeType = graph.createEdgeType("link");
    edgeType.createProperty("in", OType.LINK);
    edgeType.createProperty("out", OType.LINK);
    edgeType.createIndex("uniqueLinkIndex", "unique", "in", "out");
    graph.setAutoStartTx(true);
    Vertex vertexOutOne = graph.addVertex(null);
    Vertex vertexInOne = graph.addVertex(null);
    Vertex vertexInTwo = graph.addVertex(null);
    vertexOutOne.addEdge("link", vertexInOne);
    vertexOutOne.addEdge("link", vertexInTwo);
    vertexOutOne.addEdge("link", vertexInOne);
    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 17 with OrientGraph

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

the class ORidBagTest method stackOverflowDuringToString.

public void stackOverflowDuringToString() {
    final OrientGraph graph = new OrientGraph(database);
    OrientVertex a = graph.addVertex("A");
    OrientVertex b = graph.addVertex("B");
    OrientVertex c = graph.addVertex("C");
    a.addEdge("link", b);
    a.addEdge("link", c);
    b.addEdge("link", a);
    b.addEdge("link", c);
    c.addEdge("link", a);
    c.addEdge("link", b);
    // System.out.println("A: " + a.getRecord());
    // System.out.println("B: " + b.getRecord());
    // System.out.println("C: " + c.getRecord());
    database.commit();
}
Also used : OrientGraph(com.tinkerpop.blueprints.impls.orient.OrientGraph) OrientVertex(com.tinkerpop.blueprints.impls.orient.OrientVertex)

Example 18 with OrientGraph

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

the class TransactionConsistencyTest method testConsistencyOnDelete.

@Test
public void testConsistencyOnDelete() {
    final OrientGraph graph = new OrientGraph(url);
    if (graph.getVertexType("Foo") == null)
        graph.createVertexType("Foo");
    try {
        // Step 1
        // Create several foo's
        graph.addVertex("class:Foo", "address", "test1");
        graph.addVertex("class:Foo", "address", "test2");
        graph.addVertex("class:Foo", "address", "test3");
        graph.commit();
        // just show what is there
        List<ODocument> result = graph.getRawGraph().query(new OSQLSynchQuery<ODocument>("select * from Foo"));
        // for (ODocument d : result) {
        // System.out.println("Vertex: " + d);
        // }
        // remove those foos in a transaction
        // Step 3a
        result = graph.getRawGraph().query(new OSQLSynchQuery<ODocument>("select * from Foo where address = 'test1'"));
        Assert.assertEquals(result.size(), 1);
        // Step 4a
        graph.removeVertex(graph.getVertex(result.get(0)));
        // Step 3b
        result = graph.getRawGraph().query(new OSQLSynchQuery<ODocument>("select * from Foo where address = 'test2'"));
        Assert.assertEquals(result.size(), 1);
        // Step 4b
        graph.removeVertex(graph.getVertex(result.get(0)));
        // Step 3c
        result = graph.getRawGraph().query(new OSQLSynchQuery<ODocument>("select * from Foo where address = 'test3'"));
        Assert.assertEquals(result.size(), 1);
        // Step 4c
        graph.removeVertex(graph.getVertex(result.get(0)));
        // Step 6
        graph.commit();
        // just show what is there
        result = graph.getRawGraph().query(new OSQLSynchQuery<ODocument>("select * from Foo"));
    // for (ODocument d : result) {
    // System.out.println("Vertex: " + d);
    // }
    } finally {
        graph.shutdown();
    }
}
Also used : OrientGraph(com.tinkerpop.blueprints.impls.orient.OrientGraph) OSQLSynchQuery(com.orientechnologies.orient.core.sql.query.OSQLSynchQuery) ODocument(com.orientechnologies.orient.core.record.impl.ODocument) Test(org.testng.annotations.Test) DatabaseAbstractTest(com.orientechnologies.DatabaseAbstractTest)

Example 19 with OrientGraph

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

the class TransactionConsistencyTest method deletesWithinTransactionArentWorking.

@Test
public void deletesWithinTransactionArentWorking() throws IOException {
    OrientGraph graph = new OrientGraph(url);
    graph.setUseLightweightEdges(false);
    try {
        if (graph.getVertexType("Foo") == null)
            graph.createVertexType("Foo");
        if (graph.getVertexType("Bar") == null)
            graph.createVertexType("Bar");
        if (graph.getVertexType("Sees") == null)
            graph.createEdgeType("Sees");
        // Commenting out the transaction will result in the test succeeding.
        ODocument foo = graph.addVertex("class:Foo", "prop", "test1").getRecord();
        // Comment out these two lines and the test will succeed. The issue appears to be related to an edge
        // connecting a deleted vertex during a transaction
        ODocument bar = graph.addVertex("class:Bar", "prop", "test1").getRecord();
        ODocument sees = graph.addEdge(null, graph.getVertex(foo), graph.getVertex(bar), "Sees").getRecord();
        graph.commit();
        List<ODocument> foos = graph.getRawGraph().query(new OSQLSynchQuery("select * from Foo"));
        Assert.assertEquals(foos.size(), 1);
        graph.removeVertex(graph.getVertex(foos.get(0)));
    } finally {
        graph.shutdown();
    }
}
Also used : OrientGraph(com.tinkerpop.blueprints.impls.orient.OrientGraph) OSQLSynchQuery(com.orientechnologies.orient.core.sql.query.OSQLSynchQuery) ODocument(com.orientechnologies.orient.core.record.impl.ODocument) Test(org.testng.annotations.Test) DatabaseAbstractTest(com.orientechnologies.DatabaseAbstractTest)

Example 20 with OrientGraph

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

the class TraverseTest method init.

@BeforeClass
public void init() {
    OrientGraph graph = new OrientGraph(database);
    graph.setUseLightweightEdges(false);
    graph.createVertexType("Movie");
    graph.createVertexType("Actor");
    tomCruise = graph.addVertex("class:Actor", "name", "Tom Cruise").getRecord();
    totalElements++;
    megRyan = graph.addVertex("class:Actor", "name", "Meg Ryan").getRecord();
    totalElements++;
    nicoleKidman = graph.addVertex("class:Actor", "name", "Nicole Kidman", "attributeWithDotValue", "a.b").getRecord();
    totalElements++;
    ODocument topGun = graph.addVertex("class:Movie", "name", "Top Gun", "year", 1986).getRecord();
    totalElements++;
    ODocument missionImpossible = graph.addVertex("class:Movie", "name", "Mission: Impossible", "year", 1996).getRecord();
    totalElements++;
    ODocument youHaveGotMail = graph.addVertex("class:Movie", "name", "You've Got Mail", "year", 1998).getRecord();
    totalElements++;
    graph.addEdge(null, graph.getVertex(tomCruise), graph.getVertex(topGun), "actorIn");
    totalElements++;
    graph.addEdge(null, graph.getVertex(megRyan), graph.getVertex(topGun), "actorIn");
    totalElements++;
    graph.addEdge(null, graph.getVertex(tomCruise), graph.getVertex(missionImpossible), "actorIn");
    totalElements++;
    graph.addEdge(null, graph.getVertex(megRyan), graph.getVertex(youHaveGotMail), "actorIn");
    totalElements++;
    graph.addEdge(null, graph.getVertex(tomCruise), graph.getVertex(megRyan), "friend");
    totalElements++;
    graph.addEdge(null, graph.getVertex(tomCruise), graph.getVertex(nicoleKidman), "married").setProperty("year", 1990);
    totalElements++;
    graph.commit();
}
Also used : OrientGraph(com.tinkerpop.blueprints.impls.orient.OrientGraph) ODocument(com.orientechnologies.orient.core.record.impl.ODocument) BeforeClass(org.testng.annotations.BeforeClass)

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