/// <summary>
            /// Call the View Generator's Generate view method
            /// and collect the Views and store it in a local dictionary.
            /// </summary>
            /// <param name="entityContainerMap"></param>
            /// <param name="resultDictionary"></param>
            private void SerializedGenerateViews(StorageEntityContainerMapping entityContainerMap, Dictionary <EntitySetBase, GeneratedView> resultDictionary)
            {
                //If there are no entity set maps, don't call the view generation process
                Debug.Assert(entityContainerMap.HasViews);

                ViewGenResults viewGenResults = ViewgenGatekeeper.GenerateViewsFromMapping(entityContainerMap, m_config);
                KeyToListMap <EntitySetBase, GeneratedView> extentMappingViews = viewGenResults.Views;

                if (viewGenResults.HasErrors)
                {
                    // Can get the list of errors using viewGenResults.Errors
                    throw new MappingException(Helper.CombineErrorMessage(viewGenResults.Errors));
                }

                foreach (KeyValuePair <EntitySetBase, List <GeneratedView> > keyValuePair in extentMappingViews.KeyValuePairs)
                {
                    //Multiple Views are returned for an extent but the first view
                    //is the only one that we will use for now. In the future,
                    //we might start using the other views which are per type within an extent.
                    GeneratedView generatedView;
                    //Add the view to the local dictionary

                    if (!resultDictionary.TryGetValue(keyValuePair.Key, out generatedView))
                    {
                        generatedView = keyValuePair.Value[0];
                        resultDictionary.Add(keyValuePair.Key, generatedView);
                    }
                }
            }
Exemplo n.º 2
0
        /// <summary>
        /// This method is primarily for debugging purposes.
        /// Will be removed shortly.
        /// </summary>
        internal override void Print(int index)
        {
            StorageEntityContainerMapping.GetPrettyPrintString(ref index);
            StringBuilder sb = new StringBuilder();

            sb.Append("EntitySetMapping");
            sb.Append("   ");
            sb.Append("Name:");
            sb.Append(this.Set.Name);
            if (this.QueryView != null)
            {
                sb.Append("   ");
                sb.Append("Query View:");
                sb.Append(this.QueryView);
            }
            Console.WriteLine(sb.ToString());
            foreach (StorageTypeMapping typeMapping in TypeMappings)
            {
                typeMapping.Print(index + 5);
            }
            foreach (StorageEntityTypeModificationFunctionMapping m in m_modificationFunctionMappings)
            {
                m.Print(index + 10);
            }
        }
        /// <summary>
        /// This method is primarily for debugging purposes.
        /// Will be removed shortly.
        /// </summary>
        /// <param name="index"></param>
        internal void Print(int index)
        {
            StorageEntityContainerMapping.GetPrettyPrintString(ref index);
            StringBuilder sb = new StringBuilder();

            sb.Append("ComplexTypeMapping");
            sb.Append("   ");
            if (m_isPartial)
            {
                sb.Append("IsPartial:True");
            }
            sb.Append("   ");
            foreach (ComplexType type in m_types.Values)
            {
                sb.Append("Types:");
                sb.Append(type.FullName);
                sb.Append("   ");
            }
            foreach (ComplexType type in m_isOfTypes.Values)
            {
                sb.Append("Is-Of Types:");
                sb.Append(type.FullName);
                sb.Append("   ");
            }
            Console.WriteLine(sb.ToString());
            foreach (StorageConditionPropertyMapping conditionMap in m_conditionProperties.Values)
            {
                (conditionMap).Print(index + 5);
            }
            foreach (StoragePropertyMapping propertyMapping in Properties)
            {
                propertyMapping.Print(index + 5);
            }
        }
Exemplo n.º 4
0
        /// <summary>
        /// This method is primarily for debugging purposes.
        /// Will be removed shortly.
        /// </summary>
        /// <param name="index"></param>
        internal override void Print(int index)
        {
            StorageEntityContainerMapping.GetPrettyPrintString(ref index);
            StringBuilder sb = new StringBuilder();

            sb.Append("EntityTypeMapping");
            sb.Append("   ");
            foreach (EdmType type in m_entityTypes.Values)
            {
                sb.Append("Types:");
                sb.Append(type.FullName);
                sb.Append("   ");
            }
            foreach (EdmType type in m_isOfEntityTypes.Values)
            {
                sb.Append("Is-Of Types:");
                sb.Append(type.FullName);
                sb.Append("   ");
            }

            Console.WriteLine(sb.ToString());
            foreach (StorageMappingFragment fragment in MappingFragments)
            {
                fragment.Print(index + 5);
            }
        }
 private bool SerializedVerifyHashOverMmClosure(StorageEntityContainerMapping entityContainerMapping, EntityViewContainer entityViewContainer)
 {
     if (MetadataMappingHasherVisitor.GetMappingClosureHash(m_storageMappingItemCollection.MappingVersion, entityContainerMapping) ==
         entityViewContainer.HashOverMappingClosure)
     {
         return(true);
     }
     return(false);
 }
Exemplo n.º 6
0
 protected virtual void Visit(StorageEntityContainerMapping storageEntityContainerMapping)
 {
     Visit(storageEntityContainerMapping.EdmEntityContainer);
     Visit(storageEntityContainerMapping.StorageEntityContainer);
     foreach (var mapping in storageEntityContainerMapping.EntitySetMaps)
     {
         Visit(mapping);
     }
 }
Exemplo n.º 7
0
        internal static string GetMappingClosureHash(double mappingVersion, StorageEntityContainerMapping storageEntityContainerMapping)
        {
            Debug.Assert(storageEntityContainerMapping != null, "storageEntityContainerMapping is null!");

            MetadataMappingHasherVisitor visitor = new MetadataMappingHasherVisitor(mappingVersion);

            visitor.Visit(storageEntityContainerMapping);
            return(visitor.HashValue);
        }
        internal void Print(int index)
        {
            StorageEntityContainerMapping.GetPrettyPrintString(ref index);
            StringBuilder sb = new StringBuilder();

            sb.Append("Association Set Function Mapping");
            sb.Append("   ");
            sb.Append(this.ToString());
            Console.WriteLine(sb.ToString());
        }
        /// <summary>
        /// This helper method loads items based on contents of in-memory XmlReader instances.
        /// Assumption: This method is called only from the constructor because m_extentMappingViews is not thread safe.
        /// </summary>
        /// <param name="xmlReaders">A list of XmlReader instances</param>
        /// <param name="mappingSchemaUris">A list of URIs</param>
        /// <returns>A list of schema errors</returns>
        private List <EdmSchemaError> LoadItems(IEnumerable <XmlReader> xmlReaders,
                                                List <string> mappingSchemaUris,
                                                Dictionary <EntitySetBase, GeneratedView> userDefinedQueryViewsDict,
                                                Dictionary <OfTypeQVCacheKey, GeneratedView> userDefinedQueryViewsOfTypeDict,
                                                double expectedVersion)
        {
            Debug.Assert(m_memberMappings.Count == 0, "Assumption: This method is called only once, and from the constructor because m_extentMappingViews is not thread safe.");

            List <EdmSchemaError> errors = new List <EdmSchemaError>();

            int index = -1;

            foreach (XmlReader xmlReader in xmlReaders)
            {
                index++;
                string location = null;
                if (mappingSchemaUris == null)
                {
                    som.SchemaManager.TryGetBaseUri(xmlReader, out location);
                }
                else
                {
                    location = mappingSchemaUris[index];
                }

                StorageMappingItemLoader mapLoader = new StorageMappingItemLoader(
                    xmlReader,
                    this,
                    location,                                          // ASSUMPTION: location is only used for generating error-messages
                    m_memberMappings);
                errors.AddRange(mapLoader.ParsingErrors);

                CheckIsSameVersion(expectedVersion, mapLoader.MappingVersion, errors);

                // Process container mapping.
                StorageEntityContainerMapping containerMapping = mapLoader.ContainerMapping;
                if (mapLoader.HasQueryViews && containerMapping != null)
                {
                    // Compile the query views so that we can report the errors in the user specified views.
                    CompileUserDefinedQueryViews(containerMapping, userDefinedQueryViewsDict, userDefinedQueryViewsOfTypeDict, errors);
                }
                // Add container mapping if there are no errors and entity container mapping is not already present.
                if (MetadataHelper.CheckIfAllErrorsAreWarnings(errors) && !this.Contains(containerMapping))
                {
                    AddInternal(containerMapping);
                }
            }

            CheckForDuplicateItems(EdmItemCollection, StoreItemCollection, errors);

            return(errors);
        }
            private Dictionary <EntitySetBase, GeneratedView> SerializedGetGeneratedViews(EntityContainer container)
            {
                Debug.Assert(container != null);

                // Note that extentMappingViews will contain both query and update views.
                Dictionary <EntitySetBase, GeneratedView> extentMappingViews;

                // Get the mapping that has the entity container mapped.
                StorageEntityContainerMapping entityContainerMap = MappingMetadataHelper.GetEntityContainerMap(m_storageMappingItemCollection, container);

                // We get here because memoizer didn't find an entry for the container.
                // It might happen that the entry with generated views already exists for the counterpart container, so check it first.
                EntityContainer counterpartContainer = container.DataSpace == DataSpace.CSpace ?
                                                       entityContainerMap.StorageEntityContainer : entityContainerMap.EdmEntityContainer;

                if (m_generatedViewsMemoizer.TryGetValue(counterpartContainer, out extentMappingViews))
                {
                    return(extentMappingViews);
                }

                extentMappingViews = new Dictionary <EntitySetBase, GeneratedView>();

                if (!entityContainerMap.HasViews)
                {
                    return(extentMappingViews);
                }

                // If we are in generated views mode.
                if (m_generatedViewsMode)
                {
                    if (ObjectItemCollection.ViewGenerationAssemblies != null && ObjectItemCollection.ViewGenerationAssemblies.Count > 0)
                    {
                        SerializedCollectViewsFromObjectCollection(this.m_storageMappingItemCollection.Workspace, extentMappingViews);
                    }
                    else
                    {
                        SerializedCollectViewsFromReferencedAssemblies(this.m_storageMappingItemCollection.Workspace, extentMappingViews);
                    }
                }

                if (extentMappingViews.Count == 0)
                {
                    // We should change the mode to runtime generation of views.
                    this.m_generatedViewsMode = false;
                    this.SerializedGenerateViews(entityContainerMap, extentMappingViews);
                }

                Debug.Assert(extentMappingViews.Count > 0, "view should be generated at this point");

                return(extentMappingViews);
            }
        /// <summary>
        /// This method compiles all the user defined query views in the <paramref name="entityContainerMapping"/>.
        /// </summary>
        private static void CompileUserDefinedQueryViews(StorageEntityContainerMapping entityContainerMapping,
                                                         Dictionary <EntitySetBase, GeneratedView> userDefinedQueryViewsDict,
                                                         Dictionary <OfTypeQVCacheKey, GeneratedView> userDefinedQueryViewsOfTypeDict,
                                                         IList <EdmSchemaError> errors)
        {
            ConfigViewGenerator config = new ConfigViewGenerator();

            foreach (StorageSetMapping setMapping in entityContainerMapping.AllSetMaps)
            {
                if (setMapping.QueryView != null)
                {
                    GeneratedView generatedView;
                    if (!userDefinedQueryViewsDict.TryGetValue(setMapping.Set, out generatedView))
                    {
                        // Parse the view so that we will get back any errors in the view.
                        if (GeneratedView.TryParseUserSpecifiedView(setMapping,
                                                                    setMapping.Set.ElementType,
                                                                    setMapping.QueryView,
                                                                    true, // includeSubtypes
                                                                    entityContainerMapping.StorageMappingItemCollection,
                                                                    config,
                                                                    /*out*/ errors,
                                                                    out generatedView))
                        {
                            // Add first QueryView
                            userDefinedQueryViewsDict.Add(setMapping.Set, generatedView);
                        }

                        // Add all type-specific QueryViews
                        foreach (OfTypeQVCacheKey key in setMapping.GetTypeSpecificQVKeys())
                        {
                            Debug.Assert(key.First.Equals(setMapping.Set));

                            if (GeneratedView.TryParseUserSpecifiedView(setMapping,
                                                                        key.Second.First,  // type
                                                                        setMapping.GetTypeSpecificQueryView(key),
                                                                        key.Second.Second, // includeSubtypes
                                                                        entityContainerMapping.StorageMappingItemCollection,
                                                                        config,
                                                                        /*out*/ errors,
                                                                        out generatedView))
                            {
                                userDefinedQueryViewsOfTypeDict.Add(key, generatedView);
                            }
                        }
                    }
                }
            }
        }
        /// <summary>
        /// This method is primarily for debugging purposes.
        /// Will be removed shortly.
        /// </summary>
        /// <param name="index"></param>
        internal override void Print(int index)
        {
            StorageEntityContainerMapping.GetPrettyPrintString(ref index);
            StringBuilder sb = new StringBuilder();

            sb.Append("AssociationTypeMapping");
            sb.Append("   ");
            sb.Append("Type Name:");
            sb.Append(this.m_relation.Name);
            sb.Append("   ");
            Console.WriteLine(sb.ToString());
            foreach (StorageMappingFragment fragment in MappingFragments)
            {
                fragment.Print(index + 5);
            }
        }
Exemplo n.º 13
0
        /// <summary>
        /// This method is primarily for debugging purposes.
        /// Will be removed shortly.
        /// </summary>
        /// <param name="index"></param>
        internal override void Print(int index)
        {
            StorageEntityContainerMapping.GetPrettyPrintString(ref index);
            StringBuilder sb = new StringBuilder();

            sb.Append("ConditionPropertyMapping");
            sb.Append("   ");
            if (this.EdmProperty != null)
            {
                sb.Append("Name:");
                sb.Append(this.EdmProperty.Name);
                sb.Append("   ");
            }
            if (this.ColumnProperty != null)
            {
                sb.Append("Column Name:");
                sb.Append(this.ColumnProperty.Name);
                sb.Append("   ");
            }
            if (this.Value != null)
            {
                sb.Append("Value:");
                sb.Append("'" + Value + "'");
                sb.Append("   ");
                sb.Append("Value CLR Type:");
                sb.Append("'" + Value.GetType() + "'");
                sb.Append("   ");
            }
            sb.Append("Value TypeMetadata:");
            EdmType memberType = (ColumnProperty != null) ? ColumnProperty.TypeUsage.EdmType : null;

            if (memberType != null)
            {
                sb.Append("'" + memberType.FullName + "'");
                sb.Append("   ");
            }
            if (this.IsNull.HasValue)
            {
                sb.Append("IsNull:");
                sb.Append(this.IsNull);
                sb.Append("   ");
            }
            Console.WriteLine(sb.ToString());
        }
        /// <summary>
        /// This method is primarily for debugging purposes.
        /// Will be removed shortly.
        /// </summary>
        /// <param name="index"></param>
        internal override void Print(int index)
        {
            StorageEntityContainerMapping.GetPrettyPrintString(ref index);
            StringBuilder sb = new StringBuilder();

            sb.Append("ComplexPropertyMapping");
            sb.Append("   ");
            if (this.EdmProperty != null)
            {
                sb.Append("Name:");
                sb.Append(this.EdmProperty.Name);
                sb.Append("   ");
            }
            Console.WriteLine(sb.ToString());
            foreach (StorageComplexTypeMapping typeMapping in TypeMappings)
            {
                typeMapping.Print(index + 5);
            }
        }
Exemplo n.º 15
0
        /// <summary>
        /// This method is primarily for debugging purposes.
        /// Will be removed shortly.
        /// </summary>
        /// <param name="index"></param>
        internal virtual void Print(int index)
        {
            StorageEntityContainerMapping.GetPrettyPrintString(ref index);
            StringBuilder sb = new StringBuilder();

            sb.Append("MappingFragment");
            sb.Append("   ");
            sb.Append("Table Name:");
            sb.Append(this.m_tableExtent.Name);

            Console.WriteLine(sb.ToString());
            foreach (StorageConditionPropertyMapping conditionMap in m_conditionProperties.Values)
            {
                (conditionMap).Print(index + 5);
            }
            foreach (StoragePropertyMapping propertyMapping in m_properties)
            {
                propertyMapping.Print(index + 5);
            }
        }
Exemplo n.º 16
0
        /// <summary>
        /// This method is primarily for debugging purposes.
        /// Will be removed shortly.
        /// </summary>
        /// <param name="index"></param>
        internal override void Print(int index)
        {
            StorageEntityContainerMapping.GetPrettyPrintString(ref index);
            StringBuilder sb = new StringBuilder();

            sb.Append("ScalarPropertyMapping");
            sb.Append("   ");
            if (this.EdmProperty != null)
            {
                sb.Append("Name:");
                sb.Append(this.EdmProperty.Name);
                sb.Append("   ");
            }
            if (this.ColumnProperty != null)
            {
                sb.Append("Column Name:");
                sb.Append(this.ColumnProperty.Name);
            }
            Console.WriteLine(sb.ToString());
        }
Exemplo n.º 17
0
        protected override void Visit(StorageEntityContainerMapping storageEntityContainerMapping)
        {
            Debug.Assert(storageEntityContainerMapping != null, "storageEntityContainerMapping cannot be null!");

            // at the entry point of visitor, we setup the versions
            Debug.Assert(m_MappingVersion == storageEntityContainerMapping.StorageMappingItemCollection.MappingVersion, "the original version and the mapping collection version are not the same");
            this.m_MappingVersion = storageEntityContainerMapping.StorageMappingItemCollection.MappingVersion;
            this.m_EdmVersion     = storageEntityContainerMapping.StorageMappingItemCollection.EdmItemCollection.EdmVersion;

            this.m_EdmItemCollection = storageEntityContainerMapping.StorageMappingItemCollection.EdmItemCollection;

            int index;

            if (!this.AddObjectToSeenListAndHashBuilder(storageEntityContainerMapping, out index))
            {
                // if this has been add to the seen list, then just
                return;
            }
            if (this.m_itemsAlreadySeen.Count > 1)
            {
                // this means user try another visit over SECM, this is allowed but all the previous visit all lost due to clean
                // user can visit different SECM objects by using the same visitor to load the SECM object
                this.Clean();
                Visit(storageEntityContainerMapping);
                return;
            }

            this.AddObjectStartDumpToHashBuilder(storageEntityContainerMapping, index);

            #region Inner data visit

            this.AddObjectContentToHashBuilder(storageEntityContainerMapping.Identity);

            this.AddV2ObjectContentToHashBuilder(storageEntityContainerMapping.GenerateUpdateViews, this.m_MappingVersion);

            base.Visit(storageEntityContainerMapping);

            #endregion

            this.AddObjectEndDumpToHashBuilder();
        }
        /// <summary>
        /// This method is primarily for debugging purposes.
        /// Will be removed shortly.
        /// </summary>
        /// <param name="index"></param>
        internal override void Print(int index)
        {
            StorageEntityContainerMapping.GetPrettyPrintString(ref index);
            StringBuilder sb = new StringBuilder();

            sb.Append("EndPropertyMapping");
            sb.Append("   ");
            if (this.EndMember != null)
            {
                sb.Append("Name:");
                sb.Append(this.EndMember.Name);
                sb.Append("   ");
                sb.Append("TypeName:");
                sb.Append(this.EndMember.TypeUsage.EdmType.FullName);
            }
            sb.Append("   ");
            Console.WriteLine(sb.ToString());
            foreach (StoragePropertyMapping propertyMapping in Properties)
            {
                propertyMapping.Print(index + 5);
            }
        }
            /// <summary>
            /// Generates a single query view for a given Extent and type. It is used to generate OfType and OfTypeOnly views.
            /// </summary>
            /// <param name="includeSubtypes">Whether the view should include extents that are subtypes of the given entity</param>
            private bool TryGenerateQueryViewOfType(EntityContainer entityContainer, EntitySetBase entity, EntityTypeBase type, bool includeSubtypes, out GeneratedView generatedView)
            {
                Debug.Assert(entityContainer != null);
                Debug.Assert(entity != null);
                Debug.Assert(type != null);

                if (type.Abstract)
                {
                    generatedView = null;
                    return(false);
                }

                //Get the mapping that has the entity container mapped.
                StorageEntityContainerMapping entityContainerMap = MappingMetadataHelper.GetEntityContainerMap(m_storageMappingItemCollection, entityContainer);

                Debug.Assert(!entityContainerMap.IsEmpty, "There are no entity set maps");

                bool           success;
                ViewGenResults viewGenResults = ViewgenGatekeeper.GenerateTypeSpecificQueryView(entityContainerMap, m_config, entity, type, includeSubtypes, out success);

                if (!success)
                {
                    generatedView = null;
                    return(false); //could not generate view
                }

                KeyToListMap <EntitySetBase, GeneratedView> extentMappingViews = viewGenResults.Views;

                if (viewGenResults.HasErrors)
                {
                    throw new MappingException(Helper.CombineErrorMessage(viewGenResults.Errors));
                }

                Debug.Assert(extentMappingViews.AllValues.Count() == 1, "Viewgen should have produced only one view");
                generatedView = extentMappingViews.AllValues.First();

                return(true);
            }
Exemplo n.º 20
0
 /// <summary>
 /// Construct a new AssociationSetMapping object
 /// </summary>
 /// <param name="extent">Represents the Association Set Metadata object. Will
 ///                      change this to Extent instead of MemberMetadata.</param>
 /// <param name="entityContainerMapping">The entityContainerMapping mapping that contains this Set mapping</param>
 internal StorageAssociationSetMapping(AssociationSet extent, StorageEntityContainerMapping entityContainerMapping)
     : base(extent, entityContainerMapping)
 {
 }
Exemplo n.º 21
0
 /// <summary>
 /// Construct a EntitySet mapping object
 /// </summary>
 /// <param name="extent">EntitySet metadata object</param>
 /// <param name="entityContainerMapping">The entity Container Mapping that contains this Set mapping</param>
 internal StorageEntitySetMapping(EntitySet extent, StorageEntityContainerMapping entityContainerMapping)
     : base(extent, entityContainerMapping)
 {
     m_modificationFunctionMappings       = new List <StorageEntityTypeModificationFunctionMapping>();
     m_implicitlyMappedAssociationSetEnds = new List <AssociationSetEnd>();
 }
            private bool TryGetCorrespondingStorageEntityContainerMapping(EntityViewContainer viewContainer,
                                                                          IEnumerable <StorageEntityContainerMapping> storageEntityContainerMappingList, out StorageEntityContainerMapping storageEntityContainerMapping)
            {
                storageEntityContainerMapping = null;

                foreach (var entityContainerMapping in storageEntityContainerMappingList)
                {
                    // first check
                    if (entityContainerMapping.EdmEntityContainer.Name == viewContainer.EdmEntityContainerName &&
                        entityContainerMapping.StorageEntityContainer.Name == viewContainer.StoreEntityContainerName)
                    {
                        storageEntityContainerMapping = entityContainerMapping;
                        return(true);
                    }
                }
                return(false);
            }
 internal InputForComputingCellGroups(StorageEntityContainerMapping containerMapping, ConfigViewGenerator config)
 {
     this.ContainerMapping = containerMapping;
     this.Config           = config;
 }
Exemplo n.º 24
0
 /// <summary>
 /// Construct the new StorageSetMapping object.
 /// </summary>
 /// <param name="extent">Extent metadata object</param>
 /// <param name="entityContainerMapping">The EntityContainer mapping that contains this extent mapping</param>
 internal StorageSetMapping(EntitySetBase extent, StorageEntityContainerMapping entityContainerMapping)
 {
     this.m_entityContainerMapping = entityContainerMapping;
     this.m_extent       = extent;
     this.m_typeMappings = new List <StorageTypeMapping>();
 }