/// <summary> /// Constructor for a ref column /// </summary> /// <param name="type">column datatype</param> /// <param name="name">column name</param> /// <param name="entityIdentity">identity information for this entity</param> internal RefColumnMap(md.TypeUsage type, string name, EntityIdentity entityIdentity) : base(type, name) { Debug.Assert(entityIdentity != null, "Must specify entity identity information"); m_entityIdentity = entityIdentity; }
/// <summary> /// Basic constructor /// </summary> /// <param name="type">Column datatype</param> /// <param name="name">column name</param> /// <param name="elementMap">column map for the element of the collection</param> /// <param name="keys">list of key columns</param> /// <param name="foreignKeys">list of foreign key columns</param> internal SimpleCollectionColumnMap(md.TypeUsage type, string name, ColumnMap elementMap, SimpleColumnMap[] keys, SimpleColumnMap[] foreignKeys) : base(type, name, elementMap, keys, foreignKeys) { }
/// <summary> /// Create a simple columnmap - applies only to scalar properties /// (Temporarily, also for collections) /// Simply picks up the next available column in the reader /// </summary> /// <param name="type">Column type</param> /// <param name="name">column name</param> /// <returns>Column map for this column</returns> private SimpleColumnMap CreateSimpleColumnMap(md.TypeUsage type, string name) { Var newVar = GetNextVar(); SimpleColumnMap result = new VarRefColumnMap(type, name, newVar); return(result); }
/// <summary> /// Get the "new" type corresponding to the input type. For structured types, /// we return the flattened record type. /// For collections of structured type, we return a new collection type of the corresponding flattened /// type. /// For enum types we return the underlying type of the enum type. /// For strong spatial types we return the union type that includes the strong spatial type. /// For everything else, we return the input type /// </summary> /// <param name="type">the original type</param> /// <returns>the new type (if any)</returns> private md.TypeUsage GetNewType(md.TypeUsage type) { if (TypeUtils.IsStructuredType(type)) { TypeInfo typeInfo = GetTypeInfo(type); return(typeInfo.FlattenedTypeUsage); } md.TypeUsage elementType; if (TypeHelpers.TryGetCollectionElementType(type, out elementType)) { md.TypeUsage newElementType = GetNewType(elementType); if (newElementType.EdmEquals(elementType)) { return(type); } else { return(TypeHelpers.CreateCollectionTypeUsage(newElementType)); } } if (TypeUtils.IsEnumerationType(type)) { return(TypeHelpers.CreateEnumUnderlyingTypeUsage(type)); } if (md.TypeSemantics.IsStrongSpatialType(type)) { return(TypeHelpers.CreateSpatialUnionTypeUsage(type)); } // simple scalar return(type); }
/// <summary> /// ComparisonOp handling /// </summary> /// <param name="op"></param> /// <param name="n"></param> public override void Visit(ComparisonOp op, Node n) { // Check to see if the children are structured types. Furthermore, // if the children are of entity types, then all we really need are // the key properties (and the entityset property) // For record and ref types, simply keep going md.TypeUsage childOpType = (n.Child0.Op as ScalarOp).Type; if (!TypeUtils.IsStructuredType(childOpType)) { VisitChildren(n); } else if (md.TypeSemantics.IsRowType(childOpType) || md.TypeSemantics.IsReferenceType(childOpType)) { VisitDefault(n); } else { PlanCompiler.Assert(md.TypeSemantics.IsEntityType(childOpType), "unexpected childOpType?"); PropertyRefList desiredProperties = GetIdentityProperties(TypeHelpers.GetEdmType <md.EntityType>(childOpType)); // Now push these set of properties to each child foreach (Node chi in n.Children) { AddPropertyRefs(chi, desiredProperties); } // Visit the children VisitChildren(n); } }
/// <summary> /// Basic constructor /// </summary> /// <param name="type">datatype for this column</param> /// <param name="name">column name</param> /// <param name="commandId">Underlying command to locate this column</param> /// <param name="columnPos">Position in underlying reader</param> internal ScalarColumnMap(md.TypeUsage type, string name, int commandId, int columnPos) : base(type, name) { Debug.Assert(commandId >= 0, "invalid command id"); Debug.Assert(columnPos >= 0, "invalid column position"); m_commandId = commandId; m_columnPos = columnPos; }
/// <summary> /// Is this a structured type? /// Note: Structured, in this context means structured outside the server. /// UDTs for instance, are considered to be scalar types - all WinFS types, /// would by this argument, be scalar types. /// </summary> /// <param name="type">The type to check</param> /// <returns>true, if the type is a structured type</returns> internal static bool IsStructuredType(md.TypeUsage type) { return(md.TypeSemantics.IsReferenceType(type) || md.TypeSemantics.IsRowType(type) || md.TypeSemantics.IsEntityType(type) || md.TypeSemantics.IsRelationshipType(type) || (md.TypeSemantics.IsComplexType(type) && !IsUdt(type))); }
/// <summary> /// Constructor /// </summary> /// <param name="type">datatype of column</param> /// <param name="name">column name</param> /// <param name="elementMap">column map for collection element</param> /// <param name="keys">List of keys</param> /// <param name="foreignKeys">List of foreign keys</param> internal CollectionColumnMap(md.TypeUsage type, string name, ColumnMap elementMap, SimpleColumnMap[] keys, SimpleColumnMap[] foreignKeys) : base(type, name) { Debug.Assert(elementMap != null, "Must specify column map for element"); m_element = elementMap; m_keys = keys ?? new SimpleColumnMap[0]; m_foreignKeys = foreignKeys ?? new SimpleColumnMap[0]; }
public bool Equals(System.Data.Metadata.Edm.TypeUsage x, System.Data.Metadata.Edm.TypeUsage y) { if (x == null || y == null) { return(false); } return(TypeUsageEqualityComparer.Equals(x.EdmType, y.EdmType)); }
/// <summary> /// Constructor for a root type /// </summary> /// <param name="type"></param> internal RootTypeInfo(md.TypeUsage type, ExplicitDiscriminatorMap discriminatorMap) : base(type, null) { PlanCompiler.Assert(type.EdmType.BaseType == null, "only root types allowed here"); m_propertyMap = new Dictionary <PropertyRef, md.EdmProperty>(); m_propertyRefList = new List <PropertyRef>(); m_discriminatorMap = discriminatorMap; m_typeIdKind = TypeIdKind.Generated; }
/// <summary> /// Constructor /// </summary> /// <param name="newType">new "flat" record type corresponding to the Var's datatype</param> /// <param name="newVars">List of vars to replace current Var</param> /// <param name="newTypeProperties">List of properties in the "flat" record type</param> /// <param name="newVarsIncludeNullSentinelVar">Do the new vars include a var that represents a null sentinel either for this type or for any nested type</param> internal StructuredVarInfo(md.RowType newType, List <Var> newVars, List <md.EdmProperty> newTypeProperties, bool newVarsIncludeNullSentinelVar) { PlanCompiler.Assert(newVars.Count == newTypeProperties.Count, "count mismatch"); // I see a few places where this is legal // PlanCompiler.Assert(newVars.Count > 0, "0 vars?"); m_newVars = newVars; m_newProperties = newTypeProperties; m_newType = newType; m_newVarsIncludeNullSentinelVar = newVarsIncludeNullSentinelVar; m_newTypeUsage = md.TypeUsage.Create(newType); }
/// <summary> /// Internal constructor /// </summary> /// <param name="type">datatype of the column</param> /// <param name="name">column name</param> /// <param name="typeDiscriminator">column map for type discriminator column</param> /// <param name="baseTypeColumns">base list of fields common to all types</param> /// <param name="typeChoices">map from type discriminator value->columnMap</param> internal SimplePolymorphicColumnMap(md.TypeUsage type, string name, ColumnMap[] baseTypeColumns, SimpleColumnMap typeDiscriminator, Dictionary <object, TypedColumnMap> typeChoices) : base(type, name, baseTypeColumns) { Debug.Assert(typeDiscriminator != null, "Must specify a type discriminator column"); Debug.Assert(typeChoices != null, "No type choices for polymorphic column"); m_typedColumnMap = typeChoices; m_typeDiscriminator = typeDiscriminator; }
/// <summary> /// Get the datatype for a propertyRef. The only concrete classes that we /// handle are TypeIdPropertyRef, and BasicPropertyRef. /// AllPropertyRef is illegal here. /// For BasicPropertyRef, we simply pick up the type from the corresponding /// property. For TypeIdPropertyRef, we use "string" as the default type /// or the discriminator property type where one is available. /// </summary> /// <param name="typeInfo">typeinfo of the current type</param> /// <param name="p">current property ref</param> /// <returns>the datatype of the property</returns> private md.TypeUsage GetPropertyType(RootTypeInfo typeInfo, PropertyRef p) { md.TypeUsage result = null; PropertyRef innerProperty = null; // Get the "leaf" property first while (p is NestedPropertyRef) { NestedPropertyRef npr = (NestedPropertyRef)p; p = npr.OuterProperty; innerProperty = npr.InnerProperty; } if (p is TypeIdPropertyRef) { // // Get to the innermost type that specifies this typeid (the entity type), // get the datatype for the typeid column from that type // if (innerProperty != null && innerProperty is SimplePropertyRef) { md.TypeUsage innerType = ((SimplePropertyRef)innerProperty).Property.TypeUsage; TypeInfo innerTypeInfo = GetTypeInfo(innerType); result = innerTypeInfo.RootType.TypeIdType; } else { result = typeInfo.TypeIdType; } } else if (p is EntitySetIdPropertyRef || p is NullSentinelPropertyRef) { result = m_intType; } else if (p is RelPropertyRef) { result = (p as RelPropertyRef).Property.ToEnd.TypeUsage; } else { SimplePropertyRef simpleP = p as SimplePropertyRef; if (simpleP != null) { result = md.Helper.GetModelTypeUsage(simpleP.Property); } } result = GetNewType(result); PlanCompiler.Assert(null != result, "unrecognized property type?"); return(result); }
/// <summary> /// Internal constructor /// </summary> /// <param name="type">Column datatype</param> /// <param name="name">column name</param> /// <param name="elementMap">column map for collection element</param> /// <param name="keys">Keys for the collection</param> /// <param name="foreignKeys">Foreign keys for the collection</param> /// <param name="discriminator">Discriminator column map</param> /// <param name="discriminatorValue">Discriminator value</param> internal DiscriminatedCollectionColumnMap(md.TypeUsage type, string name, ColumnMap elementMap, SimpleColumnMap[] keys, SimpleColumnMap[] foreignKeys, SimpleColumnMap discriminator, object discriminatorValue) : base(type, name, elementMap, keys, foreignKeys) { Debug.Assert(discriminator != null, "Must specify a column map for the collection discriminator"); Debug.Assert(discriminatorValue != null, "Must specify a discriminator value"); m_discriminator = discriminator; m_discriminatorValue = discriminatorValue; }
protected TypeInfo(md.TypeUsage type, TypeInfo superType) { m_type = type; m_immediateSubTypes = new List<TypeInfo>(); m_superType = superType; if (superType != null) { // Add myself to my supertype's list of subtypes superType.m_immediateSubTypes.Add(this); // my supertype's root type is mine as well m_rootType = superType.RootType; } }
protected TypeInfo(md.TypeUsage type, TypeInfo superType) { m_type = type; m_immediateSubTypes = new List <TypeInfo>(); m_superType = superType; if (superType != null) { // Add myself to my supertype's list of subtypes superType.m_immediateSubTypes.Add(this); // my supertype's root type is mine as well m_rootType = superType.RootType; } }
/// <summary> /// Creates a column map for a column /// </summary> /// <param name="type">column datatype</param> /// <param name="name">column name</param> /// <returns></returns> private ColumnMap CreateColumnMap(md.TypeUsage type, string name) { // For simple types, create a simple column map // Temporarily, handle collections exactly the same way if (!TypeUtils.IsStructuredType(type)) { return(CreateSimpleColumnMap(type, name)); } // At this point, we must be dealing with either a record type, a // complex type, or an entity type return(CreateStructuralColumnMap(type, name)); }
private readonly RootTypeInfo m_rootType; // the top-most type in this types type hierarchy #endregion #region Constructors and factory methods /// <summary> /// Creates type information for a type /// </summary> /// <param name="type"></param> /// <param name="superTypeInfo"></param> /// <returns></returns> internal static TypeInfo Create(md.TypeUsage type, TypeInfo superTypeInfo, ExplicitDiscriminatorMap discriminatorMap) { TypeInfo result; if (superTypeInfo == null) { result = new RootTypeInfo(type, discriminatorMap); } else { result = new TypeInfo(type, superTypeInfo); } return(result); }
/// <summary> /// Find the TypeInfo entry for a type. For non-structured types, we always /// return null. For structured types, we return the entry in the typeInfoMap. /// If we don't find one, and the typeInfoMap has already been populated, then we /// assert /// </summary> /// <param name="type">the type to look up</param> /// <returns>the typeinfo for the type (null if we couldn't find one)</returns> internal TypeInfo GetTypeInfo(md.TypeUsage type) { if (!TypeUtils.IsStructuredType(type)) { return(null); } TypeInfo typeInfo = null; if (!m_typeInfoMap.TryGetValue(type, out typeInfo)) { PlanCompiler.Assert(!TypeUtils.IsStructuredType(type) || !m_typeInfoMapPopulated, "cannot find typeInfo for type " + type); } return(typeInfo); }
/// <summary> /// Internal constructor /// </summary> internal MultipleDiscriminatorPolymorphicColumnMap(md.TypeUsage type, string name, ColumnMap[] baseTypeColumns, SimpleColumnMap[] typeDiscriminators, Dictionary <md.EntityType, TypedColumnMap> typeChoices, Func <object[], md.EntityType> discriminate) : base(type, name, baseTypeColumns) { Debug.Assert(typeDiscriminators != null, "Must specify type discriminator columns"); Debug.Assert(typeChoices != null, "No type choices for polymorphic column"); Debug.Assert(discriminate != null, "Must specify discriminate"); m_typeDiscriminators = typeDiscriminators; m_typeChoices = typeChoices; m_discriminate = discriminate; }
/// <summary> /// Fills the StructuredTypeInfo instance from the itree provided. /// </summary> /// <param name="itree"></param> /// <param name="referencedTypes">referenced structured types</param> /// <param name="referencedEntitySets">referenced entitysets</param> /// <param name="freeFloatingEntityConstructorTypes">free-floating entityConstructor types</param> /// <param name="discriminatorMaps">discriminator information for entity sets mapped using TPH pattern</param> /// <param name="relPropertyHelper">helper for rel properties</param> private void Process(Command itree, HashSet <md.TypeUsage> referencedTypes, HashSet <md.EntitySet> referencedEntitySets, HashSet <md.EntityType> freeFloatingEntityConstructorTypes, Dictionary <md.EntitySetBase, DiscriminatorMapInfo> discriminatorMaps, RelPropertyHelper relPropertyHelper) { PlanCompiler.Assert(null != itree, "null itree?"); m_stringType = itree.StringType; m_intType = itree.IntegerType; m_relPropertyHelper = relPropertyHelper; ProcessEntitySets(referencedEntitySets, freeFloatingEntityConstructorTypes); ProcessDiscriminatorMaps(discriminatorMaps); ProcessTypes(referencedTypes); }
/// <summary> /// "Explode" a type. (ie) produce a flat record type with one property for each /// scalar property (top-level or nested) of the original type. /// Really deals with structured types, but also /// peels off collection wrappers /// </summary> /// <param name="type">the type to explode</param> /// <returns>the typeinfo for this type (with the explosion)</returns> private TypeInfo ExplodeType(md.TypeUsage type) { if (TypeUtils.IsStructuredType(type)) { TypeInfo typeInfo = GetTypeInfo(type); ExplodeType(typeInfo); return(typeInfo); } if (TypeUtils.IsCollectionType(type)) { md.TypeUsage elementType = TypeHelpers.GetEdmType <md.CollectionType>(type).TypeUsage; ExplodeType(elementType); return(null); } return(null); }
/// <summary> /// Create a TypeInfo (if necessary) for the type, and add it to the TypeInfo map /// </summary> /// <param name="type">the type to process</param> private void CreateTypeInfoForType(md.TypeUsage type) { // // peel off all collection wrappers // while (TypeUtils.IsCollectionType(type)) { type = TypeHelpers.GetEdmType <md.CollectionType>(type).TypeUsage; } // Only add "structured" types if (TypeUtils.IsStructuredType(type)) { // check for discriminator map... ExplicitDiscriminatorMap discriminatorMap; TryGetDiscriminatorMap(type.EdmType, out discriminatorMap); CreateTypeInfoForStructuredType(type, discriminatorMap); } }
public static void VerifyTypeUsagesEquivalent(LegacyMetadata.TypeUsage legacyTypeUsage, TypeUsage typeUsage) { if (typeUsage.EdmType.BuiltInTypeKind == BuiltInTypeKind.CollectionType) { VerifyTypeUsagesEquivalent( ((LegacyMetadata.CollectionType)legacyTypeUsage.EdmType).TypeUsage, ((CollectionType)typeUsage.EdmType).TypeUsage); } else { VerifyEdmTypesEquivalent(legacyTypeUsage.EdmType, typeUsage.EdmType); } var legacyTypeFacets = legacyTypeUsage.Facets.OrderBy(f => f.Name).ToArray(); var typeFacets = typeUsage.Facets.OrderBy(f => f.Name).ToArray(); Assert.Equal(legacyTypeFacets.Length, typeFacets.Length); for (var i = 0; i < legacyTypeFacets.Length; i++) { VerifyFacetsEquivalent(legacyTypeFacets[i], typeFacets[i]); } }
/// <summary> /// Create a column map for a structural column - ref/complextype/entity/record /// </summary> /// <param name="type">Type info for the type</param> /// <param name="name">column name</param> /// <returns></returns> private ColumnMap CreateStructuralColumnMap(md.TypeUsage type, string name) { // Get our augmented type information for this type TypeInfo typeInfo = m_typeInfo.GetTypeInfo(type); // records? if (md.TypeSemantics.IsRowType(type)) { return(CreateRecordColumnMap(typeInfo, name)); } // ref? if (md.TypeSemantics.IsReferenceType(type)) { return(CreateRefColumnMap(typeInfo, name)); } // polymorphic type? if (typeInfo.HasTypeIdProperty) { return(CreatePolymorphicColumnMap(typeInfo, name)); } // process complex/entity types appropriately if (md.TypeSemantics.IsComplexType(type)) { return(CreateComplexTypeColumnMap(typeInfo, name, null, null, null)); } if (md.TypeSemantics.IsEntityType(type)) { return(CreateEntityColumnMap(typeInfo, name, null, null, null, true)); } // Anything else is not supported (this currently includes relationship types) throw EntityUtil.NotSupported(type.Identity); }
/// <summary> /// Is this type a UDT? (ie) a structural type supported by the store /// </summary> /// <param name="type">the type in question</param> /// <returns>true, if the type was a UDT</returns> internal static bool IsUdt(md.TypeUsage type) { return(IsUdt(type.EdmType)); }
public int GetHashCode(System.Data.Metadata.Edm.TypeUsage obj) { return(obj.EdmType.Identity.GetHashCode()); }
/// <summary> /// Constructor /// </summary> /// <param name="newType">new "flat" record type corresponding to the Var's datatype</param> /// <param name="newVars">List of vars to replace current Var</param> /// <param name="newTypeProperties">List of properties in the "flat" record type</param> /// <param name="newVarsIncludeNullSentinelVar">Do the new vars include a var that represents a null sentinel either for this type or for any nested type</param> internal StructuredVarInfo(md.RowType newType, List<Var> newVars, List<md.EdmProperty> newTypeProperties, bool newVarsIncludeNullSentinelVar) { PlanCompiler.Assert(newVars.Count == newTypeProperties.Count, "count mismatch"); // I see a few places where this is legal // PlanCompiler.Assert(newVars.Count > 0, "0 vars?"); m_newVars = newVars; m_newProperties = newTypeProperties; m_newType = newType; m_newVarsIncludeNullSentinelVar = newVarsIncludeNullSentinelVar; m_newTypeUsage = md.TypeUsage.Create(newType); }
/// <summary> /// Create a new collection type based on the supplied element type /// </summary> /// <param name="elementType">element type of the collection</param> /// <returns>the new collection type</returns> internal static md.TypeUsage CreateCollectionType(md.TypeUsage elementType) { return(TypeHelpers.CreateCollectionTypeUsage(elementType)); }
/// <summary> /// Is this type an enum type? /// </summary> /// <param name="type">the current type</param> /// <returns>true, if this is an enum type</returns> internal static bool IsEnumerationType(md.TypeUsage type) { return(md.TypeSemantics.IsEnumerationType(type)); }
/// <summary> /// Simple constructor - just needs the name and type of the column /// </summary> /// <param name="type">column type</param> /// <param name="name">column name</param> internal ColumnMap(md.TypeUsage type, string name) { Debug.Assert(type != null, "Unspecified type"); m_type = type; m_name = name; }
/// <summary> /// constructor /// </summary> /// <param name="type">column datatype</param> /// <param name="name">column name</param> /// <param name="entityIdentity">entity identity information</param> /// <param name="properties">list of properties</param> internal EntityColumnMap(md.TypeUsage type, string name, ColumnMap[] properties, EntityIdentity entityIdentity) : base(type, name, properties) { Debug.Assert(entityIdentity != null, "Must specify an entity identity"); m_entityIdentity = entityIdentity; }
/// <summary> /// Fills the StructuredTypeInfo instance from the itree provided. /// </summary> /// <param name="itree"></param> /// <param name="referencedTypes">referenced structured types</param> /// <param name="referencedEntitySets">referenced entitysets</param> /// <param name="freeFloatingEntityConstructorTypes">free-floating entityConstructor types</param> /// <param name="discriminatorMaps">discriminator information for entity sets mapped using TPH pattern</param> /// <param name="relPropertyHelper">helper for rel properties</param> private void Process(Command itree, HashSet<md.TypeUsage> referencedTypes, HashSet<md.EntitySet> referencedEntitySets, HashSet<md.EntityType> freeFloatingEntityConstructorTypes, Dictionary<md.EntitySetBase, DiscriminatorMapInfo> discriminatorMaps, RelPropertyHelper relPropertyHelper) { PlanCompiler.Assert(null != itree, "null itree?"); m_stringType = itree.StringType; m_intType = itree.IntegerType; m_relPropertyHelper = relPropertyHelper; ProcessEntitySets(referencedEntitySets, freeFloatingEntityConstructorTypes); ProcessDiscriminatorMaps(discriminatorMaps); ProcessTypes(referencedTypes); }