Search in sources :

Example 1 with ListRemoveAtOperation

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

the class Stack method pop.

/**
 * Method to remove the top element in the stack and return it.
 * @return The top element that was in the Stack (now removed).
 */
public synchronized E pop() {
    makeDirty();
    if (useCache) {
        loadFromStore();
    }
    if (backingStore != null) {
        if (SCOUtils.useQueuedUpdate(ownerOP)) {
            ownerOP.getExecutionContext().addOperationToQueue(new ListRemoveAtOperation(ownerOP, backingStore, 0));
        } else {
            backingStore.remove(ownerOP, 0, useCache ? delegate.size() : -1);
        }
    }
    E removed = delegate.remove(0);
    if (ownerOP != null && !ownerOP.getExecutionContext().getTransaction().isActive()) {
        ownerOP.getExecutionContext().processNontransactionalUpdate();
    }
    return removed;
}
Also used : ListRemoveAtOperation(org.datanucleus.flush.ListRemoveAtOperation)

Example 2 with ListRemoveAtOperation

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

the class Stack method remove.

/**
 * Method to remove an element from the Stack
 * @param index The element position.
 * @return The object that was removed
 */
public synchronized 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 3 with ListRemoveAtOperation

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

the class Vector method remove.

/**
 * Method to remove an element from the Vector.
 * @param index The element position.
 * @return The object that was removed
 */
public synchronized 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 4 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) {
    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 5 with ListRemoveAtOperation

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

the class PriorityQueue 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