Search in sources :

Example 16 with RelationshipManager

use of org.datanucleus.state.RelationshipManager in project datanucleus-core by datanucleus.

the class Stack method removeAll.

/**
 * Method to remove a Collection of objects from the Stack
 * @param elements The Collection
 * @return Whether the collection of elements were removed
 */
public synchronized 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 17 with RelationshipManager

use of org.datanucleus.state.RelationshipManager in project datanucleus-core by datanucleus.

the class Stack method addAll.

/**
 * Method to add a Collection to the Stack
 * @param elements The collection
 * @return Whether it was added ok.
 */
public synchronized boolean addAll(Collection elements) {
    boolean success = delegate.addAll(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)) {
            for (Object element : elements) {
                ownerOP.getExecutionContext().addOperationToQueue(new CollectionAddOperation(ownerOP, ownerMmd.getAbsoluteFieldNumber(), element));
            }
        }
        makeDirty();
        if (ownerOP != null && !ownerOP.getExecutionContext().getTransaction().isActive()) {
            ownerOP.getExecutionContext().processNontransactionalUpdate();
        }
    }
    return success;
}
Also used : CollectionAddOperation(org.datanucleus.flush.CollectionAddOperation) RelationshipManager(org.datanucleus.state.RelationshipManager) Iterator(java.util.Iterator) ListIterator(java.util.ListIterator) SCOListIterator(org.datanucleus.store.types.SCOListIterator)

Example 18 with RelationshipManager

use of org.datanucleus.state.RelationshipManager in project datanucleus-core by datanucleus.

the class TreeSet method removeAll.

/**
 * Method to remove all elements from the collection from the TreeSet.
 * @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 19 with RelationshipManager

use of org.datanucleus.state.RelationshipManager in project datanucleus-core by datanucleus.

the class Vector method addAll.

/**
 * Method to add a Collection to the Vector.
 * @param elements The collection
 * @return Whether it was added ok.
 */
public synchronized boolean addAll(Collection elements) {
    boolean success = delegate.addAll(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)) {
            for (Object element : elements) {
                ownerOP.getExecutionContext().addOperationToQueue(new CollectionAddOperation(ownerOP, ownerMmd.getAbsoluteFieldNumber(), element));
            }
        }
        makeDirty();
        if (ownerOP != null && !ownerOP.getExecutionContext().getTransaction().isActive()) {
            ownerOP.getExecutionContext().processNontransactionalUpdate();
        }
    }
    return success;
}
Also used : CollectionAddOperation(org.datanucleus.flush.CollectionAddOperation) RelationshipManager(org.datanucleus.state.RelationshipManager) Iterator(java.util.Iterator) ListIterator(java.util.ListIterator) SCOListIterator(org.datanucleus.store.types.SCOListIterator)

Example 20 with RelationshipManager

use of org.datanucleus.state.RelationshipManager in project datanucleus-core by datanucleus.

the class Collection method removeAll.

/**
 * Method to remove a Collection of elements.
 * @param elements The collection to remove
 * @return Whether they were removed successfully.
 */
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)

Aggregations

RelationshipManager (org.datanucleus.state.RelationshipManager)47 Iterator (java.util.Iterator)44 CollectionRemoveOperation (org.datanucleus.flush.CollectionRemoveOperation)28 SCOCollectionIterator (org.datanucleus.store.types.SCOCollectionIterator)24 ListIterator (java.util.ListIterator)20 SCOListIterator (org.datanucleus.store.types.SCOListIterator)20 NucleusDataStoreException (org.datanucleus.exceptions.NucleusDataStoreException)12 CollectionAddOperation (org.datanucleus.flush.CollectionAddOperation)11 Collection (java.util.Collection)5 ListAddAtOperation (org.datanucleus.flush.ListAddAtOperation)5 SCOCollection (org.datanucleus.store.types.SCOCollection)5 SCOList (org.datanucleus.store.types.SCOList)5 ObjectProvider (org.datanucleus.state.ObjectProvider)2 AbstractList (java.util.AbstractList)1 Map (java.util.Map)1 ConcurrentHashMap (java.util.concurrent.ConcurrentHashMap)1 ExecutionContext (org.datanucleus.ExecutionContext)1 FetchPlan (org.datanucleus.FetchPlan)1 NucleusUserException (org.datanucleus.exceptions.NucleusUserException)1 AbstractClassMetaData (org.datanucleus.metadata.AbstractClassMetaData)1