Ejemplo n.º 1
0
		private void CreateIdentifierProperty(HbmId idSchema, PersistentClass rootClass, SimpleValue id)
		{
			if (idSchema.name != null)
			{
				string access = idSchema.access ?? mappings.DefaultAccess;
				id.SetTypeUsingReflection(rootClass.MappedClass == null ? null : rootClass.MappedClass.AssemblyQualifiedName,
				                          idSchema.name, access);

				Property property = new Property(id);
				property.Name = idSchema.name;

				if (property.Value.Type == null)
					throw new MappingException("could not determine a property type for: " + property.Name);

				property.PropertyAccessorName = idSchema.access ?? mappings.DefaultAccess;
				property.Cascade = mappings.DefaultCascade;
				property.IsUpdateable = true;
				property.IsInsertable = true;
				property.IsOptimisticLocked = true;
				property.Generation = PropertyGeneration.Never;
				property.MetaAttributes = GetMetas(idSchema);

				rootClass.IdentifierProperty = property;

				LogMappedProperty(property);
			}
		}
Ejemplo n.º 2
0
 public DeclaredPersistentProperty(Property property, MemberInfo memberInfo)
 {
     ArgumentsTools.CheckNotNull(property, "property");
     ArgumentsTools.CheckNotNull(memberInfo, "memberInfo");
     Member = memberInfo;
     Property = property;
 }
Ejemplo n.º 3
0
            private string WalkPropertyChain(Mapping.Property property, int index, string[] names)
            {
                if (property.IsComposite)
                {
                    return(WalkPropertyChain(((Mapping.Component)property.Value).GetProperty(names[++index]), index, names));
                }

                return(property.ColumnIterator.First().Text);
            }
Ejemplo n.º 4
0
 private static int GetMemberIdxByFieldNamingStrategies(IList<string> candidateMembersNames, Property property)
 {
     var exactFieldIdx = -1;
     foreach (var ns in DefaultFieldNamningStrategies)
     {
         var fieldName = ns.GetFieldName(property.Name);
         exactFieldIdx = candidateMembersNames.IndexOf(fieldName);
         if (exactFieldIdx >= 0)
         {
             break;
         }
     }
     return exactFieldIdx;
 }
Ejemplo n.º 5
0
		public void BindCompositeId(HbmCompositeId idSchema, PersistentClass rootClass)
		{
			if (idSchema == null)
			{
				return;
			}

			compositeId = new Component(rootClass);
			compositeId.IsKey = true;
			
			rootClass.Identifier = compositeId;

			if (idSchema.name == null)
			{
				BindComponent(null, "id", idSchema);
				rootClass.HasEmbeddedIdentifier = compositeId.IsEmbedded;
			}
			else
			{
				System.Type reflectedClass = GetPropertyType(rootClass.MappedClass, idSchema.name, idSchema);

				BindComponent(reflectedClass, idSchema.name, idSchema);

				var prop = new Property(compositeId);
				BindProperty(prop, idSchema);
				rootClass.IdentifierProperty = prop;
			}

			compositeId.Table.SetIdentifierValue(compositeId);
			compositeId.NullValue = idSchema.unsavedvalue.ToNullValue();

			System.Type compIdClass = compositeId.ComponentClass;
			if (!ReflectHelper.OverridesEquals(compIdClass))
			{
				throw new MappingException("composite-id class must override Equals(): " + compIdClass.FullName);
			}

			if (!ReflectHelper.OverridesGetHashCode(compIdClass))
			{
				throw new MappingException("composite-id class must override GetHashCode(): " + compIdClass.FullName);
			}
			// Serializability check not ported
		}
		public void BindCompositeId(HbmCompositeId idSchema, PersistentClass rootClass)
		{
			if (idSchema == null)
			{
				return;
			}

			compositeId = new Component(rootClass);
			compositeId.IsKey = true;

			rootClass.Identifier = compositeId;

			if (idSchema.name == null)
			{
				BindComponent(null, "id", idSchema);
				rootClass.HasEmbeddedIdentifier = compositeId.IsEmbedded;
			}
			else
			{
				System.Type reflectedClass = GetPropertyType(rootClass.MappedClass, idSchema.name, idSchema);

				BindComponent(reflectedClass, idSchema.name, idSchema);

				var prop = new Property(compositeId);
				BindProperty(prop, idSchema);
				rootClass.IdentifierProperty = prop;
			}

			compositeId.Table.SetIdentifierValue(compositeId);
			compositeId.NullValue = idSchema.unsavedvalue.ToNullValue();

			if (!compositeId.IsDynamic)
			{
				CheckEqualsAndGetHashCodeOverride();
			}
			// Serializability check not ported
		}
Ejemplo n.º 7
0
        private void Load()
        {
            IClassMetadata classMetadata = m_sessionFactory.GetClassMetadata(m_persistentClass);

            if (classMetadata == null)
            {
                return;
            }

            Configuration conf            = NHibernateHelper.GetSessionFactoryManager().GetConfigurationBySessionFactory(m_sessionFactory);
            var           persistentClass = conf.GetClassMapping(m_persistentClass);

            m_idProperty   = persistentClass.GetProperty(classMetadata.IdentifierPropertyName);
            this.TableName = persistentClass.Table.Name;

            for (int i = 0; i < classMetadata.PropertyNames.Length; ++i)
            {
                string s = classMetadata.PropertyNames[i];
                NHibernate.Mapping.Property property = persistentClass.GetProperty(s);
                try
                {
                    var it = property.ColumnIterator.GetEnumerator();
                    it.MoveNext();
                    if (it.Current != null && it.Current is NHibernate.Mapping.Column)
                    {
                        int  length      = ((NHibernate.Mapping.Column)it.Current).Length;
                        bool nullability = classMetadata.PropertyNullability[i];
                        m_properties[s] = new EntityPropertyMetadata {
                            Name = s, Length = length, NotNull = !nullability
                        };
                    }
                }
                catch (System.InvalidOperationException)
                {
                }
            }

            //if (Attribute.IsDefined(m_persistentClass, typeof(NHibernate.Mapping.Attributes.ClassAttribute)))
            //{
            //    Attribute[] attrs = Attribute.GetCustomAttributes(m_persistentClass, typeof(NHibernate.Mapping.Attributes.ClassAttribute));
            //    if (attrs.Length > 0)
            //    {
            //        ClassAttribute attr = attrs[0] as ClassAttribute;
            //        m_tableName = attr.Table;
            //    }
            //}

            //m_propertyAttributes.Clear();
            //PropertyInfo[] pInfos = m_persistentClass.GetProperties();
            //foreach (PropertyInfo pInfo in pInfos)
            //{
            //    if (Attribute.IsDefined(pInfo, typeof(NHibernate.Mapping.Attributes.PropertyAttribute)))
            //    {
            //        Attribute[] attrs = Attribute.GetCustomAttributes(pInfo, typeof(NHibernate.Mapping.Attributes.PropertyAttribute));
            //        foreach(var i in attrs)
            //        {
            //            PropertyAttribute attr = i as PropertyAttribute;
            //            m_propertyAttributes.Add(attr.Name == null ? pInfo.Name : attr.Name, attr);
            //        }
            //    }
            //    else if (Attribute.IsDefined(pInfo, typeof(NHibernate.Mapping.Attributes.IdAttribute)))
            //    {
            //        Attribute[] attrs = Attribute.GetCustomAttributes(pInfo, typeof(NHibernate.Mapping.Attributes.IdAttribute));
            //        if (attrs.Length > 0)
            //        {
            //            m_idAttribute = attrs[0] as IdAttribute;
            //        }
            //    }
            //}
        }
		private void BindProperty(HbmKeyProperty keyPropertySchema, Property property)
		{
			property.Name = keyPropertySchema.name;

			if (property.Value.Type == null)
				throw new MappingException("could not determine a property type for: " + property.Name);

			property.PropertyAccessorName = keyPropertySchema.access ?? mappings.DefaultAccess;
			property.Cascade = mappings.DefaultCascade;
			property.IsUpdateable = true;
			property.IsInsertable = true;
			property.IsOptimisticLocked = true;
			property.Generation = PropertyGeneration.Never;
			property.MetaAttributes = new Dictionary<string, MetaAttribute>();
			LogMappedProperty(property);
		}
		private Property CreateProperty(SimpleValue value, string propertyName, System.Type parentClass,
			HbmKeyProperty keyPropertySchema)
		{
			if (parentClass != null && value.IsSimpleValue)
				value.SetTypeUsingReflection(parentClass.AssemblyQualifiedName, propertyName,
				                             keyPropertySchema.access ?? mappings.DefaultAccess);

			// This is done here 'cos we might only know the type here (ugly!)
			var toOne = value as ToOne;
			if (toOne != null)
			{
				string propertyRef = toOne.ReferencedPropertyName;
				if (propertyRef != null)
					mappings.AddUniquePropertyReference(toOne.ReferencedEntityName, propertyRef);
			}

			value.CreateForeignKey();
			var prop = new Property {Value = value};
			BindProperty(keyPropertySchema, prop);

			return prop;
		}
		private Property CreateProperty(ToOne value, string propertyName, System.Type parentClass,
			HbmKeyManyToOne keyManyToOneSchema)
		{
			if (parentClass != null && value.IsSimpleValue)
				value.SetTypeUsingReflection(parentClass.AssemblyQualifiedName, propertyName,
				                             keyManyToOneSchema.access ?? mappings.DefaultAccess);

			string propertyRef = value.ReferencedPropertyName;
			if (propertyRef != null)
				mappings.AddUniquePropertyReference(value.ReferencedEntityName, propertyRef);

			value.CreateForeignKey();
			var prop = new Property {Value = value};
			BindProperty(keyManyToOneSchema, prop);

			return prop;
		}
Ejemplo n.º 11
0
 /// <summary>
 /// Adds a <see cref="Property"/> that is implemented by a subclass.
 /// </summary>
 /// <param name="p">The <see cref="Property"/> implemented by a subclass.</param>
 public virtual void AddSubclassProperty(Property p)
 {
     subclassProperties.Add(p);
 }
Ejemplo n.º 12
0
        private Property GetRecursiveProperty(string propertyPath, IEnumerable <Property> iter)
        {
            Property property = null;

            StringTokenizer st = new StringTokenizer(propertyPath, ".", false);

            try
            {
                foreach (string element in st)
                {
                    if (property == null)
                    {
                        // we are processing the root of the propertyPath, so we have the following
                        // considerations:
                        //		1) specifically account for identifier properties
                        //		2) specifically account for embedded composite-identifiers
                        //      3) perform a normal property lookup
                        Property identifierProperty = IdentifierProperty;
                        if (identifierProperty != null && identifierProperty.Name.Equals(element))
                        {
                            // we have a mapped identifier property and the root of
                            // the incoming property path matched that identifier
                            // property
                            property = identifierProperty;
                        }
                        else if (identifierProperty == null)
                        {
                            var component = Identifier as Component;
                            if (component != null)
                            {
                                // we have an embedded composite identifier
                                try
                                {
                                    identifierProperty = GetProperty(element, component.PropertyIterator);
                                    if (identifierProperty != null)
                                    {
                                        // the root of the incoming property path matched one
                                        // of the embedded composite identifier properties
                                        property = identifierProperty;
                                    }
                                }
                                catch (MappingException)
                                {
                                    // ignore it...
                                }
                            }
                        }

                        if (property == null)
                        {
                            property = GetProperty(element, iter);
                        }
                    }
                    else
                    {
                        //flat recursive algorithm
                        property = ((Component)property.Value).GetProperty(element);
                    }
                }
            }
            catch (MappingException)
            {
                throw new MappingException("property [" + propertyPath + "] not found on entity [" + EntityName + "]");
            }

            return(property);
        }
Ejemplo n.º 13
0
 /// <summary>
 /// Change the property definition or add a new property definition
 /// </summary>
 /// <param name="p">The <see cref="Property"/> to add.</param>
 public virtual void AddProperty(Property p)
 {
     properties.Add(p);
     p.PersistentClass = this;
 }
 private PropertyAuditingData GetIdPersistentPropertyAuditingData(Property property)
 {
     return new PropertyAuditingData(property.Name, property.PropertyAccessorName,
         ModificationStore.FULL, RelationTargetAuditMode.AUDITED, null, null, false);
 }
            private static void AddSubElement(Property property, ValidatableElement element)
            {
                if (property != null && property.IsComposite && !property.BackRef)
                {
                    Component component = (Component) property.Value;
                    if (component.IsEmbedded)
                    {
                        return;
                    }
                    var cv = Engine.GetClassValidator(property.PersistentClass.MappedClass);
                    if (cv != null)
                    {
                        if(cv.GetMemberConstraints(property.Name).OfType<ValidAttribute>().Any())
                        {
                            // the components is already marked as Valid
                            return;
                        }
                    }

                    IPropertyAccessor accesor = PropertyAccessorFactory.GetPropertyAccessor(property, EntityMode.Poco);

                    IGetter getter = accesor.GetGetter(element.EntityType, property.Name);

                    IClassValidator validator = Engine.GetClassValidator(getter.ReturnType);
                    if (validator != null)
                    {
                        ValidatableElement subElement = new ValidatableElement(getter.ReturnType, validator, getter);

                        foreach (Property currentProperty in component.PropertyIterator)
                        {
                            AddSubElement(currentProperty, subElement);
                        }

                        if (subElement.HasSubElements || subElement.Validator.HasValidationRules)
                        {
                            element.AddSubElement(subElement);
                        }
                    }
                }
            }
		public void AddProperty(Property prop)
		{
			throw new System.NotImplementedException();
		}
		public void AddProperty(Property prop, Ejb3Column[] columns)
		{
			throw new System.NotImplementedException();
		}
        private void Load()
        {
            IClassMetadata classMetadata = m_sessionFactory.GetClassMetadata(m_persistentClass);
            if (classMetadata == null)
                return;

            Configuration conf = NHibernateHelper.GetSessionFactoryManager().GetConfigurationBySessionFactory(m_sessionFactory);
            var persistentClass = conf.GetClassMapping(m_persistentClass);

            m_idProperty = persistentClass.GetProperty(classMetadata.IdentifierPropertyName);
            this.TableName = persistentClass.Table.Name;

            for (int i = 0; i < classMetadata.PropertyNames.Length; ++i)
            {
                string s = classMetadata.PropertyNames[i];
                NHibernate.Mapping.Property property = persistentClass.GetProperty(s);
                try
                {
                    var it = property.ColumnIterator.GetEnumerator();
                    it.MoveNext();
                    if (it.Current != null && it.Current is NHibernate.Mapping.Column)
                    {
                        int length = ((NHibernate.Mapping.Column)it.Current).Length;
                        bool nullability = classMetadata.PropertyNullability[i];
                        m_properties[s] = new EntityPropertyMetadata { Name = s, Length = length, NotNull = !nullability };
                    }
                }
                catch (System.InvalidOperationException)
                {
                }
            }

            //if (Attribute.IsDefined(m_persistentClass, typeof(NHibernate.Mapping.Attributes.ClassAttribute)))
            //{
            //    Attribute[] attrs = Attribute.GetCustomAttributes(m_persistentClass, typeof(NHibernate.Mapping.Attributes.ClassAttribute));
            //    if (attrs.Length > 0)
            //    {
            //        ClassAttribute attr = attrs[0] as ClassAttribute;
            //        m_tableName = attr.Table;
            //    }
            //}

            //m_propertyAttributes.Clear();
            //PropertyInfo[] pInfos = m_persistentClass.GetProperties();
            //foreach (PropertyInfo pInfo in pInfos)
            //{
            //    if (Attribute.IsDefined(pInfo, typeof(NHibernate.Mapping.Attributes.PropertyAttribute)))
            //    {
            //        Attribute[] attrs = Attribute.GetCustomAttributes(pInfo, typeof(NHibernate.Mapping.Attributes.PropertyAttribute));
            //        foreach(var i in attrs)
            //        {
            //            PropertyAttribute attr = i as PropertyAttribute;
            //            m_propertyAttributes.Add(attr.Name == null ? pInfo.Name : attr.Name, attr);
            //        }
            //    }
            //    else if (Attribute.IsDefined(pInfo, typeof(NHibernate.Mapping.Attributes.IdAttribute)))
            //    {
            //        Attribute[] attrs = Attribute.GetCustomAttributes(pInfo, typeof(NHibernate.Mapping.Attributes.IdAttribute));
            //        if (attrs.Length > 0)
            //        {
            //            m_idAttribute = attrs[0] as IdAttribute;
            //        }
            //    }
            //}
        }
 private PropertyData GetIdPropertyData(Property property)
 {
     return new PropertyData(property.Name, property.Name, property.PropertyAccessorName,
         ModificationStore.FULL);
 }
            private static void AddSubElement(Property property, ValidatableElement element)
            {
                if (property != null && property.IsComposite && !property.BackRef)
                {
                    Component component = (Component) property.Value;
                    if (component.IsEmbedded)
                    {
                        return;
                    }

                    IPropertyAccessor accesor = PropertyAccessorFactory.GetPropertyAccessor(property, EntityMode.Poco);

                    IGetter getter = accesor.GetGetter(element.EntityType, property.Name);

                    IClassValidator validator = Engine.GetClassValidator(getter.ReturnType);
                    if (validator != null)
                    {
                        ValidatableElement subElement = new ValidatableElement(getter.ReturnType, validator, getter);

                        foreach (Property currentProperty in component.PropertyIterator)
                        {
                            AddSubElement(currentProperty, subElement);
                        }

                        if (subElement.HasSubElements || subElement.Validator.HasValidationRules)
                        {
                            element.AddSubElement(subElement);
                        }
                    }
                }
            }