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;
}
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;
}
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;
}
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;
}
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;
}
Aggregations