use of org.datanucleus.flush.CollectionClearOperation in project datanucleus-core by datanucleus.
the class Queue method initialise.
public void initialise(java.util.Queue 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();
}
}
use of org.datanucleus.flush.CollectionClearOperation in project datanucleus-core by datanucleus.
the class Set 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 Stack method clear.
/**
* Method to clear the Stack
*/
public synchronized 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 Vector method initialise.
public void initialise(java.util.Vector 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();
}
}
use of org.datanucleus.flush.CollectionClearOperation in project datanucleus-core by datanucleus.
the class Collection 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();
}
}
Aggregations