Ejemplo n.º 1
0
        public static NullableType GetTypeType(int length)
        {
            var key = GetKeyForLengthOrScaleBased(typeof(TypeType).FullName, length);

            return((NullableType)typeByTypeOfName.GetOrAdd(key, k => new TypeType(SqlTypeFactory.GetString(length))));
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Gets a <see cref="DateTimeOffsetType" /> with desired fractional seconds precision.
        /// </summary>
        /// <param name="fractionalSecondsPrecision">The fractional seconds precision.</param>
        /// <returns>The NHibernate type.</returns>
        public static NullableType GetDateTimeOffsetType(byte fractionalSecondsPrecision)
        {
            var key = GetKeyForLengthOrScaleBased(NHibernateUtil.DateTimeOffset.Name, fractionalSecondsPrecision);

            return((NullableType)typeByTypeOfName.GetOrAdd(key, k => new DateTimeOffsetType(SqlTypeFactory.GetDateTimeOffset(fractionalSecondsPrecision))));
        }
Ejemplo n.º 3
0
        public static NullableType GetSerializableType(int length)
        {
            var key = GetKeyForLengthOrScaleBased(NHibernateUtil.Serializable.Name, length);

            return((NullableType)typeByTypeOfName.GetOrAdd(key, k => new SerializableType(typeof(object), SqlTypeFactory.GetBinary(length))));
        }
Ejemplo n.º 4
0
        public static NullableType GetStringType(int length)
        {
            var key = GetKeyForLengthOrScaleBased(NHibernateUtil.String.Name, length);

            return((NullableType)typeByTypeOfName.GetOrAdd(key, k => new StringType(SqlTypeFactory.GetString(length))));
        }
Ejemplo n.º 5
0
        public static NullableType GetSerializableType(System.Type serializableType, int length)
        {
            var key = GetKeyForLengthOrScaleBased(serializableType.AssemblyQualifiedName, length);

            return((NullableType)typeByTypeOfName.GetOrAdd(key, k => new SerializableType(serializableType, SqlTypeFactory.GetBinary(length))));
        }
Ejemplo n.º 6
0
        private static NullableType GetType(NullableType defaultUnqualifiedType, byte precision, byte scale, NullableTypeCreatorDelegate ctor)
        {
            var key = GetKeyForPrecisionScaleBased(defaultUnqualifiedType.Name, precision, scale);

            return((NullableType)typeByTypeOfName.GetOrAdd(key, k => ctor(SqlTypeFactory.GetSqlType(defaultUnqualifiedType.SqlType.DbType, precision, scale))));
        }
Ejemplo n.º 7
0
        /// <summary>
        /// Register other NO Default .NET type
        /// </summary>
        /// <remarks>
        /// These type will be used only when the "type" attribute was is specified in the mapping.
        /// These are in here because needed to NO override default CLR types and be available in mappings
        /// </remarks>
        private static void RegisterBuiltInTypes()
        {
            RegisterType(NHibernateUtil.AnsiString, EmptyAliases,
                         l => GetType(NHibernateUtil.AnsiString, l, len => new AnsiStringType(SqlTypeFactory.GetAnsiString(len))));

            RegisterType(NHibernateUtil.AnsiChar, EmptyAliases);

            RegisterType(NHibernateUtil.BinaryBlob, EmptyAliases,
                         l => GetType(NHibernateUtil.BinaryBlob, l, len => new BinaryBlobType(SqlTypeFactory.GetBinaryBlob(len))));

            RegisterType(NHibernateUtil.StringClob, EmptyAliases,
                         l => GetType(NHibernateUtil.StringClob, l, len => new StringClobType(SqlTypeFactory.GetStringClob(len))));

            RegisterType(NHibernateUtil.DateTimeNoMs, new[] { "datetimenoms" });
            RegisterType(NHibernateUtil.Date, new[] { "date" });
#pragma warning disable 618 // Timestamp is obsolete
            RegisterType(NHibernateUtil.Timestamp, new[] { "timestamp" });
#pragma warning restore 618
            RegisterType(NHibernateUtil.DbTimestamp, new[] { "dbtimestamp" });
            RegisterType(NHibernateUtil.UtcDbTimestamp, new[] { "utcdbtimestamp" });
            RegisterType(NHibernateUtil.Time, new[] { "time" },
                         s => GetType(NHibernateUtil.Time, s, scale => new TimeType(SqlTypeFactory.GetTime((byte)scale))));
            RegisterType(NHibernateUtil.TrueFalse, new[] { "true_false" });
            RegisterType(NHibernateUtil.YesNo, new[] { "yes_no" });
            RegisterType(NHibernateUtil.Ticks, new[] { "ticks" });
            RegisterType(NHibernateUtil.UtcTicks, new[] { "utcticks" });
            RegisterType(NHibernateUtil.TimeAsTimeSpan, new[] { "timeastimespan" },
                         s => GetType(NHibernateUtil.TimeAsTimeSpan, s, scale => new TimeAsTimeSpanType(SqlTypeFactory.GetTime((byte)scale))));
            RegisterType(NHibernateUtil.LocalDateTime, new[] { "localdatetime" },
                         s => GetType(NHibernateUtil.LocalDateTime, s, scale => new LocalDateTimeType(SqlTypeFactory.GetDateTime((byte)scale))));
            RegisterType(NHibernateUtil.UtcDateTime, new[] { "utcdatetime" },
                         s => GetType(NHibernateUtil.UtcDateTime, s, scale => new UtcDateTimeType(SqlTypeFactory.GetDateTime((byte)scale))));
            RegisterType(NHibernateUtil.LocalDateTimeNoMs, new[] { "localdatetimenoms" });
            RegisterType(NHibernateUtil.UtcDateTimeNoMs, new[] { "utcdatetimenoms" });

            RegisterType(NHibernateUtil.Currency, new[] { "currency" },
                         (p, s) => GetType(NHibernateUtil.Currency, p, s, st => new CurrencyType(st)));

#pragma warning disable 618 // DateTime2 is obsolete
            RegisterType(NHibernateUtil.DateTime2, new[] { "datetime2" },
                         s => GetType(NHibernateUtil.DateTime2, s, scale => new DateTime2Type(SqlTypeFactory.GetDateTime2((byte)scale))));
#pragma warning restore 618
            RegisterType(NHibernateUtil.Serializable, new[] { "Serializable", "serializable" },
                         l =>
                         GetType(NHibernateUtil.Serializable, l,
                                 len => new SerializableType(typeof(object), SqlTypeFactory.GetBinary(len))));
        }
Ejemplo n.º 8
0
        /// <summary>
        /// Register other Default .NET type
        /// </summary>
        /// <remarks>
        /// These type will be used, as default, even when the "type" attribute was NOT specified in the mapping
        /// </remarks>
        private static void RegisterDefaultNetTypes()
        {
            // NOTE: each .NET type should appear only one time
            RegisterType(typeof(Byte[]), NHibernateUtil.Binary, new[] { "binary" },
                         l => GetType(NHibernateUtil.Binary, l, len => new BinaryType(SqlTypeFactory.GetBinary(len))));

            RegisterType(typeof(Boolean), NHibernateUtil.Boolean, new[] { "boolean", "bool" });
            RegisterType(typeof(Byte), NHibernateUtil.Byte, new[] { "byte" });
            RegisterType(typeof(Char), NHibernateUtil.Character, new[] { "character", "char" });
            RegisterType(typeof(CultureInfo), NHibernateUtil.CultureInfo, new[] { "locale" });
            RegisterType(typeof(DateTime), NHibernateUtil.DateTime, new[] { "datetime" },
                         s => GetType(NHibernateUtil.DateTime, s, scale => new DateTimeType(SqlTypeFactory.GetDateTime((byte)scale))));
            RegisterType(typeof(DateTimeOffset), NHibernateUtil.DateTimeOffset, new[] { "datetimeoffset" },
                         s => GetType(NHibernateUtil.DateTimeOffset, s, scale => new DateTimeOffsetType(SqlTypeFactory.GetDateTimeOffset((byte)scale))));

            RegisterType(typeof(Decimal), NHibernateUtil.Decimal, new[] { "big_decimal", "decimal" },
                         (p, s) => GetType(NHibernateUtil.Decimal, p, s, st => new DecimalType(st)));

            RegisterType(typeof(Double), NHibernateUtil.Double, new[] { "double" },
                         (p, s) => GetType(NHibernateUtil.Double, p, s, st => new DoubleType(st)));

            RegisterType(typeof(Guid), NHibernateUtil.Guid, new[] { "guid" });
            RegisterType(typeof(Int16), NHibernateUtil.Int16, new[] { "short" });
            RegisterType(typeof(Int32), NHibernateUtil.Int32, new[] { "integer", "int" });
            RegisterType(typeof(Int64), NHibernateUtil.Int64, new[] { "long" });
            RegisterType(typeof(SByte), NHibernateUtil.SByte, EmptyAliases);

            RegisterType(typeof(Single), NHibernateUtil.Single, new[] { "float", "single" },
                         (p, s) => GetType(NHibernateUtil.Single, p, s, st => new SingleType(st)));

            RegisterType(typeof(String), NHibernateUtil.String, new[] { "string" },
                         l => GetType(NHibernateUtil.String, l, len => new StringType(SqlTypeFactory.GetString(len))));

            RegisterType(typeof(TimeSpan), NHibernateUtil.TimeSpan, new[] { "timespan" });

            RegisterType(typeof(System.Type), NHibernateUtil.Class, new[] { "class" },
                         l => GetType(NHibernateUtil.Class, l, len => new TypeType(SqlTypeFactory.GetString(len))));

            RegisterType(typeof(UInt16), NHibernateUtil.UInt16, new[] { "ushort" });
            RegisterType(typeof(UInt32), NHibernateUtil.UInt32, new[] { "uint" });
            RegisterType(typeof(UInt64), NHibernateUtil.UInt64, new[] { "ulong" });

            RegisterType(typeof(XmlDocument), NHibernateUtil.XmlDoc, new[] { "xmldoc", "xmldocument", "xml" });

            RegisterType(typeof(Uri), NHibernateUtil.Uri, new[] { "uri", "url" });

            RegisterType(typeof(XDocument), NHibernateUtil.XDoc, new[] { "xdoc", "xdocument" });

            // object needs to have both class and serializable setup before it can
            // be created.
            RegisterType(typeof(Object), NHibernateUtil.Object, new[] { "object" });
        }
Ejemplo n.º 9
0
 /// <summary>
 /// Initializes a new instance of <see cref="EnumStringType"/>.
 /// </summary>
 /// <param name="enumClass">The <see cref="System.Type"/> of the Enum.</param>
 /// <param name="length">The length of the string that can be written to the column.</param>
 protected EnumStringType(System.Type enumClass, int length) : base(SqlTypeFactory.GetString(length), enumClass)
 {
 }