Search in sources :

Example 11 with CollectionClearOperation

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

the class HashSet method clear.

/**
 * Method to clear the HashSet
 */
public void clear() {
    makeDirty();
    delegate.clear();
    if (backingStore != null) {
        if (SCOUtils.useQueuedUpdate(ownerOP)) {
            ownerOP.getExecutionContext().addOperationToQueue(new CollectionClearOperation(ownerOP, backingStore));
        } else {
            backingStore.clear(ownerOP);
        }
    }
    if (ownerOP != null && !ownerOP.getExecutionContext().getTransaction().isActive()) {
        ownerOP.getExecutionContext().processNontransactionalUpdate();
    }
}
Also used : CollectionClearOperation(org.datanucleus.flush.CollectionClearOperation)

Example 12 with CollectionClearOperation

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

the class LinkedHashSet method clear.

/**
 * Method to clear the LinkedHashSet
 */
public void clear() {
    makeDirty();
    delegate.clear();
    if (backingStore != null) {
        if (SCOUtils.useQueuedUpdate(ownerOP)) {
            ownerOP.getExecutionContext().addOperationToQueue(new CollectionClearOperation(ownerOP, backingStore));
        } else {
            backingStore.clear(ownerOP);
        }
    }
    if (ownerOP != null && !ownerOP.getExecutionContext().getTransaction().isActive()) {
        ownerOP.getExecutionContext().processNontransactionalUpdate();
    }
}
Also used : CollectionClearOperation(org.datanucleus.flush.CollectionClearOperation)

Example 13 with CollectionClearOperation

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

the class LinkedList method clear.

/**
 * Method to clear the LinkedList.
 */
public void clear() {
    makeDirty();
    delegate.clear();
    if (backingStore != null) {
        if (SCOUtils.useQueuedUpdate(ownerOP)) {
            ownerOP.getExecutionContext().addOperationToQueue(new CollectionClearOperation(ownerOP, backingStore));
        } else {
            backingStore.clear(ownerOP);
        }
    }
    if (ownerOP != null && !ownerOP.getExecutionContext().getTransaction().isActive()) {
        ownerOP.getExecutionContext().processNontransactionalUpdate();
    }
}
Also used : CollectionClearOperation(org.datanucleus.flush.CollectionClearOperation)

Example 14 with CollectionClearOperation

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

the class List method initialise.

public void initialise(java.util.List newValue, Object oldValue) {
    if (newValue != null) {
        // Check for the case of serialised PC elements, and assign ObjectProviders to the elements without
        if (SCOUtils.collectionHasSerialisedElements(ownerMmd) && ownerMmd.getCollection().elementIsPersistent()) {
            ExecutionContext ec = ownerOP.getExecutionContext();
            Iterator iter = newValue.iterator();
            while (iter.hasNext()) {
                Object pc = iter.next();
                ObjectProvider objSM = ec.findObjectProvider(pc);
                if (objSM == null) {
                    objSM = ec.getNucleusContext().getObjectProviderFactory().newForEmbedded(ec, pc, false, ownerOP, ownerMmd.getAbsoluteFieldNumber());
                }
            }
        }
        if (NucleusLogger.PERSISTENCE.isDebugEnabled()) {
            NucleusLogger.PERSISTENCE.debug(Localiser.msg("023008", ownerOP.getObjectAsPrintable(), ownerMmd.getName(), "" + newValue.size()));
        }
        // TODO This does clear+addAll : Improve this and work out which elements are added and which deleted
        if (backingStore != null) {
            if (SCOUtils.useQueuedUpdate(ownerOP)) {
                if (ownerOP.isFlushedToDatastore() || !ownerOP.getLifecycleState().isNew()) {
                    ownerOP.getExecutionContext().addOperationToQueue(new CollectionClearOperation(ownerOP, backingStore));
                    for (Object element : newValue) {
                        ownerOP.getExecutionContext().addOperationToQueue(new CollectionAddOperation(ownerOP, backingStore, element));
                    }
                }
            } else {
                backingStore.clear(ownerOP);
                try {
                    backingStore.addAll(ownerOP, newValue, useCache ? 0 : -1);
                } catch (NucleusDataStoreException dse) {
                    NucleusLogger.PERSISTENCE.warn(Localiser.msg("023013", "addAll", ownerMmd.getName(), dse));
                }
            }
        }
        delegate.addAll(newValue);
        isCacheLoaded = true;
        makeDirty();
    }
}
Also used : CollectionClearOperation(org.datanucleus.flush.CollectionClearOperation) CollectionAddOperation(org.datanucleus.flush.CollectionAddOperation) NucleusDataStoreException(org.datanucleus.exceptions.NucleusDataStoreException) ExecutionContext(org.datanucleus.ExecutionContext) ListIterator(java.util.ListIterator) Iterator(java.util.Iterator) SCOListIterator(org.datanucleus.store.types.SCOListIterator) ObjectProvider(org.datanucleus.state.ObjectProvider)

Example 15 with CollectionClearOperation

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

the class Queue method clear.

/**
 * Method to clear the Collection.
 */
public void clear() {
    makeDirty();
    delegate.clear();
    if (backingStore != null) {
        if (SCOUtils.useQueuedUpdate(ownerOP)) {
            ownerOP.getExecutionContext().addOperationToQueue(new CollectionClearOperation(ownerOP, backingStore));
        } else {
            backingStore.clear(ownerOP);
        }
    }
    if (ownerOP != null && !ownerOP.getExecutionContext().getTransaction().isActive()) {
        ownerOP.getExecutionContext().processNontransactionalUpdate();
    }
}
Also used : CollectionClearOperation(org.datanucleus.flush.CollectionClearOperation)

Aggregations

CollectionClearOperation (org.datanucleus.flush.CollectionClearOperation)21 Iterator (java.util.Iterator)8 ExecutionContext (org.datanucleus.ExecutionContext)8 NucleusDataStoreException (org.datanucleus.exceptions.NucleusDataStoreException)8 CollectionAddOperation (org.datanucleus.flush.CollectionAddOperation)8 ObjectProvider (org.datanucleus.state.ObjectProvider)8 ListIterator (java.util.ListIterator)5 SCOListIterator (org.datanucleus.store.types.SCOListIterator)5 SCOCollectionIterator (org.datanucleus.store.types.SCOCollectionIterator)3 Set (java.util.Set)1 SCOCollection (org.datanucleus.store.types.SCOCollection)1