Exemple #1
0
        private void DiagnoseKeyCollision(
            UpdateCompiler compiler,
            PropagatorResult change,
            CompositeKey key,
            PropagatorResult other)
        {
            KeyManager   keyManager   = compiler.m_translator.KeyManager;
            CompositeKey compositeKey = new CompositeKey(this.GetKeyConstants(other));
            bool         flag         = true;

            for (int index = 0; flag && index < key.KeyComponents.Length; ++index)
            {
                int identifier1 = key.KeyComponents[index].Identifier;
                int identifier2 = compositeKey.KeyComponents[index].Identifier;
                if (!keyManager.GetPrincipals(identifier1).Intersect <int>(keyManager.GetPrincipals(identifier2)).Any <int>())
                {
                    flag = false;
                }
            }
            if (flag)
            {
                throw new UpdateException(Strings.Update_DuplicateKeys, (Exception)null, SourceInterpreter.GetAllStateEntries(change, compiler.m_translator, this.m_table).Concat <IEntityStateEntry>((IEnumerable <IEntityStateEntry>)SourceInterpreter.GetAllStateEntries(other, compiler.m_translator, this.m_table)).Cast <ObjectStateEntry>().Distinct <ObjectStateEntry>());
            }
            HashSet <IEntityStateEntry> source = (HashSet <IEntityStateEntry>)null;

            foreach (PropagatorResult propagatorResult in ((IEnumerable <PropagatorResult>)key.KeyComponents).Concat <PropagatorResult>((IEnumerable <PropagatorResult>)compositeKey.KeyComponents))
            {
                HashSet <IEntityStateEntry> entityStateEntrySet = new HashSet <IEntityStateEntry>();
                foreach (int dependent in keyManager.GetDependents(propagatorResult.Identifier))
                {
                    PropagatorResult owner;
                    if (keyManager.TryGetIdentifierOwner(dependent, out owner) && owner.StateEntry != null)
                    {
                        entityStateEntrySet.Add(owner.StateEntry);
                    }
                }
                if (source == null)
                {
                    source = new HashSet <IEntityStateEntry>((IEnumerable <IEntityStateEntry>)entityStateEntrySet);
                }
                else
                {
                    source.IntersectWith((IEnumerable <IEntityStateEntry>)entityStateEntrySet);
                }
            }
            throw new UpdateException(Strings.Update_GeneralExecutionException, (Exception) new ConstraintException(Strings.Update_ReferentialConstraintIntegrityViolation), source.Cast <ObjectStateEntry>().Distinct <ObjectStateEntry>());
        }
Exemple #2
0
 internal override PropagatorResult Merge(
     KeyManager keyManager,
     PropagatorResult other)
 {
     PropagatorResult.KeyValue next = other as PropagatorResult.KeyValue;
     if (next == null)
     {
         EntityUtil.InternalError(EntityUtil.InternalErrorCode.UpdatePipelineResultRequestInvalid, 0, (object)"KeyValue.Merge");
     }
     if (this.Identifier != next.Identifier)
     {
         if (keyManager.GetPrincipals(next.Identifier).Contains <int>(this.Identifier))
         {
             return((PropagatorResult)this.ReplicateResultWithNewNext(next));
         }
         return((PropagatorResult)next.ReplicateResultWithNewNext(this));
     }
     if (this.m_stateEntry == null || this.m_stateEntry.IsRelationship)
     {
         return((PropagatorResult)next.ReplicateResultWithNewNext(this));
     }
     return((PropagatorResult)this.ReplicateResultWithNewNext(next));
 }
            internal override PropagatorResult Merge(KeyManager keyManager, PropagatorResult other)
            {
                var otherKey = other as KeyValue;

                if (null == otherKey)
                {
                    EntityUtil.InternalError(EntityUtil.InternalErrorCode.UpdatePipelineResultRequestInvalid, 0, "KeyValue.Merge");
                }

                // Determine which key (this or otherKey) is first in the chain. Principal keys take
                // precedence over dependent keys and entities take precedence over relationships.
                if (Identifier != otherKey.Identifier)
                {
                    // Find principal (if any)
                    if (keyManager.GetPrincipals(otherKey.Identifier).Contains(Identifier))
                    {
                        return(ReplicateResultWithNewNext(otherKey));
                    }
                    else
                    {
                        return(otherKey.ReplicateResultWithNewNext(this));
                    }
                }
                else
                {
                    // Entity takes precedence of relationship
                    if (null == m_stateEntry ||
                        m_stateEntry.IsRelationship)
                    {
                        return(otherKey.ReplicateResultWithNewNext(this));
                    }
                    else
                    {
                        return(ReplicateResultWithNewNext(otherKey));
                    }
                }
            }