コード例 #1
0
		public bool Equals(NamedParameterSpecification other)
		{
			if (ReferenceEquals(null, other))
			{
				return false;
			}
			if (ReferenceEquals(this, other))
			{
				return true;
			}
			return Equals(other.name, name);
		}
コード例 #2
0
 public bool Equals(NamedParameterSpecification other)
 {
     if (ReferenceEquals(null, other))
     {
         return(false);
     }
     if (ReferenceEquals(this, other))
     {
         return(true);
     }
     return(Equals(other.name, name));
 }
コード例 #3
0
        public ParameterTranslationsImpl(IEnumerable <IParameterSpecification> parameterSpecifications)
        {
            List <ParameterInfo> ordinalParameterList = new List <ParameterInfo>();
            NullableDictionary <string, NamedParamTempHolder> namedParameterMap = new NullableDictionary <string, NamedParamTempHolder>();

            int i = 0;

            foreach (IParameterSpecification spec in parameterSpecifications)
            {
                if (spec is PositionalParameterSpecification)
                {
                    PositionalParameterSpecification ordinalSpec = ( PositionalParameterSpecification )spec;
                    ordinalParameterList.Add(new ParameterInfo(i, ordinalSpec.ExpectedType));
                }
                else if (spec is NamedParameterSpecification)
                {
                    NamedParameterSpecification namedSpec   = ( NamedParameterSpecification )spec;
                    NamedParamTempHolder        paramHolder = namedParameterMap[namedSpec.Name];
                    if (paramHolder == null)
                    {
                        paramHolder      = new NamedParamTempHolder();
                        paramHolder.name = namedSpec.Name;
                        paramHolder.type = namedSpec.ExpectedType;
                        namedParameterMap.Add(namedSpec.Name, paramHolder);
                    }
                    paramHolder.positions.Add(i);
                }
                else
                {
                    // don't care about other param types here, just those explicitly user-defined...

                    // Steve Strong Note:  The original Java does not do this decrement; it increments i for
                    // every parameter type.  However, within the Loader.GetParameterTypes() method, this introduces
                    // nulls into the paramTypeList array, which in turn causes Loader.ConvertITypesToSqlTypes() to crash
                    // with a null dereference.  An alternative fix is to change the Loader to handle the null.  I'm
                    // not sure which fix is the most appropriate.
                    // Legacy.FumTest.CompositeIDQuery() shows the bug if you remove the decrement below...
                    i--;
                }

                i++;
            }

            _ordinalParameters = ordinalParameterList.ToArray();
            _namedParameters   = new Dictionary <string, ParameterInfo>();

            foreach (NamedParamTempHolder holder in namedParameterMap.Values)
            {
                _namedParameters.Add(holder.name, new ParameterInfo(ArrayHelper.ToIntArray(holder.positions), holder.type));
            }
        }
コード例 #4
0
		public SqlString GetNamedParameter(string name)
		{
			var parameterSpecification = new NamedParameterSpecification(1, 0, name);
			var parameter = Parameter.Placeholder;
			parameter.BackTrack = parameterSpecification.GetIdsForBackTrack(Factory).First();

			AddNamedParameter(name);
			collectedParameters.Add(parameterSpecification);
			return new SqlString(parameter);
		}
コード例 #5
0
		IASTNode GenerateNamedParameter(IASTNode delimiterNode, IASTNode nameNode)
		{
			string name = nameNode.Text;
			TrackNamedParameterPositions(name);

			// create the node initially with the param name so that it shows
			// appropriately in the "original text" attribute
			ParameterNode parameter = (ParameterNode) adaptor.Create(NAMED_PARAM, name);
			parameter.Text = "?";

			NamedParameterSpecification paramSpec = new NamedParameterSpecification(
					delimiterNode.Line,
					delimiterNode.CharPositionInLine,
					name
			);

			parameter.HqlParameterSpecification = paramSpec;
			_parameters.Add(paramSpec);
			return parameter;
		}
コード例 #6
0
			public void NamedParameter(string name, int position)
			{
				var paramSpec = new NamedParameterSpecification(1, position, name);
				var parameter = Parameter.Placeholder;
				parameter.BackTrack = paramSpec.GetIdsForBackTrack(factory).First();
				parametersSpecifications.Add(paramSpec);
				result.Add(parameter);
			}
コード例 #7
0
		protected SqlString GetSubSelectWithLimits(SqlString subquery, ICollection<IParameterSpecification> parameterSpecs, RowSelection processedRowSelection, IDictionary<string, TypedValue> parameters)
		{
			ISessionFactoryImplementor sessionFactory = Factory;
			Dialect.Dialect dialect = sessionFactory.Dialect;

			RowSelection selection = processedRowSelection;
			bool useLimit = UseLimit(selection, dialect);
			if (useLimit)
			{
				bool hasFirstRow = GetFirstRow(selection) > 0;
				bool useOffset = hasFirstRow && dialect.SupportsLimitOffset;
				int max = GetMaxOrLimit(dialect, selection);
				int? skip = useOffset ? (int?)dialect.GetOffsetValue(GetFirstRow(selection)) : null;
				int? take = max != int.MaxValue ? (int?)max : null;

				Parameter skipSqlParameter = null;
				Parameter takeSqlParameter = null;
				if (skip.HasValue)
				{
					string skipParameterName = "nhsubselectskip";
					var skipParameter = new NamedParameterSpecification(1, 0, skipParameterName) { ExpectedType = NHibernateUtil.Int32 };
					skipSqlParameter = Parameter.Placeholder;
					skipSqlParameter.BackTrack = skipParameter.GetIdsForBackTrack(sessionFactory).First();
					parameters.Add(skipParameterName, new TypedValue(skipParameter.ExpectedType, skip.Value, EntityMode.Poco));
					parameterSpecs.Add(skipParameter);
				}
				if (take.HasValue)
				{
					string takeParameterName = "nhsubselecttake";
					var takeParameter = new NamedParameterSpecification(1, 0, takeParameterName) { ExpectedType = NHibernateUtil.Int32 };
					takeSqlParameter = Parameter.Placeholder;
					takeSqlParameter.BackTrack = takeParameter.GetIdsForBackTrack(sessionFactory).First();
					parameters.Add(takeParameterName, new TypedValue(takeParameter.ExpectedType, take.Value, EntityMode.Poco));
					parameterSpecs.Add(takeParameter);
				}

				// The dialect can move the given parameters where he need, what it can't do is generates new parameters loosing the BackTrack.
				SqlString result;
				if (TryGetLimitString(dialect, subquery, skip, take, skipSqlParameter, takeSqlParameter, out result)) return result;
			}
			return subquery;
		}