Search in sources :

Example 11 with ListRemoveAtOperation

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

the class ArrayList 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) {
    makeDirty();
    if (useCache) {
        loadFromStore();
    }
    int size = useCache ? delegate.size() : -1;
    E delegateObject = useCache ? delegate.remove(index) : null;
    E backingObject = null;
    if (backingStore != null) {
        if (SCOUtils.useQueuedUpdate(ownerOP)) {
            backingObject = delegateObject;
            ownerOP.getExecutionContext().addOperationToQueue(new ListRemoveAtOperation(ownerOP, backingStore, index));
        } else {
            try {
                backingObject = backingStore.remove(ownerOP, index, size);
            } catch (NucleusDataStoreException dse) {
                NucleusLogger.PERSISTENCE.warn(Localiser.msg("023013", "remove", ownerMmd.getName(), dse));
                backingObject = null;
            }
        }
    }
    if (ownerOP != null && !ownerOP.getExecutionContext().getTransaction().isActive()) {
        ownerOP.getExecutionContext().processNontransactionalUpdate();
    }
    return (backingStore != null ? backingObject : delegateObject);
}
Also used : NucleusDataStoreException(org.datanucleus.exceptions.NucleusDataStoreException) ListRemoveAtOperation(org.datanucleus.flush.ListRemoveAtOperation)

Example 12 with ListRemoveAtOperation

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

the class ArrayList 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 13 with ListRemoveAtOperation

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

the class ArrayList 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 14 with ListRemoveAtOperation

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

the class LinkedList method remove.

/**
 * Method to remove an element from the LinkedList.
 * @param index The element position.
 * @return The object that was removed
 */
public E remove(int index) {
    makeDirty();
    if (useCache) {
        loadFromStore();
    }
    int size = useCache ? delegate.size() : -1;
    E delegateObject = useCache ? delegate.remove(index) : null;
    E backingObject = null;
    if (backingStore != null) {
        if (SCOUtils.useQueuedUpdate(ownerOP)) {
            backingObject = delegateObject;
            ownerOP.getExecutionContext().addOperationToQueue(new ListRemoveAtOperation(ownerOP, backingStore, index));
        } else {
            try {
                backingObject = backingStore.remove(ownerOP, index, size);
            } catch (NucleusDataStoreException dse) {
                NucleusLogger.PERSISTENCE.warn(Localiser.msg("023013", "remove", ownerMmd.getName(), dse));
                backingObject = null;
            }
        }
    }
    if (ownerOP != null && !ownerOP.getExecutionContext().getTransaction().isActive()) {
        ownerOP.getExecutionContext().processNontransactionalUpdate();
    }
    return backingStore != null ? backingObject : delegateObject;
}
Also used : NucleusDataStoreException(org.datanucleus.exceptions.NucleusDataStoreException) ListRemoveAtOperation(org.datanucleus.flush.ListRemoveAtOperation)

Example 15 with ListRemoveAtOperation

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

the class Queue method poll.

/**
 * Method to poll the next element in the Queue.
 * @return The element (now removed)
 */
public E poll() {
    makeDirty();
    if (useCache) {
        loadFromStore();
    }
    int size = useCache ? delegate.size() : -1;
    E delegateObject = delegate.poll();
    E backingObject = null;
    if (backingStore != null) {
        if (SCOUtils.useQueuedUpdate(ownerOP)) {
            ownerOP.getExecutionContext().addOperationToQueue(new ListRemoveAtOperation(ownerOP, backingStore, 0));
        } else {
            try {
                backingObject = backingStore.remove(ownerOP, 0, size);
            } catch (NucleusDataStoreException dse) {
                backingObject = null;
            }
        }
    }
    if (ownerOP != null && !ownerOP.getExecutionContext().getTransaction().isActive()) {
        ownerOP.getExecutionContext().processNontransactionalUpdate();
    }
    return backingStore != null ? backingObject : delegateObject;
}
Also used : NucleusDataStoreException(org.datanucleus.exceptions.NucleusDataStoreException) ListRemoveAtOperation(org.datanucleus.flush.ListRemoveAtOperation)

Aggregations

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