Search in sources :

Example 71 with ODocument

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

the class GraphTest method testEmbeddedListAsVertexProperty.

@Test
public void testEmbeddedListAsVertexProperty() {
    OrientGraph g = new OrientGraph(URL, "admin", "admin");
    try {
        OrientVertexType vertexType = g.createVertexType("EmbeddedClass");
        vertexType.createProperty("embeddedList", OType.EMBEDDEDLIST);
        OrientVertex vertex = g.addVertex("class:EmbeddedClass");
        List<ODocument> embeddedList = new ArrayList<ODocument>();
        ODocument docOne = new ODocument();
        docOne.field("prop", "docOne");
        ODocument docTwo = new ODocument();
        docTwo.field("prop", "docTwo");
        embeddedList.add(docOne);
        embeddedList.add(docTwo);
        vertex.setProperty("embeddedList", embeddedList);
        final Object id = vertex.getId();
        g.shutdown();
        g = new OrientGraph(URL, "admin", "admin");
        vertex = g.getVertex(id);
        embeddedList = vertex.getProperty("embeddedList");
        docOne = embeddedList.get(0);
        Assert.assertEquals(docOne.field("prop"), "docOne");
        docTwo = embeddedList.get(1);
        Assert.assertEquals(docTwo.field("prop"), "docTwo");
    } finally {
        g.shutdown();
    }
}
Also used : ArrayList(java.util.ArrayList) ODocument(com.orientechnologies.orient.core.record.impl.ODocument) Test(org.junit.Test)

Example 72 with ODocument

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

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

Example 74 with ODocument

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

the class TestGraphTransactionOnBatch method testDuplicateAlreadyExistingRollback.

@Test
public void testDuplicateAlreadyExistingRollback() {
    OClass clazz = db.getMetadata().getSchema().createClass("Test");
    clazz.setSuperClass(V);
    clazz.createProperty("id", OType.STRING).createIndex(INDEX_TYPE.UNIQUE);
    db.command(new OCommandSQL("create vertex Test SET id = \"12345678\"")).execute();
    try {
        db.command(new OCommandScript("sql", "BEGIN \n LET a = create vertex Test SET id = \"12345678\" \n COMMIT\n" + " RETURN $a")).execute();
        Assert.fail("expected record duplicate exception");
    } catch (ORecordDuplicatedException ex) {
    }
    List<ODocument> res = db.query(new OSQLSynchQuery("select from Test"));
    Assert.assertEquals(1, res.size());
}
Also used : OCommandSQL(com.orientechnologies.orient.core.sql.OCommandSQL) 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 75 with ODocument

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

the class OMatchStatementExecutionTest method testMaxDepth.

@Test
public void testMaxDepth() throws Exception {
    List<ODocument> qResult = db.command(new OCommandSQL("select friend.name as name from (match {class:Person, where:(name = 'n1')}.out('Friend'){as:friend, maxDepth: 1, where: ($depth=1) } return friend)")).execute();
    assertEquals(2, qResult.size());
    qResult = db.command(new OCommandSQL("select friend.name as name from (match {class:Person, where:(name = 'n1')}.out('Friend'){as:friend, maxDepth: 1 } return friend)")).execute();
    assertEquals(3, qResult.size());
    qResult = db.command(new OCommandSQL("select friend.name as name from (match {class:Person, where:(name = 'n1')}.out('Friend'){as:friend, maxDepth: 0 } return friend)")).execute();
    assertEquals(1, qResult.size());
    qResult = db.command(new OCommandSQL("select friend.name as name from (match {class:Person, where:(name = 'n1')}.out('Friend'){as:friend, maxDepth: 1, where: ($depth > 0) } return friend)")).execute();
    assertEquals(2, qResult.size());
}
Also used : OCommandSQL(com.orientechnologies.orient.core.sql.OCommandSQL) 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