Exemplo n.º 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);
        }
Exemplo n.º 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 SoqlFunctionCallExpression(string functionName, SoqlExpression p1, SoqlExpression p2)
 {
     this.FunctionName = functionName;
     this.Parameters   = new SoqlExpressionCollection();
     this.Parameters.Add(p1);
     this.Parameters.Add(p2);
 }
 public SoqlFunctionCallExpression(string functionName, SoqlExpression p1, SoqlExpression p2)
 {
     this.FunctionName = functionName;
     this.Parameters = new SoqlExpressionCollection();
     this.Parameters.Add(p1);
     this.Parameters.Add(p2);
 }
Exemplo n.º 5
0
        private SoqlFunctionCallExpression ParseFunctionCall(string functionName)
        {
            SoqlExpressionCollection par = new SoqlExpressionCollection();

            while (!tokenizer.IsEOF() && tokenizer.TokenType != SoqlTokenType.RightParen)
            {
                par.Add(ParseExpression());
                if (tokenizer.TokenType != SoqlTokenType.Comma)
                    break;
                tokenizer.GetNextToken();
            }
            tokenizer.Expect(SoqlTokenType.RightParen);

            return new SoqlFunctionCallExpression(functionName, par);
        }
Exemplo n.º 6
0
        public static SoqlBooleanExpression CollectionFor(CollectionManyToManyInfo coll, SoodaObject parent)
        {
            SoqlPathExpression  needle   = new SoqlPathExpression(coll.GetItemClass().GetFirstPrimaryKeyField().Name);
            RelationInfo        relation = coll.GetRelationInfo();
            SoqlQueryExpression query    = new SoqlQueryExpression();

            query.SelectExpressions.Add(new SoqlPathExpression(relation.Table.Fields[coll.MasterField].Name));
            query.SelectAliases.Add(string.Empty);
            query.From.Add(relation.Name);
            query.FromAliases.Add(string.Empty);
            query.WhereClause = FieldEquals(relation.Table.Fields[1 - coll.MasterField].Name, parent);
            SoqlExpressionCollection haystack = new SoqlExpressionCollection();

            haystack.Add(query);
            return(new SoqlBooleanInExpression(needle, haystack));
        }
Exemplo n.º 7
0
        private SoqlFunctionCallExpression ParseFunctionCall(string functionName)
        {
            SoqlExpressionCollection par = new SoqlExpressionCollection();

            while (!tokenizer.IsEOF() && tokenizer.TokenType != SoqlTokenType.RightParen)
            {
                par.Add(ParseExpression());
                if (tokenizer.TokenType != SoqlTokenType.Comma)
                {
                    break;
                }
                tokenizer.GetNextToken();
            }
            tokenizer.Expect(SoqlTokenType.RightParen);

            return(new SoqlFunctionCallExpression(functionName, par));
        }
Exemplo n.º 8
0
        private SoqlExpression ParseInExpression(SoqlExpression lhs)
        {
            SoqlExpressionCollection rhs = new SoqlExpressionCollection();

            tokenizer.ExpectKeyword("in");
            tokenizer.Expect(SoqlTokenType.LeftParen);
            if (!tokenizer.IsToken(SoqlTokenType.RightParen))
            {
                rhs.Add(ParseAdditiveExpression());
                while (tokenizer.TokenType == SoqlTokenType.Comma)
                {
                    tokenizer.Expect(SoqlTokenType.Comma);
                    rhs.Add(ParseAdditiveExpression());
                }
            }
            tokenizer.Expect(SoqlTokenType.RightParen);
            return(new SoqlBooleanInExpression(lhs, rhs));
        }
        public SoqlBooleanInExpression(SoqlExpression lhs, IEnumerable rhs)
        {
            this.Left = lhs;
            this.Right = new SoqlExpressionCollection();
            foreach (object expr in rhs)
            {
                if (expr is SoqlExpression)
                {
                    this.Right.Add((SoqlExpression)expr);
                    continue;
                }

                if (expr is SoodaObject)
                {
                    this.Right.Add(new SoqlLiteralExpression(((SoodaObject)expr).GetPrimaryKeyValue()));
                    continue;
                }

                this.Right.Add(new SoqlLiteralExpression(expr));
            }
        }
        public SoqlBooleanInExpression(SoqlExpression lhs, IEnumerable rhs)
        {
            this.Left  = lhs;
            this.Right = new SoqlExpressionCollection();
            foreach (object expr in rhs)
            {
                if (expr is SoqlExpression)
                {
                    this.Right.Add((SoqlExpression)expr);
                    continue;
                }

                if (expr is SoodaObject)
                {
                    this.Right.Add(new SoqlLiteralExpression(((SoodaObject)expr).GetPrimaryKeyValue()));
                    continue;
                }

                this.Right.Add(new SoqlLiteralExpression(expr));
            }
        }
 public SoqlFunctionCallExpression(string functionName, SoqlExpressionCollection parameters)
 {
     this.FunctionName = functionName;
     this.Parameters   = parameters;
 }
 public SoqlFunctionCallExpression(string functionName, SoqlExpressionCollection parameters)
 {
     this.FunctionName = functionName;
     this.Parameters = parameters;
 }
 public SoqlBooleanInExpression(SoqlExpression lhs, SoqlExpressionCollection rhs)
 {
     this.Left  = lhs;
     this.Right = rhs;
 }
 public SoqlBooleanInExpression(SoqlExpression lhs, SoqlExpressionCollection rhs)
 {
     this.Left = lhs;
     this.Right = rhs;
 }
Exemplo n.º 15
0
        private SoqlExpression ParseInExpression(SoqlExpression lhs)
        {
            SoqlExpressionCollection rhs = new SoqlExpressionCollection();

            tokenizer.ExpectKeyword("in");
            tokenizer.Expect(SoqlTokenType.LeftParen);
            if (!tokenizer.IsToken(SoqlTokenType.RightParen))
            {
                rhs.Add(ParseAdditiveExpression());
                while (tokenizer.TokenType == SoqlTokenType.Comma)
                {
                    tokenizer.Expect(SoqlTokenType.Comma);
                    rhs.Add(ParseAdditiveExpression());
                }
            }
            tokenizer.Expect(SoqlTokenType.RightParen);
            return new SoqlBooleanInExpression(lhs, rhs);
        }
Exemplo n.º 16
0
 public static SoqlBooleanExpression CollectionFor(CollectionManyToManyInfo coll, SoodaObject parent)
 {
     SoqlPathExpression needle = new SoqlPathExpression(coll.GetItemClass().GetFirstPrimaryKeyField().Name);
     RelationInfo relation = coll.GetRelationInfo();
     SoqlQueryExpression query = new SoqlQueryExpression();
     query.SelectExpressions.Add(new SoqlPathExpression(relation.Table.Fields[coll.MasterField].Name));
     query.SelectAliases.Add(string.Empty);
     query.From.Add(relation.Name);
     query.FromAliases.Add(string.Empty);
     query.WhereClause = FieldEquals(relation.Table.Fields[1 - coll.MasterField].Name, parent);
     SoqlExpressionCollection haystack = new SoqlExpressionCollection();
     haystack.Add(query);
     return new SoqlBooleanInExpression(needle, haystack);
 }
Exemplo n.º 17
0
        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;
        }