Search in sources :

Example 21 with CollectionAddOperation

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

the class Collection method add.

// ----------------------------- Mutator methods ---------------------------
/**
 * Method to add an element to the Collection.
 * @param element The element to add
 * @return Whether it was added successfully.
 */
public boolean add(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 (!List.class.isAssignableFrom(delegate.getClass()) && contains(element)) {
        return false;
    }
    if (ownerOP != null && ownerOP.getExecutionContext().getManageRelations() && !initialising) {
        // Relationship management
        ownerOP.getExecutionContext().getRelationshipManager(ownerOP).relationAdd(ownerMmd.getAbsoluteFieldNumber(), element);
    }
    boolean backingSuccess = true;
    if (backingStore != null) {
        if (SCOUtils.useQueuedUpdate(ownerOP)) {
            ownerOP.getExecutionContext().addOperationToQueue(new CollectionAddOperation(ownerOP, backingStore, element));
        } else {
            try {
                backingSuccess = backingStore.add(ownerOP, element, useCache ? delegate.size() : -1);
            } catch (NucleusDataStoreException dse) {
                throw new IllegalArgumentException(Localiser.msg("023013", "add", 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.add(element);
    if (ownerOP != null && !ownerOP.getExecutionContext().getTransaction().isActive()) {
        ownerOP.getExecutionContext().processNontransactionalUpdate();
    }
    return backingStore != null ? backingSuccess : delegateSuccess;
}
Also used : CollectionAddOperation(org.datanucleus.flush.CollectionAddOperation) NucleusDataStoreException(org.datanucleus.exceptions.NucleusDataStoreException)

Example 22 with CollectionAddOperation

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

the class Collection method addAll.

/**
 * Method to add a collection of elements.
 * @param c The collection of elements to add.
 * @return Whether they were added successfully.
 */
public boolean addAll(java.util.Collection c) {
    if (useCache) {
        loadFromStore();
    }
    if (ownerOP != null && ownerOP.getExecutionContext().getManageRelations() && !initialising) {
        // Relationship management
        Iterator iter = c.iterator();
        RelationshipManager relMgr = ownerOP.getExecutionContext().getRelationshipManager(ownerOP);
        while (iter.hasNext()) {
            relMgr.relationAdd(ownerMmd.getAbsoluteFieldNumber(), iter.next());
        }
    }
    boolean backingSuccess = true;
    if (backingStore != null) {
        if (SCOUtils.useQueuedUpdate(ownerOP)) {
            for (Object element : c) {
                ownerOP.getExecutionContext().addOperationToQueue(new CollectionAddOperation(ownerOP, backingStore, element));
            }
        } else {
            try {
                backingSuccess = backingStore.addAll(ownerOP, c, 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(c);
    if (ownerOP != null && !ownerOP.getExecutionContext().getTransaction().isActive()) {
        ownerOP.getExecutionContext().processNontransactionalUpdate();
    }
    return backingStore != null ? backingSuccess : delegateSuccess;
}
Also used : CollectionAddOperation(org.datanucleus.flush.CollectionAddOperation) NucleusDataStoreException(org.datanucleus.exceptions.NucleusDataStoreException) RelationshipManager(org.datanucleus.state.RelationshipManager) Iterator(java.util.Iterator) SCOCollectionIterator(org.datanucleus.store.types.SCOCollectionIterator)

Example 23 with CollectionAddOperation

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

the class HashSet method add.

// ------------------------------ Mutator methods --------------------------
/**
 * Method to add an element to the HashSet.
 * @param element The new element
 * @return Whether it was added ok.
 */
public boolean add(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 (contains(element)) {
        return false;
    }
    if (ownerOP != null && ownerOP.getExecutionContext().getManageRelations() && !initialising) {
        // Relationship management
        ownerOP.getExecutionContext().getRelationshipManager(ownerOP).relationAdd(ownerMmd.getAbsoluteFieldNumber(), element);
    }
    boolean backingSuccess = true;
    if (backingStore != null) {
        if (SCOUtils.useQueuedUpdate(ownerOP)) {
            ownerOP.getExecutionContext().addOperationToQueue(new CollectionAddOperation(ownerOP, backingStore, element));
        } else {
            try {
                backingSuccess = backingStore.add(ownerOP, element, useCache ? delegate.size() : -1);
            } catch (NucleusDataStoreException dse) {
                throw new IllegalArgumentException(Localiser.msg("023013", "add", 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.add(element);
    if (ownerOP != null && !ownerOP.getExecutionContext().getTransaction().isActive()) {
        ownerOP.getExecutionContext().processNontransactionalUpdate();
    }
    return backingStore != null ? backingSuccess : delegateSuccess;
}
Also used : CollectionAddOperation(org.datanucleus.flush.CollectionAddOperation) NucleusDataStoreException(org.datanucleus.exceptions.NucleusDataStoreException)

Example 24 with CollectionAddOperation

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

the class HashSet method addAll.

/**
 * Method to add a collection to the HashSet.
 * @param c The collection
 * @return Whether it was added ok.
 */
public boolean addAll(Collection c) {
    if (useCache) {
        loadFromStore();
    }
    if (ownerOP != null && ownerOP.getExecutionContext().getManageRelations() && !initialising) {
        // Relationship management
        Iterator iter = c.iterator();
        RelationshipManager relMgr = ownerOP.getExecutionContext().getRelationshipManager(ownerOP);
        while (iter.hasNext()) {
            relMgr.relationAdd(ownerMmd.getAbsoluteFieldNumber(), iter.next());
        }
    }
    boolean backingSuccess = true;
    if (backingStore != null) {
        if (SCOUtils.useQueuedUpdate(ownerOP)) {
            for (Object element : c) {
                ownerOP.getExecutionContext().addOperationToQueue(new CollectionAddOperation(ownerOP, backingStore, element));
            }
        } else {
            try {
                backingSuccess = backingStore.addAll(ownerOP, c, 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(c);
    if (ownerOP != null && !ownerOP.getExecutionContext().getTransaction().isActive()) {
        ownerOP.getExecutionContext().processNontransactionalUpdate();
    }
    return backingStore != null ? backingSuccess : delegateSuccess;
}
Also used : CollectionAddOperation(org.datanucleus.flush.CollectionAddOperation) NucleusDataStoreException(org.datanucleus.exceptions.NucleusDataStoreException) RelationshipManager(org.datanucleus.state.RelationshipManager) Iterator(java.util.Iterator) SCOCollectionIterator(org.datanucleus.store.types.SCOCollectionIterator)

Example 25 with CollectionAddOperation

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

the class LinkedHashSet method add.

// ------------------------------ Mutator methods --------------------------
/**
 * Method to add an element to the LinkedHashSet.
 * @param element The new element
 * @return Whether it was added ok.
 */
public boolean add(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 (contains(element)) {
        return false;
    }
    if (ownerOP != null && ownerOP.getExecutionContext().getManageRelations() && !initialising) {
        // Relationship management
        ownerOP.getExecutionContext().getRelationshipManager(ownerOP).relationAdd(ownerMmd.getAbsoluteFieldNumber(), element);
    }
    boolean backingSuccess = true;
    if (backingStore != null) {
        if (SCOUtils.useQueuedUpdate(ownerOP)) {
            ownerOP.getExecutionContext().addOperationToQueue(new CollectionAddOperation(ownerOP, backingStore, element));
        } else {
            try {
                backingSuccess = backingStore.add(ownerOP, element, useCache ? delegate.size() : -1);
            } catch (NucleusDataStoreException dse) {
                throw new IllegalArgumentException(Localiser.msg("023013", "add", 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.add(element);
    if (ownerOP != null && !ownerOP.getExecutionContext().getTransaction().isActive()) {
        ownerOP.getExecutionContext().processNontransactionalUpdate();
    }
    return backingStore != null ? backingSuccess : delegateSuccess;
}
Also used : CollectionAddOperation(org.datanucleus.flush.CollectionAddOperation) NucleusDataStoreException(org.datanucleus.exceptions.NucleusDataStoreException)

Aggregations

CollectionAddOperation (org.datanucleus.flush.CollectionAddOperation)40 NucleusDataStoreException (org.datanucleus.exceptions.NucleusDataStoreException)34 Iterator (java.util.Iterator)19 RelationshipManager (org.datanucleus.state.RelationshipManager)11 ListIterator (java.util.ListIterator)10 SCOListIterator (org.datanucleus.store.types.SCOListIterator)10 SCOCollectionIterator (org.datanucleus.store.types.SCOCollectionIterator)9 ExecutionContext (org.datanucleus.ExecutionContext)8 CollectionClearOperation (org.datanucleus.flush.CollectionClearOperation)8 ObjectProvider (org.datanucleus.state.ObjectProvider)8 Set (java.util.Set)1 SCOCollection (org.datanucleus.store.types.SCOCollection)1