public void AfterSetMultiColumnsCantSetSimpleColumn()
 {
     var hbmMapping = new HbmMapping();
     var member = typeof(MyComponent).GetProperty("Relation");
     var mapping = new HbmKeyManyToOne();
     var mapper = new KeyManyToOneMapper(member, mapping, hbmMapping);
     mapper.Columns(cm => cm.Length(50), cm => cm.SqlType("VARCHAR(10)"));
     mapper.Executing(m=> m.Column(cm => cm.Length(50))).Throws<ConfOrm.MappingException>();
 }
        public void CanSetAccessor()
        {
            var hbmMapping = new HbmMapping();
            var member = typeof(MyComponent).GetProperty("Relation");
            var hbm = new HbmKeyManyToOne();
            var mapper = new KeyManyToOneMapper(member, hbm, hbmMapping);

            mapper.Access(Accessor.ReadOnly);
            hbm.Access.Should().Be("readonly");
        }
        public void CanForceClassRelation()
        {
            var hbmMapping = new HbmMapping();
            var member = typeof(MyComponent).GetProperty("TheOtherRelation");
            var mapping = new HbmKeyManyToOne();
            var mapper = new KeyManyToOneMapper(member, mapping, hbmMapping);

            mapper.Class(typeof(Relation));

            mapping.Class.Should().Contain("Relation").And.Not.Contain("IRelation");
        }
Пример #4
0
 public KeyManyToOneMapper(MemberInfo member, HbmKeyManyToOne manyToOne, HbmMapping mapDoc)
 {
     this.member = member;
     this.manyToOne = manyToOne;
     this.mapDoc = mapDoc;
     if (member == null)
     {
         this.manyToOne.access = "none";
     }
     if (member == null)
     {
         entityPropertyMapper = new NoMemberPropertyMapper();
     }
     else
     {
         entityPropertyMapper = new AccessorPropertyMapper(member.DeclaringType, member.Name, x => manyToOne.access = x);
     }
 }
        public void CanSetLazyness()
        {
            var hbmMapping = new HbmMapping();
            var member = typeof(MyComponent).GetProperty("TheOtherRelation");
            var mapping = new HbmKeyManyToOne();
            var mapper = new KeyManyToOneMapper(member, mapping, hbmMapping);

            mapper.Lazy(LazyRelation.NoProxy);
            mapping.Lazy.Should().Have.Value();
            mapping.Lazy.Should().Be(HbmRestrictedLaziness.False);

            mapper.Lazy(LazyRelation.NoLazy);
            mapping.Lazy.Should().Have.Value();
            mapping.Lazy.Should().Be(HbmRestrictedLaziness.False);

            mapper.Lazy(LazyRelation.Proxy);
            mapping.Lazy.Should().Have.Value();
            mapping.Lazy.Should().Be(HbmRestrictedLaziness.Proxy);
        }
 public void WhenSetMultiColumnsValuesThenAutoassignColumnNames()
 {
     var hbmMapping = new HbmMapping();
     var member = typeof(MyComponent).GetProperty("Relation");
     var mapping = new HbmKeyManyToOne();
     var mapper = new KeyManyToOneMapper(member, mapping, hbmMapping);
     mapper.Columns(cm => cm.Length(50), cm => cm.SqlType("VARCHAR(10)"));
     mapping.Columns.Should().Have.Count.EqualTo(2);
     mapping.Columns.All(cm => cm.name.Satisfy(n => !string.IsNullOrEmpty(n)));
 }
 public void WhenSetMultiColumnsValuesThenAddColumns()
 {
     var hbmMapping = new HbmMapping();
     var member = typeof(MyComponent).GetProperty("Relation");
     var mapping = new HbmKeyManyToOne();
     var mapper = new KeyManyToOneMapper(member, mapping, hbmMapping);
     mapper.Columns(cm =>
     {
         cm.Name("column1");
         cm.Length(50);
     }, cm =>
     {
         cm.Name("column2");
         cm.SqlType("VARCHAR(10)");
     });
     mapping.Columns.Should().Have.Count.EqualTo(2);
 }
Пример #8
0
		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);
		}
 public void WhenAssignCascadeStyleThenNotThrows()
 {
     var hbmMapping = new HbmMapping();
     var hbm = new HbmKeyManyToOne();
     var mapper = new KeyManyToOneMapper(null, hbm, hbmMapping);
     mapper.Executing(m => m.Cascade(Cascade.Persist | Cascade.Remove)).NotThrows();
 }
 public void WhenSetColumnValuesThenAddColumnTag()
 {
     var hbmMapping = new HbmMapping();
     var member = typeof(MyComponent).GetProperty("Relation");
     var mapping = new HbmKeyManyToOne();
     var mapper = new KeyManyToOneMapper(member, mapping, hbmMapping);
     mapper.Column(cm =>
     {
         cm.UniqueKey("theUnique");
         cm.NotNullable(true);
     });
     mapping.column.Should().Not.Be.Null();
     mapping.Columns.Should().Have.Count.EqualTo(1);
 }
        public void WhenSetColumnValuesMoreThanOnesThenMergeColumn()
        {
            var hbmMapping = new HbmMapping();
            var member = typeof(MyComponent).GetProperty("Relation");
            var mapping = new HbmKeyManyToOne();
            var mapper = new KeyManyToOneMapper(member, mapping, hbmMapping);
            mapper.Column(cm => cm.UniqueKey("theUnique"));
            mapper.Column(cm => cm.NotNullable(true));

            var hbmColumn = mapping.Columns.Single();
            hbmColumn.uniquekey.Should().Be("theUnique");
            hbmColumn.notnull.Should().Be(true);
            hbmColumn.notnullSpecified.Should().Be(true);
        }
		private void BindProperty(HbmKeyManyToOne keyManyToOneSchema, Property property)
		{
			property.Name = keyManyToOneSchema.name;

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

			property.PropertyAccessorName = keyManyToOneSchema.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(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;
		}
		private void BindColumns(HbmKeyManyToOne keyManyToOneSchema, SimpleValue model, bool isNullable,
			bool autoColumn, string propertyPath)
		{
			Table table = model.Table;
			//COLUMN(S)
			if (keyManyToOneSchema.column1 == null)
			{
				int count = 0;

				foreach (HbmColumn columnSchema in keyManyToOneSchema.column ?? new HbmColumn[0])
				{
					Column col = new Column();
					col.Value = model;
					col.TypeIndex = count++;
					BindColumn(columnSchema, col, isNullable);

					string name = columnSchema.name;
					col.Name = mappings.NamingStrategy.ColumnName(name);
					if (table != null)
						table.AddColumn(col);
					//table=null -> an association, fill it in later
					model.AddColumn(col);

					//column index
					BindIndex(columnSchema.index, table, col);
					//column group index (although it can serve as a separate column index)

					BindUniqueKey(columnSchema.uniquekey, table, col);
				}
			}
			else
			{
				Column col = new Column();
				col.Value = compositeId;
				BindColumn(col, isNullable);
				col.Name = mappings.NamingStrategy.ColumnName(keyManyToOneSchema.column1);
				if (table != null)
					table.AddColumn(col);
				model.AddColumn(col);
				//column group index (although can serve as a separate column index)
			}

			if (autoColumn && model.ColumnSpan == 0)
			{
				Column col = new Column();
				col.Value = model;
				BindColumn(col, isNullable);
				col.Name = mappings.NamingStrategy.PropertyToColumnName(propertyPath);
				model.Table.AddColumn(col);
				model.AddColumn(col);
				//column group index (although can serve as a separate column index)
			}
		}
		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 void BindSimpleValue(HbmKeyManyToOne mapKeyManyToManyMapping, string propertyPath, bool isNullable)
		{
			new ColumnsBinder(value, Mappings).Bind(mapKeyManyToManyMapping.Columns, isNullable,
			                                        () =>
			                                        new HbmColumn
			                                        	{name = mappings.NamingStrategy.PropertyToColumnName(propertyPath),});
		}
 public void WhenSetDefaultColumnNameThenDoesNotSetTheName()
 {
     var hbmMapping = new HbmMapping();
     var member = typeof(MyComponent).GetProperty("Relation");
     var mapping = new HbmKeyManyToOne();
     var mapper = new KeyManyToOneMapper(member, mapping, hbmMapping);
     mapper.Column(cm => cm.Name("Relation"));
     mapping.column.Should().Be.Null();
     mapping.Columns.Should().Be.Empty();
 }
        public void WhenSetDifferentColumnNameThenSetTheName()
        {
            var hbmMapping = new HbmMapping();
            var member = typeof(MyComponent).GetProperty("Relation");
            var hbm = new HbmKeyManyToOne();
            var mapper = new KeyManyToOneMapper(member, hbm, hbmMapping);
            mapper.Column(cm => cm.Name("RelationId"));

            hbm.Columns.Should().Have.Count.EqualTo(1);
            hbm.Columns.Single().name.Should().Be("RelationId");
        }
        public void WhenForceClassRelationToIncompatibleTypeThenThrows()
        {
            var hbmMapping = new HbmMapping();
            var member = typeof(MyComponent).GetProperty("TheOtherRelation");
            var mapping = new HbmKeyManyToOne();
            var mapper = new KeyManyToOneMapper(member, mapping, hbmMapping);

            mapper.Executing(m=> m.Class(typeof(Whatever))).Throws<ArgumentOutOfRangeException>();
        }
        public void WhenSetFetchModeToJoinThenNotThrows()
        {
            var hbmMapping = new HbmMapping();
            var member = typeof(MyComponent).GetProperty("Relation");
            var mapping = new HbmKeyManyToOne();
            var mapper = new KeyManyToOneMapper(member, mapping, hbmMapping);

            mapper.Executing(m=> m.Fetch(FetchMode.Join)).NotThrows();
        }
		public void ManyToOne(MemberInfo property, Action<IManyToOneMapper> mapping)
		{
			var hbm = new HbmKeyManyToOne { name = property.Name };
			mapping(new KeyManyToOneMapper(property, hbm, mapDoc));
			AddProperty(hbm);
		}
		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;
			}
		}