File: StorageSetMapping.cs

package info (click to toggle)
mono 6.14.1%2Bds2-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 1,282,732 kB
  • sloc: cs: 11,182,461; xml: 2,850,281; ansic: 699,123; cpp: 122,919; perl: 58,604; javascript: 30,841; asm: 21,845; makefile: 19,602; sh: 10,973; python: 4,772; pascal: 925; sql: 859; sed: 16; php: 1
file content (249 lines) | stat: -rw-r--r-- 8,207 bytes parent folder | download | duplicates (6)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
//---------------------------------------------------------------------
// <copyright file="StorageSetMapping.cs" company="Microsoft">
//      Copyright (c) Microsoft Corporation.  All rights reserved.
// </copyright>
//
// @owner       Microsoft
// @backupOwner Microsoft
//---------------------------------------------------------------------

using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Text;
using System.Data.Metadata.Edm;
using System.Data.Common.Utils;
using System.Diagnostics;
using System.Linq;

namespace System.Data.Mapping {

    using Triple = Pair<EntitySetBase, Pair<EntityTypeBase, bool>>;

    /// <summary>
    /// Represents the Mapping metadata for an Extent in CS space.
    /// </summary>
    /// <example>
    /// For Example if conceptually you could represent the CS MSL file as following
    /// --Mapping 
    ///   --EntityContainerMapping ( CNorthwind-->SNorthwind )
    ///     --EntitySetMapping
    ///       --EntityTypeMapping
    ///         --MappingFragment
    ///       --EntityTypeMapping
    ///         --MappingFragment
    ///     --AssociationSetMapping 
    ///       --AssociationTypeMapping
    ///         --MappingFragment
    /// This class represents the metadata for all the extent map elements in the 
    /// above example namely EntitySetMapping, AssociationSetMapping and CompositionSetMapping.
    /// The SetMapping elements that are children of the EntityContainerMapping element
    /// can be accessed through the properties on this type.
    /// </example>
    internal abstract class StorageSetMapping
    {
        #region Constructors
        /// <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>();
        }
        #endregion

        #region Fields
        /// <summary>
        /// The EntityContainer mapping that contains this extent mapping.
        /// </summary>
        private StorageEntityContainerMapping m_entityContainerMapping;
        /// <summary>
        /// The extent for which this mapping represents.
        /// </summary>
        private EntitySetBase m_extent;
        /// <summary>
        /// Set of type mappings that make up the Set Mapping.
        /// Unless this is a EntitySetMapping with inheritance,
        /// you would have a single type mapping per set.
        /// </summary>
        private List<StorageTypeMapping> m_typeMappings;
        /// <summary>
        /// User defined Query View for the EntitySet.
        /// </summary>
        private string m_queryView;
        /// <summary>
        /// Line Number for Set Mapping element start tag.
        /// </summary>
        private int m_startLineNumber;
        /// <summary>
        /// Line position for Set Mapping element start tag.
        /// </summary>
        private int m_startLinePosition;
        /// <summary>
        /// Has modificationfunctionmapping for set mapping.
        /// </summary>
        private bool m_hasModificationFunctionMapping;
        /// <summary>
        /// Stores type-Specific user-defined QueryViews.
        /// </summary>
        private Dictionary<Triple, string> m_typeSpecificQueryViews = new Dictionary<Triple, string>(Triple.PairComparer.Instance);

        #endregion

        #region Properties
        /// <summary>
        /// The set for which this mapping is for
        /// </summary>
        internal EntitySetBase Set
        {
            get {
                return this.m_extent;
            }
        }

        ///// <summary>
        ///// TypeMappings that make up this set type.
        ///// For AssociationSet and CompositionSet there will be one type (at least that's what
        ///// we expect as of now). EntitySet could have mappings for multiple Entity types.
        ///// </summary>
        internal ReadOnlyCollection<StorageTypeMapping> TypeMappings
        {
            get
            {
                return this.m_typeMappings.AsReadOnly();
            }
        }

        internal StorageEntityContainerMapping EntityContainerMapping 
        {
            get 
            { 
                return m_entityContainerMapping; 
            }
        }

        /// <summary>
        /// Whether the SetMapping has empty content
        /// Returns true if there no table Mapping fragments
        /// </summary>
        internal virtual bool HasNoContent 
        {
            get
            {
                if (QueryView != null)
                {
                    return false;
                }
                foreach (StorageTypeMapping typeMap in TypeMappings)
                {
                    foreach (StorageMappingFragment mapFragment in typeMap.MappingFragments)
                    {
                        foreach (StoragePropertyMapping propertyMap in mapFragment.AllProperties)
                        {
                            return false;
                        }

                    }
                }
                return true;
            }
        }

        internal string QueryView
        {
            get { return m_queryView; }
            set { m_queryView = value; }
        }

        /// <summary>
        /// Line Number in MSL file where the Set Mapping Element's Start Tag is present.
        /// </summary>
        internal int StartLineNumber
        {
            get
            {
                return m_startLineNumber;
            }
            set
            {
                m_startLineNumber = value;
            }
        }

        /// <summary>
        /// Line Position in MSL file where the Set Mapping Element's Start Tag is present.
        /// </summary>
        internal int StartLinePosition
        {
            get
            {
                return m_startLinePosition;
            }
            set
            {
                m_startLinePosition = value;
            }
        }

        internal bool HasModificationFunctionMapping
        {
            get
            {
                return m_hasModificationFunctionMapping;
            }
            set
            {
                m_hasModificationFunctionMapping = value;
            }
        }
        #endregion

        #region Methods
        /// <summary>
        /// Add type mapping as a child under this SetMapping
        /// </summary>
        /// <param name="typeMapping"></param>
        internal void AddTypeMapping(StorageTypeMapping typeMapping)
        {
            this.m_typeMappings.Add(typeMapping);
        }

        /// <summary>
        /// This method is primarily for debugging purposes.
        /// Will be removed shortly.
        /// </summary>
        internal abstract void Print(int index);


        internal bool ContainsTypeSpecificQueryView(Triple key)
        {
            return m_typeSpecificQueryViews.ContainsKey(key);
        }

        /// <summary>
        /// Stores a type-specific user-defiend QueryView so that it can be loaded
        /// into StorageMappingItemCollection's view cache.
        /// </summary>
        internal void AddTypeSpecificQueryView(Triple key, string viewString)
        {
            Debug.Assert(!m_typeSpecificQueryViews.ContainsKey(key), "Query View already present for the given Key");
            m_typeSpecificQueryViews.Add(key, viewString);
        }

        internal ReadOnlyCollection<Triple> GetTypeSpecificQVKeys()
        {
            return new ReadOnlyCollection<Triple>(m_typeSpecificQueryViews.Keys.ToList());
        }

        internal string GetTypeSpecificQueryView(Triple key)
        {
            Debug.Assert(m_typeSpecificQueryViews.ContainsKey(key));
            return m_typeSpecificQueryViews[key];
        }

        #endregion
    }
}