Search in sources :

Example 6 with OrientVertexType

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

the class TestGraphUnwindOut method testUwindLightweightEdges.

@Test
public void testUwindLightweightEdges() {
    OrientGraph graph = new OrientGraph("memory:" + TestGraphUnwindOut.class.getSimpleName());
    graph.setUseLightweightEdges(true);
    try {
        OrientVertexType type = graph.createVertexType("edgetest");
        graph.createEdgeType("edgetestedge");
        type.createEdgeProperty(Direction.IN, "edgetestedge");
        type.createEdgeProperty(Direction.OUT, "edgetestedge");
        OrientVertex test = graph.addVertex("class:edgetest");
        test.setProperty("ida", "parentckt1");
        test.save();
        OrientVertex test1 = graph.addVertex("class:edgetest");
        test1.setProperty("ida", "childckt2");
        test1.save();
        OrientVertex test2 = graph.addVertex("class:edgetest");
        test2.setProperty("ida", "childckt3");
        test2.save();
        OrientVertex test3 = graph.addVertex("class:edgetest");
        test3.setProperty("ida", "childckt4");
        test3.save();
        graph.commit();
        graph.command(new OCommandSQL("create edge edgetestedge from (select from edgetest where ida='parentckt1') to (select from edgetest where ida like 'childckt%')")).execute();
        graph.commit();
        Iterable<OrientElement> res = graph.command(new OSQLSynchQuery("select out_edgetestedge[0] from v where out_edgetestedge.size() > 0 unwind out_edgetestedge ")).execute();
        for (OrientElement oDocument : res) {
            assertNotNull(oDocument.getRecord().field("out_edgetestedge"));
            ODocument doc = oDocument.getRecord().field("out_edgetestedge");
            assertEquals(doc.getClassName(), "edgetest");
        }
    } finally {
        graph.drop();
    }
}
Also used : OCommandSQL(com.orientechnologies.orient.core.sql.OCommandSQL) OrientGraph(com.tinkerpop.blueprints.impls.orient.OrientGraph) OSQLSynchQuery(com.orientechnologies.orient.core.sql.query.OSQLSynchQuery) OrientVertexType(com.tinkerpop.blueprints.impls.orient.OrientVertexType) OrientElement(com.tinkerpop.blueprints.impls.orient.OrientElement) OrientVertex(com.tinkerpop.blueprints.impls.orient.OrientVertex) ODocument(com.orientechnologies.orient.core.record.impl.ODocument) Test(org.junit.Test)

Example 7 with OrientVertexType

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

the class OGraphImporterSTAPITest method main.

public static void main(String[] args) throws IOException, InterruptedException {
    // String dbUrl = "memory:amazonReviews";
    String dbUrl = "plocal:/temp/databases/amazonReviews";
    final File f = new File("/temp/databases/amazonReviews");
    if (f.exists())
        OFileUtils.deleteRecursively(f);
    final OrientGraph roGraph = new OrientGraph(dbUrl, "admin", "admin");
    final OrientGraph graph = new OrientGraph(dbUrl, "admin", "admin");
    OrientVertexType user = graph.createVertexType("User");
    user.createProperty("uid", OType.STRING);
    final OIndex<?> userIndex = user.createIndex("User.uid", OClass.INDEX_TYPE.UNIQUE.toString(), (OProgressListener) null, (ODocument) null, "AUTOSHARDING", new String[] { "uid" });
    OrientVertexType product = graph.createVertexType("Product");
    product.createProperty("uid", OType.STRING);
    final OIndex<?> productIndex = product.createIndex("Product.uid", OClass.INDEX_TYPE.UNIQUE.toString(), (OProgressListener) null, (ODocument) null, "AUTOSHARDING", new String[] { "uid" });
    graph.createEdgeType("Reviewed");
    final File file = new File("/Users/luca/Downloads/ratings_Books.csv");
    final BufferedReader br = new BufferedReader(new FileReader(file));
    Orient.instance().scheduleTask(new TimerTask() {

        @Override
        public void run() {
            roGraph.makeActive();
            final long vertexCount = roGraph.countVertices();
            final long edgeCount = roGraph.countEdges();
            System.out.println(String.format("%d vertices=%d %d/sec edges=%d %d/sec", row, vertexCount, ((vertexCount - lastVertexCount) * 1000 / 2000), edgeCount, ((edgeCount - lastEdgeCount) * 1000 / 2000)));
            lastVertexCount = vertexCount;
            lastEdgeCount = edgeCount;
        }
    }, 2000, 2000);
    try {
        for (String line; (line = br.readLine()) != null; ) {
            row++;
            final String[] parts = line.split(",");
            if (parts.length != 4) {
                // SKIP IT
                System.out.print("Skipped invalid line " + row + ": " + line);
                continue;
            }
            Map<String, Object> properties = new HashMap<String, Object>();
            properties.put("score", new Float(parts[2]).intValue());
            properties.put("date", Long.parseLong(parts[3]));
            final Object k1 = userIndex.get(parts[0]);
            OrientVertex v1;
            if (k1 == null) {
                v1 = graph.addVertex("class:User", "uid", parts[0]);
            } else
                v1 = graph.getVertex(k1);
            final Object k2 = productIndex.get(parts[1]);
            OrientVertex v2;
            if (k2 == null) {
                v2 = graph.addVertex("class:Product", "uid", parts[1]);
            } else
                v2 = graph.getVertex(k2);
            final OrientEdge edge = graph.addEdge(null, v1, v2, "Reviewed");
            edge.setProperties(properties);
            if (row % 2 == 0) {
                graph.commit();
            }
        }
    } finally {
        br.close();
    }
    graph.shutdown();
    roGraph.shutdown();
}
Also used : OrientGraph(com.tinkerpop.blueprints.impls.orient.OrientGraph) HashMap(java.util.HashMap) OrientVertex(com.tinkerpop.blueprints.impls.orient.OrientVertex) OrientEdge(com.tinkerpop.blueprints.impls.orient.OrientEdge) TimerTask(java.util.TimerTask) BufferedReader(java.io.BufferedReader) OrientVertexType(com.tinkerpop.blueprints.impls.orient.OrientVertexType) FileReader(java.io.FileReader) File(java.io.File)

Example 8 with OrientVertexType

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

the class GraphValidationTest method testPropertyReadOnly.

@Test(expected = OValidationException.class)
public void testPropertyReadOnly() {
    OrientGraphNoTx graphNoTx = new OrientGraphNoTx(URL);
    OrientVertexType testType = graphNoTx.createVertexType("Test");
    OProperty prop;
    prop = testType.createProperty("name", OType.STRING).setReadonly(true);
    graphNoTx.shutdown();
    //this one passes
    Assert.assertTrue(prop.isReadonly());
    OrientGraph graph = new OrientGraph(URL);
    try {
        OrientVertex vert1 = graph.addVertex("class:Test", "name", "Sam");
        graph.commit();
        //should throw an exception
        vert1.setProperty("name", "Ben");
        graph.commit();
        //fails
        Assert.assertEquals(vert1.getProperty("name"), "Sam");
    } finally {
        graph.shutdown();
    }
}
Also used : OProperty(com.orientechnologies.orient.core.metadata.schema.OProperty) OrientGraph(com.tinkerpop.blueprints.impls.orient.OrientGraph) OrientGraphNoTx(com.tinkerpop.blueprints.impls.orient.OrientGraphNoTx) OrientVertexType(com.tinkerpop.blueprints.impls.orient.OrientVertexType) OrientVertex(com.tinkerpop.blueprints.impls.orient.OrientVertex) Test(org.junit.Test)

Example 9 with OrientVertexType

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

the class GraphValidationTest method setupSchema.

private void setupSchema() {
    OrientGraphNoTx graphNoTx = new OrientGraphNoTx(URL, "admin", "admin");
    try {
        ODatabaseDocumentTx database = graphNoTx.getRawGraph();
        OSchema oScchema = database.getMetadata().getSchema();
        oScchema.getClass("V").setStrictMode(true);
        oScchema.getClass("E").setStrictMode(true);
        OrientVertexType CmVertexBaseType = graphNoTx.createVertexType("CmVertexBase", "V");
        CmVertexBaseType.setStrictMode(true);
        OrientVertexType CmEdgeBaseType = graphNoTx.createVertexType("CmEdgeBase", "V");
        CmEdgeBaseType.setStrictMode(true);
        OClass mOClass = database.getMetadata().getSchema().createClass("M", database.getMetadata().getSchema().getClass("V"));
        mOClass.createProperty("name", OType.STRING).setMandatory(true).setNotNull(true);
        mOClass.setStrictMode(true);
        graphNoTx.commit();
    } finally {
        graphNoTx.shutdown();
    }
}
Also used : OSchema(com.orientechnologies.orient.core.metadata.schema.OSchema) OClass(com.orientechnologies.orient.core.metadata.schema.OClass) ODatabaseDocumentTx(com.orientechnologies.orient.core.db.document.ODatabaseDocumentTx) OrientGraphNoTx(com.tinkerpop.blueprints.impls.orient.OrientGraphNoTx) OrientVertexType(com.tinkerpop.blueprints.impls.orient.OrientVertexType)

Example 10 with OrientVertexType

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

the class GraphValidationTest method testNoTxGraphConstraints.

@Test
public void testNoTxGraphConstraints() {
    OrientGraphNoTx graphNoTx = new OrientGraphNoTx(URL);
    OrientVertexType testType = graphNoTx.createVertexType("Test");
    testType.createProperty("age", OType.INTEGER).setMax("3");
    OrientVertex vert1 = graphNoTx.addVertex("class:Test", "age", 2);
    try {
        vert1.setProperty("age", 4);
    } catch (OValidationException e) {
        //this fails
        Assert.assertEquals(vert1.getProperty("age"), 2);
    } finally {
        graphNoTx.shutdown();
    }
}
Also used : OValidationException(com.orientechnologies.orient.core.exception.OValidationException) OrientGraphNoTx(com.tinkerpop.blueprints.impls.orient.OrientGraphNoTx) OrientVertexType(com.tinkerpop.blueprints.impls.orient.OrientVertexType) OrientVertex(com.tinkerpop.blueprints.impls.orient.OrientVertex) Test(org.junit.Test)

Aggregations

OrientVertexType (com.tinkerpop.blueprints.impls.orient.OrientVertexType)31 OrientGraphNoTx (com.tinkerpop.blueprints.impls.orient.OrientGraphNoTx)17 OrientVertex (com.tinkerpop.blueprints.impls.orient.OrientVertex)13 OrientGraph (com.tinkerpop.blueprints.impls.orient.OrientGraph)12 Test (org.junit.Test)9 OCommandSQL (com.orientechnologies.orient.core.sql.OCommandSQL)8 ODocument (com.orientechnologies.orient.core.record.impl.ODocument)5 OrientEdgeType (com.tinkerpop.blueprints.impls.orient.OrientEdgeType)5 Vertex (com.tinkerpop.blueprints.Vertex)4 OrientGraphFactory (com.tinkerpop.blueprints.impls.orient.OrientGraphFactory)4 Before (org.junit.Before)4 OSQLSynchQuery (com.orientechnologies.orient.core.sql.query.OSQLSynchQuery)3 OrientBaseGraph (com.tinkerpop.blueprints.impls.orient.OrientBaseGraph)3 OValidationException (com.orientechnologies.orient.core.exception.OValidationException)2 ORecordId (com.orientechnologies.orient.core.id.ORecordId)2 OClass (com.orientechnologies.orient.core.metadata.schema.OClass)2 OSchema (com.orientechnologies.orient.core.metadata.schema.OSchema)2 ONeedRetryException (com.orientechnologies.common.concur.ONeedRetryException)1 ODatabaseDocumentTx (com.orientechnologies.orient.core.db.document.ODatabaseDocumentTx)1 ORID (com.orientechnologies.orient.core.id.ORID)1