use of org.datanucleus.flush.CollectionClearOperation in project datanucleus-core by datanucleus.
the class LinkedList method initialise.
public void initialise(java.util.LinkedList newValue, Object oldValue) {
if (newValue != null) {
// Check for the case of serialised PC elements, and assign ObjectProviders to the elements without
ExecutionContext ec = ownerOP.getExecutionContext();
if (SCOUtils.collectionHasSerialisedElements(ownerMmd) && ownerMmd.getCollection().elementIsPersistent()) {
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();
}
}
use of org.datanucleus.flush.CollectionClearOperation in project datanucleus-core by datanucleus.
the class List method clear.
/**
* Method to clear the List
*/
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();
}
}
use of org.datanucleus.flush.CollectionClearOperation in project datanucleus-core by datanucleus.
the class PriorityQueue method initialise.
public void initialise(java.util.PriorityQueue 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) || !ownerOP.getLifecycleState().isNew()) {
if (ownerOP.isFlushedToDatastore()) {
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();
}
}
use of org.datanucleus.flush.CollectionClearOperation in project datanucleus-core by datanucleus.
the class PriorityQueue 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();
}
}
use of org.datanucleus.flush.CollectionClearOperation in project datanucleus-core by datanucleus.
the class Collection method initialise.
/* (non-Javadoc)
* @see org.datanucleus.store.types.wrappers.Collection#initialise(java.util.Collection, java.util.Collection)
*/
@Override
public void initialise(java.util.Collection<E> newValue, Object oldValue) {
if (newValue instanceof java.util.List && !(delegate instanceof java.util.List)) {
// Need to set the value to a List so we change our delegate to match
delegate = new java.util.ArrayList();
}
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 objOP = ec.findObjectProvider(pc);
if (objOP == null) {
objOP = 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()));
}
if (delegate instanceof Set) {
// Detect which objects are added and which are deleted
initialising = true;
if (useCache) {
java.util.Collection oldColl = (java.util.Collection) oldValue;
if (oldColl != null) {
delegate.addAll(oldColl);
}
isCacheLoaded = true;
SCOUtils.updateCollectionWithCollection(ownerOP.getExecutionContext().getApiAdapter(), this, newValue);
} else {
java.util.Collection oldColl = (java.util.Collection) oldValue;
if (oldColl instanceof SCOCollection) {
oldColl = (java.util.Collection) ((SCOCollection) oldColl).getValue();
}
for (E elem : newValue) {
if (oldColl == null || !oldColl.contains(elem)) {
add(elem);
}
}
if (oldColl != null) {
Iterator iter = oldColl.iterator();
while (iter.hasNext()) {
Object elem = iter.next();
if (!newValue.contains(elem)) {
remove(elem);
}
}
}
}
initialising = false;
} else {
// 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();
}
}
}
Aggregations