/// <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 (NeedBackref(model) && !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); } }
private void BindListSecondPass(HbmList listMapping, List model, IDictionary<string, PersistentClass> persistentClasses, IDictionary<string, MetaAttribute> inheritedMetas) { BindCollectionSecondPass(listMapping, model, persistentClasses, inheritedMetas); // Index BindCollectionIndex(listMapping, model); if (listMapping.ListIndex != null && !string.IsNullOrEmpty(listMapping.ListIndex.@base)) { model.BaseIndex = Convert.ToInt32(listMapping.ListIndex.@base); } if (NeedBackref(model)) { string entityName = ((OneToMany)model.Element).ReferencedEntityName; PersistentClass referenced = mappings.GetClass(entityName); var ib = new IndexBackref(); ib.Name = '_' + model.OwnerEntityName + "." + listMapping.Name + "IndexBackref"; ib.IsUpdateable = false; ib.IsSelectable = false; ib.CollectionRole = model.Role; ib.EntityName = model.Owner.EntityName; ib.Value = model.Index; referenced.AddProperty(ib); } }