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();
}
}
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());
}
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);
}
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());
}
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());
}
Aggregations