示例#1
0
        public static SoqlBooleanExpression ClassRestriction(SoqlPathExpression path, SchemaInfo schema, ClassInfo classInfo)
        {
            // returns no additional filter clause for parent (master-parent) class
            if (classInfo.InheritsFromClass == null)
                return null;

            SoqlExpressionCollection literals = new SoqlExpressionCollection();

            foreach (ClassInfo subclass in classInfo.GetSubclassesForSchema(schema))
            {
                if (subclass.SubclassSelectorValue != null)
                {
                    literals.Add(new SoqlLiteralExpression(subclass.SubclassSelectorValue));
                }
            }
            if (classInfo.SubclassSelectorValue != null)
            {
                literals.Add(new SoqlLiteralExpression(classInfo.SubclassSelectorValue));
            }

            // returns false when class is abstract (no SubClassSelectorValue) and there is no subclasses
            if (literals.Count == 0)
                return new SoqlBooleanLiteralExpression(false);

            SoqlBooleanExpression restriction = new SoqlBooleanInExpression(
                new SoqlPathExpression(path, classInfo.SubclassSelectorField.Name),
                literals
            );

            return restriction;
        }
示例#2
0
        public static SoqlBooleanExpression ClassRestriction(SoqlPathExpression path, SchemaInfo schema, ClassInfo classInfo)
        {
            // returns no additional filter clause for parent (master-parent) class
            if (classInfo.InheritsFromClass == null)
            {
                return(null);
            }

            SoqlExpressionCollection literals = new SoqlExpressionCollection();

            foreach (ClassInfo subclass in classInfo.GetSubclassesForSchema(schema))
            {
                if (subclass.SubclassSelectorValue != null)
                {
                    literals.Add(new SoqlLiteralExpression(subclass.SubclassSelectorValue));
                }
            }
            if (classInfo.SubclassSelectorValue != null)
            {
                literals.Add(new SoqlLiteralExpression(classInfo.SubclassSelectorValue));
            }

            // returns false when class is abstract (no SubClassSelectorValue) and there is no subclasses
            if (literals.Count == 0)
            {
                return(new SoqlBooleanLiteralExpression(false));
            }

            SoqlBooleanExpression restriction = new SoqlBooleanInExpression(
                new SoqlPathExpression(path, classInfo.SubclassSelectorField.Name),
                literals
                );

            return(restriction);
        }
        public virtual void Visit(SoqlBooleanInExpression v)
        {
            if (v.Right.Count == 0)
            {
                Output.Write("0=1");
                return;
            }

            v.Left.Accept(this);
            Output.Write(" in ");
            if (v.Right.Count != 1 || !(v.Right[0] is SoqlQueryExpression))
            {
                Output.Write('(');
            }

            for (int i = 0; i < v.Right.Count; ++i)
            {
                if (i > 0)
                {
                    Output.Write(',');
                }
                v.Right[i].Accept(this);
            }
            if (v.Right.Count != 1 || !(v.Right[0] is SoqlQueryExpression))
            {
                Output.Write(')');
            }
        }
 void Sooda.QL.ISoqlVisitor.Visit(SoqlBooleanInExpression v)
 {
     v.Left.Accept(this);
     foreach (SoqlExpression expr in v.Right)
     {
         expr.Accept(this);
     }
 }
        public virtual void Visit(SoqlBooleanInExpression v)
        {
            if (v.Right.Count == 0)
            {
                Output.Write("0=1");
                return;
            }

            v.Left.Accept(this);
            Output.Write(" in ");
            if (v.Right.Count != 1 || !(v.Right[0] is SoqlQueryExpression))
                Output.Write('(');

            for (int i = 0; i < v.Right.Count; ++i)
            {
                if (i > 0)
                    Output.Write(',');
                v.Right[i].Accept(this);
            }
            if (v.Right.Count != 1 || !(v.Right[0] is SoqlQueryExpression))
                Output.Write(')');
        }
 void Sooda.QL.ISoqlVisitor.Visit(SoqlBooleanInExpression v)
 {
     v.Left.Accept(this);
     foreach (SoqlExpression expr in v.Right)
     {
         expr.Accept(this);
     }
 }
        SoqlQueryExpression CreateCollectionQuery(ClassInfo currentClass, string p, CollectionOnetoManyInfo col1n, SoqlExpression selectExpression, SoqlExpression needle)
        {
            SoqlBooleanExpression where = new SoqlBooleanRelationalExpression(
                new SoqlPathExpression(col1n.ForeignField2.Name),
                new SoqlPathExpression(new SoqlPathExpression(p.Split('.')), currentClass.GetFirstPrimaryKeyField().Name),
                SoqlRelationalOperator.Equal);

            if (col1n.Where != null && col1n.Where.Length > 0)
                where &= SoqlParser.ParseWhereClause(col1n.Where);

            string fromAlias = string.Empty;
            if (needle != null)
            {
                SoqlQueryExpression nq = needle as SoqlQueryExpression;
                if (nq != null
                    && nq.StartIdx == 0 && nq.PageCount == -1 && nq.SelectExpressions.Count == 0
                    && nq.From.Count == 1 && nq.From[0] == col1n.ClassName
                    && nq.Having == null && nq.GroupByExpressions.Count == 0)
                {
                    fromAlias = nq.FromAliases[0];
                    if (nq.WhereClause != null)
                        where &= nq.WhereClause;
                }
                else
                {
                    if (col1n.Class.GetPrimaryKeyFields().Length >= 2)
                        throw new NotSupportedException("Contains() with composite primary key");
                    SoqlExpressionCollection collection = new SoqlExpressionCollection();
                    collection.Add(needle);
                    where &= new SoqlBooleanInExpression(
                        new SoqlPathExpression(col1n.Class.GetFirstPrimaryKeyField().Name),
                        collection);
                }
            }

            SoqlQueryExpression query = new SoqlQueryExpression();
            query.SelectExpressions.Add(selectExpression);
            query.SelectAliases.Add("");
            query.From.Add(col1n.ClassName);
            query.FromAliases.Add(fromAlias);
            query.WhereClause = where;
            return query;
        }