コード例 #1
0
		public void WhenCreateThenSetDefaultTableName()
		{
			var mapdoc = new HbmMapping();
			var hbmJoin = new HbmJoin();
			new JoinMapper(typeof(MyClass), "   AA   ", hbmJoin, mapdoc);
			hbmJoin.table.Should().Be("AA");
		}
コード例 #2
0
		public void WhenCreateThenSetDefaultTableName()
		{
			var mapdoc = new HbmMapping();
			var hbmJoin = new HbmJoin();
			new JoinMapper(typeof(MyClass), "   AA   ", hbmJoin, mapdoc);
			Assert.That(hbmJoin.table, Is.EqualTo("AA"));
		}
コード例 #3
0
		public void CanSetTable()
		{
			var mapdoc = new HbmMapping();
			var hbmJoin = new HbmJoin();
			var mapper = new JoinMapper(typeof(MyClass), "AA", hbmJoin, mapdoc);
			mapper.Table("   Pizza   ");
			Assert.That(hbmJoin.table, Is.EqualTo("Pizza"));
		}
コード例 #4
0
		public void WhenCreateWithEmptySplitGroupThenThrows()
		{
			var mapdoc = new HbmMapping();
			var hbmJoin = new HbmJoin();
			Assert.That(() => new JoinMapper(typeof(MyClass), null, hbmJoin, mapdoc), Throws.TypeOf<ArgumentNullException>());
			Assert.That(() => new JoinMapper(typeof(MyClass), "", hbmJoin, mapdoc), Throws.TypeOf<ArgumentOutOfRangeException>());
			Assert.That(() => new JoinMapper(typeof(MyClass), "     ", hbmJoin, mapdoc), Throws.TypeOf<ArgumentOutOfRangeException>());
		}
コード例 #5
0
		public void WhenCreateWithEmptySplitGroupThenThrows()
		{
			var mapdoc = new HbmMapping();
			var hbmJoin = new HbmJoin();
			Executing.This(() => new JoinMapper(typeof(MyClass), null, hbmJoin, mapdoc)).Should().Throw<ArgumentNullException>();
			Executing.This(() => new JoinMapper(typeof(MyClass), "", hbmJoin, mapdoc)).Should().Throw<ArgumentOutOfRangeException>();
			Executing.This(() => new JoinMapper(typeof(MyClass), "     ", hbmJoin, mapdoc)).Should().Throw<ArgumentOutOfRangeException>();
		}
コード例 #6
0
		public void CanSetTable()
		{
			var mapdoc = new HbmMapping();
			var hbmJoin = new HbmJoin();
			var mapper = new JoinMapper(typeof(MyClass), "AA", hbmJoin, mapdoc);
			mapper.Table("   Pizza   ");
			hbmJoin.table.Should().Be("Pizza");
		}
コード例 #7
0
		public void CanSetCatalog()
		{
			var mapdoc = new HbmMapping();
			var hbmJoin = new HbmJoin();
			var mapper = new JoinMapper(typeof(MyClass), "AA", hbmJoin, mapdoc);
			mapper.Catalog("pizza");
			Assert.That(hbmJoin.catalog, Is.EqualTo("pizza"));
		}
コード例 #8
0
		public void CanSetCatalog()
		{
			var mapdoc = new HbmMapping();
			var hbmJoin = new HbmJoin();
			var mapper = new JoinMapper(typeof(MyClass), "AA", hbmJoin, mapdoc);
			mapper.Catalog("pizza");
			hbmJoin.catalog.Should().Be("pizza");
		}
コード例 #9
0
		public void WhenSetTableNameEmptyThenThrows()
		{
			var mapdoc = new HbmMapping();
			var hbmJoin = new HbmJoin();
			var mapper = new JoinMapper(typeof(MyClass), "AA", hbmJoin, mapdoc);
			Assert.That(() => mapper.Table(null), Throws.TypeOf<ArgumentNullException>());
			Assert.That(() => mapper.Table(""), Throws.TypeOf<ArgumentOutOfRangeException>());
			Assert.That(() => mapper.Table("    "), Throws.TypeOf<ArgumentOutOfRangeException>());
		}
コード例 #10
0
		public void WhenSetTableNameEmptyThenThrows()
		{
			var mapdoc = new HbmMapping();
			var hbmJoin = new HbmJoin();
			var mapper = new JoinMapper(typeof(MyClass), "AA", hbmJoin, mapdoc);
			mapper.Executing(x => x.Table(null)).Throws<ArgumentNullException>();
			mapper.Executing(x => x.Table("")).Throws<ArgumentOutOfRangeException>();
			mapper.Executing(x => x.Table("    ")).Throws<ArgumentOutOfRangeException>();
		}
コード例 #11
0
		public void WhenTableNameChangesValueThenNotify()
		{
			bool eventCalled = false;
			var mapdoc = new HbmMapping();
			var hbmJoin = new HbmJoin();
			var mapper = new JoinMapper(typeof(MyClass), "AA", hbmJoin, mapdoc);
			mapper.TableNameChanged += (m, x) =>
			                           {
																	 m.Should().Be.SameInstanceAs(mapper);
																	 x.OldName.Should().Be("AA");
																	 x.NewName.Should().Be("Pizza");
																	 eventCalled = true;
																 };
			mapper.Table("   Pizza   ");
			eventCalled.Should().Be.True();
		}
コード例 #12
0
		public void WhenTableNameChangesValueThenNotify()
		{
			bool eventCalled = false;
			var mapdoc = new HbmMapping();
			var hbmJoin = new HbmJoin();
			var mapper = new JoinMapper(typeof(MyClass), "AA", hbmJoin, mapdoc);
			mapper.TableNameChanged += (m, x) =>
									   {
																	 Assert.That(m, Is.SameAs(mapper));
																	 Assert.That(x.OldName, Is.EqualTo("AA"));
																	 Assert.That(x.NewName, Is.EqualTo("Pizza"));
																	 eventCalled = true;
																 };
			mapper.Table("   Pizza   ");
			Assert.That(eventCalled, Is.True);
		}
コード例 #13
0
		public JoinMapper(System.Type container, string splitGroupId, HbmJoin hbmJoin, HbmMapping mapDoc) : base(container, mapDoc)
		{
			if (splitGroupId == null)
			{
				throw new ArgumentNullException("splitGroupId");
			}
			if (hbmJoin == null)
			{
				throw new ArgumentNullException("hbmJoin");
			}
			this.hbmJoin = hbmJoin;
			this.hbmJoin.table = splitGroupId.Trim();
			if (string.IsNullOrEmpty(this.hbmJoin.table))
			{
				throw new ArgumentOutOfRangeException("splitGroupId", "The table-name cant be empty.");
			}
			if (hbmJoin.key == null)
			{
				hbmJoin.key = new HbmKey { column1 = container.Name.ToLowerInvariant() + "_key" };
			}
			keyMapper = new KeyMapper(container, hbmJoin.key);
		}
コード例 #14
0
		public void SetSqlDelete()
		{
			var mapdoc = new HbmMapping();
			var hbmJoin = new HbmJoin();
			var mapper = new JoinMapper(typeof(MyClass), "AA", hbmJoin, mapdoc);
			mapper.SqlDelete("blah");

			hbmJoin.SqlDelete.Should().Not.Be.Null();
			hbmJoin.SqlDelete.Text[0].Should().Be("blah");
		}
コード例 #15
0
		public void CanSetFetch()
		{
			var mapdoc = new HbmMapping();
			var hbmJoin = new HbmJoin();
			var mapper = new JoinMapper(typeof(MyClass), "AA", hbmJoin, mapdoc);
			mapper.Fetch(FetchKind.Select);
			Assert.That(hbmJoin.fetch, Is.EqualTo(HbmJoinFetch.Select));
		}
コード例 #16
0
		public void CallKeyMapper()
		{
			var mapdoc = new HbmMapping();
			var hbmJoin = new HbmJoin();
			var mapper = new JoinMapper(typeof(MyClass), "AA", hbmJoin, mapdoc);
			var keyMapperCalled = false;

			mapper.Key(km => keyMapperCalled = true);

			Assert.That(keyMapperCalled, Is.True);
		}
コード例 #17
0
		public void WhenAddPropertyThenAddItem()
		{
			var mapdoc = new HbmMapping();
			var hbmJoin = new HbmJoin();
			var mapper = new JoinMapper(typeof(MyClass), "AA", hbmJoin, mapdoc);

			mapper.Property(For<MyClass>.Property(mc => mc.Something), x => { });

			hbmJoin.Properties.Should().Have.Count.EqualTo(1);
		}
コード例 #18
0
		public void WhenCallKeyMapperMoreThanOnceThenKeyMapperIsTheSame()
		{
			var mapdoc = new HbmMapping();
			var hbmJoin = new HbmJoin();
			var mapper = new JoinMapper(typeof(MyClass), "AA", hbmJoin, mapdoc);
			IKeyMapper firstCallInstance = null;
			IKeyMapper secondCallInstance= null;

			mapper.Key(km => firstCallInstance = km);
			mapper.Key(km => secondCallInstance = km);

			firstCallInstance.Should().Be.SameInstanceAs(secondCallInstance);
		}
コード例 #19
0
		public void WhenCallKeyMapperThenKeyMapperIsNotNull()
		{
			var mapdoc = new HbmMapping();
			var hbmJoin = new HbmJoin();
			var mapper = new JoinMapper(typeof(MyClass), "AA", hbmJoin, mapdoc);

			mapper.Key(km => km.Should().Not.Be.Null());
		}
コード例 #20
0
		public void CallKeyMapper()
		{
			var mapdoc = new HbmMapping();
			var hbmJoin = new HbmJoin();
			var mapper = new JoinMapper(typeof(MyClass), "AA", hbmJoin, mapdoc);
			var keyMapperCalled = false;

			mapper.Key(km => keyMapperCalled = true);

			keyMapperCalled.Should().Be.True();
		}
コード例 #21
0
		public void CanSetFetch()
		{
			var mapdoc = new HbmMapping();
			var hbmJoin = new HbmJoin();
			var mapper = new JoinMapper(typeof(MyClass), "AA", hbmJoin, mapdoc);
			mapper.Fetch(FetchKind.Select);
			hbmJoin.fetch.Should().Be(HbmJoinFetch.Select);
		}
コード例 #22
0
		public void WhenCallKeyMapperThenKeyMapperIsNotNull()
		{
			var mapdoc = new HbmMapping();
			var hbmJoin = new HbmJoin();
			var mapper = new JoinMapper(typeof(MyClass), "AA", hbmJoin, mapdoc);

			mapper.Key(km => Assert.That(km, Is.Not.Null));
		}
コード例 #23
0
		public void CanSetOptional()
		{
			var mapdoc = new HbmMapping();
			var hbmJoin = new HbmJoin();
			var mapper = new JoinMapper(typeof(MyClass), "AA", hbmJoin, mapdoc);
			mapper.Optional(true);
			hbmJoin.optional.Should().Be.True();
		}
コード例 #24
0
		public void WhenAddPropertyThenAddItem()
		{
			var mapdoc = new HbmMapping();
			var hbmJoin = new HbmJoin();
			var mapper = new JoinMapper(typeof(MyClass), "AA", hbmJoin, mapdoc);

			mapper.Property(For<MyClass>.Property(mc => mc.Something), x => { });

			Assert.That(hbmJoin.Properties.Count(), Is.EqualTo(1));
		}
コード例 #25
0
		public void CanSetSchema()
		{
			var mapdoc = new HbmMapping();
			var hbmJoin = new HbmJoin();
			var mapper = new JoinMapper(typeof(MyClass), "AA", hbmJoin, mapdoc);
			mapper.Schema("pizza");
			hbmJoin.schema.Should().Be("pizza");
		}
コード例 #26
0
		private void BindJoin(HbmJoin joinMapping, Join join, IDictionary<string, MetaAttribute> inheritedMetas)
		{
			PersistentClass persistentClass = join.PersistentClass;

			// TABLENAME
			string schema = joinMapping.schema ?? mappings.SchemaName;
			string catalog = joinMapping.catalog ?? mappings.CatalogName;

			string action = "all"; // joinMapping.schemaaction ?? "all";

			string tableName = joinMapping.table;
			Table table = mappings.AddTable(schema, catalog, GetClassTableName(persistentClass, tableName), joinMapping.Subselect, false, action);
			join.Table = table;

			join.IsSequentialSelect = joinMapping.fetch == HbmJoinFetch.Select;
			join.IsInverse = joinMapping.inverse;
			join.IsOptional = joinMapping.optional;

			log.InfoFormat("Mapping class join: {0} -> {1}", persistentClass.EntityName, join.Table.Name);

			// KEY
			SimpleValue key;
			if (!String.IsNullOrEmpty(joinMapping.key.propertyref))
			{
				string propertyRef = joinMapping.key.propertyref;
				var propertyRefKey = new SimpleValue(persistentClass.Table)
					{
						IsAlternateUniqueKey = true
					};
				var property = persistentClass.GetProperty(propertyRef);
				join.RefIdProperty = property;
				//we only want one column
				var column = (Column) property.ColumnIterator.First();
				if (!column.Unique)
					throw new MappingException(
						string.Format(
							"Property {0}, on class {1} must be marked as unique to be joined to with a property-ref.",
							property.Name,
							persistentClass.ClassName));
				propertyRefKey.AddColumn(column);
				propertyRefKey.TypeName = property.Type.Name;
				key = new ReferenceDependantValue(table, propertyRefKey);
			}
			else
			{
				key = new DependantValue(table, persistentClass.Identifier);
			}

			key.ForeignKeyName = joinMapping.key.foreignkey;
			join.Key = key;
			key.IsCascadeDeleteEnabled = joinMapping.key.ondelete == HbmOndelete.Cascade;
			new ValuePropertyBinder(key, Mappings).BindSimpleValue(joinMapping.key, persistentClass.EntityName, false);

			join.CreatePrimaryKey(dialect);
			join.CreateForeignKey();

			// PROPERTIES
			new PropertiesBinder(Mappings, persistentClass, dialect).Bind(joinMapping.Properties, join.Table,
																							inheritedMetas, p => { },
																							join.AddProperty);

			// CUSTOM SQL
			HandleCustomSQL(joinMapping, join);
		}
コード例 #27
0
		public void CanSetSqlSubselect()
		{
			var mapdoc = new HbmMapping();
			var hbmJoin = new HbmJoin();
			var mapper = new JoinMapper(typeof(MyClass), "AA", hbmJoin, mapdoc);
			mapper.Subselect("blah");

			hbmJoin.Subselect.Should().Not.Be.Null();
			hbmJoin.subselect.Text[0].Should().Be("blah");
		}
コード例 #28
0
		public void CanSetInverse()
		{
			var mapdoc = new HbmMapping();
			var hbmJoin = new HbmJoin();
			var mapper = new JoinMapper(typeof(MyClass), "AA", hbmJoin, mapdoc);
			mapper.Inverse(true);
			hbmJoin.inverse.Should().Be.True();
		}
コード例 #29
0
		private void BindJoin(HbmJoin joinMapping, Join join, IDictionary<string, MetaAttribute> inheritedMetas)
		{
			PersistentClass persistentClass = join.PersistentClass;

			// TABLENAME
			string schema = joinMapping.schema ?? mappings.SchemaName;
			string catalog = joinMapping.catalog ?? mappings.CatalogName;

			string action = "all"; // joinMapping.schemaaction ?? "all";

			string tableName = joinMapping.table;
			Table table = mappings.AddTable(schema, catalog, GetClassTableName(persistentClass, tableName), joinMapping.Subselect, false, action);
			join.Table = table;

			join.IsSequentialSelect = joinMapping.fetch == HbmJoinFetch.Select;
			join.IsInverse = joinMapping.inverse;
			join.IsOptional = joinMapping.optional;

			log.InfoFormat("Mapping class join: {0} -> {1}", persistentClass.EntityName, join.Table.Name);

			// KEY
			SimpleValue key = new DependantValue(table, persistentClass.Identifier);
			key.ForeignKeyName = joinMapping.key.foreignkey;
			join.Key = key;
			key.IsCascadeDeleteEnabled = joinMapping.key.ondelete == HbmOndelete.Cascade;
			new ValuePropertyBinder(key, Mappings).BindSimpleValue(joinMapping.key, persistentClass.EntityName, false);

			join.CreatePrimaryKey(dialect);
			join.CreateForeignKey();

			// PROPERTIES
			new PropertiesBinder(Mappings, persistentClass, dialect).Bind(joinMapping.Properties, join.Table,
			                                                                                inheritedMetas, p => { },
			                                                                                join.AddProperty);

			// CUSTOM SQL
			HandleCustomSQL(joinMapping, join);
		}
コード例 #30
0
		public void CanSetOptional()
		{
			var mapdoc = new HbmMapping();
			var hbmJoin = new HbmJoin();
			var mapper = new JoinMapper(typeof(MyClass), "AA", hbmJoin, mapdoc);
			mapper.Optional(true);
			Assert.That(hbmJoin.optional, Is.True);
		}