use of java.util.ConcurrentModificationException in project morphia by mongodb.
the class DatastoreImpl method tryVersionedUpdate.
private <T> WriteResult tryVersionedUpdate(final DBCollection dbColl, final T entity, final DBObject dbObj, final Object idValue, final InsertOptions options, final MappedClass mc) {
WriteResult wr;
if (mc.getFieldsAnnotatedWith(Version.class).isEmpty()) {
return null;
}
final MappedField mfVersion = mc.getMappedVersionField();
final String versionKeyName = mfVersion.getNameToStore();
Long oldVersion = (Long) mfVersion.getFieldValue(entity);
long newVersion = nextValue(oldVersion);
dbObj.put(versionKeyName, newVersion);
if (idValue != null && newVersion != 1) {
final Query<?> query = find(dbColl.getName(), entity.getClass()).disableValidation().filter(Mapper.ID_KEY, idValue).enableValidation().filter(versionKeyName, oldVersion);
final UpdateResults res = update(query, dbObj, new UpdateOptions().bypassDocumentValidation(options.getBypassDocumentValidation()).writeConcern(options.getWriteConcern()));
wr = res.getWriteResult();
if (res.getUpdatedCount() != 1) {
throw new ConcurrentModificationException(format("Entity of class %s (id='%s',version='%d') was concurrently updated.", entity.getClass().getName(), idValue, oldVersion));
}
} else {
wr = saveDocument(dbColl, dbObj, options);
}
return wr;
}
use of java.util.ConcurrentModificationException in project mobile-android by photo.
the class ArrayDeque method delete.
/**
* Removes the element at the specified position in the elements array,
* adjusting head and tail as necessary. This can result in motion of
* elements backwards or forwards in the array.
* <p>
* This method is called delete rather than remove to emphasize that its
* semantics differ from those of {@link List#remove(int)}.
*
* @return true if elements moved backwards
*/
private boolean delete(int i) {
checkInvariants();
final E[] elements = this.elements;
final int mask = elements.length - 1;
final int h = head;
final int t = tail;
final int front = (i - h) & mask;
final int back = (t - i) & mask;
// Invariant: head <= i < tail mod circularity
if (front >= ((t - h) & mask))
throw new ConcurrentModificationException();
// Optimize for least element motion
if (front < back) {
if (h <= i) {
System.arraycopy(elements, h, elements, h + 1, front);
} else {
// Wrap around
System.arraycopy(elements, 0, elements, 1, i);
elements[0] = elements[mask];
System.arraycopy(elements, h, elements, h + 1, mask - h);
}
elements[h] = null;
head = (h + 1) & mask;
return false;
} else {
if (i < t) {
// Copy the null tail as well
System.arraycopy(elements, i + 1, elements, i, back);
tail = t - 1;
} else {
// Wrap around
System.arraycopy(elements, i + 1, elements, i, mask - i);
elements[mask] = elements[0];
System.arraycopy(elements, 1, elements, 0, t);
tail = (t - 1) & mask;
}
return true;
}
}
use of java.util.ConcurrentModificationException in project robovm by robovm.
the class ConcurrentModTest method testSet.
/*
* Test method for 'java.util.AbstractList.subList(int, int)'
*/
public void testSet() {
AbstractList al = new ArrayList();
Double one = new Double(1.0);
Double two = new Double(2.0);
Double three = new Double(3.0);
Double four = new Double(4.0);
al.add(one);
al.add(two);
al.add(three);
al.add(four);
List sub = al.subList(1, 3);
assertEquals(2, sub.size());
// the sub.get(1) is 3.0
assertTrue(((Double) sub.get(1)).doubleValue() <= 3.0);
assertTrue(((Double) sub.get(1)).doubleValue() > 2.0);
// remove the 2.0
al.remove(1);
try {
// illegal call the subList's method set(int,Object).
sub.set(1, two);
fail("It should throws ConcurrentModificationException.");
} catch (ConcurrentModificationException e) {
return;
}
}
use of java.util.ConcurrentModificationException in project robovm by robovm.
the class ConcurrentModTest method testGet.
/*
* Test method for 'java.util.AbstractList.subList(int, int)'
*/
public void testGet() {
AbstractList al = new ArrayList();
Double one = new Double(1.0);
Double two = new Double(2.0);
Double three = new Double(3.0);
Double four = new Double(4.0);
al.add(one);
al.add(two);
al.add(three);
al.add(four);
List sub = al.subList(1, 3);
assertEquals(2, sub.size());
// the sub.get(1) is 3.0
assertTrue(((Double) sub.get(1)).doubleValue() <= 3.0);
assertTrue(((Double) sub.get(1)).doubleValue() > 2.0);
// remove the 2.0
al.remove(1);
try {
// illegal call the subList's method get(int).
sub.get(1);
fail("It should throws ConcurrentModificationException.");
} catch (ConcurrentModificationException e) {
return;
}
try {
al.get(-1);
fail("IndexOutOfBoundsException expected");
} catch (IndexOutOfBoundsException ee) {
//expected
}
try {
al.get(al.size() + 1);
fail("IndexOutOfBoundsException expected");
} catch (IndexOutOfBoundsException ee) {
//expected
}
}
use of java.util.ConcurrentModificationException in project robovm by robovm.
the class ConcurrentModTest method testAdd.
/*
* Test method for 'java.util.AbstractList.subList(int, int)'
*/
public void testAdd() {
AbstractList al = new ArrayList();
Double one = new Double(1.0);
Double two = new Double(2.0);
Double three = new Double(3.0);
Double four = new Double(4.0);
al.add(one);
al.add(two);
al.add(three);
al.add(four);
List sub = al.subList(1, 3);
assertEquals(2, sub.size());
// the sub.get(1) is 3.0
assertTrue(((Double) sub.get(1)).doubleValue() <= 3.0);
assertTrue(((Double) sub.get(1)).doubleValue() > 2.0);
// remove the 2.0
al.remove(1);
try {
// illegal call the subList's method Add(int,Object).
sub.add(1, two);
fail("It should throws ConcurrentModificationException.");
} catch (ConcurrentModificationException e) {
return;
}
}
Aggregations