Search in sources :

Example 46 with CollectionRemoveOperation

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

the class LinkedHashSet method removeAll.

/**
 * Method to remove all elements from the collection from the LinkedHashSet.
 * @param elements The collection of elements to remove
 * @return Whether it was removed ok.
 */
public boolean removeAll(java.util.Collection elements) {
    if (elements == null) {
        throw new NullPointerException();
    } else if (elements.isEmpty()) {
        return true;
    }
    boolean success = delegate.removeAll(elements);
    if (ownerOP != null) {
        if (ownerOP.getExecutionContext().getManageRelations()) {
            // Relationship management
            Iterator iter = elements.iterator();
            RelationshipManager relMgr = ownerOP.getExecutionContext().getRelationshipManager(ownerOP);
            while (iter.hasNext()) {
                relMgr.relationRemove(ownerMmd.getAbsoluteFieldNumber(), iter.next());
            }
        }
        // Cascade delete
        if (SCOUtils.useQueuedUpdate(ownerOP)) {
            // Queue the cascade delete
            Iterator iter = elements.iterator();
            while (iter.hasNext()) {
                ownerOP.getExecutionContext().addOperationToQueue(new CollectionRemoveOperation(ownerOP, ownerMmd.getAbsoluteFieldNumber(), iter.next(), true));
            }
        } else if (SCOUtils.hasDependentElement(ownerMmd)) {
            // Perform the cascade delete
            Iterator iter = elements.iterator();
            while (iter.hasNext()) {
                ownerOP.getExecutionContext().deleteObjectInternal(iter.next());
            }
        }
    }
    if (success) {
        makeDirty();
        if (ownerOP != null && !ownerOP.getExecutionContext().getTransaction().isActive()) {
            ownerOP.getExecutionContext().processNontransactionalUpdate();
        }
    }
    return success;
}
Also used : RelationshipManager(org.datanucleus.state.RelationshipManager) Iterator(java.util.Iterator) SCOCollectionIterator(org.datanucleus.store.types.SCOCollectionIterator) CollectionRemoveOperation(org.datanucleus.flush.CollectionRemoveOperation)

Example 47 with CollectionRemoveOperation

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

the class LinkedHashSet method retainAll.

/**
 * Method to retain a Collection of elements (and remove all others).
 * @param c The collection to retain
 * @return Whether they were retained successfully.
 */
public boolean retainAll(java.util.Collection c) {
    if (c == null) {
        throw new NullPointerException("Input collection was null");
    }
    Collection collToRemove = new java.util.LinkedHashSet();
    for (Object o : delegate) {
        if (!c.contains(o)) {
            collToRemove.add(o);
        }
    }
    boolean success = delegate.retainAll(c);
    if (success) {
        makeDirty();
        if (SCOUtils.useQueuedUpdate(ownerOP)) {
            // Queue any cascade delete
            Iterator iter = collToRemove.iterator();
            while (iter.hasNext()) {
                ownerOP.getExecutionContext().addOperationToQueue(new CollectionRemoveOperation(ownerOP, ownerMmd.getAbsoluteFieldNumber(), iter.next(), true));
            }
        } else if (SCOUtils.hasDependentElement(ownerMmd)) {
            // Perform the cascade delete
            Iterator iter = collToRemove.iterator();
            while (iter.hasNext()) {
                ownerOP.getExecutionContext().deleteObjectInternal(iter.next());
            }
        }
        if (ownerOP != null && !ownerOP.getExecutionContext().getTransaction().isActive()) {
            ownerOP.getExecutionContext().processNontransactionalUpdate();
        }
    }
    return success;
}
Also used : Iterator(java.util.Iterator) SCOCollectionIterator(org.datanucleus.store.types.SCOCollectionIterator) Collection(java.util.Collection) SCOCollection(org.datanucleus.store.types.SCOCollection) CollectionRemoveOperation(org.datanucleus.flush.CollectionRemoveOperation)

Example 48 with CollectionRemoveOperation

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

the class LinkedList method removeAll.

/**
 * Method to remove a Collection from the LinkedList.
 * @param elements The collection
 * @return Whether it was removed ok.
 */
public boolean removeAll(Collection elements) {
    if (elements == null) {
        throw new NullPointerException();
    } else if (elements.isEmpty()) {
        return true;
    }
    boolean success = delegate.removeAll(elements);
    if (ownerOP != null) {
        if (ownerOP.getExecutionContext().getManageRelations()) {
            // Relationship management
            Iterator iter = elements.iterator();
            RelationshipManager relMgr = ownerOP.getExecutionContext().getRelationshipManager(ownerOP);
            while (iter.hasNext()) {
                relMgr.relationRemove(ownerMmd.getAbsoluteFieldNumber(), iter.next());
            }
        }
        // Cascade delete
        if (SCOUtils.useQueuedUpdate(ownerOP)) {
            Iterator iter = elements.iterator();
            while (iter.hasNext()) {
                ownerOP.getExecutionContext().addOperationToQueue(new CollectionRemoveOperation(ownerOP, ownerMmd.getAbsoluteFieldNumber(), iter.next(), true));
            }
        } else if (SCOUtils.hasDependentElement(ownerMmd)) {
            Iterator iter = elements.iterator();
            while (iter.hasNext()) {
                ownerOP.getExecutionContext().deleteObjectInternal(iter.next());
            }
        }
    }
    if (success) {
        makeDirty();
        if (ownerOP != null && !ownerOP.getExecutionContext().getTransaction().isActive()) {
            ownerOP.getExecutionContext().processNontransactionalUpdate();
        }
    }
    return success;
}
Also used : RelationshipManager(org.datanucleus.state.RelationshipManager) Iterator(java.util.Iterator) ListIterator(java.util.ListIterator) SCOListIterator(org.datanucleus.store.types.SCOListIterator) CollectionRemoveOperation(org.datanucleus.flush.CollectionRemoveOperation)

Example 49 with CollectionRemoveOperation

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

the class List method removeAll.

/**
 * Method to remove a collection of elements from the List.
 * @param elements Collection of elements to remove
 * @return Whether it was successful.
 */
public boolean removeAll(Collection elements) {
    if (elements == null) {
        throw new NullPointerException();
    } else if (elements.isEmpty()) {
        return true;
    }
    boolean success = delegate.removeAll(elements);
    if (ownerOP != null) {
        if (ownerOP.getExecutionContext().getManageRelations()) {
            // Relationship management
            Iterator iter = elements.iterator();
            RelationshipManager relMgr = ownerOP.getExecutionContext().getRelationshipManager(ownerOP);
            while (iter.hasNext()) {
                relMgr.relationRemove(ownerMmd.getAbsoluteFieldNumber(), iter.next());
            }
        }
        // Cascade delete
        if (SCOUtils.useQueuedUpdate(ownerOP)) {
            Iterator iter = elements.iterator();
            while (iter.hasNext()) {
                ownerOP.getExecutionContext().addOperationToQueue(new CollectionRemoveOperation(ownerOP, ownerMmd.getAbsoluteFieldNumber(), iter.next(), true));
            }
        } else if (SCOUtils.hasDependentElement(ownerMmd)) {
            Iterator iter = elements.iterator();
            while (iter.hasNext()) {
                ownerOP.getExecutionContext().deleteObjectInternal(iter.next());
            }
        }
    }
    if (success) {
        makeDirty();
        if (ownerOP != null && !ownerOP.getExecutionContext().getTransaction().isActive()) {
            ownerOP.getExecutionContext().processNontransactionalUpdate();
        }
    }
    return success;
}
Also used : RelationshipManager(org.datanucleus.state.RelationshipManager) Iterator(java.util.Iterator) ListIterator(java.util.ListIterator) SCOListIterator(org.datanucleus.store.types.SCOListIterator) CollectionRemoveOperation(org.datanucleus.flush.CollectionRemoveOperation)

Example 50 with CollectionRemoveOperation

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

the class List method clear.

/**
 * Method to clear the List
 */
public void clear() {
    if (ownerOP != null && ownerOP.getExecutionContext().getManageRelations()) {
        // Relationship management
        Iterator iter = delegate.iterator();
        RelationshipManager relMgr = ownerOP.getExecutionContext().getRelationshipManager(ownerOP);
        while (iter.hasNext()) {
            relMgr.relationRemove(ownerMmd.getAbsoluteFieldNumber(), iter.next());
        }
    }
    if (ownerOP != null && !delegate.isEmpty()) {
        // Cascade delete
        if (SCOUtils.useQueuedUpdate(ownerOP)) {
            java.util.List copy = new java.util.ArrayList(delegate);
            Iterator iter = copy.iterator();
            while (iter.hasNext()) {
                ownerOP.getExecutionContext().addOperationToQueue(new CollectionRemoveOperation(ownerOP, ownerMmd.getAbsoluteFieldNumber(), iter.next(), true));
            }
        } else if (SCOUtils.hasDependentElement(ownerMmd)) {
            java.util.List copy = new java.util.ArrayList(delegate);
            Iterator iter = copy.iterator();
            while (iter.hasNext()) {
                ownerOP.getExecutionContext().deleteObjectInternal(iter.next());
            }
        }
    }
    delegate.clear();
    makeDirty();
    if (ownerOP != null && !ownerOP.getExecutionContext().getTransaction().isActive()) {
        ownerOP.getExecutionContext().processNontransactionalUpdate();
    }
}
Also used : RelationshipManager(org.datanucleus.state.RelationshipManager) Iterator(java.util.Iterator) ListIterator(java.util.ListIterator) SCOListIterator(org.datanucleus.store.types.SCOListIterator) CollectionRemoveOperation(org.datanucleus.flush.CollectionRemoveOperation) SCOList(org.datanucleus.store.types.SCOList) AbstractList(java.util.AbstractList)

Aggregations

CollectionRemoveOperation (org.datanucleus.flush.CollectionRemoveOperation)56 Iterator (java.util.Iterator)36 RelationshipManager (org.datanucleus.state.RelationshipManager)28 NucleusDataStoreException (org.datanucleus.exceptions.NucleusDataStoreException)26 SCOCollectionIterator (org.datanucleus.store.types.SCOCollectionIterator)26 Collection (java.util.Collection)17 ListIterator (java.util.ListIterator)10 SCOCollection (org.datanucleus.store.types.SCOCollection)10 SCOListIterator (org.datanucleus.store.types.SCOListIterator)10 SCOList (org.datanucleus.store.types.SCOList)5 AbstractList (java.util.AbstractList)1