示例#1
0
        public override void MapField(
            ICustomizersHolder customizerHolder,
            IModelExplicitDeclarationsHolder modelExplicitDeclarationsHolder,
            PropertyPath currentPropertyPath,
            MetaEntity entity,
            MetaField field)
        {
            var primitiveProperty = (PrimitiveMetaField)field;
            var mappingAction     = new Action <IPropertyMapper>(mapper => {
                if (field.MaxLength != null && field.MaxLength > 0)
                {
                    mapper.Length(field.MaxLength.Value);
                }
                else
                {
                    mapper.Type(NHibernateUtil.StringClob);
                }
                mapper.Column(field.DbName);
                mapper.Unique(field.IsUnique);
                mapper.Lazy(field.IsLazy);
                mapper.NotNullable(primitiveProperty.IsRequired);
            });
            var next = new PropertyPath(currentPropertyPath, field.ClrPropertyInfo);

            customizerHolder.AddCustomizer(next, mappingAction);
            modelExplicitDeclarationsHolder.AddAsProperty(field.ClrPropertyInfo);
        }
示例#2
0
        public override void MapField(ICustomizersHolder customizerHolder,
                                      IModelExplicitDeclarationsHolder modelExplicitDeclarationsHolder,
                                      PropertyPath currentPropertyPath,
                                      MetaEntity entity,
                                      MetaField property)
        {
            var m2mProperty = property as ManyToManyMetaField;
            var refEntity   = _entityManager.GetEntity(m2mProperty.RefEntityName);
            var refProperty = refEntity.Fields[m2mProperty.MappedByFieldName];
            var joinTableThisSideFkColumn  = _nameConvention.EntityFieldToColumn(entity.Name.Split('.').Last() + "Id");
            var joinTableOtherSideFkColumn = _nameConvention.EntityFieldToColumn(refEntity.Name.Split('.').Last() + "Id");

            var bagMappingAction = new Action <IBagPropertiesMapper>(mapper => {
                mapper.Table(m2mProperty.JoinTable);
                mapper.Key(keyMapper => {
                    keyMapper.Column(joinTableThisSideFkColumn);
                    keyMapper.NotNullable(true);
                });
            });

            var m2mMappingAction = new Action <IManyToManyMapper>(mapper => {
                mapper.Class(refEntity.ClrType);
                mapper.Column(joinTableOtherSideFkColumn);
            });

            var next = new PropertyPath(currentPropertyPath, property.ClrPropertyInfo);

            customizerHolder.AddCustomizer(next, m2mMappingAction);
            customizerHolder.AddCustomizer(next, bagMappingAction);

            modelExplicitDeclarationsHolder.AddAsManyToManyItemRelation(property.ClrPropertyInfo);
            modelExplicitDeclarationsHolder.AddAsBag(property.ClrPropertyInfo);
        }
示例#3
0
 public DynamicComponentCustomizer(
     IModelExplicitDeclarationsHolder explicitDeclarationsHolder,
     ICustomizersHolder customizersHolder,
     PropertyPath propertyPath)
     : this(typeof(TComponent), explicitDeclarationsHolder, customizersHolder, propertyPath)
 {
 }
示例#4
0
        public override void MapField(ICustomizersHolder customizerHolder,
                                      IModelExplicitDeclarationsHolder modelExplicitDeclarationsHolder,
                                      PropertyPath currentPropertyPath,
                                      MetaEntity entity,
                                      MetaField property)
        {
            var o2mProperty = property as OneToManyMetaField;
            var refEntity   = _entityManager.GetEntity(o2mProperty.RefEntityName);
            var refProperty = refEntity.Fields[o2mProperty.MappedByFieldName];

            var bagMappingAction = new Action <IBagPropertiesMapper>(mapper => {
                mapper.Inverse(true);
                mapper.Key(keyMapper => {
                    keyMapper.Column(property.DbName);
                });
            });

            var o2mMappingAction = new Action <IOneToManyMapper>(mapper => {
                mapper.Class(refEntity.ClrType);
            });

            var next = new PropertyPath(currentPropertyPath, property.ClrPropertyInfo);

            customizerHolder.AddCustomizer(next, o2mMappingAction);
            customizerHolder.AddCustomizer(next, bagMappingAction);

            modelExplicitDeclarationsHolder.AddAsOneToManyRelation(property.ClrPropertyInfo);
            modelExplicitDeclarationsHolder.AddAsBag(property.ClrPropertyInfo);
        }
 public IdBagPropertiesCustomizer(IModelExplicitDeclarationsHolder explicitDeclarationsHolder, PropertyPath propertyPath, ICustomizersHolder customizersHolder)
     : base(explicitDeclarationsHolder, propertyPath, customizersHolder)
 {
     if (explicitDeclarationsHolder == null)
     {
         throw new ArgumentNullException("explicitDeclarationsHolder");
     }
     explicitDeclarationsHolder.AddAsIdBag(propertyPath.LocalMember);
 }
示例#6
0
 public ComponentCustomizer(IModelExplicitDeclarationsHolder explicitDeclarationsHolder, ICustomizersHolder customizersHolder)
     : base(explicitDeclarationsHolder, customizersHolder, null)
 {
     if (explicitDeclarationsHolder == null)
     {
         throw new ArgumentNullException("explicitDeclarationsHolder");
     }
     explicitDeclarationsHolder.AddAsComponent(typeof(TComponent));
 }
 public MapKeyManyToManyCustomizer(IModelExplicitDeclarationsHolder explicitDeclarationsHolder, PropertyPath propertyPath, ICustomizersHolder customizersHolder)
 {
     if (explicitDeclarationsHolder == null)
     {
         throw new ArgumentNullException("explicitDeclarationsHolder");
     }
     explicitDeclarationsHolder.AddAsManyToManyKeyRelation(propertyPath.LocalMember);
     this.propertyPath      = propertyPath;
     this.customizersHolder = customizersHolder;
 }
 public PropertyContainerCustomizer(IModelExplicitDeclarationsHolder explicitDeclarationsHolder, ICustomizersHolder customizersHolder, PropertyPath propertyPath)
 {
     if (explicitDeclarationsHolder == null)
     {
         throw new ArgumentNullException("explicitDeclarationsHolder");
     }
     this.explicitDeclarationsHolder = explicitDeclarationsHolder;
     CustomizersHolder = customizersHolder;
     PropertyPath      = propertyPath;
 }
 public JoinCustomizer(string splitGroupId, IModelExplicitDeclarationsHolder explicitDeclarationsHolder, ICustomizersHolder customizersHolder)
     : base(explicitDeclarationsHolder, customizersHolder, null)
 {
     if (explicitDeclarationsHolder == null)
     {
         throw new ArgumentNullException("explicitDeclarationsHolder");
     }
     this.splitGroupId = splitGroupId;
     keyMapper         = new JoinKeyCustomizer <TEntity>(customizersHolder);
 }
示例#10
0
 public CollectionElementRelationCustomizer(IModelExplicitDeclarationsHolder explicitDeclarationsHolder, PropertyPath propertyPath, ICustomizersHolder customizersHolder)
 {
     if (explicitDeclarationsHolder == null)
     {
         throw new ArgumentNullException("explicitDeclarationsHolder");
     }
     this.explicitDeclarationsHolder = explicitDeclarationsHolder;
     this.propertyPath      = propertyPath;
     this.customizersHolder = customizersHolder;
 }
		public ManyToManyCustomizer(IModelExplicitDeclarationsHolder explicitDeclarationsHolder, PropertyPath propertyPath, ICustomizersHolder customizersHolder)
		{
			if (explicitDeclarationsHolder == null)
			{
				throw new ArgumentNullException("explicitDeclarationsHolder");
			}
			explicitDeclarationsHolder.AddAsManyToManyRelation(propertyPath.LocalMember);
			this.propertyPath = propertyPath;
			this.customizersHolder = customizersHolder;
		}
示例#12
0
        public ClassCustomizer(IModelExplicitDeclarationsHolder explicitDeclarationsHolder, ICustomizersHolder customizersHolder)
            : base(explicitDeclarationsHolder, customizersHolder, null)
        {
            if (explicitDeclarationsHolder == null)
            {
                throw new ArgumentNullException("explicitDeclarationsHolder");
            }
            explicitDeclarationsHolder.AddAsRootEntity(typeof(TEntity));

            // Add an empty customizer as a way to register the class as explicity declared
            CustomizersHolder.AddCustomizer(typeof(TEntity), (IClassMapper m) => { });
        }
示例#13
0
        public UnionSubclassCustomizer(IModelExplicitDeclarationsHolder explicitDeclarationsHolder, ICustomizersHolder customizersHolder)
            : base(explicitDeclarationsHolder, customizersHolder, null)
        {
            if (explicitDeclarationsHolder == null)
            {
                throw new ArgumentNullException("explicitDeclarationsHolder");
            }
            explicitDeclarationsHolder.AddAsTablePerConcreteClassEntity(typeof(TEntity));

            // Add an empty customizer as a way to register the class as explicity declared
            CustomizersHolder.AddCustomizer(typeof(TEntity), (IUnionSubclassAttributesMapper m) => { });
        }
示例#14
0
 public ComponentCustomizer(IModelExplicitDeclarationsHolder explicitDeclarationsHolder, ICustomizersHolder customizersHolder, PropertyPath propertyPath)
     : base(explicitDeclarationsHolder, customizersHolder, propertyPath)
 {
     if (explicitDeclarationsHolder == null)
     {
         throw new ArgumentNullException("explicitDeclarationsHolder");
     }
     explicitDeclarationsHolder.AddAsComponent(typeof(TComponent));
     if (propertyPath != null)
     {
         explicitDeclarationsHolder.AddAsPersistentMember(propertyPath.LocalMember);
     }
 }
示例#15
0
 public DynamicComponentCustomizer(IModelExplicitDeclarationsHolder explicitDeclarationsHolder, ICustomizersHolder customizersHolder, PropertyPath propertyPath)
     : base(explicitDeclarationsHolder, customizersHolder, propertyPath)
 {
     if (propertyPath == null)
     {
         throw new ArgumentNullException("propertyPath");
     }
     if (explicitDeclarationsHolder == null)
     {
         throw new ArgumentNullException("explicitDeclarationsHolder");
     }
     explicitDeclarationsHolder.AddAsDynamicComponent(propertyPath.LocalMember, typeof(TComponent));
 }
示例#16
0
 public ComponentElementCustomizer(IModelExplicitDeclarationsHolder explicitDeclarationsHolder, PropertyPath propertyPath, ICustomizersHolder customizersHolder)
 {
     if (explicitDeclarationsHolder == null)
     {
         throw new ArgumentNullException("explicitDeclarationsHolder");
     }
     this.explicitDeclarationsHolder = explicitDeclarationsHolder;
     this.propertyPath      = propertyPath;
     this.customizersHolder = customizersHolder;
     explicitDeclarationsHolder.AddAsComponent(typeof(TComponent));
     if (propertyPath != null)
     {
         explicitDeclarationsHolder.AddAsPersistentMember(propertyPath.LocalMember);
     }
 }
示例#17
0
        public override void MapField(ICustomizersHolder customizerHolder,
                                      IModelExplicitDeclarationsHolder modelExplicitDeclarationsHolder,
                                      PropertyPath currentPropertyPath,
                                      MetaEntity entity,
                                      MetaField property)
        {
            var m2oProperty   = property as ManyToOneMetaField;
            var mappingAction = new Action <IManyToOneMapper>(mapper => {
                mapper.Column(property.DbName);
                mapper.NotNullable(m2oProperty.IsRequired);
            });
            var next = new PropertyPath(currentPropertyPath, property.ClrPropertyInfo);

            customizerHolder.AddCustomizer(next, mappingAction);
            modelExplicitDeclarationsHolder.AddAsManyToOneRelation(property.ClrPropertyInfo);
        }
示例#18
0
        public override void MapField(ICustomizersHolder customizerHolder,
                                      IModelExplicitDeclarationsHolder modelExplicitDeclarationsHolder,
                                      PropertyPath currentPropertyPath,
                                      MetaEntity entity,
                                      MetaField field)
        {
            var mappingAction = new Action <IClassMapper>(mapper => {
                mapper.Id(idMapper => {
                    idMapper.Column(field.DbName);
                });
            });
            var next = new PropertyPath(currentPropertyPath, field.ClrPropertyInfo);

            customizerHolder.AddCustomizer(field.ClrPropertyInfo.DeclaringType, mappingAction);
            modelExplicitDeclarationsHolder.AddAsPoid(field.ClrPropertyInfo);
        }
        /// <summary>
        /// Gets the name of the version property for a given entity
        /// </summary>
        /// <param name="modelInspector">An instance the model inspector</param>
        /// <param name="entityType">The type of the entity</param>
        /// <returns>The name of the Version property</returns>
        public static string GetVersionPropertyName(this IModelInspector modelInspector, Type entityType)
        {
            string versionPropertyName = null;

            if (modelInspector.GetType().Equals(typeof(SimpleModelInspector)))
            {
                var declaredModelField = typeof(SimpleModelInspector).GetField("declaredModel", BindingFlags.NonPublic | BindingFlags.GetField | BindingFlags.Instance);
                if (declaredModelField != null)
                {
                    IModelExplicitDeclarationsHolder modelHolder = declaredModelField.GetValue(modelInspector) as IModelExplicitDeclarationsHolder;
                    if (modelHolder != null)
                    {
                        versionPropertyName = modelHolder.VersionProperties.Where(i => entityType.GetBaseTypes().Contains(i.DeclaringType)).Select(i => i.Name).SingleOrDefault();
                    }
                }
            }

            return(versionPropertyName);
        }
示例#20
0
        internal DynamicComponentCustomizer(
            System.Type componentType,
            IModelExplicitDeclarationsHolder explicitDeclarationsHolder,
            ICustomizersHolder customizersHolder,
            PropertyPath propertyPath)
            : base(explicitDeclarationsHolder, customizersHolder, propertyPath)
        {
            if (propertyPath == null)
            {
                throw new ArgumentNullException(nameof(propertyPath));
            }

            if (explicitDeclarationsHolder == null)
            {
                throw new ArgumentNullException(nameof(explicitDeclarationsHolder));
            }

            _componentType = componentType;
            explicitDeclarationsHolder.AddAsDynamicComponent(propertyPath.LocalMember, _componentType);
        }
示例#21
0
        public static void Merge(this IModelExplicitDeclarationsHolder destination, IModelExplicitDeclarationsHolder source)
        {
            if (destination == null || source == null)
            {
                return;
            }

            System.Array.ForEach(source.RootEntities.ToArray(), destination.AddAsRootEntity);
            System.Array.ForEach(source.Components.ToArray(), destination.AddAsComponent);
            System.Array.ForEach(source.TablePerClassEntities.ToArray(), destination.AddAsTablePerClassEntity);
            System.Array.ForEach(source.TablePerClassHierarchyEntities.ToArray(), destination.AddAsTablePerClassHierarchyEntity);
            System.Array.ForEach(source.TablePerConcreteClassEntities.ToArray(), destination.AddAsTablePerConcreteClassEntity);

            System.Array.ForEach(source.OneToOneRelations.ToArray(), destination.AddAsOneToOneRelation);
            System.Array.ForEach(source.ManyToOneRelations.ToArray(), destination.AddAsManyToOneRelation);
            System.Array.ForEach(source.KeyManyToManyRelations.ToArray(), destination.AddAsManyToManyKeyRelation);
            System.Array.ForEach(source.ItemManyToManyRelations.ToArray(), destination.AddAsManyToManyItemRelation);
            System.Array.ForEach(source.ManyToAnyRelations.ToArray(), destination.AddAsManyToAnyRelation);
            System.Array.ForEach(source.OneToManyRelations.ToArray(), destination.AddAsOneToManyRelation);
            System.Array.ForEach(source.Any.ToArray(), destination.AddAsAny);

            System.Array.ForEach(source.Poids.ToArray(), destination.AddAsPoid);
            System.Array.ForEach(source.ComposedIds.ToArray(), destination.AddAsPartOfComposedId);
            System.Array.ForEach(source.VersionProperties.ToArray(), destination.AddAsVersionProperty);
            System.Array.ForEach(source.NaturalIds.ToArray(), destination.AddAsNaturalId);

            System.Array.ForEach(source.Sets.ToArray(), destination.AddAsSet);
            System.Array.ForEach(source.Bags.ToArray(), destination.AddAsBag);
            System.Array.ForEach(source.IdBags.ToArray(), destination.AddAsIdBag);
            System.Array.ForEach(source.Lists.ToArray(), destination.AddAsList);
            System.Array.ForEach(source.Arrays.ToArray(), destination.AddAsArray);
            System.Array.ForEach(source.Dictionaries.ToArray(), destination.AddAsMap);
            System.Array.ForEach(source.Properties.ToArray(), destination.AddAsProperty);
            System.Array.ForEach(source.PersistentMembers.ToArray(), destination.AddAsPersistentMember);
            System.Array.ForEach(source.SplitDefinitions.ToArray(), destination.AddAsPropertySplit);
            foreach (var dynamicComponent in source.DynamicComponents)
            {
                var template = source.GetDynamicComponentTemplate(dynamicComponent);
                destination.AddAsDynamicComponent(dynamicComponent, template);
            }
        }
		public static void Merge(this IModelExplicitDeclarationsHolder destination, IModelExplicitDeclarationsHolder source)
		{
			if (destination == null || source == null)
			{
				return;
			}

			System.Array.ForEach(source.RootEntities.ToArray(), destination.AddAsRootEntity);
			System.Array.ForEach(source.Components.ToArray(), destination.AddAsComponent);
			System.Array.ForEach(source.TablePerClassEntities.ToArray(), destination.AddAsTablePerClassEntity);
			System.Array.ForEach(source.TablePerClassHierarchyEntities.ToArray(), destination.AddAsTablePerClassHierarchyEntity);
			System.Array.ForEach(source.TablePerConcreteClassEntities.ToArray(), destination.AddAsTablePerConcreteClassEntity);

			System.Array.ForEach(source.OneToOneRelations.ToArray(), destination.AddAsOneToOneRelation);
			System.Array.ForEach(source.ManyToOneRelations.ToArray(), destination.AddAsManyToOneRelation);
			System.Array.ForEach(source.KeyManyToManyRelations.ToArray(), destination.AddAsManyToManyKeyRelation);
			System.Array.ForEach(source.ItemManyToManyRelations.ToArray(), destination.AddAsManyToManyItemRelation);
			System.Array.ForEach(source.ManyToAnyRelations.ToArray(), destination.AddAsManyToAnyRelation);
			System.Array.ForEach(source.OneToManyRelations.ToArray(), destination.AddAsOneToManyRelation);
			System.Array.ForEach(source.Any.ToArray(), destination.AddAsAny);

			System.Array.ForEach(source.Poids.ToArray(), destination.AddAsPoid);
			System.Array.ForEach(source.ComposedIds.ToArray(), destination.AddAsPartOfComposedId);
			System.Array.ForEach(source.VersionProperties.ToArray(), destination.AddAsVersionProperty);
			System.Array.ForEach(source.NaturalIds.ToArray(), destination.AddAsNaturalId);

			System.Array.ForEach(source.Sets.ToArray(), destination.AddAsSet);
			System.Array.ForEach(source.Bags.ToArray(), destination.AddAsBag);
			System.Array.ForEach(source.IdBags.ToArray(), destination.AddAsIdBag);
			System.Array.ForEach(source.Lists.ToArray(), destination.AddAsList);
			System.Array.ForEach(source.Arrays.ToArray(), destination.AddAsArray);
			System.Array.ForEach(source.Dictionaries.ToArray(), destination.AddAsMap);
			System.Array.ForEach(source.Properties.ToArray(), destination.AddAsProperty);
			System.Array.ForEach(source.PersistentMembers.ToArray(), destination.AddAsPersistentMember);
			System.Array.ForEach(source.SplitDefinitions.ToArray(), destination.AddAsPropertySplit);
			foreach (var dynamicComponent in source.DynamicComponents)
			{
				var template = source.GetDynamicComponentTemplate(dynamicComponent);
				destination.AddAsDynamicComponent(dynamicComponent, template);
			}
		}
示例#23
0
        public override void MapField(ICustomizersHolder customizerHolder,
                                      IModelExplicitDeclarationsHolder modelExplicitDeclarationsHolder,
                                      PropertyPath currentPropertyPath,
                                      MetaEntity entity,
                                      MetaField field)
        {
            var genericHibernateEnumTypeType = typeof(global::NHibernate.Type.EnumStringType <>);
            var hibernateEnumTypeType        = genericHibernateEnumTypeType.MakeGenericType(field.ClrPropertyInfo.PropertyType);
            var hibernateEnumType            = Activator.CreateInstance(hibernateEnumTypeType) as IType;

            var primitiveField = (EnumerableMetaField)field;
            var mappingAction  = new Action <global::NHibernate.Mapping.ByCode.IPropertyMapper>(mapper => {
                mapper.Column(field.DbName);
                mapper.Type(hibernateEnumType);
                mapper.NotNullable(primitiveField.IsRequired);
            });
            var next = new PropertyPath(currentPropertyPath, field.ClrPropertyInfo);

            customizerHolder.AddCustomizer(next, mappingAction);
            modelExplicitDeclarationsHolder.AddAsProperty(field.ClrPropertyInfo);
        }
示例#24
0
        public override void MapField(ICustomizersHolder customizerHolder,
                                      IModelExplicitDeclarationsHolder modelExplicitDeclarationsHolder,
                                      PropertyPath currentPropertyPath,
                                      MetaEntity entity,
                                      MetaField field)
        {
            var mappingAction = new Action <IPropertyMapper>(mapper => {
                var userType = this.MakeTextBasedJsonType(field.ClrPropertyInfo.PropertyType);
                mapper.Type(userType, null);
                mapper.Unique(false);
                mapper.Lazy(field.IsLazy);
                mapper.Column(field.DbName);
                mapper.NotNullable(field is IMetaFieldWithIsRequired fr && fr.IsRequired);
                if (field.MaxLength != null && field.MaxLength > 0)
                {
                    mapper.Length(field.MaxLength.Value);
                }
            });
            var next = new PropertyPath(currentPropertyPath, field.ClrPropertyInfo);

            customizerHolder.AddCustomizer(next, mappingAction);
            modelExplicitDeclarationsHolder.AddAsProperty(field.ClrPropertyInfo);
        }
 public CollectionKeyCustomizer(IModelExplicitDeclarationsHolder explicitDeclarationsHolder, PropertyPath propertyPath, ICustomizersHolder customizersHolder)
 {
     this.propertyPath = propertyPath;
     CustomizersHolder = customizersHolder;
 }
示例#26
0
 public abstract void MapField(
     ICustomizersHolder customizerHolder,
     IModelExplicitDeclarationsHolder modelExplicitDeclarationsHolder,
     PropertyPath currentFieldPath,
     MetaEntity enttiy,
     MetaField field);
示例#27
0
 public MapKeyComponentCustomizer(IModelExplicitDeclarationsHolder explicitDeclarationsHolder, PropertyPath propertyPath, ICustomizersHolder customizersHolder)
 {
     this.propertyPath      = propertyPath;
     this.customizersHolder = customizersHolder;
 }
示例#28
0
 public CollectionPropertiesCustomizer(IModelExplicitDeclarationsHolder explicitDeclarationsHolder, PropertyPath propertyPath, ICustomizersHolder customizersHolder)
 {
     PropertyPath      = propertyPath;
     CustomizersHolder = customizersHolder;
     keyMapper         = new CollectionKeyCustomizer <TEntity>(explicitDeclarationsHolder, propertyPath, customizersHolder);
 }
 public NaturalIdCustomizer(IModelExplicitDeclarationsHolder explicitDeclarationsHolder, ICustomizersHolder customizersHolder)
     : base(explicitDeclarationsHolder, customizersHolder, null)
 {
 }