Search in sources :

Example 21 with OrientGraphNoTx

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

the class GraphValidationTest method testValidationOnVertices.

@Test
public void testValidationOnVertices() {
    OrientGraphNoTx g1 = new OrientGraphNoTx(URL, "admin", "admin");
    try {
        final OrientVertexType validationTestType = g1.createVertexType("ValidationTest");
        validationTestType.createEdgeProperty(Direction.OUT, "Connection").setMandatory(true);
        validationTestType.createEdgeProperty(Direction.IN, "Connection").setMandatory(true);
        final OrientEdgeType connectionType = g1.createEdgeType("Connection");
        connectionType.createProperty("in", OType.LINK, validationTestType).setMandatory(true);
        connectionType.createProperty("out", OType.LINK, validationTestType).setMandatory(true);
    } finally {
        g1.shutdown();
    }
    OrientGraph g2 = new OrientGraph(URL, "admin", "admin");
    try {
        OrientVertex vertex1 = g2.addTemporaryVertex("ValidationTest");
        OrientVertex vertex2 = g2.addTemporaryVertex("ValidationTest");
        OrientVertex vertex3 = g2.addTemporaryVertex("ValidationTest");
        OrientVertex vertex4 = g2.addTemporaryVertex("ValidationTest");
        vertex1.addEdge("Connection", vertex2);
        vertex2.addEdge("Connection", vertex3);
        vertex3.addEdge("Connection", vertex4);
        vertex4.addEdge("Connection", vertex1);
        g2.commit();
    } finally {
        g2.shutdown();
    }
}
Also used : OrientEdgeType(com.tinkerpop.blueprints.impls.orient.OrientEdgeType) 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 22 with OrientGraphNoTx

use of com.tinkerpop.blueprints.impls.orient.OrientGraphNoTx 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 23 with OrientGraphNoTx

use of com.tinkerpop.blueprints.impls.orient.OrientGraphNoTx 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)

Example 24 with OrientGraphNoTx

use of com.tinkerpop.blueprints.impls.orient.OrientGraphNoTx 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 25 with OrientGraphNoTx

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

the class TestGraphRecovering method testRecoverPerfectGraphLW.

@Test
public void testRecoverPerfectGraphLW() {
    final OrientBaseGraph g = new OrientGraphNoTx("memory:testRecoverPerfectGraphLW");
    try {
        init(g, true);
        final TestListener eventListener = new TestListener();
        new OGraphRepair().setEventListener(eventListener).repair(g, null, null);
        Assert.assertEquals(eventListener.scannedEdges, 0);
        Assert.assertEquals(eventListener.removedEdges, 0);
        Assert.assertEquals(eventListener.scannedVertices, 3);
        Assert.assertEquals(eventListener.scannedLinks, 6);
        Assert.assertEquals(eventListener.removedLinks, 0);
        Assert.assertEquals(eventListener.repairedVertices, 0);
    } finally {
        g.shutdown();
    }
}
Also used : OGraphRepair(com.tinkerpop.blueprints.impls.orient.OGraphRepair) OrientGraphNoTx(com.tinkerpop.blueprints.impls.orient.OrientGraphNoTx) OrientBaseGraph(com.tinkerpop.blueprints.impls.orient.OrientBaseGraph) Test(org.junit.Test)

Aggregations

OrientGraphNoTx (com.tinkerpop.blueprints.impls.orient.OrientGraphNoTx)72 OrientVertex (com.tinkerpop.blueprints.impls.orient.OrientVertex)28 OCommandSQL (com.orientechnologies.orient.core.sql.OCommandSQL)23 Test (org.junit.Test)22 OrientGraphFactory (com.tinkerpop.blueprints.impls.orient.OrientGraphFactory)20 ODatabaseDocumentTx (com.orientechnologies.orient.core.db.document.ODatabaseDocumentTx)17 OrientVertexType (com.tinkerpop.blueprints.impls.orient.OrientVertexType)17 ODocument (com.orientechnologies.orient.core.record.impl.ODocument)16 OrientBaseGraph (com.tinkerpop.blueprints.impls.orient.OrientBaseGraph)15 OSQLSynchQuery (com.orientechnologies.orient.core.sql.query.OSQLSynchQuery)7 Vertex (com.tinkerpop.blueprints.Vertex)6 OrientGraph (com.tinkerpop.blueprints.impls.orient.OrientGraph)6 OClass (com.orientechnologies.orient.core.metadata.schema.OClass)5 OGraphMLReader (com.orientechnologies.orient.graph.graphml.OGraphMLReader)5 OGraphRepair (com.tinkerpop.blueprints.impls.orient.OGraphRepair)5 OIdentifiable (com.orientechnologies.orient.core.db.record.OIdentifiable)4 Edge (com.tinkerpop.blueprints.Edge)4 OSchema (com.orientechnologies.orient.core.metadata.schema.OSchema)3 OrientEdge (com.tinkerpop.blueprints.impls.orient.OrientEdge)3 File (java.io.File)3