Search in sources :

Example 86 with OIdentifiable

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");
}
Also used : OCommandSQL(com.orientechnologies.orient.core.sql.OCommandSQL) OrientVertex(com.tinkerpop.blueprints.impls.orient.OrientVertex) OIdentifiable(com.orientechnologies.orient.core.db.record.OIdentifiable) ODocument(com.orientechnologies.orient.core.record.impl.ODocument) Test(org.junit.Test) GraphTxAbstractTest(com.orientechnologies.orient.graph.GraphTxAbstractTest)

Example 87 with OIdentifiable

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);
}
Also used : OCommandSQL(com.orientechnologies.orient.core.sql.OCommandSQL) OrientVertex(com.tinkerpop.blueprints.impls.orient.OrientVertex) OIdentifiable(com.orientechnologies.orient.core.db.record.OIdentifiable) ODocument(com.orientechnologies.orient.core.record.impl.ODocument) Test(org.junit.Test) GraphTxAbstractTest(com.orientechnologies.orient.graph.GraphTxAbstractTest)

Example 88 with OIdentifiable

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());
}
Also used : OCommandSQL(com.orientechnologies.orient.core.sql.OCommandSQL) ArrayList(java.util.ArrayList) OrientVertex(com.tinkerpop.blueprints.impls.orient.OrientVertex) OIdentifiable(com.orientechnologies.orient.core.db.record.OIdentifiable) OrientEdge(com.tinkerpop.blueprints.impls.orient.OrientEdge) ODocument(com.orientechnologies.orient.core.record.impl.ODocument) GraphNoTxAbstractTest(com.orientechnologies.orient.graph.GraphNoTxAbstractTest) Test(org.junit.Test)

Example 89 with OIdentifiable

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);
}
Also used : OCommandSQL(com.orientechnologies.orient.core.sql.OCommandSQL) OrientVertex(com.tinkerpop.blueprints.impls.orient.OrientVertex) OIdentifiable(com.orientechnologies.orient.core.db.record.OIdentifiable) ODocument(com.orientechnologies.orient.core.record.impl.ODocument) GraphNoTxAbstractTest(com.orientechnologies.orient.graph.GraphNoTxAbstractTest) Test(org.junit.Test)

Example 90 with OIdentifiable

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);
}
Also used : OCommandSQL(com.orientechnologies.orient.core.sql.OCommandSQL) OrientVertex(com.tinkerpop.blueprints.impls.orient.OrientVertex) OIdentifiable(com.orientechnologies.orient.core.db.record.OIdentifiable) ODocument(com.orientechnologies.orient.core.record.impl.ODocument) GraphNoTxAbstractTest(com.orientechnologies.orient.graph.GraphNoTxAbstractTest) Test(org.junit.Test)

Aggregations

OIdentifiable (com.orientechnologies.orient.core.db.record.OIdentifiable)536 ODocument (com.orientechnologies.orient.core.record.impl.ODocument)278 ORecordId (com.orientechnologies.orient.core.id.ORecordId)120 Test (org.testng.annotations.Test)104 HashSet (java.util.HashSet)89 OCommandSQL (com.orientechnologies.orient.core.sql.OCommandSQL)79 ORidBag (com.orientechnologies.orient.core.db.record.ridbag.ORidBag)70 ORID (com.orientechnologies.orient.core.id.ORID)56 OIndexCursor (com.orientechnologies.orient.core.index.OIndexCursor)47 Test (org.junit.Test)43 OClass (com.orientechnologies.orient.core.metadata.schema.OClass)42 ODatabaseDocumentTx (com.orientechnologies.orient.core.db.document.ODatabaseDocumentTx)41 ArrayList (java.util.ArrayList)39 ORecord (com.orientechnologies.orient.core.record.ORecord)35 Map (java.util.Map)31 ByteBuffer (java.nio.ByteBuffer)28 OrientVertex (com.tinkerpop.blueprints.impls.orient.OrientVertex)26 OIndexTxAwareOneValue (com.orientechnologies.orient.core.index.OIndexTxAwareOneValue)22 OSQLSynchQuery (com.orientechnologies.orient.core.sql.query.OSQLSynchQuery)22 OCommandExecutionException (com.orientechnologies.orient.core.exception.OCommandExecutionException)21