Ejemplo n.º 1
0
        /// <summary>
        /// Generates an Array of Parameters for the columns that make up the IType
        /// </summary>
        /// <param name="factory">The SessionFactory to use to get the DbTypes.</param>
        /// <param name="tableAlias">The Alias for the Table.</param>
        /// <param name="columnNames">The names of the Columns that compose the IType</param>
        /// <param name="type">The IType to turn into Parameters</param>
        /// <returns>An Array of <see cref="Parameter"/> objects</returns>
        public static Parameter[] GenerateParameters(IMapping factory, string tableAlias, string[] columnNames, IType type)
        {
            SqlType[] sqlTypes = type.SqlTypes(factory);

            Parameter[] parameters = new Parameter[sqlTypes.Length];

            for (int i = 0; i < sqlTypes.Length; i++)
            {
                if (sqlTypes[i].LengthDefined)
                {
                    ParameterLength param = new ParameterLength(columnNames[i], tableAlias, sqlTypes[i]);
                    parameters[i] = param;
                }
                else if (sqlTypes[i].PrecisionDefined)
                {
                    ParameterPrecisionScale param = new ParameterPrecisionScale(columnNames[i], tableAlias, sqlTypes[i]);
                    parameters[i] = param;
                }
                else
                {
                    parameters[i] = new Parameter(columnNames[i], tableAlias, sqlTypes[i]);
                }
            }

            return(parameters);
        }
        /// <summary>
        /// Determines wether this instance and the specified object
        /// are the same Type and have the same values.
        /// </summary>
        /// <param name="obj">An object to compare to this instance.</param>
        /// <returns>
        /// <c>true</c> if the object is a <see cref="ParameterPrecisionScale" /> and has the
        /// same values.
        /// </returns>
        public override bool Equals(object obj)
        {
            ParameterPrecisionScale rhs = null;

            // Step1: Perform an equals test
            if (obj == this)
            {
                return(true);
            }

            // Step	2: Instance of check - don't need to worry about subclasses
            // getting in here because this class is sealed.
            rhs = obj as ParameterPrecisionScale;
            if (rhs == null)
            {
                return(false);
            }

            //Step 3: Check each important field

            // isTypeSensitive is false because we want to check the values
            // of the fields - we know the rhs is a subclass of Parameter.
            if (this.Equals(rhs, false) == false)
            {
                return(false);
            }

            return(this.Precision == rhs.Precision &&
                   this.Scale == rhs.Scale);
        }
		public void EqualsPrecisionDiffType()
		{
			Parameter x = new Parameter( "name", "alias", new SqlTypes.DecimalSqlType( 20, 4 ) );
			ParameterPrecisionScale y = new ParameterPrecisionScale( "name", "alias", new SqlTypes.DecimalSqlType( 20, 4 ) );
			
			// even though these contain the exact same values - they should not be 
			// equal because they are different types
			Assert.IsFalse( x.Equals(y) );
			Assert.IsFalse( y.Equals(x) );
		}
		/// <summary>
		/// Generates an Array of Parameters for the columns that make up the IType
		/// </summary>
		/// <param name="factory">The SessionFactory to use to get the DbTypes.</param>
		/// <param name="tableAlias">The Alias for the Table.</param>
		/// <param name="columnNames">The names of the Columns that compose the IType</param>
		/// <param name="type">The IType to turn into Parameters</param>
		/// <returns>An Array of <see cref="Parameter"/> objects</returns>
		public static Parameter[ ] GenerateParameters( IMapping factory, string tableAlias, string[ ] columnNames, IType type )
		{
			SqlType[ ] sqlTypes = type.SqlTypes( factory );

			Parameter[ ] parameters = new Parameter[sqlTypes.Length];

			for( int i = 0; i < sqlTypes.Length; i++ )
			{
				if( sqlTypes[ i ].LengthDefined )
				{
					ParameterLength param = new ParameterLength( columnNames[i], tableAlias, sqlTypes[i] );
					parameters[ i ] = param;
				}
				else if( sqlTypes[ i ].PrecisionDefined )
				{
					ParameterPrecisionScale param = new ParameterPrecisionScale( columnNames[i], tableAlias, sqlTypes[i] );
					parameters[ i ] = param;
				}
				else
				{
					parameters[ i ] = new Parameter( columnNames[i], tableAlias, sqlTypes[i] );
				}
			}

			return parameters;
		}
		public void EqualsPrecisionType()
		{
			ParameterPrecisionScale x = new ParameterPrecisionScale( "name", "alias", new SqlTypes.DecimalSqlType( 20, 4 ) );
			ParameterPrecisionScale y = new ParameterPrecisionScale( "name", "alias", new SqlTypes.DecimalSqlType( 20, 4 ) );
			ParameterPrecisionScale z = new ParameterPrecisionScale( "name", "alias", new SqlTypes.DecimalSqlType( 20, 4 ) );
			
			Assert.IsTrue( x.Equals(y) );
			Assert.IsTrue( y.Equals(x) );
			Assert.IsTrue( y.Equals(z) );
			Assert.IsTrue( x.Equals(z) );
			Assert.IsFalse( x.Equals(null) );

			y = new ParameterPrecisionScale( "name2", "alias", new SqlTypes.DecimalSqlType( 20, 4 ) );

			Assert.IsFalse( x.Equals(y) );
			Assert.IsFalse( y.Equals(x) );
		}
		public void TestParameterPrecisionClone()
		{
			ParameterPrecisionScale original = new ParameterPrecisionScale( "originalName", new SqlTypes.DecimalSqlType(19, 5) );
			ParameterPrecisionScale cloned = null;

			cloned = (ParameterPrecisionScale)original.Clone();

			Assert.IsTrue((original==cloned)==false, "Not the same object by ==");
			Assert.AreEqual(original.SqlType.DbType, cloned.SqlType.DbType, "Same DbType");
			Assert.AreEqual(original.Name, cloned.Name, "Same Name");
			Assert.AreEqual(original.Precision, cloned.Precision, "Same Precision");
			Assert.AreEqual(original.Scale, cloned.Scale, "Same Scale");
			
		}