/// <summary>
        /// Gets the edm type name from the spatial type based on facets.
        /// </summary>
        /// <param name="spatialType">Spatial type with factes.</param>
        /// <returns>Edm type name.</returns>
        private SpatialShapeKind GetKindBasedOnFacets(SpatialDataType spatialType)
        {
            // first we look for SpatialShapeKind, then EdmTypeName, and lastly UnqualifiedDatabaseTypeName
            // TODO: should SpatialShapeKind override EdmTypeName? 
            // seems reasonable if SSK: Point, ETN: Geography, but what about SSK: Point, ETN: LineString?
            var shape = spatialType.GetFacetValue<SpatialShapeKindFacet, SpatialShapeKind>(SpatialShapeKind.Unspecified);
            if (shape != SpatialShapeKind.Unspecified)
            {
                return shape;
            }

            var edmTypeName = spatialType.GetFacetValue<EdmTypeNameFacet, string>(string.Empty);
            if (!string.IsNullOrEmpty(edmTypeName))
            {
                return (SpatialShapeKind)Enum.Parse(typeof(SpatialShapeKind), edmTypeName, false);
            }

            var providerTypeName = spatialType.GetFacetValue<UnqualifiedDatabaseTypeNameFacet, string>(string.Empty).ToUpperInvariant();
            if (providerTypeName == "GEOMETRY")
            {
                return SpatialShapeKind.Geometry;
            }
            else
            {
                ExceptionUtilities.Assert(providerTypeName == "GEOGRAPHY", "Can't determine edm type given the provided facets.");
                return SpatialShapeKind.Geography;
            }
        }
Exemple #2
0
 /// <summary>
 /// Initializes a new instance of the QueryMappedScalarTypeWithStructure class.
 /// </summary>
 /// <param name="modelType">The conceptual model type.</param>
 /// <param name="storeType">The store model type.</param>
 /// <param name="evaluationStrategy">The evaluation strategy.</param>
 public QueryMappedScalarTypeWithStructure(SpatialDataType modelType, SpatialDataType storeType, IQueryEvaluationStrategy evaluationStrategy)
     : base(modelType, storeType, evaluationStrategy)
 {
     this.Properties = new List <QueryProperty>();
     this.Methods    = new List <Function>();
     this.IsReadOnly = false;
 }
Exemple #3
0
        private QueryClrSpatialType GetDefaultQueryClrTypeForSpatial(SpatialDataType spatialDataType, Type clrType)
        {
            ExceptionUtilities.CheckArgumentNotNull(spatialDataType, "spatialDataType");
            ExceptionUtilities.CheckArgumentNotNull(clrType, "clrType");

            QueryClrSpatialType spatialClrType;

            if (this.defaultQueryClrSpatialTypes.TryGetValue(spatialDataType, out spatialClrType))
            {
                return(spatialClrType);
            }

            spatialClrType = new QueryClrSpatialType(clrType, this.evaluationStrategy);
            this.defaultQueryClrSpatialTypes[spatialDataType] = spatialClrType;
            this.clrTypeToQueryScalarTypeMap[clrType]         = spatialClrType;

            // wire-up inheritance based on CLR types
            var derivedTypes = clrType.GetAssembly().GetTypes().Where(t => t.IsSubclassOf(clrType)).ToList();

            foreach (var derivedType in derivedTypes)
            {
                // only add types which are in EDM
                PrimitiveDataType edmType;
                if (this.TryGetEdmDataType(derivedType, out edmType))
                {
                    spatialClrType.DerivedTypes.Add((QueryClrSpatialType)this.GetDefaultQueryScalarType(derivedType));
                }
            }

            spatialClrType.Add(spatialDataType.Properties.Select(p => QueryProperty.Create(p.Name, this.GetDefaultQueryType(p.PropertyType))));
            spatialClrType.Add(spatialDataType.Methods);

            return(spatialClrType.MakeReadOnly());
        }
Exemple #4
0
        /// <summary>
        /// Finds and returns the data generator for given Spatial Data type
        /// </summary>
        /// <param name="spatialType">the spatial data type to get data generator for</param>
        /// <param name="isUnique">whether the generator should produce unique data.</param>
        /// <param name="random">The random number generator.</param>
        /// <param name="hints">The data generation hints.</param>
        /// <returns>the data generator for given spatial type</returns>
        public IDataGenerator GetDataGenerator(SpatialDataType spatialType, bool isUnique, IRandomNumberGenerator random, params DataGenerationHint[] hints)
        {
            ExceptionUtilities.CheckArgumentNotNull(spatialType, "spatialType");

            string dataTypeName = spatialType.GetFacetValue <EdmTypeNameFacet, string>(string.Empty);
            var    shapeKind    = GetHintValue <SpatialShapeKindHint, SpatialShapeKind>(SpatialShapeKind.Unspecified, hints);

            if (shapeKind != SpatialShapeKind.Unspecified)
            {
                dataTypeName = shapeKind.ToString();
            }

            ExceptionUtilities.Assert(
                !string.IsNullOrEmpty(dataTypeName),
                "the data type is not supported as spatial data type.");

            string          defaultSrid;
            SpatialTypeKind kind;

            if (dataTypeName.StartsWith("Geom", StringComparison.OrdinalIgnoreCase))
            {
                defaultSrid = SpatialConstants.DefaultSridForGeometry;
                kind        = SpatialTypeKind.Geometry;
            }
            else
            {
                defaultSrid = SpatialConstants.DefaultSridForGeography;
                kind        = SpatialTypeKind.Geography;
            }

            bool isNullable = spatialType.IsNullable && !hints.OfType <NoNullsHint>().Any();

            return(this.BuildGenerator(defaultSrid, dataTypeName, kind, isUnique, random, isNullable));
        }
        /// <summary>
        /// Gets the edm type name from the spatial type based on facets.
        /// </summary>
        /// <param name="spatialType">Spatial type with factes.</param>
        /// <returns>Edm type name.</returns>
        private SpatialShapeKind GetKindBasedOnFacets(SpatialDataType spatialType)
        {
            // first we look for SpatialShapeKind, then EdmTypeName, and lastly UnqualifiedDatabaseTypeName
            // TODO: should SpatialShapeKind override EdmTypeName?
            // seems reasonable if SSK: Point, ETN: Geography, but what about SSK: Point, ETN: LineString?
            var shape = spatialType.GetFacetValue <SpatialShapeKindFacet, SpatialShapeKind>(SpatialShapeKind.Unspecified);

            if (shape != SpatialShapeKind.Unspecified)
            {
                return(shape);
            }

            var edmTypeName = spatialType.GetFacetValue <EdmTypeNameFacet, string>(string.Empty);

            if (!string.IsNullOrEmpty(edmTypeName))
            {
                return((SpatialShapeKind)Enum.Parse(typeof(SpatialShapeKind), edmTypeName, false));
            }

            var providerTypeName = spatialType.GetFacetValue <UnqualifiedDatabaseTypeNameFacet, string>(string.Empty).ToUpperInvariant();

            if (providerTypeName == "GEOMETRY")
            {
                return(SpatialShapeKind.Geometry);
            }
            else
            {
                ExceptionUtilities.Assert(providerTypeName == "GEOGRAPHY", "Can't determine edm type given the provided facets.");
                return(SpatialShapeKind.Geography);
            }
        }
Exemple #6
0
        public static bool IsGeometricSpatialType(SpatialDataType spatialDataType)
        {
            ExceptionUtilities.CheckArgumentNotNull(spatialDataType, "spatialDataType");
            string dataTypeName = GetSpatialTypeName(spatialDataType);

            return(dataTypeName.StartsWith("Geom", StringComparison.OrdinalIgnoreCase));
        }
Exemple #7
0
        private QueryScalarType GetDefaultQueryTypeForSpatial(PrimitiveDataType storeType, PrimitiveDataType modelType, SpatialDataType spatialDataType)
        {
            ExceptionUtilities.CheckArgumentNotNull(storeType, "storeType");
            ExceptionUtilities.CheckArgumentNotNull(modelType, "modelType");
            ExceptionUtilities.CheckArgumentNotNull(spatialDataType, "spatialDataType");

            QueryMappedScalarTypeWithStructure spatialQDT;

            if (this.defaultQuerySpatialTypes.TryGetValue(spatialDataType, out spatialQDT))
            {
                return(spatialQDT);
            }

            SpatialDataType spatialStoreType = storeType as SpatialDataType;
            SpatialDataType spatialModelType = modelType as SpatialDataType;

            var spatialMappedType = new QueryMappedScalarTypeWithStructure(spatialModelType, spatialStoreType, this.evaluationStrategy);

            this.defaultQuerySpatialTypes[spatialDataType] = spatialMappedType;

            spatialMappedType.Add(spatialModelType.Properties.Select(p => QueryProperty.Create(p.Name, this.GetDefaultQueryType(p.PropertyType))));
            spatialMappedType.Add(spatialModelType.Methods);

            return(spatialMappedType.MakeReadOnly());
        }
Exemple #8
0
        private IDataGenerator ResolveNonCollectionDataGenerator(DataType dataType, bool isUnique, IList <DataGenerationHint> dataGenHints)
        {
            ComplexDataType complexDataType = dataType as ComplexDataType;

            if (complexDataType != null)
            {
                var complexGenerator = this.GetOrCreateAndRegisterStructuralDataGeneratorForComplexType(complexDataType.Definition);
                if (dataType.IsNullable)
                {
                    return(new NullableNamedValuesGeneratorProxy(complexGenerator, this.Random, dataGenHints));
                }

                return(complexGenerator);
            }

            EnumDataType enumDataType = dataType as EnumDataType;

            if (enumDataType != null)
            {
                return(this.GetOrCreateAndRegisterNonCollectionDataGeneratorForEnumType(enumDataType, isUnique, dataGenHints));
            }

            PrimitiveDataType primitiveDataType = dataType as PrimitiveDataType;
            SpatialDataType   spatialType       = dataType as SpatialDataType;

            if (primitiveDataType == null)
            {
                throw new TaupoNotSupportedException(
                          string.Format(CultureInfo.InvariantCulture, "Data generator creation is not supported for this data type: '{0}'.", dataType.ToString()));
            }
            else if (spatialType != null)
            {
                ExceptionUtilities.CheckObjectNotNull(
                    this.SpatialDataGeneratorResolver,
                    "Cannot generate value for spatial data type '{0}' without SpatialDataGeneratorResolver being set",
                    dataType);

                var isUniqueHint = dataGenHints.OfType <AllUniqueHint>().SingleOrDefault();

                if (isUniqueHint != null)
                {
                    isUnique = true;
                }

                return(this.SpatialDataGeneratorResolver.GetDataGenerator(spatialType, isUnique, this.Random, dataGenHints.ToArray()));
            }
            else
            {
                Type clrType    = null;
                bool isNullable = true;

                clrType = primitiveDataType.GetFacetValue <PrimitiveClrTypeFacet, Type>(null);
                ExceptionUtilities.CheckObjectNotNull(clrType, "Facet of type '{0}' not defined on a property type '{1}'.", typeof(PrimitiveClrTypeFacet).Name, dataType);
                isNullable = primitiveDataType.IsNullable;

                return(this.ResolvePrimitiveDataGeneratorBasedOnClrType(clrType, isUnique, isNullable, dataGenHints));
            }
        }
Exemple #9
0
        /// <summary>
        /// Parses the primitive type
        /// </summary>
        /// <param name="typeName">the name of the primitive type</param>
        /// <param name="facets">the facets attributes associated with the type</param>
        /// <returns>the primitive data type representation in the entity model schema</returns>
        protected override PrimitiveDataType ParsePrimitiveType(string typeName, IEnumerable <XAttribute> facets)
        {
            IEnumerable <string> spatialTypes =
                EdmDataTypes.GetAllPrimitiveTypes(EdmVersion.V40)
                .OfType <SpatialDataType>()
                .Select(t => EdmDataTypes.GetEdmName(t));

            if (typeName == "Binary")
            {
                return(EdmDataTypes.Binary(
                           this.GetIntFacetValue(facets, "MaxLength")));
            }
            else if (typeName == "DateTime")
            {
                return(EdmDataTypes.DateTime(this.GetIntFacetValue(facets, "Precision")));
            }
            else if (typeName == "DateTimeOffset")
            {
                return(EdmDataTypes.DateTimeOffset(this.GetIntFacetValue(facets, "Precision")));
            }
            else if (typeName == "Decimal")
            {
                return(EdmDataTypes.Decimal(
                           this.GetIntFacetValue(facets, "Precision"),
                           this.GetIntFacetValue(facets, "Scale")));
            }
            else if (typeName == "String")
            {
                return(EdmDataTypes.String(
                           this.GetIntFacetValue(facets, "MaxLength"),
                           this.GetBoolFacetValue(facets, "Unicode")));
            }
            else if (typeName == "Duration")
            {
                return(EdmDataTypes.Time(this.GetIntFacetValue(facets, "Precision")));
            }
            else if (this.ConsiderSrid)
            {
                if (spatialTypes.Contains(typeName))
                {
                    SpatialDataType spatialDataType = name2EdmDataType[typeName] as SpatialDataType;
                    return(this.GetSpatialDataTypeWithSrid(spatialDataType, facets));
                }
                else
                {
                    ExceptionUtilities.Assert(name2EdmDataType.ContainsKey(typeName), "EDM type '" + typeName + "' not supported.");
                    return(name2EdmDataType[typeName]);
                }
            }
            else
            {
                ExceptionUtilities.Assert(name2EdmDataType.ContainsKey(typeName), "EDM type '" + typeName + "' not supported.");
                return(name2EdmDataType[typeName]);
            }
        }
        /// <summary>
        /// Finds and returns the clr type for given spatial type
        /// </summary>
        /// <returns>the clr type for given spatial type</returns>
        /// <param name="spatialType">the spatial type to get clr type for</param>
        public Type GetClrType(SpatialDataType spatialType)
        {
            ExceptionUtilities.CheckArgumentNotNull(spatialType, "spatialType");

            string dataTypeName = spatialType.GetFacetValue<EdmTypeNameFacet, string>(string.Empty).ToUpperInvariant();
            Type clrType;
            ExceptionUtilities.Assert(
                spatialClrTypes.TryGetValue(dataTypeName, out clrType),
                "the data type {0} is not supported as spatial data type.",
                dataTypeName);

            return clrType;
        }
Exemple #11
0
        private SpatialDataType GetSpatialDataTypeWithSrid(SpatialDataType spatialDataType, IEnumerable <XAttribute> facets)
        {
            if (facets != null)
            {
                var attribute = facets.SingleOrDefault(c => c.Name == "SRID");
                if (attribute != null)
                {
                    return(spatialDataType.WithSrid(attribute.Value));
                }
            }

            return(spatialDataType);
        }
        /// <summary>
        /// Resolves the full definition of the spatial type, potentially given only the EDM type name
        /// </summary>
        /// <param name="dataType">The basic definition which has at least the EDM type name</param>
        /// <returns>The fully defined spatial type with properties and methods</returns>
        public SpatialDataType ResolveFullDefinition(SpatialDataType dataType)
        {
            ExceptionUtilities.CheckArgumentNotNull(dataType, "dataType");

            var kind       = this.GetKindBasedOnFacets(dataType);
            var returnType = this.GetDataTypeForKind(kind);

            foreach (var facet in dataType.Facets.Where(f => !(f is EdmTypeNameFacet) && !(f is SpatialShapeKindFacet) && !(f is EdmNamespaceFacet) && !(f is PrimitiveClrTypeFacet)))
            {
                returnType = returnType.WithFacet(facet);
            }

            return(returnType);
        }
        /// <summary>
        /// Finds and returns the clr type for given spatial type
        /// </summary>
        /// <returns>the clr type for given spatial type</returns>
        /// <param name="spatialType">the spatial type to get clr type for</param>
        public Type GetClrType(SpatialDataType spatialType)
        {
            ExceptionUtilities.CheckArgumentNotNull(spatialType, "spatialType");

            string dataTypeName = spatialType.GetFacetValue <EdmTypeNameFacet, string>(string.Empty).ToUpperInvariant();
            Type   clrType;

            ExceptionUtilities.Assert(
                spatialClrTypes.TryGetValue(dataTypeName, out clrType),
                "the data type {0} is not supported as spatial data type.",
                dataTypeName);

            return(clrType);
        }
        /// <summary>
        /// Resolves the full definition of the spatial type, potentially given only the EDM type name
        /// </summary>
        /// <param name="dataType">The basic definition which has at least the EDM type name</param>
        /// <returns>The fully defined spatial type with properties and methods</returns>
        public SpatialDataType ResolveFullDefinition(SpatialDataType dataType)
        {
            ExceptionUtilities.CheckArgumentNotNull(dataType, "dataType");

            var kind = this.GetKindBasedOnFacets(dataType);
            var returnType = this.GetDataTypeForKind(kind);

            foreach (var facet in dataType.Facets.Where(f => !(f is EdmTypeNameFacet) && !(f is SpatialShapeKindFacet) && !(f is EdmNamespaceFacet) && !(f is PrimitiveClrTypeFacet)))
            {
                returnType = returnType.WithFacet(facet);
            }

            return returnType;
        }
        private void CompareSpatialDataType(string memberName, SpatialDataType expectedSpatialDataType, SpatialDataType actualSpatialDataType)
        {
            SridFacet expectedSridFacet = expectedSpatialDataType.Facets.OfType <SridFacet>().SingleOrDefault();
            SridFacet actualSridFacet   = actualSpatialDataType.Facets.OfType <SridFacet>().SingleOrDefault();

            if (expectedSridFacet == null)
            {
                this.WriteErrorIfFalse(actualSridFacet == null, "Expected no SRID facet on member '{0}' but got '{1}'", memberName, actualSridFacet);
            }
            else if (actualSridFacet == null)
            {
                this.WriteError("Expected SRID '{0}' on member '{1}' but got none", expectedSridFacet, memberName);
            }
            else
            {
                this.WriteErrorIfFalse(expectedSridFacet.Value == actualSridFacet.Value, "Expected SRID '{0}' on member '{1}' but got '{2}'", expectedSridFacet, memberName, actualSridFacet);
            }
        }
Exemple #16
0
 /// <summary>
 /// Initializes static members of the DataTypes class.
 /// </summary>
 static DataTypes()
 {
     Integer = new IntegerDataType();
     Stream = new StreamDataType();
     String = new StringDataType();
     Boolean = new BooleanDataType();
     FixedPoint = new FixedPointDataType();
     FloatingPoint = new FloatingPointDataType();
     DateTime = new DateTimeDataType();
     Binary = new BinaryDataType();
     Guid = new GuidDataType();
     TimeOfDay = new TimeOfDayDataType();
     ComplexType = new ComplexDataType();
     EntityType = new EntityDataType();
     CollectionType = new CollectionDataType();
     ReferenceType = new ReferenceDataType();
     RowType = new RowDataType();
     EnumType = new EnumDataType();
     Spatial = new SpatialDataType();
 }
Exemple #17
0
        private PrimitiveDataType TryResolveConceptualSpatialDataType(SpatialDataType spatialDataType)
        {
            PrimitiveDataType resolved = null;

            if (this.modelDataTypeResolver != null)
            {
                try
                {
                    resolved = this.modelDataTypeResolver.ResolvePrimitiveType(spatialDataType);
                }
                catch (TaupoInvalidOperationException)
                {
                }
                catch (TaupoNotSupportedException)
                {
                }
            }

            return(resolved);
        }
        private void CompareMemberPropertyDatatype(string memberName, DataType expectedDataType, DataType actualDataType)
        {
            PrimitiveDataType  expectedPrimitiveDataType  = expectedDataType as PrimitiveDataType;
            ComplexDataType    expectedComplexDataType    = expectedDataType as ComplexDataType;
            CollectionDataType expectedCollectionDataType = expectedDataType as CollectionDataType;
            SpatialDataType    expectedSpatialDataType    = expectedDataType as SpatialDataType;

            if (expectedPrimitiveDataType != null)
            {
                PrimitiveDataType actualPrimitiveDataType = actualDataType as PrimitiveDataType;
                this.WriteErrorIfFalse(actualPrimitiveDataType != null, "Expected member '{0}' with primitiveDataType '{1}' instead of '{2}'", memberName, expectedPrimitiveDataType, actualDataType);

                if (expectedSpatialDataType != null)
                {
                    SpatialDataType actualSpatialDataType = actualDataType as SpatialDataType;
                    this.CompareSpatialDataType(memberName, expectedSpatialDataType, actualSpatialDataType);
                }
            }
            else if (expectedComplexDataType != null)
            {
                ComplexDataType actualComplexDataType = actualDataType as ComplexDataType;
                if (!this.WriteErrorIfFalse(expectedComplexDataType != null, "Expected member '{0}' with complexDataType '{1}' instead of '{2}'", memberName, expectedComplexDataType, actualDataType))
                {
                    this.WriteErrorIfFalse(expectedComplexDataType.Definition.Name == actualComplexDataType.Definition.Name, "Expected member '{0}' with complexType Name '{1}' not '{2}'", memberName, expectedComplexDataType.Definition.Name, actualComplexDataType.Definition.Name);
                }
            }
            else
            {
                CollectionDataType actualCollectionDataType = actualDataType as CollectionDataType;
                if (!this.WriteErrorIfFalse(expectedCollectionDataType != null, "Expected member '{0}' with collectionType '{1}' instead of '{2}'", memberName, expectedCollectionDataType, actualDataType))
                {
                    this.CompareMemberPropertyDatatype(memberName, expectedCollectionDataType.ElementDataType, actualCollectionDataType.ElementDataType);
                }
            }

            // Complex properties need not be handled specially as they can also have IsNullable = true. The scenario for complex property is given below:
            // For reflection and custom: If the DSV <= 2 then it should always contain Nullable=’false’. For DSV >= 3, it should always contain Nullable=’true’
            // For EF: For all DSV values it should always contain Nullable=’false’ since complex types are always non-nullable in EF.
            this.WriteErrorIfFalse(expectedDataType.IsNullable == actualDataType.IsNullable, "Expected member '{0}' to have an IsNullable of '{1}' instead of '{2}'", memberName, expectedDataType.IsNullable, actualDataType.IsNullable);
        }
Exemple #19
0
 /// <summary>
 /// Resolves the specified data type specification into EDM data type.
 /// </summary>
 /// <param name="dataType">The data type.</param>
 /// <returns>Implementation-specific value.</returns>
 PrimitiveDataType IPrimitiveDataTypeVisitor <PrimitiveDataType> .Visit(SpatialDataType dataType)
 {
     ExceptionUtilities.CheckObjectNotNull(this.parent.SpatialDefinitionResolver, "Cannot resolve full type definition data type. {0} is not provided.", typeof(ISpatialDataTypeDefinitionResolver));
     return(this.parent.SpatialDefinitionResolver.ResolveFullDefinition(dataType));
 }
Exemple #20
0
        private SpatialDataType GetSpatialDataTypeWithSrid(SpatialDataType spatialDataType, IEnumerable<XAttribute> facets)
        {
            if (facets != null)
            {
                var attribute = facets.SingleOrDefault(c => c.Name == "SRID");
                if (attribute != null)
                {
                    return spatialDataType.WithSrid(attribute.Value);
                }
            }

            return spatialDataType;
        }
        private void CompareSpatialDataType(string memberName, SpatialDataType expectedSpatialDataType, SpatialDataType actualSpatialDataType)
        {
            SridFacet expectedSridFacet = expectedSpatialDataType.Facets.OfType<SridFacet>().SingleOrDefault();
            SridFacet actualSridFacet = actualSpatialDataType.Facets.OfType<SridFacet>().SingleOrDefault();

            if (expectedSridFacet == null)
            {
                this.WriteErrorIfFalse(actualSridFacet == null, "Expected no SRID facet on member '{0}' but got '{1}'", memberName, actualSridFacet);
            }
            else if (actualSridFacet == null)
            {
                this.WriteError("Expected SRID '{0}' on member '{1}' but got none", expectedSridFacet, memberName);
            }
            else
            {
                this.WriteErrorIfFalse(expectedSridFacet.Value == actualSridFacet.Value, "Expected SRID '{0}' on member '{1}' but got '{2}'", expectedSridFacet, memberName, actualSridFacet);
            }
        }
        IEdmPrimitiveTypeReference IPrimitiveDataTypeVisitor <IEdmPrimitiveTypeReference> .Visit(SpatialDataType dataType)
        {
            IEdmPrimitiveType typeDefinition = this.GetEdmTypeDefinition(dataType);

            return(new EdmSpatialTypeReference(typeDefinition, dataType.IsNullable, null));
        }