示例#1
0
        // ctor: Maximized
        internal Predicate(
            DbNode subject,
            MaximizationType maximizationType,
            bool sign,
            LogicalOperator logicalOperator,
            OrderingArgument maximizedExpression,
            long top = 1)
        {
            DbMapping.CheckNullAndThrow(subject);

            if (maximizedExpression == null)
            {
                throw new QueryTalkException("Predicate.ctor", QueryTalkExceptionType.ArgumentNull,
                                             "maximized expression = null", Text.Method.HavingMaxMin);
            }

            // check expression DbColumn type
            if (maximizedExpression.ArgType == typeof(DbColumn))
            {
                var column = (DbColumn)maximizedExpression.Original;
                if (column.Parent != null && column.Parent.Prev != null)
                {
                    throw new QueryTalkException("Predicate.ctor", QueryTalkExceptionType.InvalidHavingPredicateArgument,
                                                 String.Format("node = {0}", column.Parent), Text.Method.HavingMaxMin);
                }

                // column parent must be the same as the subject
                if (!column.Parent.Equals(subject))
                {
                    throw new QueryTalkException("Predicate.ctor", QueryTalkExceptionType.InvalidHavingPredicateArgument,
                                                 String.Format("node = {0}{1}   subject = {2}", column.Parent, Environment.NewLine, subject),
                                                 Text.Method.HavingMaxMin);
                }
            }

            Subject                = subject;
            Sign                   = sign;
            LogicalOperator        = logicalOperator;
            PredicateType          = Wall.PredicateType.Maximized;
            MaximizedType          = maximizationType;
            MaximizedExpression    = maximizedExpression;
            MaximizedTop           = top;
            IsFinalizeable         = true;
            subject.IsFinalizeable = true;
        }
示例#2
0
        // ctor: Existential, Quantified, TopQuantified
        internal Predicate(
            DbNode subject,
            PredicateType predicateType,
            bool sign,
            LogicalOperator logicalOperator,
            ISemantic sentence,
            Quantifier quantifier = null,
            bool isDefault        = false // default predicate is made by broken chain
            )
        {
            DbMapping.CheckNullAndThrow(subject);

            if (sentence == null)
            {
                throw new QueryTalkException("Predicate.ctor", QueryTalkExceptionType.ArgumentNull,
                                             "predicate argument = null", "predicate method");
            }

            if (((IPredicate)subject).HasOr)
            {
                logicalOperator             = Wall.LogicalOperator.Or;
                ((IPredicate)subject).HasOr = false;    // reset the flag - !
            }
            if (((IPredicate)subject).HasNot)
            {
                sign = false;
                ((IPredicate)subject).HasNot = false;   // reset the flag - !
            }

            Subject         = subject;
            Sign            = sign;
            LogicalOperator = logicalOperator;
            Sentence        = sentence;
            IsFinalizeable  = true;
            IsDefault       = isDefault;

            // set quantifier type:
            PredicateType = predicateType;
            if (quantifier != null && quantifier.QuantifierType == QuantifierType.Most)
            {
                if (sentence.Subject == null)
                {
                    string predicateExpression = Text.NotAvailable;
                    if (sentence is Expression)
                    {
                        predicateExpression = ((Expression)sentence).Build(BuildContext.CreateAdHoc(), new BuildArgs(null));
                    }

                    if (sentence is Expression)
                    {
                        Translate.ThrowInvalidQuantifierException(this, null, sentence, null, predicateExpression);
                    }

                    throw new QueryTalkException("Predicate.ctor", QueryTalkExceptionType.InvalidPredicate,
                                                 String.Format("predicate = {0}", predicateExpression), "predicate method");
                }

                PredicateType = Wall.PredicateType.TopQuantified;
                sentence.Subject.IsFinalizeable = false;
                IsFinalizeable = false;
            }

            SetPredicateGroup(((IPredicate)subject).PredicateGroup);
            ((IPredicate)subject).ResetPredicateGroup();
            Quantifier = quantifier;

            // pass parent
            sentence.RootSubject = Subject;
        }