Search in sources :

Example 61 with ODocument

use of com.orientechnologies.orient.core.record.impl.ODocument in project orientdb by orientechnologies.

the class TestGraphTransactionOnBatch method testReferToNotExistingVertex.

/**
   * This test is different from the original reported, because in case of empty query result the 'create edge ' command just don't
   * create edges without failing
   *
   */
@Test
public void testReferToNotExistingVertex() {
    try {
        db.command(new OCommandScript("sql", "begin \n \n LET t2 = create vertex V set Mid = \"2\" \n" + "LET t5 = select from V where Mid = '123456789' \n LET t3 = create edge E from $t5 to $t2 \n" + "\n commit \n return [$t3] ")).execute();
        Assert.fail();
    } catch (OCommandExecutionException e) {
    }
    List<ODocument> res = db.query(new OSQLSynchQuery("select from E"));
    Assert.assertEquals(res.size(), 0);
}
Also used : OCommandScript(com.orientechnologies.orient.core.command.script.OCommandScript) OSQLSynchQuery(com.orientechnologies.orient.core.sql.query.OSQLSynchQuery) OCommandExecutionException(com.orientechnologies.orient.core.exception.OCommandExecutionException) ODocument(com.orientechnologies.orient.core.record.impl.ODocument) Test(org.junit.Test)

Example 62 with ODocument

use of com.orientechnologies.orient.core.record.impl.ODocument in project orientdb by orientechnologies.

the class TestGraphTransactionOnBatch method testDuplicateEdgeRollback.

@Test
public void testDuplicateEdgeRollback() {
    OClass clazz = db.getMetadata().getSchema().createClass("Test");
    clazz.setSuperClass(E);
    clazz.createProperty("aKey", OType.STRING).createIndex(INDEX_TYPE.UNIQUE);
    try {
        db.command(new OCommandScript("sql", "BEGIN \n LET a = create vertex V \n LET b = create vertex V \n LET c =create edge Test from $a to $b SET aKey = \"12345\" \n LET d =create edge Test from $a to $b SET aKey = \"12345\"  \n COMMIT \n" + " RETURN $c")).execute();
        Assert.fail("expected record duplicate exception");
    } catch (ORecordDuplicatedException ex) {
    }
    List<ODocument> res = db.query(new OSQLSynchQuery("select from Test"));
    Assert.assertEquals(0, res.size());
}
Also used : ORecordDuplicatedException(com.orientechnologies.orient.core.storage.ORecordDuplicatedException) OCommandScript(com.orientechnologies.orient.core.command.script.OCommandScript) OSQLSynchQuery(com.orientechnologies.orient.core.sql.query.OSQLSynchQuery) OClass(com.orientechnologies.orient.core.metadata.schema.OClass) ODocument(com.orientechnologies.orient.core.record.impl.ODocument) Test(org.junit.Test)

Example 63 with ODocument

use of com.orientechnologies.orient.core.record.impl.ODocument 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 64 with ODocument

use of com.orientechnologies.orient.core.record.impl.ODocument 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 65 with ODocument

use of com.orientechnologies.orient.core.record.impl.ODocument 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)

Aggregations

ODocument (com.orientechnologies.orient.core.record.impl.ODocument)2200 Test (org.testng.annotations.Test)651 OSQLSynchQuery (com.orientechnologies.orient.core.sql.query.OSQLSynchQuery)426 OCommandSQL (com.orientechnologies.orient.core.sql.OCommandSQL)422 OIdentifiable (com.orientechnologies.orient.core.db.record.OIdentifiable)277 Test (org.junit.Test)267 ODatabaseDocumentTx (com.orientechnologies.orient.core.db.document.ODatabaseDocumentTx)257 OClass (com.orientechnologies.orient.core.metadata.schema.OClass)244 ORID (com.orientechnologies.orient.core.id.ORID)196 ORecordId (com.orientechnologies.orient.core.id.ORecordId)139 OSchema (com.orientechnologies.orient.core.metadata.schema.OSchema)122 ArrayList (java.util.ArrayList)118 ORidBag (com.orientechnologies.orient.core.db.record.ridbag.ORidBag)103 HashMap (java.util.HashMap)103 HashSet (java.util.HashSet)96 ORecord (com.orientechnologies.orient.core.record.ORecord)80 Set (java.util.Set)76 OETLBaseTest (com.orientechnologies.orient.etl.OETLBaseTest)75 ODatabaseDocument (com.orientechnologies.orient.core.db.document.ODatabaseDocument)68 Collection (java.util.Collection)55