Search in sources :

Example 81 with OCommandSQL

use of com.orientechnologies.orient.core.sql.OCommandSQL in project orientdb by orientechnologies.

the class LinkBagIndexTest method testIndexRidBagUpdateRemoveItemInTx.

public void testIndexRidBagUpdateRemoveItemInTx() throws Exception {
    final ODocument docOne = new ODocument();
    docOne.save();
    final ODocument docTwo = new ODocument();
    docTwo.save();
    final ODocument document = new ODocument("RidBagIndexTestClass");
    final ORidBag ridBag = new ORidBag();
    ridBag.add(docOne);
    ridBag.add(docTwo);
    document.field("ridBag", ridBag);
    document.save();
    try {
        database.begin();
        ODocument loadedDocument = database.load(document.getIdentity());
        loadedDocument.<ORidBag>field("ridBag").remove(docTwo);
        loadedDocument.save();
        database.commit();
    } catch (Exception e) {
        database.rollback();
        throw e;
    }
    List<ODocument> result = database.command(new OCommandSQL("select key, rid from index:ridBagIndex")).execute();
    Assert.assertNotNull(result);
    Assert.assertEquals(result.size(), 1);
    for (ODocument d : result) {
        Assert.assertTrue(d.containsField("key"));
        Assert.assertTrue(d.containsField("rid"));
        if (!d.field("key").equals(docOne.getIdentity())) {
            Assert.fail("Unknown key found: " + d.field("key"));
        }
    }
}
Also used : OCommandSQL(com.orientechnologies.orient.core.sql.OCommandSQL) ORidBag(com.orientechnologies.orient.core.db.record.ridbag.ORidBag) ODocument(com.orientechnologies.orient.core.record.impl.ODocument)

Example 82 with OCommandSQL

use of com.orientechnologies.orient.core.sql.OCommandSQL in project orientdb by orientechnologies.

the class LinkBagIndexTest method testIndexRidBagUpdate.

public void testIndexRidBagUpdate() {
    final ODocument docOne = new ODocument();
    docOne.save();
    final ODocument docTwo = new ODocument();
    docTwo.save();
    final ODocument docThree = new ODocument();
    docThree.save();
    final ODocument document = new ODocument("RidBagIndexTestClass");
    final ORidBag ridBagOne = new ORidBag();
    ridBagOne.add(docOne);
    ridBagOne.add(docTwo);
    document.field("ridBag", ridBagOne);
    document.save();
    final ORidBag ridBagTwo = new ORidBag();
    ridBagTwo.add(docOne);
    ridBagTwo.add(docThree);
    document.field("ridBag", ridBagTwo);
    document.save();
    List<ODocument> result = database.command(new OCommandSQL("select key, rid from index:ridBagIndex")).execute();
    Assert.assertNotNull(result);
    Assert.assertEquals(result.size(), 2);
    for (ODocument d : result) {
        Assert.assertTrue(d.containsField("key"));
        Assert.assertTrue(d.containsField("rid"));
        if (!d.field("key").equals(docOne.getIdentity()) && !d.field("key").equals(docThree.getIdentity())) {
            Assert.fail("Unknown key found: " + d.field("key"));
        }
    }
}
Also used : OCommandSQL(com.orientechnologies.orient.core.sql.OCommandSQL) ORidBag(com.orientechnologies.orient.core.db.record.ridbag.ORidBag) ODocument(com.orientechnologies.orient.core.record.impl.ODocument)

Example 83 with OCommandSQL

use of com.orientechnologies.orient.core.sql.OCommandSQL in project orientdb by orientechnologies.

the class LinkBagIndexTest method testIndexRidBagUpdateRemoveItem.

public void testIndexRidBagUpdateRemoveItem() {
    final ODocument docOne = new ODocument();
    docOne.save();
    final ODocument docTwo = new ODocument();
    docTwo.save();
    final ODocument document = new ODocument("RidBagIndexTestClass");
    final ORidBag ridBag = new ORidBag();
    ridBag.add(docOne);
    ridBag.add(docTwo);
    document.field("ridBag", ridBag);
    document.save();
    database.command(new OCommandSQL("UPDATE " + document.getIdentity() + " remove ridBag = " + docTwo.getIdentity())).execute();
    List<ODocument> result = database.command(new OCommandSQL("select key, rid from index:ridBagIndex")).execute();
    Assert.assertNotNull(result);
    Assert.assertEquals(result.size(), 1);
    for (ODocument d : result) {
        Assert.assertTrue(d.containsField("key"));
        Assert.assertTrue(d.containsField("rid"));
        if (!d.field("key").equals(docOne.getIdentity())) {
            Assert.fail("Unknown key found: " + d.field("key"));
        }
    }
}
Also used : OCommandSQL(com.orientechnologies.orient.core.sql.OCommandSQL) ORidBag(com.orientechnologies.orient.core.db.record.ridbag.ORidBag) ODocument(com.orientechnologies.orient.core.record.impl.ODocument)

Example 84 with OCommandSQL

use of com.orientechnologies.orient.core.sql.OCommandSQL in project orientdb by orientechnologies.

the class LinkBagIndexTest method testIndexRidBagRemoveInTx.

public void testIndexRidBagRemoveInTx() throws Exception {
    final ODocument docOne = new ODocument();
    docOne.save();
    final ODocument docTwo = new ODocument();
    docTwo.save();
    final ODocument document = new ODocument("RidBagIndexTestClass");
    final ORidBag ridBag = new ORidBag();
    ridBag.add(docOne);
    ridBag.add(docTwo);
    document.field("ridBag", ridBag);
    document.save();
    try {
        database.begin();
        document.delete();
        database.commit();
    } catch (Exception e) {
        database.rollback();
        throw e;
    }
    List<ODocument> result = database.command(new OCommandSQL("select key, rid from index:ridBagIndex")).execute();
    Assert.assertNotNull(result);
    Assert.assertEquals(result.size(), 0);
}
Also used : OCommandSQL(com.orientechnologies.orient.core.sql.OCommandSQL) ORidBag(com.orientechnologies.orient.core.db.record.ridbag.ORidBag) ODocument(com.orientechnologies.orient.core.record.impl.ODocument)

Example 85 with OCommandSQL

use of com.orientechnologies.orient.core.sql.OCommandSQL in project orientdb by orientechnologies.

the class LinkListIndexTest method testIndexCollectionRemoveInTx.

public void testIndexCollectionRemoveInTx() throws Exception {
    final ODocument docOne = new ODocument();
    docOne.save();
    final ODocument docTwo = new ODocument();
    docTwo.save();
    final ODocument document = new ODocument("LinkListIndexTestClass");
    document.field("linkCollection", new ArrayList<ORID>(Arrays.asList(docOne.getIdentity(), docTwo.getIdentity())));
    document.save();
    try {
        database.begin();
        document.delete();
        database.commit();
    } catch (Exception e) {
        database.rollback();
        throw e;
    }
    List<ODocument> result = database.command(new OCommandSQL("select key, rid from index:linkCollectionIndex")).execute();
    Assert.assertNotNull(result);
    Assert.assertEquals(result.size(), 0);
}
Also used : OCommandSQL(com.orientechnologies.orient.core.sql.OCommandSQL) ORID(com.orientechnologies.orient.core.id.ORID) ODocument(com.orientechnologies.orient.core.record.impl.ODocument)

Aggregations

OCommandSQL (com.orientechnologies.orient.core.sql.OCommandSQL)621 ODocument (com.orientechnologies.orient.core.record.impl.ODocument)422 Test (org.junit.Test)97 Test (org.testng.annotations.Test)93 OClass (com.orientechnologies.orient.core.metadata.schema.OClass)83 OIdentifiable (com.orientechnologies.orient.core.db.record.OIdentifiable)79 OSQLSynchQuery (com.orientechnologies.orient.core.sql.query.OSQLSynchQuery)78 ORID (com.orientechnologies.orient.core.id.ORID)64 ODatabaseDocumentTx (com.orientechnologies.orient.core.db.document.ODatabaseDocumentTx)61 OSchema (com.orientechnologies.orient.core.metadata.schema.OSchema)54 Set (java.util.Set)53 HashMap (java.util.HashMap)45 ODatabaseDocumentInternal (com.orientechnologies.orient.core.db.ODatabaseDocumentInternal)42 OrientVertex (com.tinkerpop.blueprints.impls.orient.OrientVertex)41 List (java.util.List)25 Before (org.junit.Before)24 OStorage (com.orientechnologies.orient.core.storage.OStorage)23 OrientGraphNoTx (com.tinkerpop.blueprints.impls.orient.OrientGraphNoTx)23 ORecordId (com.orientechnologies.orient.core.id.ORecordId)21 Vertex (com.tinkerpop.blueprints.Vertex)19