예제 #1
0
		private void BindTimestamp(HbmTimestamp timestampSchema, PersistentClass rootClass, Table table, IDictionary<string, MetaAttribute> inheritedMetas)
		{
			if (timestampSchema == null)
				return;

			string propertyName = timestampSchema.name;
			var simpleValue = new SimpleValue(table);
			new ColumnsBinder(simpleValue, Mappings).Bind(timestampSchema.Columns, false,
			                                              () =>
			                                              new HbmColumn
			                                              	{name = mappings.NamingStrategy.PropertyToColumnName(propertyName)});

			if (!simpleValue.IsTypeSpecified)
			{
				switch (timestampSchema.source)
				{
					case HbmTimestampSource.Vm:
						simpleValue.TypeName = NHibernateUtil.Timestamp.Name; 
						break;
					case HbmTimestampSource.Db:
						simpleValue.TypeName = NHibernateUtil.DbTimestamp.Name; 
						break;
					default:
						simpleValue.TypeName = NHibernateUtil.Timestamp.Name;
						break;
				}
			}

			var property = new Property(simpleValue);
			BindProperty(timestampSchema, property, inheritedMetas);

			// for version properties marked as being generated, make sure they are "always"
			// generated; "insert" is invalid. This is dis-allowed by the schema, but just to make
			// sure...

			if (property.Generation == PropertyGeneration.Insert)
				throw new MappingException("'generated' attribute cannot be 'insert' for versioning property");
			simpleValue.NullValue = timestampSchema.unsavedvalue == HbmTimestampUnsavedvalue.Null ? null : "undefined";
			rootClass.Version = property;
			rootClass.AddProperty(property);
		}
예제 #2
0
        private void BindProperties(PersistentClass pclass, IEnumerable<PropertyInfo> infos)
        {
            var table = pclass.Table;

            foreach (var propertyInfo in infos) {
                if (typeof(IEnumerable).IsAssignableFrom(propertyInfo.PropertyType) && propertyInfo.PropertyType != typeof(string))
                    continue;
                // Bind a simple value property
                IValue value = new SimpleValue(table);
                BindColumn((SimpleValue) value, true, propertyInfo.Name);

                Property property = CreateProperty(value, propertyInfo, pclass.ClassName);
                //	property.IsUpdateable = false;
                pclass.AddProperty(property);
            }
        }
예제 #3
0
		private void BindVersion(HbmVersion versionSchema, PersistentClass rootClass, Table table, IDictionary<string, MetaAttribute> inheritedMetas)
		{
			if (versionSchema == null)
				return;

			string propertyName = versionSchema.name;
			var simpleValue = new SimpleValue(table);
			new TypeBinder(simpleValue, Mappings).Bind(versionSchema.type);
			new ColumnsBinder(simpleValue, Mappings).Bind(versionSchema.Columns, false,
			                                              () =>
			                                              new HbmColumn
			                                              	{name = mappings.NamingStrategy.PropertyToColumnName(propertyName)});

			if (!simpleValue.IsTypeSpecified)
				simpleValue.TypeName = NHibernateUtil.Int32.Name;

			var property = new Property(simpleValue);
			BindProperty(versionSchema, property, inheritedMetas);

			// for version properties marked as being generated, make sure they are "always"
			// generated; "insert" is invalid. This is dis-allowed by the schema, but just to make
			// sure...

			if (property.Generation == PropertyGeneration.Insert)
				throw new MappingException("'generated' attribute cannot be 'insert' for versioning property");

			simpleValue.NullValue = versionSchema.unsavedvalue;
			rootClass.Version = property;
			rootClass.AddProperty(property);
		}
예제 #4
0
        protected void PropertiesFromXML(XmlNode node, PersistentClass model)
        {
            Table table = model.Table;

            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;
                string propertyName = GetPropertyName(subnode);

                IValue value = null;
                CollectionBinder collectionBinder = new CollectionBinder(this);
                if (collectionBinder.CanCreate(name))
                {
                    Mapping.Collection collection = collectionBinder.Create(name, subnode, model.EntityName,
                        propertyName, model, model.MappedClass);

                    mappings.AddCollection(collection);
                    value = collection;
                }
                else if ("many-to-one".Equals(name))
                {
                    value = new ManyToOne(table);
                    BindManyToOne(subnode, (ManyToOne) value, propertyName, true);
                }
                else if ("any".Equals(name))
                {
                    value = new Any(table);
                    BindAny(subnode, (Any) value, true);
                }
                else if ("one-to-one".Equals(name))
                {
                    value = new OneToOne(table, model);
                    BindOneToOne(subnode, (OneToOne) value);
                }
                else if ("property".Equals(name))
                {
                    value = new SimpleValue(table);
                    BindSimpleValue(subnode, (SimpleValue) value, true, propertyName);
                }
                else if ("component".Equals(name) || "dynamic-component".Equals(name))
                {
                    // NH: Modified from H2.1 to allow specifying the type explicitly using class attribute
                    System.Type reflectedClass = GetPropertyType(subnode, model.MappedClass, propertyName);
                    value = new Component(model);
                    BindComponent(subnode, (Component) value, reflectedClass, model.EntityName, propertyName, true);
                }
                else if ("join".Equals(name))
                {
                    Join join = new Join();
                    join.PersistentClass = model;
                    BindJoin(subnode, join);
                    model.AddJoin(join);
                }
                else if ("subclass".Equals(name))
                    new SubclassBinder(this).HandleSubclass(model, subnode);

                else if ("joined-subclass".Equals(name))
                    new JoinedSubclassBinder(this).HandleJoinedSubclass(model, subnode);

                else if ("union-subclass".Equals(name))
                    new UnionSubclassBinder(this).HandleUnionSubclass(model, subnode);

                else if ("filter".Equals(name))
                    ParseFilter(subnode, model);

                if (value != null)
                    model.AddProperty(CreateProperty(value, propertyName, model.MappedClass, subnode));
            }
        }
 protected virtual void BindProperty(PropertyMapping propertyMapping, IValue value, PersistentClass model)
 {
     var property = CreateProperty(model, value, propertyMapping.PropertyInfo);
     model.AddProperty(property);
 }
예제 #6
0
		private void BindTimestamp(HbmTimestamp timestampSchema, PersistentClass rootClass, Table table)
		{
			if (timestampSchema == null)
				return;

			string propertyName = timestampSchema.name;
			SimpleValue simpleValue = new SimpleValue(table);

			BindColumns(timestampSchema, simpleValue, propertyName);

			if (!simpleValue.IsTypeSpecified)
				simpleValue.TypeName = NHibernateUtil.Timestamp.Name;

			Mapping.Property property = new Mapping.Property(simpleValue);
			BindProperty(timestampSchema, property);

			// for version properties marked as being generated, make sure they are "always"
			// generated; "insert" is invalid. This is dis-allowed by the schema, but just to make
			// sure...

			if (property.Generation == PropertyGeneration.Insert)
				throw new MappingException("'generated' attribute cannot be 'insert' for versioning property");

			simpleValue.NullValue = timestampSchema.unsavedvalue;
			rootClass.Version = property;
			rootClass.AddProperty(property);
		}
예제 #7
0
        private static void AddColumn(PersistentClass mapping, string columnName, Type accessorType)
        {
            var typeName = DICT_TYPE_TO_NAME[accessorType];
            bool isNullable = typeName[typeName.Length - 1] == '?';
            if (isNullable)
                typeName = typeName.Substring(0, typeName.Length - 1);

            // String annotations can be null also
            isNullable = isNullable || Equals(STRING_TYPE_NAME, typeName);

            var column = new Column(columnName) {IsNullable = isNullable};
            mapping.Table.AddColumn(column);
            var value = new SimpleValue(mapping.Table) {TypeName = typeName};
            value.AddColumn(column);
            var property = new Property(value)
            {
                Name = columnName,
                PropertyAccessorName = accessorType.AssemblyQualifiedName
            };
            mapping.AddProperty(property);
        }
예제 #8
0
		protected void PropertiesFromXML(XmlNode node, PersistentClass model, IDictionary<string, MetaAttribute> inheritedMetas, UniqueKey uniqueKey, bool mutable, bool nullable, bool naturalId)
		{
			string entityName = model.EntityName;

			Table table = model.Table;

			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;
				string propertyName = GetPropertyName(subnode);

				IValue value = null;
				CollectionBinder collectionBinder = new CollectionBinder(this);
				if (collectionBinder.CanCreate(name))
				{
					Mapping.Collection collection = collectionBinder.Create(name, subnode, entityName, propertyName, model,
					                                                        model.MappedClass, inheritedMetas);

					mappings.AddCollection(collection);
					value = collection;
				}
				else if ("many-to-one".Equals(name))
				{
					value = new ManyToOne(table);
					BindManyToOne(subnode, (ManyToOne) value, propertyName, true);
				}
				else if ("any".Equals(name))
				{
					value = new Any(table);
					BindAny(subnode, (Any) value, true);
				}
				else if ("one-to-one".Equals(name))
				{
					value = new OneToOne(table, model);
					BindOneToOne(subnode, (OneToOne) value);
				}
				else if ("property".Equals(name))
				{
					value = new SimpleValue(table);
					BindSimpleValue(subnode, (SimpleValue) value, true, propertyName);
				}
				else if ("component".Equals(name) || "dynamic-component".Equals(name))
				{
					string subpath = StringHelper.Qualify(entityName, propertyName);
					// NH: Modified from H2.1 to allow specifying the type explicitly using class attribute
					System.Type reflectedClass = GetPropertyType(subnode, model.MappedClass, propertyName);
					value = new Component(model);
					BindComponent(subnode, (Component) value, reflectedClass, entityName, propertyName, subpath, true, inheritedMetas);
				}
				else if ("join".Equals(name))
				{
					Join join = new Join();
					join.PersistentClass = model;
					BindJoin(subnode, join, inheritedMetas);
					model.AddJoin(join);
				}
				else if ("subclass".Equals(name))
					new SubclassBinder(this).HandleSubclass(model, subnode, inheritedMetas);

				else if ("joined-subclass".Equals(name))
					new JoinedSubclassBinder(this).HandleJoinedSubclass(model, subnode, inheritedMetas);

				else if ("union-subclass".Equals(name))
					new UnionSubclassBinder(this).HandleUnionSubclass(model, subnode, inheritedMetas);

				else if ("filter".Equals(name))
					ParseFilter(subnode, model);
				else if ("natural-id".Equals(name))
				{
					UniqueKey uk = new UniqueKey();
					uk.Name = "_UniqueKey";
					uk.Table = table;
					//by default, natural-ids are "immutable" (constant)

					bool mutableId = false;
					if (subnode.Attributes["mutable"] != null)
					{
						mutableId = "true".Equals(subnode.Attributes["mutable"]);						
					}

					PropertiesFromXML(subnode, model, inheritedMetas, uk, mutableId, false, true);
					table.AddUniqueKey(uk);
				}

				if (value != null)
				{
					Property property = CreateProperty(value, propertyName, model.ClassName, subnode, inheritedMetas);
					if (!mutable)
						property.IsUpdateable = false;
					if (naturalId)
						property.IsNaturalIdentifier = true;
					model.AddProperty(property);
					if (uniqueKey != null)
						uniqueKey.AddColumns(new SafetyEnumerable<Column>(property.ColumnIterator));
				}
			}
		}