use of org.datanucleus.exceptions.NucleusDataStoreException in project datanucleus-core by datanucleus.
the class SortedSet method add.
// ------------------------------ Mutator methods --------------------------
/**
* Method to add an element to the SortedSet.
* @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 field 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;
}
use of org.datanucleus.exceptions.NucleusDataStoreException in project datanucleus-core by datanucleus.
the class SortedSet method removeAll.
/**
* Method to remove all elements from the collection from the SortedSet.
* @param elements The collection of elements to remove
* @return Whether it was removed ok.
*/
public boolean removeAll(java.util.Collection elements) {
if (elements == null) {
throw new NullPointerException();
} else if (elements.isEmpty()) {
return true;
}
makeDirty();
if (useCache) {
loadFromStore();
}
int size = useCache ? delegate.size() : -1;
Collection contained = null;
if (backingStore != null && SCOUtils.useQueuedUpdate(ownerOP)) {
// Check which are contained before updating the delegate
contained = new java.util.HashSet();
for (Object elem : elements) {
if (contains(elem)) {
contained.add(elem);
}
}
}
boolean delegateSuccess = delegate.removeAll(elements);
if (ownerOP != null && ownerOP.getExecutionContext().getManageRelations() && !initialising) {
// Relationship management
Iterator iter = elements.iterator();
RelationshipManager relMgr = ownerOP.getExecutionContext().getRelationshipManager(ownerOP);
while (iter.hasNext()) {
relMgr.relationRemove(ownerMmd.getAbsoluteFieldNumber(), iter.next());
}
}
if (backingStore != null && ownerOP != null) {
boolean backingSuccess = true;
if (SCOUtils.useQueuedUpdate(ownerOP)) {
if (contained != null && !contained.isEmpty()) {
backingSuccess = false;
for (Object element : contained) {
backingSuccess = true;
ownerOP.getExecutionContext().addOperationToQueue(new CollectionRemoveOperation(ownerOP, backingStore, element, true));
}
}
} else {
try {
backingSuccess = backingStore.removeAll(ownerOP, elements, size);
} catch (NucleusDataStoreException dse) {
NucleusLogger.PERSISTENCE.warn(Localiser.msg("023013", "removeAll", ownerMmd.getName(), dse));
backingSuccess = false;
}
}
if (!ownerOP.getExecutionContext().getTransaction().isActive()) {
ownerOP.getExecutionContext().processNontransactionalUpdate();
}
return backingSuccess;
}
if (ownerOP != null && !ownerOP.getExecutionContext().getTransaction().isActive()) {
ownerOP.getExecutionContext().processNontransactionalUpdate();
}
return delegateSuccess;
}
use of org.datanucleus.exceptions.NucleusDataStoreException in project datanucleus-core by datanucleus.
the class SortedSet method remove.
/**
* Method to remove an element from the collection, and observe the flag for whether to allow cascade delete.
* @param element The element
* @param allowCascadeDelete Whether to allow cascade delete
*/
public boolean remove(Object element, boolean allowCascadeDelete) {
makeDirty();
if (useCache) {
loadFromStore();
}
int size = useCache ? delegate.size() : -1;
boolean contained = delegate.contains(element);
boolean delegateSuccess = delegate.remove(element);
if (ownerOP != null && ownerOP.getExecutionContext().getManageRelations() && !initialising) {
ownerOP.getExecutionContext().getRelationshipManager(ownerOP).relationRemove(ownerMmd.getAbsoluteFieldNumber(), element);
}
boolean backingSuccess = true;
if (backingStore != null) {
if (SCOUtils.useQueuedUpdate(ownerOP)) {
backingSuccess = contained;
if (backingSuccess) {
ownerOP.getExecutionContext().addOperationToQueue(new CollectionRemoveOperation(ownerOP, backingStore, element, allowCascadeDelete));
}
} else {
try {
backingSuccess = backingStore.remove(ownerOP, element, size, allowCascadeDelete);
} catch (NucleusDataStoreException dse) {
NucleusLogger.PERSISTENCE.warn(Localiser.msg("023013", "remove", ownerMmd.getName(), dse));
backingSuccess = false;
}
}
}
if (ownerOP != null && !ownerOP.getExecutionContext().getTransaction().isActive()) {
ownerOP.getExecutionContext().processNontransactionalUpdate();
}
return backingStore != null ? backingSuccess : delegateSuccess;
}
use of org.datanucleus.exceptions.NucleusDataStoreException in project datanucleus-core by datanucleus.
the class SortedSet method addAll.
/**
* Method to add a collection to the SortedSet.
* @param elements The collection
* @return Whether it was added ok.
*/
public boolean addAll(Collection elements) {
if (useCache) {
loadFromStore();
}
if (ownerOP != null && ownerOP.getExecutionContext().getManageRelations() && !initialising) {
// Relationship management
Iterator iter = elements.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 : elements) {
ownerOP.getExecutionContext().addOperationToQueue(new CollectionAddOperation(ownerOP, backingStore, element));
}
} else {
try {
backingSuccess = backingStore.addAll(ownerOP, elements, 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 field 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(elements);
if (ownerOP != null && !ownerOP.getExecutionContext().getTransaction().isActive()) {
ownerOP.getExecutionContext().processNontransactionalUpdate();
}
return backingStore != null ? backingSuccess : delegateSuccess;
}
use of org.datanucleus.exceptions.NucleusDataStoreException 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;
}
Aggregations