Search in sources :

Example 1 with ListAddAtOperation

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

the class Stack method push.

/**
 * Method to push an element onto the stack and return it.
 * @param element The element to push onto the stack.
 * @return The element that was pushed onto the Stack
 */
public E push(E element) {
    // Reject inappropriate elements
    if (!allowNulls && element == null) {
        throw new NullPointerException("Nulls not allowed for collection at field " + ownerMmd.getName() + " but element is null");
    }
    if (useCache) {
        loadFromStore();
    }
    if (backingStore != null) {
        if (SCOUtils.useQueuedUpdate(ownerOP)) {
            ownerOP.getExecutionContext().addOperationToQueue(new ListAddAtOperation(ownerOP, backingStore, 0, element));
        } else {
            backingStore.add(ownerOP, element, 0, useCache ? delegate.size() : -1);
        }
    }
    // Only make it dirty after adding the element(s) to the datastore so we give it time
    // to be inserted - otherwise jdoPreStore on this object would have been called before completing the addition
    makeDirty();
    delegate.add(0, element);
    if (ownerOP != null && !ownerOP.getExecutionContext().getTransaction().isActive()) {
        ownerOP.getExecutionContext().processNontransactionalUpdate();
    }
    return element;
}
Also used : ListAddAtOperation(org.datanucleus.flush.ListAddAtOperation)

Example 2 with ListAddAtOperation

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

the class Stack method addAll.

/**
 * Method to add a Collection to a position in the Stack
 * @param index Position to insert the collection.
 * @param elements The collection
 * @return Whether it was added ok.
 */
public synchronized boolean addAll(int index, Collection elements) {
    if (useCache) {
        loadFromStore();
    }
    boolean backingSuccess = true;
    if (backingStore != null) {
        if (SCOUtils.useQueuedUpdate(ownerOP)) {
            int pos = index;
            for (Object element : elements) {
                ownerOP.getExecutionContext().addOperationToQueue(new ListAddAtOperation(ownerOP, backingStore, pos++, element));
            }
        } else {
            try {
                backingSuccess = backingStore.addAll(ownerOP, elements, index, useCache ? delegate.size() : -1);
            } catch (NucleusDataStoreException dse) {
                throw new IllegalArgumentException(Localiser.msg("023013", "addAll", ownerMmd.getName(), dse), dse);
            }
        }
    }
    // Only make it dirty after adding the element(s) to the datastore so we give it time
    // to be inserted - otherwise jdoPreStore on this object would have been called before completing the addition
    makeDirty();
    boolean delegateSuccess = delegate.addAll(index, elements);
    if (ownerOP != null && !ownerOP.getExecutionContext().getTransaction().isActive()) {
        ownerOP.getExecutionContext().processNontransactionalUpdate();
    }
    return backingStore != null ? backingSuccess : delegateSuccess;
}
Also used : NucleusDataStoreException(org.datanucleus.exceptions.NucleusDataStoreException) ListAddAtOperation(org.datanucleus.flush.ListAddAtOperation)

Example 3 with ListAddAtOperation

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

the class LinkedList method add.

// ---------------------------- Mutator methods ----------------------------
/**
 * Method to add an element to a position in the LinkedList.
 * @param index The position
 * @param element The new element
 */
public void add(int index, E element) {
    // Reject inappropriate elements
    if (!allowNulls && element == null) {
        throw new NullPointerException("Nulls not allowed for collection at field " + ownerMmd.getName() + " but element is null");
    }
    if (useCache) {
        loadFromStore();
    }
    if (backingStore != null) {
        if (SCOUtils.useQueuedUpdate(ownerOP)) {
            ownerOP.getExecutionContext().addOperationToQueue(new ListAddAtOperation(ownerOP, backingStore, index, element));
        } else {
            try {
                backingStore.add(ownerOP, element, index, useCache ? delegate.size() : -1);
            } catch (NucleusDataStoreException dse) {
                NucleusLogger.PERSISTENCE.warn(Localiser.msg("023013", "add", ownerMmd.getName(), dse));
            }
        }
    }
    // Only make it dirty after adding the element(s) to the datastore so we give it time
    // to be inserted - otherwise jdoPreStore on this object would have been called before completing the addition
    makeDirty();
    delegate.add(index, element);
    if (ownerOP != null && !ownerOP.getExecutionContext().getTransaction().isActive()) {
        ownerOP.getExecutionContext().processNontransactionalUpdate();
    }
}
Also used : NucleusDataStoreException(org.datanucleus.exceptions.NucleusDataStoreException) ListAddAtOperation(org.datanucleus.flush.ListAddAtOperation)

Example 4 with ListAddAtOperation

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

the class LinkedList method addAll.

/**
 * Method to add a Collection to a position in the LinkedList.
 * @param index Position to insert the collection.
 * @param elements The collection
 * @return Whether it was added ok.
 */
public boolean addAll(int index, Collection elements) {
    if (useCache) {
        loadFromStore();
    }
    boolean backingSuccess = true;
    if (backingStore != null) {
        if (SCOUtils.useQueuedUpdate(ownerOP)) {
            int pos = index;
            for (Object element : elements) {
                ownerOP.getExecutionContext().addOperationToQueue(new ListAddAtOperation(ownerOP, backingStore, pos++, element));
            }
        } else {
            try {
                backingSuccess = backingStore.addAll(ownerOP, elements, index, useCache ? delegate.size() : -1);
            } catch (NucleusDataStoreException dse) {
                throw new IllegalArgumentException(Localiser.msg("023013", "addAll", ownerMmd.getName(), dse), dse);
            }
        }
    }
    // Only make it dirty after adding the element(s) to the datastore so we give it time
    // to be inserted - otherwise jdoPreStore on this object would have been called before completing the addition
    makeDirty();
    boolean delegateSuccess = delegate.addAll(index, elements);
    if (ownerOP != null && !ownerOP.getExecutionContext().getTransaction().isActive()) {
        ownerOP.getExecutionContext().processNontransactionalUpdate();
    }
    return backingStore != null ? backingSuccess : delegateSuccess;
}
Also used : NucleusDataStoreException(org.datanucleus.exceptions.NucleusDataStoreException) ListAddAtOperation(org.datanucleus.flush.ListAddAtOperation)

Example 5 with ListAddAtOperation

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

the class List method addAll.

/**
 * Method to add a collection of elements.
 * @param elements The collection of elements to add.
 * @param index The position to add them
 * @return Whether they were added successfully.
 */
public boolean addAll(int index, Collection elements) {
    if (useCache) {
        loadFromStore();
    }
    boolean backingSuccess = true;
    if (backingStore != null) {
        if (SCOUtils.useQueuedUpdate(ownerOP)) {
            int pos = index;
            for (Object element : elements) {
                ownerOP.getExecutionContext().addOperationToQueue(new ListAddAtOperation(ownerOP, backingStore, pos++, element));
            }
        } else {
            try {
                backingSuccess = backingStore.addAll(ownerOP, elements, index, useCache ? delegate.size() : -1);
            } catch (NucleusDataStoreException dse) {
                throw new IllegalArgumentException(Localiser.msg("023013", "addAll", ownerMmd.getName(), dse), dse);
            }
        }
    }
    // Only make it dirty after adding the element(s) to the datastore so we give it time
    // to be inserted - otherwise jdoPreStore on this object would have been called before completing the addition
    makeDirty();
    boolean delegateSuccess = delegate.addAll(index, elements);
    if (ownerOP != null && !ownerOP.getExecutionContext().getTransaction().isActive()) {
        ownerOP.getExecutionContext().processNontransactionalUpdate();
    }
    return backingStore != null ? backingSuccess : delegateSuccess;
}
Also used : NucleusDataStoreException(org.datanucleus.exceptions.NucleusDataStoreException) ListAddAtOperation(org.datanucleus.flush.ListAddAtOperation)

Aggregations

ListAddAtOperation (org.datanucleus.flush.ListAddAtOperation)21 NucleusDataStoreException (org.datanucleus.exceptions.NucleusDataStoreException)10 Iterator (java.util.Iterator)5 ListIterator (java.util.ListIterator)5 RelationshipManager (org.datanucleus.state.RelationshipManager)5 SCOListIterator (org.datanucleus.store.types.SCOListIterator)5