1 //--------------------------------------------------------------------- 2 // <copyright file="DbProviderManifest.cs" company="Microsoft"> 3 // Copyright (c) Microsoft Corporation. All rights reserved. 4 // </copyright> 5 // 6 // @owner Microsoft 7 // @backupOwner Microsoft 8 //--------------------------------------------------------------------- 9 10 namespace System.Data.Common 11 { 12 using System.Data.Metadata.Edm; 13 using System.Xml; 14 15 /// <summary> 16 /// Metadata Interface for all CLR types types 17 /// </summary> 18 [System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Naming", "CA1709:IdentifiersShouldBeCasedCorrectly", MessageId = "Db")] 19 public abstract class DbProviderManifest 20 { 21 /// <summary> 22 /// Constructor 23 /// </summary> DbProviderManifest()24 protected DbProviderManifest() 25 { 26 } 27 28 /// <summary>Value to pass to GetInformation to get the StoreSchemaDefinition</summary> 29 public static readonly string StoreSchemaDefinition = "StoreSchemaDefinition"; 30 /// <summary>Value to pass to GetInformation to get the StoreSchemaMapping</summary> 31 public static readonly string StoreSchemaMapping = "StoreSchemaMapping"; 32 /// <summary>Value to pass to GetInformation to get the ConceptualSchemaDefinition</summary> 33 public static readonly string ConceptualSchemaDefinition = "ConceptualSchemaDefinition"; 34 35 /// <summary>Value to pass to GetInformation to get the StoreSchemaDefinitionVersion3</summary> 36 public static readonly string StoreSchemaDefinitionVersion3 = "StoreSchemaDefinitionVersion3"; 37 /// <summary>Value to pass to GetInformation to get the StoreSchemaMappingVersion3</summary> 38 public static readonly string StoreSchemaMappingVersion3 = "StoreSchemaMappingVersion3"; 39 /// <summary>Value to pass to GetInformation to get the ConceptualSchemaDefinitionVersion3</summary> 40 public static readonly string ConceptualSchemaDefinitionVersion3 = "ConceptualSchemaDefinitionVersion3"; 41 42 // System Facet Info 43 /// <summary> 44 /// Name of the MaxLength Facet 45 /// </summary> 46 internal const string MaxLengthFacetName = "MaxLength"; 47 48 /// <summary> 49 /// Name of the Unicode Facet 50 /// </summary> 51 internal const string UnicodeFacetName = "Unicode"; 52 53 /// <summary> 54 /// Name of the FixedLength Facet 55 /// </summary> 56 internal const string FixedLengthFacetName = "FixedLength"; 57 58 /// <summary> 59 /// Name of the Precision Facet 60 /// </summary> 61 internal const string PrecisionFacetName = "Precision"; 62 63 /// <summary> 64 /// Name of the Scale Facet 65 /// </summary> 66 internal const string ScaleFacetName = "Scale"; 67 68 /// <summary> 69 /// Name of the Nullable Facet 70 /// </summary> 71 internal const string NullableFacetName = "Nullable"; 72 73 /// <summary> 74 /// Name of the DefaultValue Facet 75 /// </summary> 76 internal const string DefaultValueFacetName = "DefaultValue"; 77 78 /// <summary> 79 /// Name of the Collation Facet 80 /// </summary> 81 internal const string CollationFacetName = "Collation"; 82 83 /// <summary> 84 /// Name of the SRID Facet 85 /// </summary> 86 internal const string SridFacetName = "SRID"; 87 88 /// <summary> 89 /// Name of the IsStrict Facet 90 /// </summary> 91 internal const string IsStrictFacetName = "IsStrict"; 92 93 /// <summary> 94 /// Returns the namespace used by this provider manifest 95 /// </summary> 96 public abstract string NamespaceName {get;} 97 98 /// <summary> 99 /// Return the set of types supported by the store 100 /// </summary> 101 /// <returns>A collection of primitive types</returns> GetStoreTypes()102 public abstract System.Collections.ObjectModel.ReadOnlyCollection<PrimitiveType> GetStoreTypes(); 103 104 /// <summary> 105 /// Returns all the edm functions supported by the provider manifest. 106 /// </summary> 107 /// <returns>A collection of edm functions.</returns> GetStoreFunctions()108 public abstract System.Collections.ObjectModel.ReadOnlyCollection<EdmFunction> GetStoreFunctions(); 109 110 /// <summary> 111 /// Returns all the FacetDescriptions for a particular type 112 /// </summary> 113 /// <param name="edmType">the type to return FacetDescriptions for</param> 114 /// <returns>The FacetDescriptions for the type given</returns> 115 [System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Naming", "CA1704:IdentifiersShouldBeSpelledCorrectly", MessageId = "edm")] GetFacetDescriptions(EdmType edmType)116 public abstract System.Collections.ObjectModel.ReadOnlyCollection<FacetDescription> GetFacetDescriptions(EdmType edmType); 117 118 /// <summary> 119 /// This method allows a provider writer to take a type and a set of facets 120 /// and reason about what the best mapped equivalent type in EDM would be. 121 /// </summary> 122 /// <param name="storeType">A TypeUsage encapsulating a store type and a set of facets</param> 123 /// <returns>A TypeUsage encapsulating an EDM type and a set of facets</returns> 124 [System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Naming", "CA1704:IdentifiersShouldBeSpelledCorrectly", MessageId = "Edm")] GetEdmType(TypeUsage storeType)125 public abstract TypeUsage GetEdmType(TypeUsage storeType); 126 127 /// <summary> 128 /// This method allows a provider writer to take a type and a set of facets 129 /// and reason about what the best mapped equivalent type in the store would be. 130 /// </summary> 131 /// <param name="storeType">A TypeUsage encapsulating an EDM type and a set of facets</param> 132 /// <returns>A TypeUsage encapsulating a store type and a set of facets</returns> 133 [System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Naming", "CA1704:IdentifiersShouldBeSpelledCorrectly", MessageId = "edm")] GetStoreType(TypeUsage edmType)134 public abstract TypeUsage GetStoreType(TypeUsage edmType); 135 136 /// <summary> 137 /// Providers should override this to return information specific to their provider. 138 /// 139 /// This method should never return null. 140 /// </summary> 141 /// <param name="informationType">The name of the information to be retrieved.</param> 142 /// <returns>An XmlReader at the begining of the information requested.</returns> 143 [System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Naming", "CA1709:IdentifiersShouldBeCasedCorrectly", MessageId = "Db")] GetDbInformation(string informationType)144 protected abstract XmlReader GetDbInformation(string informationType); 145 146 /// <summary> 147 /// Gets framework and provider specific information 148 /// 149 /// This method should never return null. 150 /// </summary> 151 /// <param name="informationType">The name of the information to be retrieved.</param> 152 /// <returns>An XmlReader at the begining of the information requested.</returns> GetInformation(string informationType)153 public XmlReader GetInformation(string informationType) 154 { 155 XmlReader reader = null; 156 try 157 { 158 reader = GetDbInformation(informationType); 159 } 160 catch (Exception e) 161 { 162 // we should not be wrapping all exceptions 163 if (EntityUtil.IsCatchableExceptionType(e)) 164 { 165 // we don't want folks to have to know all the various types of exceptions that can 166 // occur, so we just rethrow a ProviderIncompatibleException and make whatever we caught 167 // the inner exception of it. 168 throw EntityUtil.ProviderIncompatible( 169 System.Data.Entity.Strings.EntityClient_FailedToGetInformation(informationType), e); 170 } 171 throw; 172 } 173 if (reader == null) 174 { 175 // if the provider returned null for the conceptual schema definition, return the default one 176 if (informationType == ConceptualSchemaDefinitionVersion3 || 177 informationType == ConceptualSchemaDefinition) 178 { 179 return DbProviderServices.GetConceptualSchemaDefinition(informationType); 180 } 181 182 throw EntityUtil.ProviderIncompatible(System.Data.Entity.Strings.ProviderReturnedNullForGetDbInformation(informationType)); 183 } 184 return reader; 185 186 } 187 188 /// <summary> 189 /// Does the provider support escaping strings to be used as patterns in a Like expression. 190 /// If the provider overrides this method to return true, <cref = "EscapeLikeArgument"/> should 191 /// also be overridden. 192 /// </summary> 193 /// <param name="escapeCharacter">If the provider supports escaping, the character that would be used 194 /// as the escape character</param> 195 /// <returns>True, if this provider supports escaping strings to be used as patterns in a Like expression, 196 /// false otherwise. The default implementation returns false.</returns> SupportsEscapingLikeArgument(out char escapeCharacter)197 public virtual bool SupportsEscapingLikeArgument(out char escapeCharacter) 198 { 199 escapeCharacter = default(char); 200 return false; 201 } 202 203 /// <summary> 204 /// Provider writers should override this method to returns the argument with the wildcards and the escape 205 /// character escaped. This method is only used if <cref = "SupportsEscapingLikeArgument"/> returns true. 206 /// </summary> 207 /// <param name="argument">The argument to be escaped</param> 208 /// <returns>The argument with the wildcards and the escape character escaped</returns> EscapeLikeArgument(string argument)209 public virtual string EscapeLikeArgument(string argument) 210 { 211 throw EntityUtil.ProviderIncompatible(System.Data.Entity.Strings.ProviderShouldOverrideEscapeLikeArgument); 212 } 213 } 214 } 215