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