Search in sources :

Example 31 with OConcurrentModificationException

use of com.orientechnologies.orient.core.exception.OConcurrentModificationException in project orientdb by orientechnologies.

the class OCommandExecutorSQLUpdate method execute.

public Object execute(final Map<Object, Object> iArgs) {
    if (subjectName == null)
        throw new OCommandExecutionException("Cannot execute the command because it has not been parsed yet");
    parameters = new OCommandParameters(iArgs);
    Map<Object, Object> queryArgs;
    if (parameters.size() > 0 && parameters.getByName(0) != null) {
        queryArgs = new HashMap<Object, Object>();
        for (int i = parameterCounter; i < parameters.size(); i++) {
            if (parameters.getByName(i) != null)
                queryArgs.put(i - parameterCounter, parameters.getByName(i));
        }
    } else {
        queryArgs = iArgs;
    }
    query.setContext(context);
    returnHandler.reset();
    if (lockStrategy.equals("RECORD"))
        query.getContext().setVariable("$locking", OStorage.LOCKING_STRATEGY.EXCLUSIVE_LOCK);
    getDatabase().query(query, queryArgs);
    if (upsertMode && !updated) {
        // IF UPDATE DOES NOT PRODUCE RESULTS AND UPSERT MODE IS ENABLED, CREATE DOCUMENT AND APPLY SET/ADD/PUT/MERGE and so on
        final ODocument doc = subjectName != null ? new ODocument(subjectName) : new ODocument();
        final String suspendedLockStrategy = lockStrategy;
        // New record hasn't been created under exclusive lock - just to avoid releasing locks by result(doc)
        lockStrategy = "NONE";
        try {
            result(doc);
        } catch (ORecordDuplicatedException e) {
            if (upsertMode)
                // UPDATE THE NEW RECORD
                getDatabase().query(query, queryArgs);
            else
                throw e;
        } catch (ORecordNotFoundException e) {
            if (upsertMode)
                // UPDATE THE NEW RECORD
                getDatabase().query(query, queryArgs);
            else
                throw e;
        } catch (OConcurrentModificationException e) {
            if (upsertMode)
                // UPDATE THE NEW RECORD
                getDatabase().query(query, queryArgs);
            else
                throw e;
        }
        lockStrategy = suspendedLockStrategy;
    }
    return returnHandler.ret();
}
Also used : ORecordDuplicatedException(com.orientechnologies.orient.core.storage.ORecordDuplicatedException) ORecordNotFoundException(com.orientechnologies.orient.core.exception.ORecordNotFoundException) OCommandExecutionException(com.orientechnologies.orient.core.exception.OCommandExecutionException) OConcurrentModificationException(com.orientechnologies.orient.core.exception.OConcurrentModificationException) ODocument(com.orientechnologies.orient.core.record.impl.ODocument)

Example 32 with OConcurrentModificationException

use of com.orientechnologies.orient.core.exception.OConcurrentModificationException in project orientdb by orientechnologies.

the class OConflictManagementTest method testDefaultStrategy.

public void testDefaultStrategy() {
    ODocument rootDoc = new ODocument().field("name", "Jay").save();
    ODocument copy = rootDoc.copy();
    rootDoc.field("name", "Jay1");
    rootDoc.save();
    copy.field("name", "Jay2");
    try {
        copy.save();
        Assert.assertTrue(false);
    } catch (OConcurrentModificationException e) {
    }
}
Also used : OConcurrentModificationException(com.orientechnologies.orient.core.exception.OConcurrentModificationException) ODocument(com.orientechnologies.orient.core.record.impl.ODocument)

Example 33 with OConcurrentModificationException

use of com.orientechnologies.orient.core.exception.OConcurrentModificationException in project orientdb by orientechnologies.

the class ORidBagAtomicUpdateTest method testAddInternalDocumentsAndSubDocumentsWithCME.

public void testAddInternalDocumentsAndSubDocumentsWithCME() {
    final ODocument cmeDoc = new ODocument();
    cmeDoc.save();
    database.begin();
    ODocument rootDoc = new ODocument();
    ORidBag ridBag = new ORidBag();
    rootDoc.field("ridBag", ridBag);
    ODocument docOne = new ODocument();
    docOne.save();
    ODocument docTwo = new ODocument();
    docTwo.save();
    ridBag.add(docOne);
    ridBag.add(docTwo);
    rootDoc.save();
    database.commit();
    long recordsCount = database.countClusterElements(database.getDefaultClusterId());
    rootDoc = database.load(rootDoc.getIdentity());
    ridBag = rootDoc.field("ridBag");
    database.getLocalCache().clear();
    ODocument staleCMEDoc = database.load(cmeDoc.getIdentity());
    Assert.assertNotSame(staleCMEDoc, cmeDoc);
    cmeDoc.field("v", "v");
    cmeDoc.save();
    database.begin();
    ODocument docThree = new ODocument();
    docThree.save();
    ODocument docFour = new ODocument();
    docFour.save();
    ridBag.add(docThree);
    ridBag.add(docFour);
    rootDoc.save();
    ODocument docThreeOne = new ODocument();
    docThreeOne.save();
    ODocument docThreeTwo = new ODocument();
    docThreeTwo.save();
    ORidBag ridBagThree = new ORidBag();
    ridBagThree.add(docThreeOne);
    ridBagThree.add(docThreeTwo);
    docThree.field("ridBag", ridBagThree);
    docThree.save();
    ODocument docFourOne = new ODocument();
    docFourOne.save();
    ODocument docFourTwo = new ODocument();
    docFourTwo.save();
    ORidBag ridBagFour = new ORidBag();
    ridBagFour.add(docFourOne);
    ridBagFour.add(docFourTwo);
    docFour.field("ridBag", ridBagFour);
    docFour.save();
    staleCMEDoc.field("v", "vn");
    staleCMEDoc.save();
    try {
        database.commit();
        Assert.fail();
    } catch (OConcurrentModificationException e) {
    }
    Assert.assertEquals(database.countClusterElements(database.getDefaultClusterId()), recordsCount);
    List<OIdentifiable> addedDocs = new ArrayList<OIdentifiable>(Arrays.asList(docOne, docTwo));
    rootDoc = database.load(rootDoc.getIdentity());
    ridBag = rootDoc.field("ridBag");
    Iterator<OIdentifiable> iterator = ridBag.iterator();
    Assert.assertTrue(addedDocs.remove(iterator.next()));
    Assert.assertTrue(addedDocs.remove(iterator.next()));
}
Also used : ORidBag(com.orientechnologies.orient.core.db.record.ridbag.ORidBag) ArrayList(java.util.ArrayList) OConcurrentModificationException(com.orientechnologies.orient.core.exception.OConcurrentModificationException) OIdentifiable(com.orientechnologies.orient.core.db.record.OIdentifiable) ODocument(com.orientechnologies.orient.core.record.impl.ODocument)

Example 34 with OConcurrentModificationException

use of com.orientechnologies.orient.core.exception.OConcurrentModificationException in project orientdb by orientechnologies.

the class ORidBagAtomicUpdateTest method testAddTwoSavedDocumentsWithoutTx.

/**
   * This test is no longer useful
   */
@Test(enabled = false)
public void testAddTwoSavedDocumentsWithoutTx() {
    ODocument docOne = new ODocument();
    ODocument docTwo = new ODocument();
    ODocument rootDoc = new ODocument();
    ORidBag ridBag = new ORidBag();
    rootDoc.field("ridBag", ridBag);
    rootDoc.save();
    ODocument staleRooDoc = database.load(rootDoc.getIdentity());
    ORidBag staleRidBag = staleRooDoc.field("ridBag");
    staleRidBag.add(docOne);
    staleRidBag.add(docTwo);
    rootDoc.setDirty();
    rootDoc.save();
    try {
        staleRooDoc.save();
        Assert.fail();
    } catch (OConcurrentModificationException e) {
    }
    rootDoc = database.load(rootDoc.getIdentity());
    ridBag = rootDoc.field("ridBag");
    Assert.assertEquals(ridBag.size(), 0);
}
Also used : ORidBag(com.orientechnologies.orient.core.db.record.ridbag.ORidBag) OConcurrentModificationException(com.orientechnologies.orient.core.exception.OConcurrentModificationException) ODocument(com.orientechnologies.orient.core.record.impl.ODocument) Test(org.testng.annotations.Test) DatabaseAbstractTest(com.orientechnologies.DatabaseAbstractTest)

Example 35 with OConcurrentModificationException

use of com.orientechnologies.orient.core.exception.OConcurrentModificationException in project orientdb by orientechnologies.

the class ORidBagAtomicUpdateTest method testFromSBTreeToEmbeddedTxWithCME.

public void testFromSBTreeToEmbeddedTxWithCME() {
    OGlobalConfiguration.RID_BAG_EMBEDDED_TO_SBTREEBONSAI_THRESHOLD.setValue(5);
    OGlobalConfiguration.RID_BAG_SBTREEBONSAI_TO_EMBEDDED_THRESHOLD.setValue(7);
    ODocument cmeDoc = new ODocument();
    cmeDoc.save();
    List<OIdentifiable> docsToAdd = new ArrayList<OIdentifiable>();
    ODocument document = new ODocument();
    ORidBag ridBag = new ORidBag();
    document.field("ridBag", ridBag);
    document.save();
    database.begin();
    for (int i = 0; i < 10; i++) {
        ODocument docToAdd = new ODocument();
        docToAdd.save();
        ridBag.add(docToAdd);
        docsToAdd.add(docToAdd);
    }
    document.save();
    database.commit();
    Assert.assertEquals(docsToAdd.size(), 10);
    Assert.assertTrue(!ridBag.isEmbedded());
    document = database.load(document.getIdentity());
    ridBag = document.field("ridBag");
    database.getLocalCache().clear();
    ODocument staleDoc = database.load(cmeDoc.getIdentity());
    Assert.assertNotSame(staleDoc, cmeDoc);
    cmeDoc.field("v", "sd");
    cmeDoc.save();
    database.begin();
    for (int i = 0; i < 4; i++) {
        OIdentifiable docToRemove = docsToAdd.get(i);
        ridBag.remove(docToRemove);
    }
    Assert.assertTrue(document.isDirty());
    document.save();
    staleDoc.field("v", "d");
    staleDoc.save();
    try {
        database.commit();
        Assert.fail();
    } catch (OConcurrentModificationException e) {
    }
    document = database.load(document.getIdentity());
    ridBag = document.field("ridBag");
    Assert.assertTrue(!ridBag.isEmbedded());
    for (OIdentifiable identifiable : ridBag) Assert.assertTrue(docsToAdd.remove(identifiable));
    Assert.assertTrue(docsToAdd.isEmpty());
}
Also used : ORidBag(com.orientechnologies.orient.core.db.record.ridbag.ORidBag) ArrayList(java.util.ArrayList) OConcurrentModificationException(com.orientechnologies.orient.core.exception.OConcurrentModificationException) OIdentifiable(com.orientechnologies.orient.core.db.record.OIdentifiable) ODocument(com.orientechnologies.orient.core.record.impl.ODocument)

Aggregations

OConcurrentModificationException (com.orientechnologies.orient.core.exception.OConcurrentModificationException)40 ODocument (com.orientechnologies.orient.core.record.impl.ODocument)25 ODatabaseDocumentTx (com.orientechnologies.orient.core.db.document.ODatabaseDocumentTx)11 OIdentifiable (com.orientechnologies.orient.core.db.record.OIdentifiable)11 ORidBag (com.orientechnologies.orient.core.db.record.ridbag.ORidBag)11 OrientVertex (com.tinkerpop.blueprints.impls.orient.OrientVertex)8 ArrayList (java.util.ArrayList)8 Test (org.testng.annotations.Test)8 Vertex (com.tinkerpop.blueprints.Vertex)7 DatabaseAbstractTest (com.orientechnologies.DatabaseAbstractTest)6 Test (org.junit.Test)5 ORID (com.orientechnologies.orient.core.id.ORID)4 OCommandSQL (com.orientechnologies.orient.core.sql.OCommandSQL)4 OrientBaseGraph (com.tinkerpop.blueprints.impls.orient.OrientBaseGraph)4 OrientGraph (com.tinkerpop.blueprints.impls.orient.OrientGraph)4 ORecordNotFoundException (com.orientechnologies.orient.core.exception.ORecordNotFoundException)3 ONeedRetryException (com.orientechnologies.common.concur.ONeedRetryException)2 ODatabaseDocument (com.orientechnologies.orient.core.db.document.ODatabaseDocument)2 OClass (com.orientechnologies.orient.core.metadata.schema.OClass)2 ORecord (com.orientechnologies.orient.core.record.ORecord)2