Search in sources :

Example 51 with OrientGraph

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

the class TestAsyncReplMode2ServersAddEdge method dbClient1.

protected void dbClient1() {
    OGlobalConfiguration.LOG_CONSOLE_LEVEL.setValue("FINEST");
    synchronized (LOCK) {
        OrientBaseGraph graph = new OrientGraph(getLocalURL());
        try {
            OrientVertex parentV1 = graph.addVertex("vertextype", (String) null);
            graph.commit();
            assertEquals(1, parentV1.getRecord().getVersion());
            parentV1Id = parentV1.getId();
            for (int i = 0; i < NUM_OF_LOOP_ITERATIONS; i++) {
                Vertex childV = graph.addVertex("vertextype", (String) null);
                graph.commit();
                assertEquals(1, ((OrientVertex) childV).getRecord().getVersion());
                parentV1.addEdge("edgetype", childV);
                graph.commit();
                OLogManager.instance().error(this, "parentV1 %s v%d should be v%d", parentV1.getIdentity(), parentV1.getRecord().getVersion(), i + 2);
                assertEquals(i + 2, ((OrientVertex) parentV1).getRecord().getVersion());
                assertEquals(2, ((OrientVertex) childV).getRecord().getVersion());
            }
            pause();
        } catch (Throwable e) {
            OLogManager.instance().error(this, "Exception", e);
            if (exceptionInThread == null) {
                exceptionInThread = e;
            }
        } finally {
            System.out.println("Shutting down");
            graph.shutdown();
            LOCK.notifyAll();
        }
    }
}
Also used : OrientVertex(com.tinkerpop.blueprints.impls.orient.OrientVertex) Vertex(com.tinkerpop.blueprints.Vertex) OrientGraph(com.tinkerpop.blueprints.impls.orient.OrientGraph) OrientVertex(com.tinkerpop.blueprints.impls.orient.OrientVertex) OrientBaseGraph(com.tinkerpop.blueprints.impls.orient.OrientBaseGraph)

Example 52 with OrientGraph

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

the class OGremlinConsole method importDatabase.

@Override
@ConsoleCommand(description = "Import a database into the current one", splitInWords = false)
public void importDatabase(@ConsoleParameter(name = "options", description = "Import options") String text) throws IOException {
    checkForDatabase();
    final List<String> items = OStringSerializerHelper.smartSplit(text, ' ');
    final String fileName = items.size() <= 0 || (items.get(1)).charAt(0) == '-' ? null : items.get(1);
    final String optionsAsString = fileName != null ? text.substring((items.get(0)).length() + (items.get(1)).length() + 1).trim() : text;
    final Map<String, List<String>> options = parseOptions(optionsAsString);
    final String format = options.containsKey("-format") ? options.get("-format").get(0) : null;
    if ((format != null && format.equalsIgnoreCase("graphml")) || (fileName != null && (fileName.endsWith(".graphml") || fileName.endsWith(".xml")))) {
        // GRAPHML
        message("\nImporting GRAPHML database from " + fileName + " with options (" + optionsAsString + ")...");
        try {
            final OrientGraph g = (OrientGraph) OrientGraphFactory.getTxGraphImplFactory().getGraph(currentDatabase);
            g.setUseLog(false);
            g.setWarnOnForceClosingTx(false);
            final long totalEdges = g.countEdges();
            final long totalVertices = g.countVertices();
            final File file = new File(fileName);
            if (!file.exists())
                throw new ODatabaseImportException("Input file '" + fileName + "' not exists");
            InputStream is = new FileInputStream(file);
            if (fileName.endsWith(".zip"))
                is = new ZipInputStream(is);
            else if (fileName.endsWith(".gz"))
                is = new GZIPInputStream(is);
            try {
                new OGraphMLReader(g).setOptions(options).setOutput(new OCommandOutputListener() {

                    @Override
                    public void onMessage(final String iText) {
                        System.out.print("\r" + iText);
                    }
                }).inputGraph(is);
                g.commit();
                currentDatabase.commit();
                message("\nDone: imported %d vertices and %d edges", g.countVertices() - totalVertices, g.countEdges() - totalEdges);
            } finally {
                is.close();
            }
        } catch (ODatabaseImportException e) {
            printError(e);
        }
    } else if ((format != null && format.equalsIgnoreCase("graphson")) || (fileName != null && (fileName.endsWith(".graphson")))) {
        // GRAPHSON
        message("\nImporting GRAPHSON database from " + fileName + " with options (" + optionsAsString + ")...");
        try {
            final OrientGraph g = (OrientGraph) OrientGraphFactory.getTxGraphImplFactory().getGraph(currentDatabase);
            g.setUseLog(false);
            g.setWarnOnForceClosingTx(false);
            final long totalEdges = g.countEdges();
            final long totalVertices = g.countVertices();
            final File file = new File(fileName);
            if (!file.exists())
                throw new ODatabaseImportException("Input file '" + fileName + "' not exists");
            InputStream is = new FileInputStream(file);
            if (fileName.endsWith(".zip")) {
                is = new ZipInputStream(is);
            } else if (fileName.endsWith(".gz")) {
                is = new GZIPInputStream(is);
            }
            try {
                new OGraphSONReader(g).setOutput(new OCommandOutputListener() {

                    @Override
                    public void onMessage(final String iText) {
                        System.out.print("\r" + iText);
                    }
                }).inputGraph(is, 10000);
                // new OGraphMLReader(g).setOptions(options).inputGraph(g, fileName);
                g.commit();
                currentDatabase.commit();
                message("\nDone: imported %d vertices and %d edges", g.countVertices() - totalVertices, g.countEdges() - totalEdges);
            } finally {
                is.close();
            }
        } catch (ODatabaseImportException e) {
            printError(e);
        }
    } else if (format == null)
        super.importDatabase(text);
    else
        throw new IllegalArgumentException("Format '" + format + "' is not supported");
}
Also used : OrientGraph(com.tinkerpop.blueprints.impls.orient.OrientGraph) GZIPInputStream(java.util.zip.GZIPInputStream) ZipInputStream(java.util.zip.ZipInputStream) FileInputStream(java.io.FileInputStream) InputStream(java.io.InputStream) ODatabaseImportException(com.orientechnologies.orient.core.db.tool.ODatabaseImportException) FileInputStream(java.io.FileInputStream) GZIPInputStream(java.util.zip.GZIPInputStream) ZipInputStream(java.util.zip.ZipInputStream) OGraphSONReader(com.orientechnologies.orient.graph.graphml.OGraphSONReader) OGraphMLReader(com.orientechnologies.orient.graph.graphml.OGraphMLReader) List(java.util.List) File(java.io.File) OCommandOutputListener(com.orientechnologies.orient.core.command.OCommandOutputListener) ConsoleCommand(com.orientechnologies.common.console.annotation.ConsoleCommand)

Example 53 with OrientGraph

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

the class OETLBaseTest method setUp.

@Before
public void setUp() {
    graph = new OrientGraph("memory:OETLBaseTest");
    graph.setUseLightweightEdges(false);
    proc = new OETLProcessor();
    proc.getFactory().registerLoader(OETLStubLoader.class);
}
Also used : OrientGraph(com.tinkerpop.blueprints.impls.orient.OrientGraph) Before(org.junit.Before)

Example 54 with OrientGraph

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

the class OMergeTransformerTest method shouldUpdateExistingVertices.

@Test
public void shouldUpdateExistingVertices() throws Exception {
    //prepare graph
    graph.addVertex("class:Person", "num", 10000, "name", "FirstName");
    graph.commit();
    assertThat(graph.countVertices("Person")).isEqualTo(1);
    Iterable<Vertex> vertices = graph.getVertices("Person.num", 10000);
    assertThat(vertices).hasSize(1);
    final Vertex inserted = vertices.iterator().next();
    assertThat(inserted.getProperty("name")).isEqualTo("FirstName");
    assertThat(inserted.getProperty("num")).isEqualTo(10000);
    //update graph with CSV: avoid num to be casted to integer forcing string
    process(" {source: { content: { value: 'num,name\n10000,FirstNameUpdated' } }, " + "extractor : { csv: {} }," + " transformers: [" + "{merge: {  joinFieldName:'num', lookup:'Person.num'}}, " + "{vertex: { class:'Person', skipDuplicates: false}}" + "]," + "loader: { orientdb: { dbURL: 'memory:OETLBaseTest', dbType:'graph', tx: true} } }");
    //verify
    graph = new OrientGraph("memory:OETLBaseTest");
    assertThat(graph.countVertices("Person")).isEqualTo(1);
    vertices = graph.getVertices("Person.num", 10000);
    assertThat(vertices).hasSize(1);
    final Vertex updated = vertices.iterator().next();
    ORecord load = graph.getRawGraph().load((ORID) updated.getId());
    assertThat(updated.getProperty("name")).isEqualTo("FirstNameUpdated");
    assertThat(updated.getProperty("num")).isEqualTo(10000);
}
Also used : Vertex(com.tinkerpop.blueprints.Vertex) OrientGraph(com.tinkerpop.blueprints.impls.orient.OrientGraph) ORecord(com.orientechnologies.orient.core.record.ORecord) OETLBaseTest(com.orientechnologies.orient.etl.OETLBaseTest) Test(org.junit.Test)

Example 55 with OrientGraph

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

the class DirtyManagerGraph method testLoopOfNew.

@Test
public void testLoopOfNew() {
    OrientGraph graph = new OrientGraph("memory:" + DirtyManagerGraph.class.getSimpleName());
    try {
        graph.createEdgeType("next");
        OrientVertex vertex = graph.addVertex(null);
        OrientVertex vertex1 = graph.addVertex(null);
        OrientVertex vertex2 = graph.addVertex(null);
        OrientVertex vertex3 = graph.addVertex(null);
        OrientEdge edge1 = (OrientEdge) vertex.addEdge("next", vertex1);
        OrientEdge edge2 = (OrientEdge) vertex1.addEdge("next", vertex2);
        OrientEdge edge3 = (OrientEdge) vertex2.addEdge("next", vertex3);
        OrientEdge edge4 = (OrientEdge) vertex3.addEdge("next", vertex);
        ODocument rec = vertex.getRecord();
        ODirtyManager manager = ORecordInternal.getDirtyManager(rec);
        List<OIdentifiable> pointed = manager.getPointed(vertex.getRecord());
        assertEquals(2, pointed.size());
        assertTrue(pointed.contains(edge1.getRecord()));
        assertTrue(pointed.contains(edge4.getRecord()));
        pointed = manager.getPointed(vertex1.getRecord());
        assertEquals(2, pointed.size());
        assertTrue(pointed.contains(edge1.getRecord()));
        assertTrue(pointed.contains(edge2.getRecord()));
        pointed = manager.getPointed(vertex2.getRecord());
        assertEquals(2, pointed.size());
        assertTrue(pointed.contains(edge2.getRecord()));
        assertTrue(pointed.contains(edge3.getRecord()));
        pointed = manager.getPointed(vertex3.getRecord());
        assertEquals(2, pointed.size());
        assertTrue(pointed.contains(edge3.getRecord()));
        assertTrue(pointed.contains(edge4.getRecord()));
        pointed = manager.getPointed(edge1.getRecord());
        assertEquals(2, pointed.size());
        assertTrue(pointed.contains(vertex.getRecord()));
        assertTrue(pointed.contains(vertex1.getRecord()));
        pointed = manager.getPointed(edge2.getRecord());
        assertEquals(2, pointed.size());
        assertTrue(pointed.contains(vertex1.getRecord()));
        assertTrue(pointed.contains(vertex2.getRecord()));
        pointed = manager.getPointed(edge3.getRecord());
        assertEquals(2, pointed.size());
        assertTrue(pointed.contains(vertex2.getRecord()));
        assertTrue(pointed.contains(vertex3.getRecord()));
        pointed = manager.getPointed(edge4.getRecord());
        assertEquals(2, pointed.size());
        assertTrue(pointed.contains(vertex3.getRecord()));
        assertTrue(pointed.contains(vertex.getRecord()));
    } finally {
        graph.drop();
    }
}
Also used : OrientGraph(com.tinkerpop.blueprints.impls.orient.OrientGraph) ODirtyManager(com.orientechnologies.orient.core.record.impl.ODirtyManager) OrientVertex(com.tinkerpop.blueprints.impls.orient.OrientVertex) OIdentifiable(com.orientechnologies.orient.core.db.record.OIdentifiable) OrientEdge(com.tinkerpop.blueprints.impls.orient.OrientEdge) ODocument(com.orientechnologies.orient.core.record.impl.ODocument) Test(org.junit.Test)

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