Search in sources :

Example 36 with ODatabaseDocumentTx

use of com.orientechnologies.orient.core.db.document.ODatabaseDocumentTx 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 37 with ODatabaseDocumentTx

use of com.orientechnologies.orient.core.db.document.ODatabaseDocumentTx 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 38 with ODatabaseDocumentTx

use of com.orientechnologies.orient.core.db.document.ODatabaseDocumentTx 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 39 with ODatabaseDocumentTx

use of com.orientechnologies.orient.core.db.document.ODatabaseDocumentTx 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 40 with ODatabaseDocumentTx

use of com.orientechnologies.orient.core.db.document.ODatabaseDocumentTx in project orientdb by orientechnologies.

the class OCommandExecutorSQLCreateEdgeTest method setUp.

@Before
public void setUp() throws Exception {
    db = new ODatabaseDocumentTx("memory:" + OCommandExecutorSQLCreateEdgeTest.class.getSimpleName());
    if (db.exists()) {
        db.open("admin", "admin");
        db.drop();
    }
    db.create();
    final OSchema schema = db.getMetadata().getSchema();
    schema.createClass("Owner", schema.getClass("V"));
    schema.createClass("link", schema.getClass("E"));
    owner1 = new ODocument("Owner");
    owner1.field("id", 1);
    owner1.save();
    owner2 = new ODocument("Owner");
    owner2.field("id", 2);
    owner2.save();
}
Also used : OSchema(com.orientechnologies.orient.core.metadata.schema.OSchema) ODatabaseDocumentTx(com.orientechnologies.orient.core.db.document.ODatabaseDocumentTx) ODocument(com.orientechnologies.orient.core.record.impl.ODocument) Before(org.junit.Before)

Aggregations

ODatabaseDocumentTx (com.orientechnologies.orient.core.db.document.ODatabaseDocumentTx)590 ODocument (com.orientechnologies.orient.core.record.impl.ODocument)257 Test (org.testng.annotations.Test)182 OClass (com.orientechnologies.orient.core.metadata.schema.OClass)120 ODatabaseDocument (com.orientechnologies.orient.core.db.document.ODatabaseDocument)81 Test (org.junit.Test)79 OCommandSQL (com.orientechnologies.orient.core.sql.OCommandSQL)61 OSQLSynchQuery (com.orientechnologies.orient.core.sql.query.OSQLSynchQuery)47 OSchema (com.orientechnologies.orient.core.metadata.schema.OSchema)46 OIdentifiable (com.orientechnologies.orient.core.db.record.OIdentifiable)41 ORID (com.orientechnologies.orient.core.id.ORID)39 ORecordId (com.orientechnologies.orient.core.id.ORecordId)34 Before (org.junit.Before)34 File (java.io.File)33 OProperty (com.orientechnologies.orient.core.metadata.schema.OProperty)25 ArrayList (java.util.ArrayList)25 BeforeClass (org.testng.annotations.BeforeClass)23 BeforeMethod (org.testng.annotations.BeforeMethod)23 OStorage (com.orientechnologies.orient.core.storage.OStorage)21 List (java.util.List)20