Ejemplo n.º 1
0
        /// <summary>
        /// Resolves all <see cref="ISqlParameter"/> found so far and merges/overrides as appropriate to accomodate identical side by side parameters and
        /// global overriding ones etc.
        /// </summary>
        /// <returns></returns>
        public IEnumerable <ISqlParameter> GetFinalResolvedParametersList()
        {
            State = ParameterManagerLifecycleState.Finalized;

            var toReturn = new List <ParameterFoundAtLevel>();

            foreach (KeyValuePair <ParameterLevel, List <ISqlParameter> > kvp in ParametersFoundSoFarInQueryGeneration)
            {
                foreach (ISqlParameter sqlParameter in kvp.Value)
                {
                    AddParameterToCollection(new ParameterFoundAtLevel(sqlParameter, kvp.Key), toReturn);
                }
            }


            //There can be empty parameters during resolution but only if it finds an overriding one further up the hierarchy
            var emptyParameter = toReturn.FirstOrDefault(t => string.IsNullOrWhiteSpace(t.Parameter.Value));

            if (emptyParameter != null)
            {
                string exceptionMessage = "No Value defined for Parameter " + emptyParameter.Parameter.ParameterName;
                var    asConcreteObject = emptyParameter.Parameter as IMapsDirectlyToDatabaseTable;

                //problem was in a freaky parameter e.g. a constant one that doesn't come from database (rare to happen I would expect)
                if (asConcreteObject == null)
                {
                    throw new QueryBuildingException(exceptionMessage);
                }

                //problem was from a user one from their Catalogue Database, tell them the ProblemObject aswell
                throw new QueryBuildingException(exceptionMessage, new[] { asConcreteObject });
            }

            return(toReturn.Select(t => t.Parameter));
        }
Ejemplo n.º 2
0
 /// <summary>
 /// Removes all non global parameters from the <see cref="ParameterManager"/> and returns the <see cref="State"/> to allow new parameters
 /// </summary>
 public void ClearNonGlobals()
 {
     ParametersFoundSoFarInQueryGeneration[ParameterLevel.CompositeQueryLevel].Clear();
     ParametersFoundSoFarInQueryGeneration[ParameterLevel.QueryLevel].Clear();
     ParametersFoundSoFarInQueryGeneration[ParameterLevel.TableInfo].Clear();
     State = ParameterManagerLifecycleState.ParameterDiscovery;
     _memoryRepository.Clear();
 }
Ejemplo n.º 3
0
        private void AddParametersFor(ICollectSqlParameters collector, List <ISqlParameter> toAddTo)
        {
            if (State == ParameterManagerLifecycleState.Finalized)
            {
                throw new InvalidOperationException("Cannot add new " + collector.GetType().Name + " level parameters because state is " + State);
            }

            State = ParameterManagerLifecycleState.ParameterDiscovery;

            toAddTo.AddRange(collector.GetAllParameters());
        }
Ejemplo n.º 4
0
        /// <summary>
        /// Creates a new <see cref="ParameterManager"/> with the specified global parameters
        /// </summary>
        /// <param name="globals"></param>
        public ParameterManager(ISqlParameter[] globals = null)
        {
            State = ParameterManagerLifecycleState.AllowingGlobals;

            ParametersFoundSoFarInQueryGeneration.Add(ParameterLevel.TableInfo, new List <ISqlParameter>());
            ParametersFoundSoFarInQueryGeneration.Add(ParameterLevel.QueryLevel, new List <ISqlParameter>());
            ParametersFoundSoFarInQueryGeneration.Add(ParameterLevel.CompositeQueryLevel, new List <ISqlParameter>());
            ParametersFoundSoFarInQueryGeneration.Add(ParameterLevel.Global, new List <ISqlParameter>());

            if (globals != null)
            {
                ParametersFoundSoFarInQueryGeneration[ParameterLevel.Global].AddRange(globals);
            }
        }