use of com.orientechnologies.orient.core.db.record.OIdentifiable in project orientdb by orientechnologies.
the class SQLMoveVertexCommandInTxTest method testMoveSingleRecordToAnotherClass.
@Test
public void testMoveSingleRecordToAnotherClass() {
ODocument doc = new ODocument("Customer").field("name", "Jay").field("test", "testMoveSingleRecordToAnotherClass").save();
Assert.assertEquals(doc.getIdentity().getClusterId(), customer.getDefaultClusterId());
Iterable<OrientVertex> result = graph.command(new OCommandSQL("MOVE VERTEX " + doc.getIdentity() + " TO CLASS:Provider")).execute();
// CHECK RESULT
ODocument fromTo = result.iterator().next().getRecord();
Assert.assertFalse(result.iterator().hasNext());
OIdentifiable from = fromTo.field("old");
OIdentifiable to = fromTo.field("new");
// CHECK FROM
Assert.assertEquals(from, doc.getIdentity());
// CHECK DESTINATION
Assert.assertEquals(to.getIdentity().getClusterId(), provider.getDefaultClusterId());
ODocument newDocument = to.getRecord();
Assert.assertEquals(newDocument.getClassName(), "Provider");
Assert.assertEquals(newDocument.field("name"), "Jay");
Assert.assertEquals(newDocument.field("test"), "testMoveSingleRecordToAnotherClass");
}
use of com.orientechnologies.orient.core.db.record.OIdentifiable in project orientdb by orientechnologies.
the class SQLMoveVertexCommandInTxTest method testMoveMultipleRecordToAnotherCluster.
@Test
public void testMoveMultipleRecordToAnotherCluster() {
new ODocument("Customer").field("name", "Jay").field("workedOn", "Amiga").save();
new ODocument("Customer").field("name", "Steve").field("workedOn", "Mac").save();
new ODocument("Customer").field("name", "Bill").field("workedOn", "Ms-Dos").save();
new ODocument("Customer").field("name", "Tim").field("workedOn", "Amiga").save();
graph.commit();
Iterable<OrientVertex> result = graph.command(new OCommandSQL("MOVE VERTEX (select from Customer where workedOn = 'Amiga') TO CLUSTER:Customer_genius")).execute();
// CHECK RESULT
int tot = 0;
for (OrientVertex v : result) {
tot++;
ODocument fromTo = v.getRecord();
OIdentifiable from = fromTo.field("old");
OIdentifiable to = fromTo.field("new");
// CHECK FROM
Assert.assertEquals(from.getIdentity().getClusterId(), customer.getDefaultClusterId());
// CHECK DESTINATION
Assert.assertEquals(to.getIdentity().getClusterId(), customerGeniusCluster);
ODocument newDocument = to.getRecord();
Assert.assertEquals(newDocument.getClassName(), "Customer");
Assert.assertEquals(newDocument.field("workedOn"), "Amiga");
}
Assert.assertEquals(tot, 2);
}
use of com.orientechnologies.orient.core.db.record.OIdentifiable in project orientdb by orientechnologies.
the class SQLMoveVertexCommandTest method testMoveSingleRecordToAnotherCluster.
@Test
public void testMoveSingleRecordToAnotherCluster() {
OrientVertex v1 = graph.addVertex("class:Customer").setProperties("name", "Jay1", "test", "testMoveSingleRecordToAnotherCluster");
OrientVertex v2 = graph.addVertex("class:Customer").setProperties("name", "Jay2", "test", "testMoveSingleRecordToAnotherCluster");
OrientVertex v3 = graph.addVertex("class:Customer").setProperties("name", "Jay3", "test", "testMoveSingleRecordToAnotherCluster");
// SELF
v1.addEdge("knows", v1);
v1.addEdge("knows", v2);
v1.addEdge("knows", v3);
v2.addEdge("knows", v1);
Assert.assertEquals(v1.getIdentity().getClusterId(), customer.getDefaultClusterId());
Iterable<OrientVertex> result = graph.command(new OCommandSQL("MOVE VERTEX " + v1.getIdentity() + " TO CLUSTER:Customer_genius")).execute();
// CHECK RESULT
final ArrayList<OIdentifiable> newRids = new ArrayList<OIdentifiable>();
int tot = 0;
for (OrientVertex v : result) {
tot++;
ODocument fromTo = v.getRecord();
OIdentifiable from = fromTo.field("old");
OIdentifiable to = fromTo.field("new");
newRids.add(to);
// CHECK FROM
Assert.assertEquals(from, v1.getIdentity());
// CHECK DESTINATION
Assert.assertEquals(to.getIdentity().getClusterId(), customerGeniusCluster);
ODocument newDocument = to.getRecord();
Assert.assertEquals(newDocument.field("name"), "Jay1");
Assert.assertEquals(newDocument.field("test"), "testMoveSingleRecordToAnotherCluster");
}
Assert.assertEquals(tot, 1);
Iterable<OrientEdge> result2 = graph.command(new OCommandSQL("SELECT FROM knows where out = " + v1.getIdentity() + " or in = " + v1.getIdentity())).execute();
Assert.assertFalse(result2.iterator().hasNext());
}
use of com.orientechnologies.orient.core.db.record.OIdentifiable in project orientdb by orientechnologies.
the class SQLMoveVertexCommandTest method testMoveMultipleRecordToAnotherClassInTx.
@Test
public void testMoveMultipleRecordToAnotherClassInTx() {
new ODocument("Customer").field("name", "Luca").field("city", "Rome").save();
new ODocument("Customer").field("name", "Jill").field("city", "Austin").save();
new ODocument("Customer").field("name", "Marco").field("city", "Rome").save();
new ODocument("Customer").field("name", "XXX").field("city", "Athens").save();
Iterable<OrientVertex> result = graph.command(new OCommandSQL("MOVE VERTEX (select from Customer where city = 'Rome') TO CLASS:Provider")).execute();
// CHECK RESULT
int tot = 0;
for (OrientVertex v : result) {
tot++;
ODocument fromTo = v.getRecord();
OIdentifiable from = fromTo.field("old");
OIdentifiable to = fromTo.field("new");
// CHECK FROM
Assert.assertEquals(from.getIdentity().getClusterId(), customer.getDefaultClusterId());
// CHECK DESTINATION
Assert.assertEquals(to.getIdentity().getClusterId(), provider.getDefaultClusterId());
ODocument newDocument = to.getRecord();
Assert.assertEquals(newDocument.getClassName(), "Provider");
Assert.assertEquals(newDocument.field("city"), "Rome");
}
Assert.assertEquals(tot, 2);
}
use of com.orientechnologies.orient.core.db.record.OIdentifiable in project orientdb by orientechnologies.
the class SQLMoveVertexCommandTest method testMoveMultipleRecordToAnotherClass.
@Test
public void testMoveMultipleRecordToAnotherClass() {
new ODocument("Customer").field("name", "Luca").field("city", "Rome").save();
new ODocument("Customer").field("name", "Jill").field("city", "Austin").save();
new ODocument("Customer").field("name", "Marco").field("city", "Rome").save();
new ODocument("Customer").field("name", "XXX").field("city", "Athens").save();
Iterable<OrientVertex> result = graph.command(new OCommandSQL("MOVE VERTEX (select from Customer where city = 'Rome') TO CLASS:Provider")).execute();
// CHECK RESULT
int tot = 0;
for (OrientVertex v : result) {
tot++;
ODocument fromTo = v.getRecord();
OIdentifiable from = fromTo.field("old");
OIdentifiable to = fromTo.field("new");
// CHECK FROM
Assert.assertEquals(from.getIdentity().getClusterId(), customer.getDefaultClusterId());
// CHECK DESTINATION
Assert.assertEquals(to.getIdentity().getClusterId(), provider.getDefaultClusterId());
ODocument newDocument = to.getRecord();
Assert.assertEquals(newDocument.getClassName(), "Provider");
Assert.assertEquals(newDocument.field("city"), "Rome");
}
Assert.assertEquals(tot, 2);
}
Aggregations