Search in sources :

Example 6 with ConcurrentModificationException

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;
}
Also used : MappedField(org.mongodb.morphia.mapping.MappedField) ConcurrentModificationException(java.util.ConcurrentModificationException) WriteResult(com.mongodb.WriteResult) Version(org.mongodb.morphia.annotations.Version) UpdateResults(org.mongodb.morphia.query.UpdateResults) DBCollectionUpdateOptions(com.mongodb.client.model.DBCollectionUpdateOptions)

Example 7 with ConcurrentModificationException

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;
    }
}
Also used : ConcurrentModificationException(java.util.ConcurrentModificationException)

Example 8 with ConcurrentModificationException

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;
    }
}
Also used : AbstractList(java.util.AbstractList) ConcurrentModificationException(java.util.ConcurrentModificationException) ArrayList(java.util.ArrayList) List(java.util.List) AbstractList(java.util.AbstractList) ArrayList(java.util.ArrayList)

Example 9 with ConcurrentModificationException

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
    }
}
Also used : AbstractList(java.util.AbstractList) ConcurrentModificationException(java.util.ConcurrentModificationException) ArrayList(java.util.ArrayList) List(java.util.List) AbstractList(java.util.AbstractList) ArrayList(java.util.ArrayList)

Example 10 with ConcurrentModificationException

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;
    }
}
Also used : AbstractList(java.util.AbstractList) ConcurrentModificationException(java.util.ConcurrentModificationException) ArrayList(java.util.ArrayList) List(java.util.List) AbstractList(java.util.AbstractList) ArrayList(java.util.ArrayList)

Aggregations

ConcurrentModificationException (java.util.ConcurrentModificationException)89 Iterator (java.util.Iterator)24 HashSet (java.util.HashSet)19 Set (java.util.Set)18 ResultSet (java.sql.ResultSet)16 ArrayList (java.util.ArrayList)12 IOException (java.io.IOException)11 HashMap (java.util.HashMap)9 GameLocal (org.apache.openejb.test.entity.cmr.manytomany.GameLocal)8 PlatformLocal (org.apache.openejb.test.entity.cmr.manytomany.PlatformLocal)8 ArtistLocal (org.apache.openejb.test.entity.cmr.onetomany.ArtistLocal)8 SongLocal (org.apache.openejb.test.entity.cmr.onetomany.SongLocal)8 List (java.util.List)7 Test (org.junit.Test)7 Map (java.util.Map)6 AbstractList (java.util.AbstractList)5 NoSuchElementException (java.util.NoSuchElementException)5 Collection (java.util.Collection)4 CountDownLatch (java.util.concurrent.CountDownLatch)4 MultiMapRecord (com.hazelcast.multimap.impl.MultiMapRecord)3