Search in sources :

Example 1 with OConsoleDatabaseApp

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

the class OGremlinConsole method main.

public static void main(final String[] args) {
    int result;
    try {
        boolean tty = false;
        try {
            if (setTerminalToCBreak())
                tty = true;
        } catch (Exception e) {
        }
        final OConsoleDatabaseApp console = new OGremlinConsole(args);
        if (tty)
            console.setReader(new TTYConsoleReader());
        result = console.run();
    } finally {
        try {
            stty("echo");
        } catch (Exception e) {
        }
    }
    System.exit(result);
}
Also used : TTYConsoleReader(com.orientechnologies.common.console.TTYConsoleReader) OConsoleDatabaseApp(com.orientechnologies.orient.console.OConsoleDatabaseApp) OStorageException(com.orientechnologies.orient.core.exception.OStorageException) ODatabaseImportException(com.orientechnologies.orient.core.db.tool.ODatabaseImportException) IOException(java.io.IOException) OCommandExecutorNotFoundException(com.orientechnologies.orient.core.command.OCommandExecutorNotFoundException)

Example 2 with OConsoleDatabaseApp

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

the class OConsoleDatabaseAppTest method testWrongCommand.

@Test
public void testWrongCommand() {
    String dbUrl = "memory:OConsoleDatabaseAppTest2";
    StringBuilder builder = new StringBuilder();
    builder.append("create database " + dbUrl + ";\n");
    builder.append("create class foo;\n");
    builder.append("insert into foo set name = 'foo';\n");
    builder.append("insert into foo set name = 'bla';\n");
    // <- wrong command, this should break the console
    builder.append("blabla;\n");
    builder.append("update foo set surname = 'bar' where name = 'foo';\n");
    ConsoleTest c = new ConsoleTest(new String[] { builder.toString() });
    OConsoleDatabaseApp console = c.console();
    try {
        console.run();
        ODatabaseDocumentTx db = new ODatabaseDocumentTx(dbUrl);
        db.open("admin", "admin");
        try {
            List<ODocument> result = db.query(new OSQLSynchQuery<ODocument>("select from foo where name = 'foo'"));
            Assert.assertEquals(1, result.size());
            ODocument doc = result.get(0);
            Assert.assertNull(doc.field("surname"));
        } finally {
            db.close();
        }
    } finally {
        console.close();
    }
}
Also used : ODatabaseDocumentTx(com.orientechnologies.orient.core.db.document.ODatabaseDocumentTx) OConsoleDatabaseApp(com.orientechnologies.orient.console.OConsoleDatabaseApp) ODocument(com.orientechnologies.orient.core.record.impl.ODocument) Test(org.junit.Test)

Example 3 with OConsoleDatabaseApp

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

the class OConsoleDatabaseAppTest method testSimple.

@Test
public void testSimple() {
    String dbUrl = "memory:OConsoleDatabaseAppTest";
    StringBuilder builder = new StringBuilder();
    builder.append("create database " + dbUrl + ";\n");
    builder.append("profile storage on;\n");
    builder.append("create class foo;\n");
    builder.append("config;\n");
    builder.append("list classes;\n");
    builder.append("list properties;\n");
    builder.append("list clusters;\n");
    builder.append("list indexes;\n");
    builder.append("info class OUser;\n");
    builder.append("info property OUser.name;\n");
    builder.append("begin;\n");
    builder.append("insert into foo set name = 'foo';\n");
    builder.append("insert into foo set name = 'bla';\n");
    builder.append("update foo set surname = 'bar' where name = 'foo';\n");
    builder.append("commit;\n");
    builder.append("select from foo;\n");
    builder.append("create class bar;\n");
    builder.append("create property bar.name STRING;\n");
    builder.append("create index bar_name on bar (name) NOTUNIQUE;\n");
    builder.append("insert into bar set name = 'foo';\n");
    builder.append("delete from bar;\n");
    builder.append("begin;\n");
    builder.append("insert into bar set name = 'foo';\n");
    builder.append("rollback;\n");
    builder.append("create vertex V set name = 'foo';\n");
    builder.append("create vertex V set name = 'bar';\n");
    builder.append("traverse out() from V;\n");
    builder.append("create edge from (select from V where name = 'foo') to (select from V where name = 'bar');\n");
    builder.append("traverse out() from V;\n");
    //    builder.append("create user TestUser identified by password ROLE ['reader','writer'];\n");
    builder.append("drop user TestUser;\n");
    builder.append("profile storage off;\n");
    builder.append("repair database -v;\n");
    ConsoleTest c = new ConsoleTest(new String[] { builder.toString() });
    OConsoleDatabaseApp console = c.console();
    try {
        console.run();
        ODatabaseDocumentTx db = new ODatabaseDocumentTx(dbUrl);
        db.open("admin", "admin");
        try {
            List<ODocument> result = db.query(new OSQLSynchQuery<ODocument>("select from foo where name = 'foo'"));
            Assert.assertEquals(1, result.size());
            ODocument doc = result.get(0);
            Assert.assertEquals("bar", doc.field("surname"));
            result = db.query(new OSQLSynchQuery<ODocument>("select from bar"));
            Assert.assertEquals(0, result.size());
        } finally {
            db.close();
        }
        OrientGraph graph = new OrientGraph(dbUrl);
        try {
            Iterable<Vertex> result = graph.command(new OSQLSynchQuery<Vertex>("select expand(out()) from (select from V where name = 'foo')")).execute();
            Iterator<Vertex> iterator = result.iterator();
            Assert.assertTrue(iterator.hasNext());
            Vertex next = iterator.next();
            Assert.assertEquals("bar", next.getProperty("name"));
            Assert.assertFalse(iterator.hasNext());
        } finally {
            graph.shutdown();
        }
    } finally {
        console.close();
    }
}
Also used : Vertex(com.tinkerpop.blueprints.Vertex) OrientGraph(com.tinkerpop.blueprints.impls.orient.OrientGraph) OSQLSynchQuery(com.orientechnologies.orient.core.sql.query.OSQLSynchQuery) ODatabaseDocumentTx(com.orientechnologies.orient.core.db.document.ODatabaseDocumentTx) OConsoleDatabaseApp(com.orientechnologies.orient.console.OConsoleDatabaseApp) ODocument(com.orientechnologies.orient.core.record.impl.ODocument) Test(org.junit.Test)

Example 4 with OConsoleDatabaseApp

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

the class OGremlinConsoleTest method testGraphMLImportWithSmallBatch.

@Test
public void testGraphMLImportWithSmallBatch() {
    final String INPUT_FILE = "src/test/resources/graph-example-2.xml";
    String dbUrl = "memory:testGraphMLImportWithSmallBatch";
    StringBuilder builder = new StringBuilder();
    builder.append("create database " + dbUrl + ";\n");
    builder.append("import database " + INPUT_FILE + " batchSize=10;\n");
    OConsoleDatabaseApp console = new TestOGremlinConsole(new String[] { builder.toString() });
    try {
        console.run();
        ODatabaseDocumentTx db = new ODatabaseDocumentTx(dbUrl);
        db.open("admin", "admin");
        try {
            List<ODocument> result = db.query(new OSQLSynchQuery<ODocument>("select from V"));
            Assert.assertFalse(result.isEmpty());
        } finally {
            db.close();
        }
    } finally {
        console.close();
    }
}
Also used : ODatabaseDocumentTx(com.orientechnologies.orient.core.db.document.ODatabaseDocumentTx) OConsoleDatabaseApp(com.orientechnologies.orient.console.OConsoleDatabaseApp) ODocument(com.orientechnologies.orient.core.record.impl.ODocument) Test(org.junit.Test)

Example 5 with OConsoleDatabaseApp

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

the class OGremlinConsoleTest method testMoveVertexCommand.

@Test
public void testMoveVertexCommand() {
    final String INPUT_FILE = "src/test/resources/graph-example-2.xml";
    String dbUrl = "memory:testMoveVertexCommand";
    StringBuilder builder = new StringBuilder();
    builder.append("create database " + dbUrl + ";\n");
    builder.append("import database " + INPUT_FILE + " batchSize=10;\n");
    builder.append("create class newposition extends V;\n");
    builder.append("move vertex (select from V) to class:newposition;\n");
    OConsoleDatabaseApp console = new TestOGremlinConsole(new String[] { builder.toString() });
    try {
        console.run();
        ODatabaseDocumentTx db = new ODatabaseDocumentTx(dbUrl);
        db.open("admin", "admin");
        try {
            List<ODocument> result = db.query(new OSQLSynchQuery<ODocument>("select from newposition"));
            Assert.assertFalse(result.isEmpty());
        } finally {
            db.close();
        }
    } finally {
        console.close();
    }
}
Also used : ODatabaseDocumentTx(com.orientechnologies.orient.core.db.document.ODatabaseDocumentTx) OConsoleDatabaseApp(com.orientechnologies.orient.console.OConsoleDatabaseApp) ODocument(com.orientechnologies.orient.core.record.impl.ODocument) 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