Ejemplo n.º 1
0
        protected override void OnCopy(ModelElement sourceElement)
        {
            base.OnCopy(sourceElement);

            EntityIndex sourceIndex = (EntityIndex)sourceElement;

            this.Fields     = sourceIndex.Fields.Clone();
            this.FillFactor = Common.ExtensionMethods.Clone(sourceIndex.FillFactor);
            this.IndexName  = Common.ExtensionMethods.Clone(sourceIndex.IndexName);
            this.Unique     = Common.ExtensionMethods.Clone(sourceIndex.Unique);
        }
Ejemplo n.º 2
0
        public IOrmAttribute MergeChanges(IOrmAttribute otherAttribute, MergeConflictAction mergeConflictAction)
        {
            EntityIndex other = (EntityIndex)otherAttribute;

            EntityIndex mergedResult = new EntityIndex((Store)null);

            mergedResult.Unique     = this.Unique.Merge(other.Unique, mergeConflictAction);
            mergedResult.FillFactor = this.FillFactor.Merge(other.FillFactor, mergeConflictAction);
            mergedResult.IndexName  = this.IndexName.Merge(other.IndexName, mergeConflictAction);

            mergedResult.Fields = this.Fields.MergeChanges(other.Fields, mergeConflictAction);

            return(mergedResult);
        }
Ejemplo n.º 3
0
        protected override Image CompartmentImageProvider(ModelElement element)
        {
            if (element is PropertyBase)
            {
                return(base.CompartmentImageProvider(element));
            }

            if (element is EntityIndex)
            {
                EntityIndex index = (EntityIndex)element;
                return(index.Unique.IsCustom() && index.Unique.Value ? Resources.IndexUnique : Resources.Index);
            }

            return(Resources.Property);
        }
Ejemplo n.º 4
0
        public override void ExecCommand(MenuCommand menuCommand)
        {
            var            currentSelection      = GetCurrentSelectedPersistentType();
            PersistentType currentPersistentType = currentSelection.CurrentPersistentType;

            EntityIndex newIndex = null;

            currentSelection.MakeActionWithinTransaction(
                string.Format("Add entity index into '{0}'", currentPersistentType.Name),
                () =>
            {
                Interface ownerInterface = (Interface)currentPersistentType;
                newIndex = new EntityIndex(currentPersistentType.Partition);
                ownerInterface.Indexes.Add(newIndex);
                newIndex.Name = string.Format("Index{0}", ownerInterface.Indexes.Count);
            });

            if (newIndex != null)
            {
                DiagramUtil.SelectCompartmentItem(currentSelection.DiagramDocView,
                                                  currentPersistentType, "Indexes", newIndex);
            }
        }
Ejemplo n.º 5
0
        private void InternalImplementToType(IEntityBase targetType, ImplementTypeOptions options)
        {
            EntityBase entityBase = (EntityBase)targetType;

            List <PropertyBase> addedProperties = new List <PropertyBase>();

            foreach (PropertyBase property in this.Properties)
            {
                if (!entityBase.ContainsProperty(property.PropertyKind, property.Name))
                {
                    PropertyBase copiedProperty =
                        (PropertyBase)property.Copy(new[] { PersistentTypeHasProperties.PersistentTypeDomainRoleId });
                    entityBase.Properties.Add(copiedProperty);
                    addedProperties.Add(copiedProperty);
                }
            }

            foreach (NavigationProperty navigationProperty in this.NavigationProperties)
            {
                if (!entityBase.ContainsProperty(PropertyKind.Navigation, navigationProperty.Name))
                {
                    NavigationProperty copiedNavigationProperty = (NavigationProperty)navigationProperty.Copy(new[]
                    {
                        PersistentTypeHasNavigationProperties.PersistentTypeOfNavigationPropertyDomainRoleId,
                    });
                    entityBase.NavigationProperties.Add(copiedNavigationProperty);
                    copiedNavigationProperty.PersistentTypeHasAssociations.SourcePersistentType = entityBase;
                    addedProperties.Add(copiedNavigationProperty);
                }
            }

            foreach (EntityIndex entityIndex in this.Indexes)
            {
                if (!entityBase.ContainsIndex(entityIndex))
                {
                    EntityIndex copiedIndex =
                        (EntityIndex)entityIndex.Copy(new[] { InterfaceHasIndexes.InterfaceOfIndexDomainRoleId });
                    entityBase.Indexes.Add(copiedIndex);
                }
            }

            if (Util.IsFlagSet(ImplementTypeOptions.CopyInheritedInterfaces, options))
            {
                foreach (Interface inheritedInterface in this.InheritedInterfaces)
                {
                    if (!entityBase.InheritedInterfaces.Contains(inheritedInterface))
                    {
                        entityBase.InheritedInterfaces.Add(inheritedInterface);
                    }
                }
            }

            if (!targetType.InheritedInterfaces.Contains(this))
            {
                entityBase.InheritedInterfaces.Add(this);
            }

            var duplicatedInfo = PersistentTypeValidation.FindDuplicatedPropertieInInheritanceTree(targetType, null);

            foreach (var addedProperty in addedProperties)
            {
                Func <IPropertyBase, bool> foundPropertyFunc =
                    item => item.PropertyKind == addedProperty.PropertyKind &&
                    Util.StringEqual(item.Name, addedProperty.Name, true);

                addedProperty.IsInherited =
                    duplicatedInfo.PropertiesWithDifferentType.Any(foundPropertyFunc) ||
                    duplicatedInfo.PropertiesWithSameType.Any(foundPropertyFunc);
            }
        }
Ejemplo n.º 6
0
        private static void CustomReadPropertiesFromElements(SerializationContext serializationContext, EntityIndex element, XmlReader reader)
        {
            while (!serializationContext.Result.Failed && !reader.EOF && reader.NodeType == System.Xml.XmlNodeType.Element)
            {
                switch (reader.LocalName)
                {
                case "unique":
                    if (reader.IsEmptyElement)
                    {                                        // No serialized value, must be default one.
                        SerializationUtilities.Skip(reader); // Skip this tag.
                    }
                    else
                    {
                        Defaultable <bool> unique = new Defaultable <bool>();
                        unique.DeserializeFromXml(reader);
                        element.Unique = unique;

                        SerializationUtilities.SkipToNextElement(reader);
                        reader.SkipToNextElementFix();
                    }
                    break;

                case "fillFactor":
                    if (reader.IsEmptyElement)
                    {                                        // No serialized value, must be default one.
                        SerializationUtilities.Skip(reader); // Skip this tag.
                    }
                    else
                    {
                        Defaultable <double> fillfactor = new Defaultable <double>();
                        fillfactor.DeserializeFromXml(reader);
                        element.FillFactor = fillfactor;

                        SerializationUtilities.SkipToNextElement(reader);
                        reader.SkipToNextElementFix();
                    }
                    break;

                case "indexName":
                    if (reader.IsEmptyElement)
                    {                                        // No serialized value, must be default one.
                        SerializationUtilities.Skip(reader); // Skip this tag.
                    }
                    else
                    {
                        Defaultable <string> indexName = new Defaultable <string>();
                        indexName.DeserializeFromXml(reader);
                        element.IndexName = indexName;

                        SerializationUtilities.SkipToNextElement(reader);
                        reader.SkipToNextElementFix();
                    }
                    break;

                case "fields":
                    if (reader.IsEmptyElement)
                    {                                        // No serialized value, must be default one.
                        SerializationUtilities.Skip(reader); // Skip this tag.
                    }
                    else
                    {
                        OrmIndexFields fields = new OrmIndexFields();
                        fields.DeserializeFromXml(reader);
                        element.Fields = fields;

                        SerializationUtilities.SkipToNextElement(reader);
                        reader.SkipToNextElementFix();
                    }
                    break;

                default:
                    return;      // Don't know this element.
                }
            }
        }
Ejemplo n.º 7
0
        private static void CustomWritePropertiesAsElements(SerializationContext context, EntityIndex element, XmlWriter writer)
        {
            // Unique
            if (!context.Result.Failed)
            {
                Defaultable <bool> propValue = element.Unique;
                propValue.SerializeToXml(writer, "unique");
            }

            // FillFactor
            if (!context.Result.Failed)
            {
                Defaultable <double> propValue = element.FillFactor;
                propValue.SerializeToXml(writer, "fillFactor");
            }

            // IndexName
            if (!context.Result.Failed)
            {
                Defaultable <string> indexName = element.IndexName;
                indexName.SerializeToXml(writer, "indexName");
            }

            // Fields
            if (!context.Result.Failed)
            {
                element.Fields.SerializeToXml(writer);
            }
        }