Search in sources :

Example 1 with LifeCycleState

use of org.datanucleus.state.LifeCycleState 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;
    }
}
Also used : RelationshipManager(org.datanucleus.state.RelationshipManager) LifeCycleState(org.datanucleus.state.LifeCycleState) ObjectProvider(org.datanucleus.state.ObjectProvider) Map(java.util.Map) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap)

Aggregations

Map (java.util.Map)1 ConcurrentHashMap (java.util.concurrent.ConcurrentHashMap)1 LifeCycleState (org.datanucleus.state.LifeCycleState)1 ObjectProvider (org.datanucleus.state.ObjectProvider)1 RelationshipManager (org.datanucleus.state.RelationshipManager)1