Example #1
0
            public void Should_get_the_correct_value_from_column()
            {
                const string expected = "VARCHAR2";
                HbmId        id       = new HbmId
                {
                    column = new[]
                    {
                        new HbmColumn
                        {
                            sqltype = expected
                        }
                    }
                };
                string result = id.GetSqlType();

                result.ShouldBeEqualTo(expected);
            }
Example #2
0
 public IdMapper(MemberInfo member, HbmId hbmId)
 {
     this.member = member;
     this.hbmId  = hbmId;
     if (member != null)
     {
         System.Type idType = member.GetPropertyOrFieldType();
         hbmId.name     = member.Name;
         hbmId.type1    = idType.GetNhTypeName();
         accessorMapper = new AccessorPropertyMapper(member.DeclaringType, member.Name, x => hbmId.access = x);
     }
     else
     {
         hbmId.type1    = typeof(int).GetNhTypeName();
         accessorMapper = new NoMemberPropertyMapper();
     }
 }
Example #3
0
            public void Should_get_the_correct_value_from_column_given_null_column()
            {
                const string expected = "FirstName";
                HbmId        id       = new HbmId
                {
                    column = new[]
                    {
                        new HbmColumn
                        {
                            name = expected
                        }
                    }
                };
                string result = id.GetColumnName();

                result.ShouldBeEqualTo(expected);
            }
Example #4
0
        private static IDictionary <string, MetaAttribute> GetMetas(HbmId idSchema)
        {
            Dictionary <string, MetaAttribute> map = new Dictionary <string, MetaAttribute>();

            foreach (HbmMeta metaSchema in idSchema.meta ?? new HbmMeta[0])
            {
                MetaAttribute meta;
                if (!map.TryGetValue(metaSchema.attribute, out meta))
                {
                    meta = new MetaAttribute(metaSchema.attribute);
                    map[metaSchema.attribute] = meta;
                }

                meta.AddValue(metaSchema.GetText());
            }

            return(map);
        }
Example #5
0
            public void Should_get_the_correct_value_from_column()
            {
                const string expected = "Name";
                HbmId        id       = new HbmId
                {
                    column = new[]
                    {
                        new HbmColumn
                        {
                            index = expected
                        }
                    }
                };
                string result = id.GetUniqueIndex();

                result.ShouldNotBeNull();
                result.ShouldBeEqualTo(expected);
            }
Example #6
0
            public void Should_get__false__given_column_notnullSpecified_is_true_and_notnull_is_true()
            {
                HbmId id = new HbmId
                {
                    column = new[]
                    {
                        new HbmColumn
                        {
                            notnullSpecified = true,
                            notnull          = true
                        }
                    }
                };
                bool?result = id.CanBeNull();

                result.ShouldNotBeNull();
                result.Value.ShouldBeFalse();
            }
Example #7
0
            public void Should_get__false__given_column_uniqueSpecified_is_true_and_column_unique_is_false()
            {
                HbmId id = new HbmId
                {
                    column = new[]
                    {
                        new HbmColumn
                        {
                            uniqueSpecified = true,
                            unique          = false
                        }
                    }
                };
                bool?result = id.IsUnique();

                result.ShouldNotBeNull();
                result.Value.ShouldBeFalse();
            }
Example #8
0
        public ClassMapper(System.Type rootClass, HbmMapping mapDoc, MemberInfo idProperty)
            : base(rootClass, mapDoc)
        {
            classMapping      = new HbmClass();
            classMapping.name = rootClass.GetShortClassName(mapDoc);
            if (rootClass.IsAbstract)
            {
                classMapping.@abstract         = true;
                classMapping.abstractSpecified = true;
            }

            var hbmId = new HbmId();

            classMapping.Item = hbmId;
            idMapper          = new IdMapper(idProperty, hbmId);

            mapDoc.Items = ArrayHelper.Append(mapDoc.Items, classMapping);
        }
Example #9
0
            public void Should_get_the_correct_value_from_column_given_null_length()
            {
                const int expected = 16;
                HbmId     id       = new HbmId
                {
                    column = new[]
                    {
                        new HbmColumn
                        {
                            length = expected.ToString()
                        }
                    }
                };
                int?result = id.GetMaxLength();

                result.ShouldNotBeNull();
                result.Value.ShouldBeEqualTo(expected);
            }
Example #10
0
        private IDictionary <string, string> GetGeneratorProperties(HbmId idSchema, IValue id)
        {
            Dictionary <string, string> results = new Dictionary <string, string>();

            if (id.Table.Schema != null)
            {
                results.Add(Id.PersistentIdGeneratorParmsNames.Schema, id.Table.Schema);
            }
            else if (mappings.SchemaName != null)
            {
                results.Add(Id.PersistentIdGeneratorParmsNames.Schema, dialect.QuoteForSchemaName(mappings.SchemaName));
            }

            foreach (HbmParam paramSchema in idSchema.generator.param ?? new HbmParam[0])
            {
                results.Add(paramSchema.name, paramSchema.GetText());
            }

            return(results);
        }
Example #11
0
        public ClassMapper(Type rootClass, HbmMapping mapDoc, MemberInfo idProperty)
            : base(rootClass, mapDoc)
        {
            classMapping = new HbmClass();
            var toAdd = new[] { classMapping };

            classMapping.name = rootClass.GetShortClassName(mapDoc);
            if (rootClass.IsAbstract)
            {
                classMapping.@abstract         = true;
                classMapping.abstractSpecified = true;
            }

            var hbmId = new HbmId();

            classMapping.Item = hbmId;
            idMapper          = new IdMapper(idProperty, hbmId);

            mapDoc.Items = mapDoc.Items == null ? toAdd : mapDoc.Items.Concat(toAdd).ToArray();
        }
Example #12
0
        public void BindId(HbmId idSchema, PersistentClass rootClass, Table table)
        {
            if (idSchema != null)
            {
                var id = new SimpleValue(table);
                new TypeBinder(id, Mappings).Bind(idSchema.Type);

                rootClass.Identifier = id;

                Func <HbmColumn> defaultColumn = () => new HbmColumn
                {
                    name   = idSchema.name ?? RootClass.DefaultIdentifierColumnName,
                    length = idSchema.length
                };
                new ColumnsBinder(id, Mappings).Bind(idSchema.Columns, false, defaultColumn);

                CreateIdentifierProperty(idSchema, rootClass, id);
                VerifiyIdTypeIsValid(id, rootClass.EntityName);
                new IdGeneratorBinder(Mappings).BindGenerator(id, idSchema.generator);
                id.Table.SetIdentifierValue(id);
                BindUnsavedValue(idSchema, id);
            }
        }
Example #13
0
        private void AddColumnsFromList(HbmId idSchema, SimpleValue id)
        {
            int count = 0;

            foreach (HbmColumn columnSchema in idSchema.column ?? new HbmColumn[0])
            {
                Column column = CreateColumn(columnSchema, id, count++);
                column.Name = mappings.NamingStrategy.ColumnName(columnSchema.name);

                if (id.Table != null)
                {
                    id.Table.AddColumn(column);
                }
                //table=null -> an association, fill it in later

                id.AddColumn(column);

                if (columnSchema.index != null && id.Table != null)
                {
                    var tokens = new StringTokenizer(columnSchema.index, ",", false);
                    foreach (string token in tokens)
                    {
                        id.Table.GetOrCreateIndex(token.Trim()).AddColumn(column);
                    }
                }

                if (columnSchema.uniquekey != null && id.Table != null)
                {
                    var tokens = new StringTokenizer(columnSchema.uniquekey, ",", false);
                    foreach (string token in tokens)
                    {
                        id.Table.GetOrCreateUniqueKey(token.Trim()).AddColumn(column);
                    }
                }
            }
        }
Example #14
0
 public IdMapper(HbmId hbmId)
     : this(null, hbmId)
 {
 }
Example #15
0
 public IdMapper(HbmId hbmId)
 {
     this.hbmId = hbmId;
 }
Example #16
0
 public static string GetUniqueIndex(this HbmId item)
 {
     return(item.Column().GetUniqueIndex());
 }
Example #17
0
 public static string GetPropertyName(this HbmId item)
 {
     return(item.name);
 }
Example #18
0
 public static string GetReturnType(this HbmId item)
 {
     return(item.type1.GetTypeName());
 }
Example #19
0
 public static bool?CanBeNull(this HbmId item)
 {
     return(item.Column().CanBeNull());
 }
Example #20
0
 public static bool?IsUnique(this HbmId item)
 {
     return(item.Column().IsUnique());
 }
Example #21
0
 public static string GetSqlType(this HbmId item)
 {
     return(item.Column().sqltype);
 }
Example #22
0
 private static void BindUnsavedValue(HbmId idSchema, SimpleValue id)
 {
     id.NullValue = idSchema.unsavedvalue ?? (id.IdentifierGeneratorStrategy == "assigned" ? "undefined" : null);
 }