/// <summary> /// Returns true if RequestTimeFilterFastArrivalSearches instances are equal /// </summary> /// <param name="other">Instance of RequestTimeFilterFastArrivalSearches to be compared</param> /// <returns>Boolean</returns> public bool Equals(RequestTimeFilterFastArrivalSearches other) { if (other is null) { return(false); } if (ReferenceEquals(this, other)) { return(true); } return (( ManyToOne == other.ManyToOne || ManyToOne != null && other.ManyToOne != null && ManyToOne.SequenceEqual(other.ManyToOne) ) && ( OneToMany == other.OneToMany || OneToMany != null && other.OneToMany != null && OneToMany.SequenceEqual(other.OneToMany) )); }
private void BindManyToOne(HbmManyToOne manyToOneMapping, ManyToOne model, string defaultColumnName, bool isNullable) { new ValuePropertyBinder(model, Mappings).BindSimpleValue(manyToOneMapping, defaultColumnName, isNullable); InitOuterJoinFetchSetting(manyToOneMapping, model); InitLaziness(manyToOneMapping.Lazy, model, true); var ukName = !string.IsNullOrEmpty(manyToOneMapping.propertyref) ? manyToOneMapping.propertyref : null; if (ukName != null) model.ReferencedPropertyName = ukName; model.ReferencedEntityName = GetEntityName(manyToOneMapping, mappings); model.IsIgnoreNotFound = manyToOneMapping.NotFoundMode == HbmNotFoundMode.Ignore; if (ukName != null && !model.IsIgnoreNotFound) { AddManyToOneSecondPass(model); } if (manyToOneMapping.unique) { model.IsLogicalOneToOne = true; } BindForeignKey(manyToOneMapping.foreignkey, model); }
private void BindManyToMany(HbmManyToMany manyToManyMapping, Mapping.Collection model) { var manyToMany = new ManyToOne(model.CollectionTable); model.Element = manyToMany; new ValuePropertyBinder(manyToMany, Mappings).BindSimpleValue(manyToManyMapping, Mapping.Collection.DefaultElementColumnName, false); InitOuterJoinFetchSetting(manyToManyMapping, manyToMany); var restrictedLaziness = manyToManyMapping.lazySpecified ? manyToManyMapping.lazy : (HbmRestrictedLaziness?)null; InitLaziness(restrictedLaziness, manyToMany, true); if (!string.IsNullOrEmpty(manyToManyMapping.propertyref)) { manyToMany.ReferencedPropertyName = manyToManyMapping.propertyref; } manyToMany.ReferencedEntityName = GetEntityName(manyToManyMapping, mappings); manyToMany.IsIgnoreNotFound = manyToManyMapping.NotFoundMode == HbmNotFoundMode.Ignore; if (!string.IsNullOrEmpty(manyToManyMapping.foreignkey)) { manyToMany.ForeignKeyName = manyToManyMapping.foreignkey; } BindManyToManySubelements(manyToManyMapping, model); }
private void BindManyToOne(HbmKeyManyToOne keyManyToOneSchema, ManyToOne manyToOne, string defaultColumnName, bool isNullable) { BindColumns(keyManyToOneSchema, manyToOne, isNullable, true, defaultColumnName); manyToOne.FetchMode = FetchMode.Default; manyToOne.IsLazy = !keyManyToOneSchema.lazySpecified ? manyToOne.IsLazy : keyManyToOneSchema.lazy == HbmRestrictedLaziness.Proxy; string typeNode = keyManyToOneSchema.@class; if (typeNode != null) { manyToOne.ReferencedEntityName = GetClassName(typeNode, mappings); } else { manyToOne.ReferencedEntityName = null; } manyToOne.IsIgnoreNotFound = false; if (keyManyToOneSchema.foreignkey != null) { manyToOne.ForeignKeyName = keyManyToOneSchema.foreignkey; } }
public override void DoSecondPass(IDictionary <string, PersistentClass> persistentClasses) { if (value is ManyToOne) { ManyToOne manyToOne = (ManyToOne)value; PersistentClass @ref; persistentClasses.TryGetValue(manyToOne.ReferencedEntityName, out @ref); if (@ref == null) { throw new AnnotationException( "@OneToOne or @ManyToOne on " + StringHelper.Qualify(entityClassName, path) + " references an unknown entity: " + manyToOne.ReferencedEntityName); } BinderHelper.CreateSyntheticPropertyReference(columns, @ref, null, manyToOne, false, mappings); TableBinder.BindFk(@ref, null, columns, manyToOne, unique, mappings); //HbmBinder does this only when property-ref != null, but IMO, it makes sense event if it is null if (!manyToOne.IsIgnoreNotFound) { manyToOne.CreatePropertyRefConstraints(persistentClasses); } } else if (value is OneToOne) { value.CreateForeignKey(); } else { throw new AssertionFailure("FkSecondPass for a wrong value type: " + value.GetType().Name); } }
private void BindManyToOne(HbmKeyManyToOne keyManyToOneSchema, ManyToOne manyToOne, string defaultColumnName, bool isNullable) { new ColumnsBinder(manyToOne, mappings).Bind(keyManyToOneSchema.Columns, isNullable, () => new HbmColumn { name = mappings.NamingStrategy.PropertyToColumnName(defaultColumnName) }); manyToOne.FetchMode = FetchMode.Default; manyToOne.IsLazy = !keyManyToOneSchema.lazySpecified ? manyToOne.IsLazy : keyManyToOneSchema.lazy == HbmRestrictedLaziness.Proxy; string typeNode = keyManyToOneSchema.@class; if (typeNode != null) { manyToOne.ReferencedEntityName = GetClassName(typeNode, mappings); } else { manyToOne.ReferencedEntityName = null; } manyToOne.IsIgnoreNotFound = false; if (keyManyToOneSchema.foreignkey != null) { manyToOne.ForeignKeyName = keyManyToOneSchema.foreignkey; } }
private void BindComponent(System.Type reflectedClass, string path, HbmCompositeId idSchema) { if (idSchema.@class != null) { compositeId.ComponentClass = ClassForNameChecked(idSchema.@class, mappings, "component class not found: {0}"); compositeId.IsEmbedded = false; } else if (reflectedClass != null) { compositeId.ComponentClass = reflectedClass; compositeId.IsEmbedded = false; } else { // an "embedded" component (ids only) if (compositeId.Owner.HasPocoRepresentation) { compositeId.ComponentClass = compositeId.Owner.MappedClass; compositeId.IsEmbedded = true; } else { // if not - treat compositeid as a dynamic-component compositeId.IsDynamic = true; } } foreach (object item in idSchema.Items ?? new object[0]) { var keyManyToOneSchema = item as HbmKeyManyToOne; var keyPropertySchema = item as HbmKeyProperty; if (keyManyToOneSchema != null) { var manyToOne = new ManyToOne(compositeId.Table); string propertyName = keyManyToOneSchema.name == null ? null : StringHelper.Qualify(path, keyManyToOneSchema.name); BindManyToOne(keyManyToOneSchema, manyToOne, propertyName, false); Property property = CreateProperty(manyToOne, keyManyToOneSchema.name, compositeId.ComponentClass, keyManyToOneSchema); compositeId.AddProperty(property); } else if (keyPropertySchema != null) { var value = new SimpleValue(compositeId.Table); string propertyName = keyPropertySchema.name == null ? null : StringHelper.Qualify(path, keyPropertySchema.name); BindSimpleValue(keyPropertySchema, value, false, propertyName); Property property = CreateProperty(value, keyPropertySchema.name, compositeId.ComponentClass, keyPropertySchema); compositeId.AddProperty(property); } } }
private void HandleManyToManySet(Property property, PersistentClass classMapping) { var collection = property.Value as Collection; if (collection == null || collection.IsOneToMany || collection.GenericArguments.Length != 1 || collection.GenericArguments[0] != typeof(User)) { return; } UpdateForeignKeyReferences(classMapping, collection.Element.Table); var one = collection.Element as ManyToOne; if (one != null) { var element = new ManyToOne(one.Table) { IsLazy = one.IsLazy, ReferencedEntityName = _userType.FullName, ReferencedPropertyName = one.ReferencedPropertyName, IsIgnoreNotFound = one.IsIgnoreNotFound }; CopyColumns(one, element); collection.Element = element; } }
/// <summary> /// Creates a many to one /// </summary> /// <typeparam name="DataType">Data type</typeparam> /// <param name="Expression">Expression</param> /// <returns>The many to one object</returns> public IManyToOne <ClassType, DataType> ManyToOne <DataType>(Expression <Func <ClassType, DataType> > Expression) where DataType : class, new() { Setup(); ManyToOne <ClassType, DataType> Return = new ManyToOne <ClassType, DataType>(Expression, this); Properties.Add(Return); return(Return); }
private void InitOuterJoinFetchSetting(HbmManyToOne manyToOneMapping, ManyToOne model) { FetchMode fetchStyle = !manyToOneMapping.fetchSpecified ? (!manyToOneMapping.outerjoinSpecified ? FetchMode.Default : GetFetchStyle(manyToOneMapping.outerjoin)) : GetFetchStyle(manyToOneMapping.fetch); model.FetchMode = fetchStyle; }
private void BindIndexManyToMany(HbmIndexManyToMany indexManyToManyMapping, ManyToOne model, string defaultColumnName, bool isNullable) { new ValuePropertyBinder(model, Mappings).BindSimpleValue(indexManyToManyMapping, defaultColumnName, isNullable); model.ReferencedEntityName = GetEntityName(indexManyToManyMapping, mappings); BindForeignKey(indexManyToManyMapping.foreignkey, model); }
private IEnumerable <IValueChange> ExtractRelationChanges(Attribute attribute) { Trace.Assert(attribute.Relation != null); return(attribute.Relation switch { OneToMany oneToMany => ExtractOneToManyChanges(oneToMany), ManyToOne manyToOne => ExtractManyToOneChanges(manyToOne), ManyToMany manyToMany => ExtractManyToManyChanges(manyToMany), _ => throw new NotSupportedException("Relation type is not supported") });
private void BindKeyManyToOne(HbmKeyManyToOne keyManyToOneMapping, ManyToOne model, string defaultColumnName, bool isNullable) { new ValuePropertyBinder(model, Mappings).BindSimpleValue(keyManyToOneMapping, defaultColumnName, isNullable); InitLaziness(keyManyToOneMapping.Lazy, model, true); model.ReferencedEntityName = GetEntityName(keyManyToOneMapping, mappings); model.IsIgnoreNotFound = keyManyToOneMapping.NotFoundMode == HbmNotFoundMode.Ignore; BindForeingKey(keyManyToOneMapping.foreignkey, model); }
private void CopyColumns(ManyToOne src, ManyToOne dest) { foreach (ISelectable selectable in src.ColumnIterator) { Column col = selectable as Column; if (col != null) { dest.AddColumn(col); } } }
/// <summary> /// Creates a many to one /// </summary> /// <typeparam name="DataType">Data type</typeparam> /// <param name="Expression">Expression</param> /// <returns>The many to one object</returns> public ManyToOne <ClassType, DataType> ManyToOne <DataType>(System.Linq.Expressions.Expression <Func <ClassType, DataType> > Expression) where DataType : class { if (Expression == null) { throw new ArgumentNullException(nameof(Expression)); } var ReturnValue = new ManyToOne <ClassType, DataType>(Expression, this); Properties.Add(ReturnValue); return(ReturnValue); }
private void HandleManyToOne(Property property, PersistentClass classMapping) { ManyToOne manyToOne = property.Value as ManyToOne; if (manyToOne == null || manyToOne.ReferencedEntityName != typeof(IUser).FullName) { return; } ManyToOne value = new ManyToOne(classMapping.Table); value.ReferencedEntityName = userType.FullName; CopyColumns(manyToOne, value); property.Value = value; }
internal EntityField(PropertyInfo propertyInfo, Entity entity) { PropertyInfo = propertyInfo; Owner = entity; PrimaryKey = (PrimaryKey)Attribute.GetCustomAttribute(propertyInfo, typeof(PrimaryKey)); OneToMany = (OneToMany)Attribute.GetCustomAttribute(propertyInfo, typeof(OneToMany)); ManyToOne = (ManyToOne)Attribute.GetCustomAttribute(propertyInfo, typeof(ManyToOne)); Column = (Column)Attribute.GetCustomAttribute(propertyInfo, typeof(Column)); NotNull = (NotNull)Attribute.GetCustomAttribute(propertyInfo, typeof(NotNull)); Names = new Dictionary <Entity, string>(); Names.Add(entity, GetName()); }
private void EnsureTestDataManyToOne(IMongoDatabase database, string collectionName) { database.DropCollection(collectionName); var collection = database.GetCollection <ManyToOne>(collectionName); var documents = new ManyToOne[] { new ManyToOne { Id = 1, From = new[] { 2, 3 }, To = 1 }, new ManyToOne { Id = 2, From = new[] { 3, 4 }, To = 2 }, }; collection.InsertMany(documents); }
/// <summary> /// Gets the hash code /// </summary> /// <returns>Hash code</returns> public override int GetHashCode() { unchecked // Overflow is fine, just wrap { var hashCode = 41; // Suitable nullity checks etc, of course :) if (ManyToOne != null) { hashCode = hashCode * 59 + ManyToOne.GetHashCode(); } if (OneToMany != null) { hashCode = hashCode * 59 + OneToMany.GetHashCode(); } return(hashCode); } }
/// <summary> /// Called for Maps /// </summary> private void BindMapSecondPass(XmlNode node, Map model, IDictionary <string, PersistentClass> persistentClasses, IDictionary <string, MetaAttribute> inheritedMetas) { BindCollectionSecondPass(node, model, persistentClasses, inheritedMetas); foreach (XmlNode subnode in node.ChildNodes) { //I am only concerned with elements that are from the nhibernate namespace if (subnode.NamespaceURI != Configuration.MappingSchemaXMLNS) { continue; } string name = subnode.LocalName; //.Name; if ("index".Equals(name) || "map-key".Equals(name)) { SimpleValue value = new SimpleValue(model.CollectionTable); BindSimpleValue(subnode, value, model.IsOneToMany, IndexedCollection.DefaultIndexColumnName); model.Index = value; if (model.Index.Type == null) { throw new MappingException("map index element must specify a type: " + model.Role); } } else if ("index-many-to-many".Equals(name) || "map-key-many-to-many".Equals(name)) { ManyToOne mto = new ManyToOne(model.CollectionTable); BindManyToOne(subnode, mto, IndexedCollection.DefaultIndexColumnName, model.IsOneToMany); model.Index = mto; } else if ("composite-index".Equals(name) || "composite-map-key".Equals(name)) { Component component = new Component(model); BindComponent(subnode, component, null, null, null, model.Role + ".index", model.IsOneToMany, inheritedMetas); model.Index = component; } else if ("index-many-to-any".Equals(name)) { Any any = new Any(model.CollectionTable); BindAny(subnode, any, model.IsOneToMany); model.Index = any; } } }
private async Task Demo05_ManyToOne() { Console.WriteLine(nameof(Demo05_ManyToOne)); var length = 1200; System.IO.File.WriteAllBytes("ones.bin", GetArray(length, 1)); System.IO.File.WriteAllBytes("twos.bin", GetArray(length, 2)); var multiStart = new MultiStart(); var fileSource1 = new FileSource("ones.bin"); var fileSource2 = new FileSource("twos.bin"); var manytoOne = new ManyToOne(); var fileWriter = new FileWriter("threes.bin"); multiStart.Connect(fileSource1, fileSource2); fileSource1.Connect(manytoOne); fileSource2.Connect(manytoOne); manytoOne.Connect(fileWriter); await multiStart.Start(); }
public static void MapManyToOne <TEntityInterface, TEntity>(this Configuration cfg) { foreach (var persistentClass in cfg.ClassMappings) { var propertyNames = new List <string>(); foreach (PropertyInfo property in persistentClass.MappedClass.GetProperties()) { if (property.PropertyType == typeof(TEntityInterface)) { propertyNames.Add(property.Name); } } if (propertyNames.Count == 0) { continue; } var prop = new Property(); PersistentClass targetClass = cfg.GetClassMapping(typeof(TEntity)); foreach (string propertyName in propertyNames) { Table table = targetClass.Table; var value = new ManyToOne(table); value.ReferencedEntityName = typeof(TEntity).FullName; var column = new Column(propertyName); value.AddColumn(column); prop.Value = value; prop.Name = propertyName; prop.PersistentClass = targetClass; persistentClass.AddProperty(prop); persistentClass.Table.AddColumn(column); string fkName = string.Format("FK_{0}To{1}", propertyName, persistentClass.MappedClass.Name); persistentClass.Table.CreateForeignKey(fkName, new[] { column, }, typeof(TEntity).FullName); } } }
private T LoadManyToOne <T>(object poco, Column column, ref T loadTo, ManyToOne relation) { var cache = _ctx.Cache; var targetEntity = relation.ToEntity; var selectQueryBuilder = new SelectQueryBuilder <T>(_ctx, relation.ToPocoType); var pk = _entity.PkColumn.PropInfo.GetMethod.Invoke(poco, new object[0]); // load shadowEntity from cache because it holds the foreign key var cachePoco = cache.GetOrInsert(_entity, (long)pk, poco); cachePoco.ShadowAttributes.TryGetValue(column.Name, out var fk); var whereColumn = relation.To; selectQueryBuilder = selectQueryBuilder .Where( BinaryExpression.Eq( new ColumnExpression(whereColumn.Name), new ValueExpression(fk, whereColumn.DbType.PStmtDbType) ) ); return(selectQueryBuilder.Build().Execute().FirstOrDefault()); }
public ManyToOneConstraint(ManyToOne relation) { _relation = relation; }
/// <summary> /// Called for Maps /// </summary> private void BindMapSecondPass(HbmMap mapMapping, Map model, IDictionary <string, PersistentClass> persistentClasses, IDictionary <string, MetaAttribute> inheritedMetas) { BindCollectionSecondPass(mapMapping, model, persistentClasses, inheritedMetas); HbmIndex indexMapping; HbmMapKey mapKeyMapping; HbmIndexManyToMany indexManyToManyMapping; HbmMapKeyManyToMany mapKeyManyToManyMapping; HbmCompositeIndex compositeIndexMapping; HbmCompositeMapKey compositeMapKeyMapping; HbmIndexManyToAny indexManyToAnyMapping; if ((indexMapping = mapMapping.Item as HbmIndex) != null) { var value = new SimpleValue(model.CollectionTable); new ValuePropertyBinder(value, Mappings).BindSimpleValue(indexMapping, IndexedCollection.DefaultIndexColumnName, model.IsOneToMany); model.Index = value; if (string.IsNullOrEmpty(model.Index.TypeName)) { throw new MappingException("map index element must specify a type: " + model.Role); } } else if ((mapKeyMapping = mapMapping.Item as HbmMapKey) != null) { var value = new SimpleValue(model.CollectionTable); new ValuePropertyBinder(value, Mappings).BindSimpleValue(mapKeyMapping, IndexedCollection.DefaultIndexColumnName, model.IsOneToMany); model.Index = value; if (string.IsNullOrEmpty(model.Index.TypeName)) { throw new MappingException("map index element must specify a type: " + model.Role); } } else if ((indexManyToManyMapping = mapMapping.Item as HbmIndexManyToMany) != null) { var manyToOne = new ManyToOne(model.CollectionTable); BindIndexManyToMany(indexManyToManyMapping, manyToOne, IndexedCollection.DefaultIndexColumnName, model.IsOneToMany); model.Index = manyToOne; } else if ((mapKeyManyToManyMapping = mapMapping.Item as HbmMapKeyManyToMany) != null) { var manyToOne = new ManyToOne(model.CollectionTable); BindMapKeyManyToMany(mapKeyManyToManyMapping, manyToOne, IndexedCollection.DefaultIndexColumnName, model.IsOneToMany); model.Index = manyToOne; } else if ((compositeIndexMapping = mapMapping.Item as HbmCompositeIndex) != null) { var component = new Component(model); BindComponent(compositeIndexMapping, component, null, null, model.Role + ".index", model.IsOneToMany, inheritedMetas); model.Index = component; } else if ((compositeMapKeyMapping = mapMapping.Item as HbmCompositeMapKey) != null) { var component = new Component(model); BindComponent(compositeMapKeyMapping, component, null, null, model.Role + ".index", model.IsOneToMany, inheritedMetas); model.Index = component; } else if ((indexManyToAnyMapping = mapMapping.Item as HbmIndexManyToAny) != null) { var any = new Any(model.CollectionTable); BindIndexManyToAny(indexManyToAnyMapping, any, model.IsOneToMany); model.Index = any; } }
public static void CreateSyntheticPropertyReference(Ejb3JoinColumn[] columns, PersistentClass @ref, object o, ManyToOne one, bool b, ExtendedMappings mappings) { throw new System.NotImplementedException(); }
private void AddManyToOneSecondPass(ManyToOne manyToOne) { mappings.AddSecondPass(manyToOne.CreatePropertyRefConstraints); }
/// <remarks> /// Called for all collections /// </remarks> private void BindCollectionSecondPass(XmlNode node, Mapping.Collection model, IDictionary <string, PersistentClass> persistentClasses, IDictionary <string, MetaAttribute> inheritedMetas) { if (model.IsOneToMany) { OneToMany oneToMany = (OneToMany)model.Element; string associatedEntityName = oneToMany.ReferencedEntityName; PersistentClass persistentClass; if (persistentClasses.TryGetValue(associatedEntityName, out persistentClass) == false) { throw new MappingException("Association references unmapped class: " + associatedEntityName); } oneToMany.AssociatedClass = persistentClass; model.CollectionTable = persistentClass.Table; if (log.IsInfoEnabled) { log.Info("mapping collection: " + model.Role + " -> " + model.CollectionTable.Name); } } //CHECK XmlAttribute chNode = node.Attributes["check"]; if (chNode != null) { model.CollectionTable.AddCheckConstraint(chNode.Value); } //contained elements: foreach (XmlNode subnode in node.ChildNodes) { //I am only concerned with elements that are from the nhibernate namespace if (subnode.NamespaceURI != Configuration.MappingSchemaXMLNS) { continue; } string name = subnode.LocalName; //.Name; if ("key".Equals(name) || "generated-key".Equals(name)) { string propRef = model.ReferencedPropertyName; IKeyValue keyValue; if (propRef == null) { keyValue = model.Owner.Identifier; } else { keyValue = (IKeyValue)model.Owner.GetProperty(propRef).Value; } DependantValue key = new DependantValue(model.CollectionTable, keyValue); if (subnode.Attributes["on-delete"] != null) { key.IsCascadeDeleteEnabled = "cascade".Equals(subnode.Attributes["on-delete"].Value); } BindSimpleValue(subnode, key, model.IsOneToMany, Mapping.Collection.DefaultKeyColumnName); if (key.Type.ReturnedClass.IsArray) { throw new MappingException("illegal use of an array as an identifier (arrays don't reimplement Equals)"); } model.Key = key; XmlAttribute notNull = subnode.Attributes["not-null"]; key.SetNullable(notNull == null || IsFalse(notNull.Value)); XmlAttribute updateable = subnode.Attributes["update"]; key.SetUpdateable(updateable == null || IsTrue(updateable.Value)); } else if ("element".Equals(name)) { var elt = new SimpleValue(model.CollectionTable); model.Element = elt; if (model.IsGeneric) { switch (model.GenericArguments.Length) { case 1: // a collection with a generic type parameter elt.TypeName = model.GenericArguments[0].AssemblyQualifiedName; break; case 2: // a map (IDictionary) with 2 parameters elt.TypeName = model.GenericArguments[1].AssemblyQualifiedName; break; } } BindSimpleValue(subnode, elt, true, Mapping.Collection.DefaultElementColumnName); } else if ("many-to-many".Equals(name)) { ManyToOne element = new ManyToOne(model.CollectionTable); model.Element = element; BindManyToOne(subnode, element, Mapping.Collection.DefaultElementColumnName, false); BindManyToManySubelements(model, subnode); } else if ("composite-element".Equals(name)) { Component element = new Component(model); model.Element = element; BindComponent(subnode, element, null, null, null, model.Role + ".element", true, inheritedMetas); } else if ("many-to-any".Equals(name)) { Any element = new Any(model.CollectionTable); model.Element = element; BindAny(subnode, element, true); } else if ("jcs-cache".Equals(name) || "cache".Equals(name)) { XmlAttribute usageNode = subnode.Attributes["usage"]; model.CacheConcurrencyStrategy = (usageNode != null) ? usageNode.Value : null; XmlAttribute regionNode = subnode.Attributes["region"]; model.CacheRegionName = (regionNode != null) ? regionNode.Value : null; } } }
public void Bind(IEnumerable <IEntityPropertyMapping> properties, Table table, IDictionary <string, MetaAttribute> inheritedMetas, Action <Property> modifier, Action <Property> addToModelAction) { if (table == null) { throw new ArgumentNullException("table"); } if (modifier == null) { throw new ArgumentNullException("modifier"); } if (addToModelAction == null) { throw new ArgumentNullException("addToModelAction"); } foreach (var entityPropertyMapping in properties) { Property property = null; string propertyName = entityPropertyMapping.Name; ICollectionPropertiesMapping collectionMapping; HbmManyToOne manyToOneMapping; HbmAny anyMapping; HbmOneToOne oneToOneMapping; HbmProperty propertyMapping; HbmComponent componentMapping; HbmDynamicComponent dynamicComponentMapping; HbmNestedCompositeElement nestedCompositeElementMapping; HbmKeyProperty keyPropertyMapping; HbmKeyManyToOne keyManyToOneMapping; if ((propertyMapping = entityPropertyMapping as HbmProperty) != null) { var value = new SimpleValue(table); new ValuePropertyBinder(value, Mappings).BindSimpleValue(propertyMapping, propertyName, true); property = CreateProperty(entityPropertyMapping, className, value, inheritedMetas); BindValueProperty(propertyMapping, property); } else if ((collectionMapping = entityPropertyMapping as ICollectionPropertiesMapping) != null) { var collectionBinder = new CollectionBinder(Mappings, dialect); string propertyPath = propertyName == null ? null : StringHelper.Qualify(propertyBasePath, propertyName); Mapping.Collection collection = collectionBinder.Create(collectionMapping, entityName, propertyPath, persistentClass, mappedClass, inheritedMetas); mappings.AddCollection(collection); property = CreateProperty(collectionMapping, className, collection, inheritedMetas); BindCollectionProperty(collectionMapping, property); } else if ((manyToOneMapping = entityPropertyMapping as HbmManyToOne) != null) { var value = new ManyToOne(table); BindManyToOne(manyToOneMapping, value, propertyName, true); property = CreateProperty(entityPropertyMapping, className, value, inheritedMetas); BindManyToOneProperty(manyToOneMapping, property); } else if ((componentMapping = entityPropertyMapping as HbmComponent) != null) { string subpath = propertyName == null ? null : StringHelper.Qualify(propertyBasePath, propertyName); var value = CreateNewComponent(table); // NH: Modified from H2.1 to allow specifying the type explicitly using class attribute System.Type reflectedClass = mappedClass == null ? null : GetPropertyType(componentMapping.Class, mappedClass, propertyName, componentMapping.Access); BindComponent(componentMapping, value, reflectedClass, entityName, subpath, componetDefaultNullable, inheritedMetas); property = CreateProperty(entityPropertyMapping, className, value, inheritedMetas); BindComponentProperty(componentMapping, property, value); } else if ((oneToOneMapping = entityPropertyMapping as HbmOneToOne) != null) { var value = new OneToOne(table, persistentClass); BindOneToOne(oneToOneMapping, value); property = CreateProperty(entityPropertyMapping, className, value, inheritedMetas); BindOneToOneProperty(oneToOneMapping, property); } else if ((dynamicComponentMapping = entityPropertyMapping as HbmDynamicComponent) != null) { string subpath = propertyName == null ? null : StringHelper.Qualify(propertyBasePath, propertyName); var value = CreateNewComponent(table); // NH: Modified from H2.1 to allow specifying the type explicitly using class attribute System.Type reflectedClass = mappedClass == null ? null : GetPropertyType(dynamicComponentMapping.Class, mappedClass, propertyName, dynamicComponentMapping.Access); BindComponent(dynamicComponentMapping, value, reflectedClass, entityName, subpath, componetDefaultNullable, inheritedMetas); property = CreateProperty(entityPropertyMapping, className, value, inheritedMetas); BindComponentProperty(dynamicComponentMapping, property, value); } else if ((anyMapping = entityPropertyMapping as HbmAny) != null) { var value = new Any(table); BindAny(anyMapping, value, true); property = CreateProperty(entityPropertyMapping, className, value, inheritedMetas); BindAnyProperty(anyMapping, property); } else if ((nestedCompositeElementMapping = entityPropertyMapping as HbmNestedCompositeElement) != null) { if (component == null) { throw new AssertionFailure("Nested Composite Element without a owner component."); } string subpath = propertyName == null ? null : StringHelper.Qualify(propertyBasePath, propertyName); var value = CreateNewComponent(table); // NH: Modified from H2.1 to allow specifying the type explicitly using class attribute System.Type reflectedClass = mappedClass == null ? null : GetPropertyType(nestedCompositeElementMapping.Class, mappedClass, propertyName, nestedCompositeElementMapping.access); BindComponent(nestedCompositeElementMapping, value, reflectedClass, entityName, subpath, componetDefaultNullable, inheritedMetas); property = CreateProperty(entityPropertyMapping, className, value, inheritedMetas); } else if ((keyPropertyMapping = entityPropertyMapping as HbmKeyProperty) != null) { var value = new SimpleValue(table); new ValuePropertyBinder(value, Mappings).BindSimpleValue(keyPropertyMapping, propertyName, componetDefaultNullable); property = CreateProperty(entityPropertyMapping, className, value, inheritedMetas); } else if ((keyManyToOneMapping = entityPropertyMapping as HbmKeyManyToOne) != null) { var value = new ManyToOne(table); BindKeyManyToOne(keyManyToOneMapping, value, propertyName, componetDefaultNullable); property = CreateProperty(entityPropertyMapping, className, value, inheritedMetas); } if (property != null) { modifier(property); property.LogMapped(log); addToModelAction(property); } } }
/// <summary> /// Called for Maps /// </summary> private void BindMapSecondPass(HbmMap mapMapping, Map model, IDictionary <string, PersistentClass> persistentClasses, IDictionary <string, MetaAttribute> inheritedMetas) { BindCollectionSecondPass(mapMapping, model, persistentClasses, inheritedMetas); HbmIndex indexMapping; HbmMapKey mapKeyMapping; HbmIndexManyToMany indexManyToManyMapping; HbmMapKeyManyToMany mapKeyManyToManyMapping; HbmCompositeIndex compositeIndexMapping; HbmCompositeMapKey compositeMapKeyMapping; HbmIndexManyToAny indexManyToAnyMapping; if ((indexMapping = mapMapping.Item as HbmIndex) != null) { var value = new SimpleValue(model.CollectionTable); new ValuePropertyBinder(value, Mappings).BindSimpleValue(indexMapping, IndexedCollection.DefaultIndexColumnName, model.IsOneToMany); model.Index = value; if (string.IsNullOrEmpty(model.Index.TypeName)) { throw new MappingException("map index element must specify a type: " + model.Role); } } else if ((mapKeyMapping = mapMapping.Item as HbmMapKey) != null) { var value = new SimpleValue(model.CollectionTable); new ValuePropertyBinder(value, Mappings).BindSimpleValue(mapKeyMapping, IndexedCollection.DefaultIndexColumnName, model.IsOneToMany); model.Index = value; if (string.IsNullOrEmpty(model.Index.TypeName)) { throw new MappingException("map index element must specify a type: " + model.Role); } } else if ((indexManyToManyMapping = mapMapping.Item as HbmIndexManyToMany) != null) { var manyToOne = new ManyToOne(model.CollectionTable); BindIndexManyToMany(indexManyToManyMapping, manyToOne, IndexedCollection.DefaultIndexColumnName, model.IsOneToMany); model.Index = manyToOne; } else if ((mapKeyManyToManyMapping = mapMapping.Item as HbmMapKeyManyToMany) != null) { var manyToOne = new ManyToOne(model.CollectionTable); BindMapKeyManyToMany(mapKeyManyToManyMapping, manyToOne, IndexedCollection.DefaultIndexColumnName, model.IsOneToMany); model.Index = manyToOne; } else if ((compositeIndexMapping = mapMapping.Item as HbmCompositeIndex) != null) { var component = new Component(model); BindComponent(compositeIndexMapping, component, null, null, model.Role + ".index", model.IsOneToMany, inheritedMetas); model.Index = component; } else if ((compositeMapKeyMapping = mapMapping.Item as HbmCompositeMapKey) != null) { var component = new Component(model); BindComponent(compositeMapKeyMapping, component, null, null, model.Role + ".index", model.IsOneToMany, inheritedMetas); model.Index = component; } else if ((indexManyToAnyMapping = mapMapping.Item as HbmIndexManyToAny) != null) { var any = new Any(model.CollectionTable); BindIndexManyToAny(indexManyToAnyMapping, any, model.IsOneToMany); model.Index = any; } bool indexIsFormula = model.Index.ColumnIterator.Any(x => x.IsFormula); if (model.IsOneToMany && !model.Key.IsNullable && !model.IsInverse && !indexIsFormula) { string entityName = ((OneToMany)model.Element).ReferencedEntityName; PersistentClass referenced = mappings.GetClass(entityName); var ib = new IndexBackref(); ib.Name = '_' + model.OwnerEntityName + "." + mapMapping.Name + "IndexBackref"; ib.IsUpdateable = false; ib.IsSelectable = false; ib.CollectionRole = model.Role; ib.EntityName = model.Owner.EntityName; ib.Value = model.Index; referenced.AddProperty(ib); } }