Search in sources :

Example 6 with OConsoleDatabaseApp

use of com.orientechnologies.orient.console.OConsoleDatabaseApp in project orientdb by orientechnologies.

the class OInternalGraphImporter method runImport.

public void runImport(String inputFile, String dbURL) throws IOException, FileNotFoundException {
    if (inputFile == null)
        throw new OSystemException("needed an input file as first argument");
    if (dbURL == null)
        throw new OSystemException("needed an database location as second argument");
    ODatabaseDocumentTx db = new ODatabaseDocumentTx(dbURL);
    ODatabaseHelper.deleteDatabase(db, db.getStorage().getType());
    OrientBaseGraph g = OrientGraphFactory.getNoTxGraphImplFactory().getGraph(dbURL);
    System.out.println("Importing graph from file '" + inputFile + "' into database: " + g + "...");
    final long startTime = System.currentTimeMillis();
    OConsoleDatabaseApp console = new OGremlinConsole(new String[] { "import database " + inputFile }).setCurrentDatabase(g.getRawGraph());
    console.run();
    System.out.println("Imported in " + (System.currentTimeMillis() - startTime) + "ms. Vertexes: " + g.countVertices());
    g.command(new OCommandSQL("alter database TIMEZONE 'GMT'")).execute();
    g.command(new OCommandSQL("alter database LOCALECOUNTRY 'UK'")).execute();
    g.command(new OCommandSQL("alter database LOCALELANGUAGE 'EN'")).execute();
    g.shutdown();
}
Also used : OCommandSQL(com.orientechnologies.orient.core.sql.OCommandSQL) OSystemException(com.orientechnologies.common.exception.OSystemException) ODatabaseDocumentTx(com.orientechnologies.orient.core.db.document.ODatabaseDocumentTx) OrientBaseGraph(com.tinkerpop.blueprints.impls.orient.OrientBaseGraph) OConsoleDatabaseApp(com.orientechnologies.orient.console.OConsoleDatabaseApp)

Example 7 with OConsoleDatabaseApp

use of com.orientechnologies.orient.console.OConsoleDatabaseApp in project orientdb by orientechnologies.

the class OConsoleDatatabaseAppTest method testSelectBinaryDoc.

@Test
public void testSelectBinaryDoc() throws IOException {
    final StringBuilder builder = new StringBuilder();
    OConsoleDatabaseApp app = new OConsoleDatabaseApp(new String[] {}) {

        @Override
        public void message(String iMessage, Object... iArgs) {
            builder.append(String.format(iMessage, iArgs)).append("\n");
        }
    };
    app.createDatabase("memory:test", null, null, "memory", null, null);
    ODatabaseDocument db = app.getCurrentDatabase();
    db.addBlobCluster("blobTest");
    ORecord record = db.save(new ORecordBytes("blobContent".getBytes()), "blobTest");
    builder.setLength(0);
    app.select(" from " + record.getIdentity() + " limit -1 ");
    assertTrue(builder.toString().contains("<binary>"));
}
Also used : ODatabaseDocument(com.orientechnologies.orient.core.db.document.ODatabaseDocument) ORecord(com.orientechnologies.orient.core.record.ORecord) ORecordBytes(com.orientechnologies.orient.core.record.impl.ORecordBytes) OConsoleDatabaseApp(com.orientechnologies.orient.console.OConsoleDatabaseApp) Test(org.junit.Test)

Example 8 with OConsoleDatabaseApp

use of com.orientechnologies.orient.console.OConsoleDatabaseApp in project orientdb by orientechnologies.

the class OConsoleDatabaseAppTest method testDisplayRawRecord.

@Test
public void testDisplayRawRecord() {
    String dbUrl = "memory:OConsoleDatabaseAppTestDisplayRawRecord";
    // builder.append("display raw record " + rid);
    // OConsoleDatabaseApp console = new OConsoleDatabaseApp(new String[] { builder.toString() });
    OConsoleDatabaseApp console = new OConsoleDatabaseApp(null);
    ByteArrayOutputStream out = new ByteArrayOutputStream();
    PrintStream stream = new PrintStream(out);
    console.setOutput(stream);
    try {
        console.createDatabase(dbUrl, null, null, null, null, null);
        console.createClass("class foo");
        console.insert("into foo set name = 'barbar'");
        byte[] result = out.toByteArray();
        out.close();
        stream.close();
        out = new ByteArrayOutputStream();
        stream = new PrintStream(out);
        console.setOutput(stream);
        String resultString = new String(result);
        String rid = resultString.substring(resultString.indexOf("#"), resultString.indexOf("#") + 5).trim();
        console.set("maxBinaryDisplay", "10000");
        console.displayRawRecord(rid);
        result = out.toByteArray();
        resultString = new String(result);
        Assert.assertTrue(resultString.contains("Raw record content."));
        if ("ORecordSerializerBinary".equals(((ODatabaseDocumentTx) console.getCurrentDatabase()).getSerializer().toString())) {
            Assert.assertTrue(resultString.contains("class name: foo"));
            Assert.assertTrue(resultString.contains("property value: barbar"));
        }
    } catch (IOException e) {
        Assert.fail();
    } finally {
        try {
            out.close();
        } catch (Exception e) {
            e.printStackTrace();
        }
        try {
            stream.close();
        } catch (Exception e) {
            e.printStackTrace();
        }
        console.close();
    }
}
Also used : PrintStream(java.io.PrintStream) ODatabaseDocumentTx(com.orientechnologies.orient.core.db.document.ODatabaseDocumentTx) ByteArrayOutputStream(java.io.ByteArrayOutputStream) IOException(java.io.IOException) OConsoleDatabaseApp(com.orientechnologies.orient.console.OConsoleDatabaseApp) IOException(java.io.IOException) Test(org.junit.Test)

Example 9 with OConsoleDatabaseApp

use of com.orientechnologies.orient.console.OConsoleDatabaseApp in project orientdb by orientechnologies.

the class OGremlinConsoleTest method testGremlin.

@Test
public void testGremlin() {
    final String INPUT_FILE = "src/test/resources/graph-example-2.xml";
    String dbUrl = "memory:testGremlin";
    StringBuilder builder = new StringBuilder();
    builder.append("create database " + dbUrl + ";\n");
    builder.append("import database " + INPUT_FILE + " batchSize=10;\n");
    builder.append("gremlin g.V;\n");
    OConsoleDatabaseApp console = new TestOGremlinConsole(new String[] { builder.toString() });
    try {
        console.run();
        ODatabaseDocumentTx db = new ODatabaseDocumentTx(dbUrl);
        db.open("admin", "admin");
        try {
            long totalVertices = db.countClass("V");
            Assert.assertTrue(totalVertices > 0);
            long totalEdges = db.countClass("E");
            Assert.assertTrue(totalEdges > 0);
        } finally {
            db.close();
        }
    } finally {
        console.close();
    }
}
Also used : ODatabaseDocumentTx(com.orientechnologies.orient.core.db.document.ODatabaseDocumentTx) OConsoleDatabaseApp(com.orientechnologies.orient.console.OConsoleDatabaseApp) Test(org.junit.Test)

Example 10 with OConsoleDatabaseApp

use of com.orientechnologies.orient.console.OConsoleDatabaseApp in project orientdb by orientechnologies.

the class OGremlinConsoleTest method testGraphMLExport.

@Test
public void testGraphMLExport() {
    final String INPUT_FILE = "src/test/resources/graph-example-2.xml";
    final String OUTPUT_FILE = "target/test/resources/graph-example-2.xml";
    String dbUrl = "memory:testGraphMLExport";
    StringBuilder builder = new StringBuilder();
    builder.append("create database " + dbUrl + ";\n");
    builder.append("import database " + INPUT_FILE + ";\n");
    builder.append("export database " + OUTPUT_FILE + ";\n");
    OConsoleDatabaseApp console = new TestOGremlinConsole(new String[] { builder.toString() });
    try {
        console.run();
        final File f = new File(OUTPUT_FILE);
        Assert.assertTrue(f.exists());
        Assert.assertTrue(f.length() > 0);
    } finally {
        console.close();
    }
}
Also used : OConsoleDatabaseApp(com.orientechnologies.orient.console.OConsoleDatabaseApp) Test(org.junit.Test)

Aggregations

OConsoleDatabaseApp (com.orientechnologies.orient.console.OConsoleDatabaseApp)11 Test (org.junit.Test)9 ODatabaseDocumentTx (com.orientechnologies.orient.core.db.document.ODatabaseDocumentTx)8 ODocument (com.orientechnologies.orient.core.record.impl.ODocument)5 OSQLSynchQuery (com.orientechnologies.orient.core.sql.query.OSQLSynchQuery)2 IOException (java.io.IOException)2 TTYConsoleReader (com.orientechnologies.common.console.TTYConsoleReader)1 OSystemException (com.orientechnologies.common.exception.OSystemException)1 OCommandExecutorNotFoundException (com.orientechnologies.orient.core.command.OCommandExecutorNotFoundException)1 ODatabaseDocument (com.orientechnologies.orient.core.db.document.ODatabaseDocument)1 ODatabaseImportException (com.orientechnologies.orient.core.db.tool.ODatabaseImportException)1 OStorageException (com.orientechnologies.orient.core.exception.OStorageException)1 ORecord (com.orientechnologies.orient.core.record.ORecord)1 ORecordBytes (com.orientechnologies.orient.core.record.impl.ORecordBytes)1 OCommandSQL (com.orientechnologies.orient.core.sql.OCommandSQL)1 Vertex (com.tinkerpop.blueprints.Vertex)1 OrientBaseGraph (com.tinkerpop.blueprints.impls.orient.OrientBaseGraph)1 OrientGraph (com.tinkerpop.blueprints.impls.orient.OrientGraph)1 ByteArrayOutputStream (java.io.ByteArrayOutputStream)1 PrintStream (java.io.PrintStream)1