Search in sources :

Example 16 with ListRemoveAtOperation

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

the class Stack method set.

/**
 * Wrapper addition that allows turning off of the dependent-field checks
 * when doing the position setting. This means that we can prevent the deletion of
 * the object that was previously in that position. This particular feature is used
 * when attaching a list field and where some elements have changed positions.
 * @param index The position
 * @param element The new element
 * @return The element previously at that position
 */
public E set(int index, E element, boolean allowDependentField) {
    E prevElement = delegate.set(index, element);
    if (ownerOP != null && allowDependentField && !delegate.contains(prevElement)) {
        // Cascade delete
        if (SCOUtils.useQueuedUpdate(ownerOP)) {
            ownerOP.getExecutionContext().addOperationToQueue(new ListRemoveAtOperation(ownerOP, ownerMmd.getAbsoluteFieldNumber(), index, prevElement));
        } else if (SCOUtils.hasDependentElement(ownerMmd)) {
            ownerOP.getExecutionContext().deleteObjectInternal(prevElement);
        }
    }
    makeDirty();
    if (ownerOP != null && !ownerOP.getExecutionContext().getTransaction().isActive()) {
        ownerOP.getExecutionContext().processNontransactionalUpdate();
    }
    return prevElement;
}
Also used : ListRemoveAtOperation(org.datanucleus.flush.ListRemoveAtOperation)

Example 17 with ListRemoveAtOperation

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

the class List method remove.

/**
 * Method to remove an element from the ArrayList.
 * @param index The element position.
 * @return The object that was removed
 */
public E remove(int index) {
    E element = delegate.remove(index);
    if (ownerOP != null && ownerOP.getExecutionContext().getManageRelations()) {
        ownerOP.getExecutionContext().getRelationshipManager(ownerOP).relationRemove(ownerMmd.getAbsoluteFieldNumber(), element);
    }
    if (ownerOP != null) {
        // Cascade delete
        if (SCOUtils.useQueuedUpdate(ownerOP)) {
            ownerOP.getExecutionContext().addOperationToQueue(new ListRemoveAtOperation(ownerOP, ownerMmd.getAbsoluteFieldNumber(), index, element));
        } else if (SCOUtils.hasDependentElement(ownerMmd)) {
            ownerOP.getExecutionContext().deleteObjectInternal(element);
        }
    }
    makeDirty();
    if (ownerOP != null && !ownerOP.getExecutionContext().getTransaction().isActive()) {
        ownerOP.getExecutionContext().processNontransactionalUpdate();
    }
    return element;
}
Also used : ListRemoveAtOperation(org.datanucleus.flush.ListRemoveAtOperation)

Example 18 with ListRemoveAtOperation

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

the class List method set.

/**
 * wrapper addition that allows turning off of the dependent-field checks
 * when doing the position setting. This means that we can prevent the deletion of
 * the object that was previously in that position. This particular feature is used
 * when attaching a list field and where some elements have changed positions.
 * @param index The position
 * @param element The new element
 * @return The element previously at that position
 */
public E set(int index, E element, boolean allowDependentField) {
    E prevElement = delegate.set(index, element);
    if (ownerOP != null && allowDependentField && !delegate.contains(prevElement)) {
        // Cascade delete
        if (SCOUtils.useQueuedUpdate(ownerOP)) {
            ownerOP.getExecutionContext().addOperationToQueue(new ListRemoveAtOperation(ownerOP, ownerMmd.getAbsoluteFieldNumber(), index, prevElement));
        } else if (SCOUtils.hasDependentElement(ownerMmd)) {
            ownerOP.getExecutionContext().deleteObjectInternal(prevElement);
        }
    }
    makeDirty();
    if (ownerOP != null && !ownerOP.getExecutionContext().getTransaction().isActive()) {
        ownerOP.getExecutionContext().processNontransactionalUpdate();
    }
    return prevElement;
}
Also used : ListRemoveAtOperation(org.datanucleus.flush.ListRemoveAtOperation)

Aggregations

ListRemoveAtOperation (org.datanucleus.flush.ListRemoveAtOperation)18 NucleusDataStoreException (org.datanucleus.exceptions.NucleusDataStoreException)7