Ejemplo n.º 1
0
 void IPredicate.SetPredicateGroup(PredicateGroupType predicateGroupType)
 {
     PredicateGroup.SetPredicateGroup(this, predicateGroupType);
 }
Ejemplo n.º 2
0
        // General translation method for the database (table) node.
        internal static Chainer TranslateNode(SemqContext context, DbNode predecessor, DbNode node)
        {
            var currentNode = node.Root;

            if (context == null)
            {
                context = new SemqContext(currentNode);
            }

            context.AddNode(currentNode);
            currentNode.CheckReuseAndThrow();
            context.SetIndex(currentNode);

            Chainer query = Translate.CreateQueryFromSubject(currentNode);

            if (currentNode.HasExpression)
            {
                query.ExpressionGroupType = ExpressionGroupType.BeginEnd;
                Translate.ProcessExpression(currentNode, null, ref query);
            }
            else
            {
                currentNode.SetAsUsed();
            }

            Translate.ConvertChainIntoPredicate(currentNode);

            if (((IPredicate)currentNode).HasPredicate)
            {
                Predicate prevPredicate = null;
                var       predicates    = ((IPredicate)currentNode).Predicates;
                var       pix           = 0;

                foreach (var predicate in predicates)
                {
                    SetExpressionGrouping(query, predicates, predicate, ref pix);

                    CheckHavingPredicateAndThrow(predicate, ref prevPredicate);

                    var innerNode = ((ISemantic)predicate).Subject;
                    if (innerNode != null)
                    {
                        context.AddNode(innerNode);

                        if (CheckSelfPredicate(currentNode, innerNode))
                        {
                            innerNode          = innerNode.BreakChain();
                            predicate.Sentence = (ISemantic)innerNode;
                        }
                        else if (innerNode.Equals(currentNode) && innerNode.HasExpression)
                        {
                            // let the predicate subject have the same level as its caller
                            innerNode.ChangeIndex(currentNode.Index);

                            Translate.ProcessExpression(innerNode, predicate, ref query);

                            continue;
                        }

                        // get link
                        var link = DbMapping.TryFindPredicateLink(currentNode, innerNode);

                        // process intermediate node
                        DbNode intermediate = null;
                        if (link.HasIntermediate)
                        {
                            intermediate = Translate.ProcessIntermediate(context, predicate, innerNode, link);
                        }

                        // process a simple foreign key (if possible)
                        else if (Translate.ProcessSimpleForeignKey(currentNode, innerNode, predicate, link, ref query))
                        {
                            CheckQuantifierAndThrow(currentNode, innerNode, intermediate, predicate);
                            continue;
                        }

                        CheckQuantifierAndThrow(currentNode, innerNode, intermediate, predicate);

                        Translate.ProcessPredicate(context, predicate, ref query);
                    }
                    else
                    {
                        Translate.ProcessSelfPredicate(context, currentNode, predicate, ref query);
                    }
                }
            }

            if (predecessor != null)
            {
                Translate.Finalize(predecessor, currentNode, ref query);
            }

            if (((IPredicate)currentNode).PredicateGroupLevel != 0)
            {
                PredicateGroup.ThrowInvalidPredicateGroupingException((DbNode)currentNode);
            }

            return(query);
        }