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); }
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(); } }
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); }
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); }
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); }
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(); }
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(); }
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); }
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); }
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); }
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(); }
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); } }
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); } } } }
public IdMapper(HbmId hbmId) : this(null, hbmId) { }
public IdMapper(HbmId hbmId) { this.hbmId = hbmId; }
public static string GetUniqueIndex(this HbmId item) { return(item.Column().GetUniqueIndex()); }
public static string GetPropertyName(this HbmId item) { return(item.name); }
public static string GetReturnType(this HbmId item) { return(item.type1.GetTypeName()); }
public static bool?CanBeNull(this HbmId item) { return(item.Column().CanBeNull()); }
public static bool?IsUnique(this HbmId item) { return(item.Column().IsUnique()); }
public static string GetSqlType(this HbmId item) { return(item.Column().sqltype); }
private static void BindUnsavedValue(HbmId idSchema, SimpleValue id) { id.NullValue = idSchema.unsavedvalue ?? (id.IdentifierGeneratorStrategy == "assigned" ? "undefined" : null); }