use of org.datanucleus.state.RelationshipManager in project datanucleus-core by datanucleus.
the class ManagedRelationsHandler method execute.
public void execute() {
if (managedRelationDetails.isEmpty()) {
return;
}
try {
executing = true;
if (NucleusLogger.PERSISTENCE.isDebugEnabled()) {
NucleusLogger.PERSISTENCE.debug(Localiser.msg("013000"));
}
if (performChecks) {
// Tests for negative situations where inconsistently assigned
Iterator<Map.Entry<ObjectProvider, RelationshipManager>> managedRelEntryIter = managedRelationDetails.entrySet().iterator();
while (managedRelEntryIter.hasNext()) {
Map.Entry<ObjectProvider, RelationshipManager> managedRelEntry = managedRelEntryIter.next();
ObjectProvider op = managedRelEntry.getKey();
LifeCycleState lc = op.getLifecycleState();
if (lc == null || lc.isDeleted()) {
// Has been deleted so ignore all relationship changes
continue;
}
managedRelEntry.getValue().checkConsistency();
}
}
// Process updates to manage the other side of the relations
Iterator<Map.Entry<ObjectProvider, RelationshipManager>> managedRelEntryIter = managedRelationDetails.entrySet().iterator();
while (managedRelEntryIter.hasNext()) {
Map.Entry<ObjectProvider, RelationshipManager> managedRelEntry = managedRelEntryIter.next();
ObjectProvider op = managedRelEntry.getKey();
LifeCycleState lc = op.getLifecycleState();
if (lc == null || lc.isDeleted()) {
// Has been deleted so ignore all relationship changes
continue;
}
RelationshipManager relMgr = managedRelEntry.getValue();
relMgr.process();
relMgr.clearFields();
}
managedRelationDetails.clear();
if (NucleusLogger.PERSISTENCE.isDebugEnabled()) {
NucleusLogger.PERSISTENCE.debug(Localiser.msg("013001"));
}
} finally {
executing = false;
}
}
use of org.datanucleus.state.RelationshipManager in project datanucleus-core by datanucleus.
the class Set 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 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(c);
if (ownerOP != null && !ownerOP.getExecutionContext().getTransaction().isActive()) {
ownerOP.getExecutionContext().processNontransactionalUpdate();
}
return backingStore != null ? backingSuccess : delegateSuccess;
}
use of org.datanucleus.state.RelationshipManager in project datanucleus-core by datanucleus.
the class Set method removeAll.
/**
* Method to remove a Collection of elements.
* @param elements The collection to remove
* @return Whether they were removed successfully.
*/
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 = false;
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.state.RelationshipManager 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.state.RelationshipManager 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;
}
Aggregations