Inheritance: ISelectable, ICloneable
		public void UnmatchingColumns()
		{
			Table primaryTable = new Table("pktable");
			primaryTable.PrimaryKey = new PrimaryKey();
			SimpleValue sv = new SimpleValue();
			sv.TypeName = NHibernateUtil.Int16.Name;
			Column pkColumn = new Column("pk_column");
			pkColumn.Value = sv;

			primaryTable.PrimaryKey.AddColumn(pkColumn);

			Table fkTable = new Table("fktable");

			ForeignKey fk = new ForeignKey();
			sv = new SimpleValue();
			sv.TypeName = NHibernateUtil.Int16.Name;
			Column fkColumn1 = new Column("col1");
			fkColumn1.Value = sv;

			sv = new SimpleValue();
			sv.TypeName = NHibernateUtil.Int16.Name;
			Column fkColumn2 = new Column("col2");
			fkColumn2.Value = sv;

			fk.AddColumn(fkColumn1);
			fk.AddColumn(fkColumn2);

			fk.Table = fkTable;

			fk.ReferencedTable = primaryTable;
			Assert.Throws<FKUnmatchingColumnsException>(() => fk.AlignColumns());
		}
 private static void BindColumn(Column model, bool isNullable)
 {
     model.IsNullable = isNullable;
     model.IsUnique = false;
     model.CheckConstraint = string.Empty;
     model.SqlType = null;
 }
        private MigrationColumn SelectMigrationColumn(Column column)
        {
            if (column.Value.Type.ReturnedClass == typeof(Guid))
                return new GuidMigrationColumn(column);

            if (column.Value.Type.ReturnedClass == typeof(decimal))
                return new DecimalMigrationColumn(column);

            if (column.Value.Type.ReturnedClass == typeof(string))
                return new StringMigrationColumn(column);

            if (column.Value.Type.ReturnedClass == typeof(DateTime))
                return new DateTimeMigrationColumn(column);

            if (column.Value.Type.ReturnedClass == typeof(bool))
                return new BoolMigrationColumn(column);

            if (column.Value.Type.ReturnedClass == typeof(short))
                return new ShortMigrationColumn(column);

            //TODO Blob

            // if (column.Value.Type.ReturnedClass.IsEnum || column.Value.Type.ReturnedClass == typeof(int))
            return new IntegerMigrationColumn(column);
        }
Beispiel #4
0
 private static void BindColumn(Column column, bool isNullable)
 {
     column.IsNullable = isNullable;
     column.IsUnique = false;
     column.CheckConstraint = string.Empty;
     column.SqlType = null;
 }
 public MigrationColumn(Column column, MigrationColumnType type)
 {
     Name = column.Name;
     IsNullable = column.IsNullable;
     Type = type;
     IsPrimaryKey = false;
 }
		/// <summary>
		/// 
		/// </summary>
		/// <param name="column"></param>
		public virtual void AddColumn( Column column )
		{
			if( !columns.Contains( column ) )
			{
				columns.Add( column );
			}
		}
		public void UnmatchingColumns()
		{

			Table primaryTable = new Table();
			primaryTable.Name = "pktable";
			primaryTable.PrimaryKey = new PrimaryKey();
			Column pkColumn = new Column( NHibernateUtil.Int16, 0 );
			pkColumn.Name = "pk_column";

			primaryTable.PrimaryKey.AddColumn( pkColumn );

			Table fkTable = new Table();
			fkTable.Name = "fktable";

			ForeignKey fk = new ForeignKey();
			Column fkColumn1 = new Column( NHibernateUtil.Int16, 0 );
			fkColumn1.Name = "col1";

			Column fkColumn2 = new Column( NHibernateUtil.Int16, 0 );
			fkColumn2.Name = "col2";

			fk.AddColumn( fkColumn1 );
			fk.AddColumn( fkColumn2 );
			
			fk.Table = fkTable;

			fk.ReferencedTable = primaryTable;

		}
Beispiel #8
0
		static void remapGetDateDefaultValues(Column column)
		{
			if (string.Compare(column.SqlType, "datetime", StringComparison.OrdinalIgnoreCase) != 0 &&
				string.Compare(column.DefaultValue, "getdate()", StringComparison.OrdinalIgnoreCase) != 0)
				return;

			column.DefaultValue = "CURRENT_TIMESTAMP";
		}
		private static void BindUniqueKey(string uniqueKeyAttribute, Table table, Column column)
		{
			if (uniqueKeyAttribute != null && table != null)
			{
				var tokens = uniqueKeyAttribute.Split(',');
				System.Array.ForEach(tokens, t => table.GetOrCreateUniqueKey(t.Trim()).AddColumn(column));
			}
		}
		private static void BindIndex(string indexAttribute, Table table, Column column)
		{
			if (indexAttribute != null && table != null)
			{
				var tokens = indexAttribute.Split(',');
				System.Array.ForEach(tokens, t => table.GetOrCreateIndex(t.Trim()).AddColumn(column));
			}
		}
        public MigrationColumn Create(Column column)
        {

            var result = SelectMigrationColumn(column);
            result.OwnerTable = OwnerTable;

            return result;
        }
 protected static void BindIndex(string indexAttribute, Table table, Column column)
 {
     if (indexAttribute != null && table != null)
     {
         StringTokenizer tokens = new StringTokenizer(indexAttribute, ", ");
         foreach (string token in tokens)
             table.GetOrCreateIndex(token).AddColumn(column);
     }
 }
		public void StringSqlType()
		{
			Column column = new Column(NHibernateUtil.String, 0);
			Assert.AreEqual("NVARCHAR(255)", column.GetSqlType(_dialect, null));

			column.Length = 100;
			Assert.AreEqual("NVARCHAR(100)", column.GetSqlType(_dialect, null));

		}
		public void YesNoSqlType()
		{
			SimpleValue sv = new SimpleValue();
			sv.TypeName = NHibernateUtil.YesNo.Name;
			Column column = new Column();
			column.Value = sv;
			string type = column.GetSqlType(_dialect, null);
			Assert.AreEqual("CHAR(1)", type);
		}
Beispiel #15
0
		public void Bug()
		{
			Table table1 = new Table("ATABLE");

			Column table1ITestManyA = new Column("itestmanyaid");
			Column table1ITestManyB = new Column("itestmanybid");
			string t1Fk = table1.UniqueColumnString(new object[] { table1ITestManyA }, "BluewireTechnologies.Core.Framework.DynamicTypes2.Albatross.ITestManyA");
			string t2Fk = table1.UniqueColumnString(new object[] { table1ITestManyB }, "BluewireTechnologies.Core.Framework.DynamicTypes2.Albatross.ITestManyB");
			Assert.AreNotEqual(t1Fk, t2Fk, "Different columns in differents tables create the same FK name.");
		}
        private static void BindColumn(HbmDiscriminator discriminatorSchema, Column column)
        {
            if (discriminatorSchema.length != null)
                column.Length = int.Parse(discriminatorSchema.length);

            column.IsNullable = !discriminatorSchema.notnull;
            column.IsUnique = false;
            column.CheckConstraint = string.Empty;
            column.SqlType = null;
        }
Beispiel #17
0
		/// <summary>
		/// Constructor.
		/// </summary>
		/// <param name="column"></param>
		/// <param name="config"></param>
		/// <param name="dialect"></param>
		internal ColumnInfo(Column column, Configuration config, Dialect dialect)
		{
			_name = column.Name;
			_nullable = column.IsNullable;
			_sqlType = column.GetSqlType(dialect, new Mapping(config));

            //as of NH2.0, the length column seems to be set at 255 for non-string-like columns, which makes no sense
            //therefore ignore NH length for non-string like columns, and use -1 which corresponds to the pre-2.0 behaviour
            _length = (this.SqlType.IndexOf("char", System.StringComparison.InvariantCultureIgnoreCase) > -1) ? column.Length : -1;
        }
Beispiel #18
0
        private static void BindColumn(HbmKeyProperty keyPropertySchema, Column model, bool isNullable)
        {
            if (keyPropertySchema.length != null)
                model.Length = int.Parse(keyPropertySchema.length);

            model.IsNullable = isNullable;
            model.IsUnique = false;
            model.CheckConstraint = string.Empty;
            model.SqlType = null;
        }
        protected static void BindColumn(HbmColumn columnSchema, Column column, bool isNullable)
        {
            if (columnSchema.length != null)
                column.Length = int.Parse(columnSchema.length);

            column.IsNullable = columnSchema.notnullSpecified ? !columnSchema.notnull : isNullable;
            column.IsUnique = columnSchema.uniqueSpecified && columnSchema.unique;
            column.CheckConstraint = columnSchema.check ?? string.Empty;
            column.SqlType = columnSchema.sqltype;
        }
		public void StringSqlType()
		{
			SimpleValue sv = new SimpleValue();
			sv.TypeName = NHibernateUtil.String.Name;
			Column column = new Column();
			column.Value = sv;
			Assert.AreEqual("NVARCHAR(255)", column.GetSqlType(_dialect, null));

			column.Length = 100;
			Assert.AreEqual("NVARCHAR(100)", column.GetSqlType(_dialect, null));
		}
		public virtual void AddColumn(Column column)
		{
			if (!columns.Contains(column))
			{
				columns.Add(column);
			}

			// TODO H3:			
//			column.Value = this;
//			column.TypeIndex = columns.Count - 1;
		}
		public void GetAliasRespectsMaxAliasLength(string columnName)
		{
			var dialect = new GenericDialect();

			// Verify test case assumption.
			Assert.That(dialect.MaxAliasLength, Is.EqualTo(10));

			var column = new Column(columnName);
			string generatedAlias = column.GetAlias(dialect);

			Assert.That(generatedAlias, Has.Length.LessThanOrEqualTo(dialect.MaxAliasLength));
		}
		public override Column GetColumn(Column column)
		{
			Column superColumn = base.GetColumn(column);
			if (superColumn != null)
			{
				return superColumn;
			}
			else
			{
				return includedTable.GetColumn(column);
			}
		}
Beispiel #24
0
		void remap(Column column)
		{
			remapGetDateDefaultValues(column);

			if (string.IsNullOrEmpty(column.SqlType))
				return;

			// Remap SqlTypes as necessary
			string sqlType;
			if (_map.TryGetValue(column.SqlType, out sqlType))
				column.SqlType = sqlType;
		}
		private static void ValidateStringValue(Column column, object sourceObject, PropertyInfo info)
		{
			if (info.PropertyType == typeof(string))
			{
				string value = info.GetValue(sourceObject, null) as string;
				if (value == null && !column.IsNullable)
					throw new DataValidationException(String.Format("The specified column is not nullable ({0}).", column.Name));
				else if (String.IsNullOrEmpty(value) && column.IsUnique)
					throw new DataValidationException(String.Format("The specified column value must be unique ({0}).", column.Name));
				else if (value != null && value.Length > column.Length)
					throw new DataValidationException(String.Format("The specified value exceeds the maximum length (column={0}:{1}, value='{2}').", column.Name, column.Length, value));
			}
		}
Beispiel #26
0
        private static Column CreateColumn(HbmId idSchema)
        {
            Column column = new Column();

            if (idSchema.length != null)
                column.Length = int.Parse(idSchema.length);

            column.IsNullable = false;
            column.IsUnique = false;
            column.CheckConstraint = string.Empty;
            column.SqlType = null;

            return column;
        }
		private void BindColumns(HbmDiscriminator discriminatorSchema, SimpleValue discriminator)
		{
			Table table = discriminator.Table;

			//COLUMN(S)
			if (discriminatorSchema.column != null)
			{
				Column col = new Column();
				col.Value = discriminator;
				BindColumn(discriminatorSchema, col);
				col.Name = mappings.NamingStrategy.ColumnName(discriminatorSchema.column);

				if (table != null)
					table.AddColumn(col);

				discriminator.AddColumn(col);
			}
			else if (discriminatorSchema.Item != null && discriminatorSchema.Item is HbmColumn)
			{
				HbmColumn theCol = (HbmColumn)discriminatorSchema.Item;
				Column col = new Column();
				col.Value = discriminator;
				BindColumn(theCol, col, false);

				col.Name = mappings.NamingStrategy.ColumnName(theCol.name);

				if (table != null)
					table.AddColumn(col);
				//table=null -> an association, fill it in later

				discriminator.AddColumn(col);

				BindIndex(theCol.index, table, col);
				BindUniqueKey(theCol.uniquekey, table, col);
			}

			if (discriminator.ColumnSpan == 0)
			{
				Column col = new Column();
				col.Value = discriminator;
				BindColumn(discriminatorSchema, col);

				col.Name = mappings.NamingStrategy.PropertyToColumnName(
					RootClass.DefaultDiscriminatorColumnName);

				discriminator.Table.AddColumn(col);
				discriminator.AddColumn(col);
			}
		}
		private void BindColumn(HbmColumn hbmColumn, Table table, bool isNullable)
		{
			var col = new Column {Value = value};
			BindColumn(hbmColumn, col, isNullable);

			if (table != null)
				table.AddColumn(col);

			value.AddColumn(col);

			//column index
			BindIndex(hbmColumn.index, table, col);
			//column group index (although it can serve as a separate column index)
			BindUniqueKey(hbmColumn.uniquekey, table, col);
		}
Beispiel #29
0
        private static Column CreateColumn(HbmColumn columnSchema, IValue type, int index)
        {
            Column column = new Column();
            column.Value = type;
            column.TypeIndex = index;

            if (columnSchema.length != null)
                column.Length = int.Parse(columnSchema.length);

            column.IsNullable = columnSchema.notnullSpecified ? columnSchema.notnull : false;
            column.IsUnique = columnSchema.uniqueSpecified && columnSchema.unique;
            column.CheckConstraint = columnSchema.check ?? string.Empty;
            column.SqlType = columnSchema.sqltype;

            return column;
        }
        protected static void BindColumn(XmlNode node, Column model, bool isNullable)
        {
            XmlAttribute lengthNode = node.Attributes["length"];
            if (lengthNode != null)
                model.Length = int.Parse(lengthNode.Value);

            XmlAttribute nullNode = node.Attributes["not-null"];
            model.IsNullable = (nullNode != null) ? !StringHelper.BooleanValue(nullNode.Value) : isNullable;

            XmlAttribute unqNode = node.Attributes["unique"];
            model.IsUnique = unqNode != null && StringHelper.BooleanValue(unqNode.Value);

            XmlAttribute chkNode = node.Attributes["check"];
            model.CheckConstraint = chkNode != null ? chkNode.Value : string.Empty;

            XmlAttribute typeNode = node.Attributes["sql-type"];
            model.SqlType = (typeNode == null) ? null : typeNode.Value;
        }
Beispiel #31
0
 public static bool HasDefaultValue(this NHibernate.Mapping.Column col)
 {
     return(!String.IsNullOrWhiteSpace(col.DefaultValue));
 }