Search in sources :

Example 16 with OrientGraphNoTx

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

the class OGremlinConsoleTest method testGraphMLImportIgnoreEAttribute.

@Test
public void testGraphMLImportIgnoreEAttribute() throws IOException {
    final String INPUT_FILE = "src/test/resources/graph-example-fromexport.xml";
    String dbUrl = "memory:testGraphMLImportIgnoreEAttribute";
    new OGraphMLReader(new OrientGraphNoTx(dbUrl)).defineEdgeAttributeStrategy("friend", new OIgnoreGraphMLImportStrategy()).inputGraph(INPUT_FILE);
    ODatabaseDocumentTx db = new ODatabaseDocumentTx(dbUrl);
    db.open("admin", "admin");
    try {
        List<ODocument> result = db.query(new OSQLSynchQuery<ODocument>("select from E"));
        Assert.assertFalse(result.isEmpty());
        for (ODocument d : result) {
            Assert.assertFalse(d.containsField("friend"));
        }
    } finally {
        db.close();
    }
}
Also used : OIgnoreGraphMLImportStrategy(com.orientechnologies.orient.graph.graphml.OIgnoreGraphMLImportStrategy) OGraphMLReader(com.orientechnologies.orient.graph.graphml.OGraphMLReader) ODatabaseDocumentTx(com.orientechnologies.orient.core.db.document.ODatabaseDocumentTx) OrientGraphNoTx(com.tinkerpop.blueprints.impls.orient.OrientGraphNoTx) ODocument(com.orientechnologies.orient.core.record.impl.ODocument) Test(org.junit.Test)

Example 17 with OrientGraphNoTx

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

the class OGremlinConsoleTest method testGraphMLImportRenameVAttribute.

@Test
public void testGraphMLImportRenameVAttribute() throws IOException {
    final String INPUT_FILE = "src/test/resources/graph-example-fromexport.xml";
    String dbUrl = "memory:testGraphMLImportRenameVAttribute";
    final OrientGraphNoTx graph = new OrientGraphNoTx(dbUrl);
    try {
        new OGraphMLReader(graph).defineVertexAttributeStrategy("__type__", new ORenameGraphMLImportStrategy("t")).inputGraph(INPUT_FILE);
        ODatabaseDocumentTx db = new ODatabaseDocumentTx(dbUrl);
        db.open("admin", "admin");
        try {
            List<ODocument> result = db.query(new OSQLSynchQuery<ODocument>("select from Person"));
            Assert.assertFalse(result.isEmpty());
            for (ODocument d : result) {
                Assert.assertTrue(d.containsField("t"));
                Assert.assertFalse(d.containsField("__type__"));
            }
        } finally {
            db.close();
        }
    } finally {
        graph.shutdown();
    }
}
Also used : ORenameGraphMLImportStrategy(com.orientechnologies.orient.graph.graphml.ORenameGraphMLImportStrategy) OGraphMLReader(com.orientechnologies.orient.graph.graphml.OGraphMLReader) ODatabaseDocumentTx(com.orientechnologies.orient.core.db.document.ODatabaseDocumentTx) OrientGraphNoTx(com.tinkerpop.blueprints.impls.orient.OrientGraphNoTx) ODocument(com.orientechnologies.orient.core.record.impl.ODocument) Test(org.junit.Test)

Example 18 with OrientGraphNoTx

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

the class OGremlinConsoleTest method testGraphMLImportDirect.

@Test
public void testGraphMLImportDirect() throws IOException {
    final String INPUT_FILE = "src/test/resources/graph-example-fromexport.xml";
    String dbUrl = "memory:testGraphMLImportDirect";
    new OGraphMLReader(new OrientGraphNoTx(dbUrl)).inputGraph(INPUT_FILE);
    ODatabaseDocumentTx db = new ODatabaseDocumentTx(dbUrl);
    db.open("admin", "admin");
    try {
        boolean foundTypeVAttr = false;
        boolean foundFriendEAttr = false;
        List<ODocument> result = db.query(new OSQLSynchQuery<ODocument>("select from V"));
        Assert.assertFalse(result.isEmpty());
        for (ODocument d : result) {
            if (d.containsField("__type__"))
                foundTypeVAttr = true;
        }
        Assert.assertTrue(foundTypeVAttr);
        result = db.query(new OSQLSynchQuery<ODocument>("select from E"));
        Assert.assertFalse(result.isEmpty());
        for (ODocument d : result) {
            if (d.containsField("friend"))
                foundFriendEAttr = true;
        }
        Assert.assertTrue(foundFriendEAttr);
    } finally {
        db.close();
    }
}
Also used : OSQLSynchQuery(com.orientechnologies.orient.core.sql.query.OSQLSynchQuery) OGraphMLReader(com.orientechnologies.orient.graph.graphml.OGraphMLReader) ODatabaseDocumentTx(com.orientechnologies.orient.core.db.document.ODatabaseDocumentTx) OrientGraphNoTx(com.tinkerpop.blueprints.impls.orient.OrientGraphNoTx) ODocument(com.orientechnologies.orient.core.record.impl.ODocument) Test(org.junit.Test)

Example 19 with OrientGraphNoTx

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

the class OGremlinConsoleTest method testGraphSONImport.

@Test
public void testGraphSONImport() throws IOException {
    final String INPUT_FILE = "src/test/resources/graph-example-fromexport.xml";
    String dbUrl1 = "memory:testGraphSONImport1";
    String dbUrl2 = "memory:testGraphSONImport2";
    final OrientGraphNoTx g1 = new OrientGraphNoTx(dbUrl1);
    new OGraphMLReader(g1).inputGraph(INPUT_FILE);
    // EXPORT IN GRAPHSON FORMAT
    final ByteArrayOutputStream output = new ByteArrayOutputStream();
    new GraphSONWriter(g1).outputGraph(output, null, null, GraphSONMode.NORMAL);
    final OrientGraphNoTx g2 = new OrientGraphNoTx(dbUrl2);
    ByteArrayInputStream is = new ByteArrayInputStream(output.toByteArray());
    new OGraphSONReader(g2).inputGraph(is);
    ODatabaseDocumentTx db = new ODatabaseDocumentTx(dbUrl2);
    db.open("admin", "admin");
    try {
        boolean foundTypeVAttr = false;
        boolean foundFriendEAttr = false;
        List<ODocument> result = db.query(new OSQLSynchQuery<ODocument>("select from V"));
        Assert.assertFalse(result.isEmpty());
        for (ODocument d : result) {
            if (d.containsField("__type__"))
                foundTypeVAttr = true;
        }
        Assert.assertTrue(foundTypeVAttr);
        result = db.query(new OSQLSynchQuery<ODocument>("select from E"));
        Assert.assertFalse(result.isEmpty());
        for (ODocument d : result) {
            if (d.containsField("friend"))
                foundFriendEAttr = true;
        }
        Assert.assertTrue(foundFriendEAttr);
    } finally {
        db.close();
    }
}
Also used : GraphSONWriter(com.tinkerpop.blueprints.util.io.graphson.GraphSONWriter) OSQLSynchQuery(com.orientechnologies.orient.core.sql.query.OSQLSynchQuery) ODatabaseDocumentTx(com.orientechnologies.orient.core.db.document.ODatabaseDocumentTx) OGraphSONReader(com.orientechnologies.orient.graph.graphml.OGraphSONReader) OGraphMLReader(com.orientechnologies.orient.graph.graphml.OGraphMLReader) OrientGraphNoTx(com.tinkerpop.blueprints.impls.orient.OrientGraphNoTx) ODocument(com.orientechnologies.orient.core.record.impl.ODocument) Test(org.junit.Test)

Example 20 with OrientGraphNoTx

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

the class GraphValidationTest method edgesCannotBeVertices.

@Test
public void edgesCannotBeVertices() {
    OrientGraphNoTx gNoTx = new OrientGraphNoTx(URL, "admin", "admin");
    try {
        gNoTx.createVertexType("TestV");
        gNoTx.createEdgeType("TestE");
        OrientVertex v = gNoTx.addVertex("class:TestV");
        OrientVertex loadedV = gNoTx.getVertex(v.getIdentity());
        try {
            OrientEdge e = gNoTx.getEdge(v.getIdentity().toString());
            Assert.fail();
        } catch (IllegalArgumentException e) {
        // OK
        }
    } finally {
        gNoTx.shutdown();
    }
    OrientGraph g = new OrientGraph(URL, "admin", "admin");
    try {
        OrientVertex v = g.addVertex("class:TestV");
        OrientVertex loadedV = g.getVertex(v.getIdentity().toString());
        try {
            OrientEdge e = g.getEdge(v.getIdentity());
            Assert.fail();
        } catch (IllegalArgumentException e) {
        // OK
        }
    } finally {
        g.shutdown();
    }
}
Also used : OrientGraph(com.tinkerpop.blueprints.impls.orient.OrientGraph) OrientGraphNoTx(com.tinkerpop.blueprints.impls.orient.OrientGraphNoTx) OrientVertex(com.tinkerpop.blueprints.impls.orient.OrientVertex) OrientEdge(com.tinkerpop.blueprints.impls.orient.OrientEdge) 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