Search in sources :

Example 21 with ListAddAtOperation

use of org.datanucleus.flush.ListAddAtOperation in project datanucleus-core by datanucleus.

the class ArrayList method addAll.

/**
 * Method to add a Collection to a position in the ArrayList.
 * @param index Position to insert the collection.
 * @param elements The collection
 * @return Whether it was added ok.
 */
public boolean addAll(int index, Collection elements) {
    boolean success = delegate.addAll(index, elements);
    if (ownerOP != null && ownerOP.getExecutionContext().getManageRelations()) {
        // Relationship management
        Iterator iter = elements.iterator();
        RelationshipManager relMgr = ownerOP.getExecutionContext().getRelationshipManager(ownerOP);
        while (iter.hasNext()) {
            relMgr.relationAdd(ownerMmd.getAbsoluteFieldNumber(), iter.next());
        }
    }
    if (success) {
        if (SCOUtils.useQueuedUpdate(ownerOP)) {
            int pos = index;
            for (Object element : elements) {
                ownerOP.getExecutionContext().addOperationToQueue(new ListAddAtOperation(ownerOP, ownerMmd.getAbsoluteFieldNumber(), pos++, element));
            }
        }
        makeDirty();
        if (ownerOP != null && !ownerOP.getExecutionContext().getTransaction().isActive()) {
            ownerOP.getExecutionContext().processNontransactionalUpdate();
        }
    }
    return success;
}
Also used : RelationshipManager(org.datanucleus.state.RelationshipManager) ListAddAtOperation(org.datanucleus.flush.ListAddAtOperation) Iterator(java.util.Iterator) ListIterator(java.util.ListIterator) SCOListIterator(org.datanucleus.store.types.SCOListIterator)

Aggregations

ListAddAtOperation (org.datanucleus.flush.ListAddAtOperation)21 NucleusDataStoreException (org.datanucleus.exceptions.NucleusDataStoreException)10 Iterator (java.util.Iterator)5 ListIterator (java.util.ListIterator)5 RelationshipManager (org.datanucleus.state.RelationshipManager)5 SCOListIterator (org.datanucleus.store.types.SCOListIterator)5