Search in sources :

Example 11 with OCommandScript

use of com.orientechnologies.orient.core.command.script.OCommandScript in project orientdb by orientechnologies.

the class TestGraphTransactionOnBatch method testReferToNotExistingVariableInTx.

@Test
public void testReferToNotExistingVariableInTx() {
    db.command(new OCommandSQL(" create vertex V set Mid ='2'")).execute();
    Assert.assertFalse(db.getTransaction().isActive());
    List<ODocument> res = db.query(new OSQLSynchQuery("select from V"));
    Assert.assertEquals(1, res.size());
    try {
        db.command(new OCommandScript("sql", "begin \n Let t0 = delete vertex V where Mid='2' \n LET t1 = create edge E from $t2 to $t3 \n commit \n return $t1 ")).execute();
        Assert.fail("it should go in exception because referring to not existing variable");
    } catch (Exception ex) {
    }
    Assert.assertFalse(db.getTransaction().isActive());
    res = db.query(new OSQLSynchQuery("select from V"));
    Assert.assertEquals(1, res.size());
}
Also used : OCommandSQL(com.orientechnologies.orient.core.sql.OCommandSQL) OCommandScript(com.orientechnologies.orient.core.command.script.OCommandScript) OSQLSynchQuery(com.orientechnologies.orient.core.sql.query.OSQLSynchQuery) OCommandExecutionException(com.orientechnologies.orient.core.exception.OCommandExecutionException) ORecordDuplicatedException(com.orientechnologies.orient.core.storage.ORecordDuplicatedException) ODocument(com.orientechnologies.orient.core.record.impl.ODocument) Test(org.junit.Test)

Example 12 with OCommandScript

use of com.orientechnologies.orient.core.command.script.OCommandScript 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 13 with OCommandScript

use of com.orientechnologies.orient.core.command.script.OCommandScript 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 14 with OCommandScript

use of com.orientechnologies.orient.core.command.script.OCommandScript in project orientdb by orientechnologies.

the class TestGraphTransactionOnBatch method testAbsoluteDuplicateEdgeAlreadyPresentRollback.

@Test
public void testAbsoluteDuplicateEdgeAlreadyPresentRollback() {
    OClass clazz = db.getMetadata().getSchema().createClass("Test");
    clazz.setSuperClass(E);
    clazz.createProperty("in", OType.LINK);
    clazz.createProperty("out", OType.LINK);
    clazz.createIndex("Unique", INDEX_TYPE.UNIQUE, "in", "out");
    try {
        db.command(new OCommandScript("sql", "BEGIN \n LET a = create vertex V set name='a' \n LET b = create vertex V  set name='b' \n LET c =create edge Test from $a to $b  \n LET d =create edge Test from $a to $b \n COMMIT \n" + " RETURN $c")).execute();
        db.command(new OCommandScript("sql", "BEGIN \n LET c =create edge Test from (select from V  where name='a') to (select from V where name='b')  \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 15 with OCommandScript

use of com.orientechnologies.orient.core.command.script.OCommandScript in project orientdb by orientechnologies.

the class TestGraphTransactionOnBatch method testReferInTxDeleteVertex.

@Test
public void testReferInTxDeleteVertex() {
    try {
        db.command(new OCommandSQL("create vertex V set Mid = '1' ")).execute();
        db.command(new OCommandScript("sql", "begin \n LET t0 = select from V where Mid='1' \n" + "LET t1 = delete vertex V where Mid = '1' \n LET t2 = create vertex V set Mid = '2' \n" + "LET t4 = create edge E from $t2 to $t0 \n commit \n return [$t4] ")).execute();
        Assert.fail("it should go in exception because referring to a in transaction delete vertex");
    } catch (Exception ex) {
    }
    List<ODocument> res = db.query(new OSQLSynchQuery("select from E"));
    Assert.assertEquals(res.size(), 0);
}
Also used : OCommandSQL(com.orientechnologies.orient.core.sql.OCommandSQL) OCommandScript(com.orientechnologies.orient.core.command.script.OCommandScript) OSQLSynchQuery(com.orientechnologies.orient.core.sql.query.OSQLSynchQuery) OCommandExecutionException(com.orientechnologies.orient.core.exception.OCommandExecutionException) ORecordDuplicatedException(com.orientechnologies.orient.core.storage.ORecordDuplicatedException) ODocument(com.orientechnologies.orient.core.record.impl.ODocument) Test(org.junit.Test)

Aggregations

OCommandScript (com.orientechnologies.orient.core.command.script.OCommandScript)43 ODocument (com.orientechnologies.orient.core.record.impl.ODocument)21 OCommandSQL (com.orientechnologies.orient.core.sql.OCommandSQL)18 Test (org.junit.Test)13 OSQLSynchQuery (com.orientechnologies.orient.core.sql.query.OSQLSynchQuery)11 ORecordDuplicatedException (com.orientechnologies.orient.core.storage.ORecordDuplicatedException)9 InputStream (java.io.InputStream)9 Test (org.testng.annotations.Test)9 Before (org.junit.Before)8 ODatabaseDocumentTx (com.orientechnologies.orient.core.db.document.ODatabaseDocumentTx)6 OClass (com.orientechnologies.orient.core.metadata.schema.OClass)6 OIdentifiable (com.orientechnologies.orient.core.db.record.OIdentifiable)4 OCommandExecutionException (com.orientechnologies.orient.core.exception.OCommandExecutionException)4 IOException (java.io.IOException)4 Collection (java.util.Collection)3 List (java.util.List)3 StandardAnalyzer (org.apache.lucene.analysis.standard.StandardAnalyzer)3 ONeedRetryException (com.orientechnologies.common.concur.ONeedRetryException)2 OException (com.orientechnologies.common.exception.OException)2 OCommandRequest (com.orientechnologies.orient.core.command.OCommandRequest)2