Search in sources :

Example 11 with OrientGraph

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

the class ServerClusterSchemaTest method executeTest.

@Override
protected void executeTest() throws Exception {
    for (int s = 0; s < SERVERS; ++s) {
        OrientGraphFactory factory = new OrientGraphFactory("plocal:target/server" + s + "/databases/" + getDatabaseName());
        OrientGraphNoTx g = factory.getNoTx();
        try {
            System.out.println("Creating vertex class Client" + s + " against server " + g + "...");
            OrientVertexType t = g.createVertexType("Client" + s);
            t.createProperty("name", OType.STRING).setMandatory(true);
            System.out.println("Creating vertex class Knows" + s + " against server " + g + "...");
            g.createEdgeType("Knows" + s);
        } finally {
            g.shutdown();
        }
    }
    for (int s = 0; s < SERVERS; ++s) {
        System.out.println("Checking vertices classes on server " + s + "...");
        OrientGraphFactory factory = new OrientGraphFactory("plocal:target/server" + s + "/databases/" + getDatabaseName());
        OrientGraphNoTx g = factory.getNoTx();
        try {
            for (int i = 0; i < SERVERS; ++i) {
                Assert.assertNotNull(g.getVertexType("Client" + i));
                Assert.assertNotNull(g.getEdgeType("Knows" + i));
            }
        } finally {
            g.shutdown();
        }
    }
    for (int s = 0; s < SERVERS; ++s) {
        System.out.println("Add vertices on server " + s + "...");
        OrientGraphFactory factory = new OrientGraphFactory("plocal:target/server" + s + "/databases/" + getDatabaseName());
        OrientGraphNoTx g = factory.getNoTx();
        try {
            for (int i = 0; i < SERVERS; ++i) {
                try {
                    final OrientVertex v = g.addVertex("class:" + "Client" + i);
                    Assert.assertTrue(false);
                } catch (OValidationException e) {
                // EXPECTED
                }
            }
        } finally {
            g.shutdown();
        }
    }
    for (int s = 0; s < SERVERS; ++s) {
        System.out.println("Add vertices in TX on server " + s + "...");
        OrientGraphFactory factory = new OrientGraphFactory("plocal:target/server" + s + "/databases/" + getDatabaseName());
        OrientGraph g = factory.getTx();
        try {
            for (int i = 0; i < SERVERS; ++i) {
                try {
                    final OrientVertex v = g.addVertex("class:" + "Client" + i);
                    g.commit();
                    Assert.assertTrue(false);
                } catch (ONeedRetryException e) {
                // EXPECTED
                } catch (OValidationException e) {
                // EXPECTED
                }
            }
        } finally {
            g.shutdown();
        }
    }
}
Also used : OValidationException(com.orientechnologies.orient.core.exception.OValidationException) OrientGraph(com.tinkerpop.blueprints.impls.orient.OrientGraph) ONeedRetryException(com.orientechnologies.common.concur.ONeedRetryException) OrientGraphFactory(com.tinkerpop.blueprints.impls.orient.OrientGraphFactory) OrientGraphNoTx(com.tinkerpop.blueprints.impls.orient.OrientGraphNoTx) OrientVertexType(com.tinkerpop.blueprints.impls.orient.OrientVertexType) OrientVertex(com.tinkerpop.blueprints.impls.orient.OrientVertex)

Example 12 with OrientGraph

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

the class VertexIndexTest method testFullTextIndexOnvertex.

@Test
public void testFullTextIndexOnvertex() {
    OrientGraph graph = new OrientGraph("memory:TestDB", "admin", "admin");
    OrientVertexType vType = graph.getVertexType("V");
    vType.createProperty("title", OType.STRING);
    vType.createProperty("text", OType.STRING);
    vType.createIndex("V.", "FULLTEXT", null, null, "LUCENE", new String[] { "title", "text" });
    graph.drop();
}
Also used : OrientGraph(com.tinkerpop.blueprints.impls.orient.OrientGraph) OrientVertexType(com.tinkerpop.blueprints.impls.orient.OrientVertexType) Test(org.junit.Test)

Example 13 with OrientGraph

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

the class DbListenerTest method testEmbeddedDbListenersGraph.

@Test
public void testEmbeddedDbListenersGraph() throws IOException {
    if (database.getURL().startsWith("remote:"))
        return;
    if (database.exists())
        ODatabaseHelper.deleteDatabase(database, getStorageType());
    ODatabaseHelper.createDatabase(database, url, getStorageType());
    database.open("admin", "admin");
    OrientGraph g = new OrientGraph(database);
    OrientVertex v = g.addVertex(null);
    v.setProperty("name", "Jay");
    g.commit();
    final DocumentChangeListener cl = new DocumentChangeListener(g);
    v.setProperty("surname", "Miner");
    g.shutdown();
    Assert.assertEquals(cl.getChanges().size(), 1);
    ODatabaseHelper.deleteDatabase(database, getStorageType());
    ODatabaseHelper.createDatabase(database, url, getStorageType());
}
Also used : OrientGraph(com.tinkerpop.blueprints.impls.orient.OrientGraph) OrientVertex(com.tinkerpop.blueprints.impls.orient.OrientVertex) Test(org.testng.annotations.Test)

Example 14 with OrientGraph

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

the class GraphDatabaseTest method populate.

@Test
public void populate() {
    OClass vehicleClass = database.createVertexType("GraphVehicle");
    database.createVertexType("GraphCar", vehicleClass);
    database.createVertexType("GraphMotocycle", "GraphVehicle");
    ODocument carNode = database.addVertex("class:GraphCar", "brand", "Hyundai", "model", "Coupe", "year", 2003).getRecord();
    ODocument motoNode = database.addVertex("class:GraphMotocycle", "brand", "Yamaha", "model", "X-City 250", "year", 2009).getRecord();
    database.commit();
    database.addEdge(null, database.getVertex(carNode), database.getVertex(motoNode), "E").save();
    List<ODocument> result = database.getRawGraph().query(new OSQLSynchQuery<ODocument>("select from GraphVehicle"));
    Assert.assertEquals(result.size(), 2);
    for (ODocument v : result) {
        Assert.assertTrue(v.getSchemaClass().isSubClassOf(vehicleClass));
    }
    database.shutdown();
    database = new OrientGraph(url);
    database.setUseLightweightEdges(false);
    database.getRawGraph().getMetadata().getSchema().reload();
    result = database.getRawGraph().query(new OSQLSynchQuery<ODocument>("select from GraphVehicle"));
    Assert.assertEquals(result.size(), 2);
    Edge edge1 = null;
    Edge edge2 = null;
    for (ODocument v : result) {
        Assert.assertTrue(v.getSchemaClass().isSubClassOf("GraphVehicle"));
        if (v.getClassName().equals("GraphCar")) {
            Assert.assertEquals(database.getVertex(v).countEdges(Direction.OUT), 1);
            edge1 = database.getVertex(v).getEdges(Direction.OUT).iterator().next();
        } else {
            Assert.assertEquals(database.getVertex(v).countEdges(Direction.IN), 1);
            edge2 = database.getVertex(v).getEdges(Direction.IN).iterator().next();
        }
    }
    Assert.assertEquals(edge1, edge2);
}
Also used : OrientGraph(com.tinkerpop.blueprints.impls.orient.OrientGraph) OSQLSynchQuery(com.orientechnologies.orient.core.sql.query.OSQLSynchQuery) OClass(com.orientechnologies.orient.core.metadata.schema.OClass) OrientEdge(com.tinkerpop.blueprints.impls.orient.OrientEdge) Edge(com.tinkerpop.blueprints.Edge) ODocument(com.orientechnologies.orient.core.record.impl.ODocument) Test(org.testng.annotations.Test)

Example 15 with OrientGraph

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

the class GraphDatabaseTest method init.

@BeforeMethod
public void init() {
    database = new OrientGraph(url);
    database.setUseLightweightEdges(false);
}
Also used : OrientGraph(com.tinkerpop.blueprints.impls.orient.OrientGraph) BeforeMethod(org.testng.annotations.BeforeMethod)

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