private ResultSetBuilder VisitBinary(Expression expression)
        {
            switch (expression.NodeType)
            {
            case ExpressionType.Equal:
            case ExpressionType.NotEqual:
                return(EvaluateEquals(expression));

            case ExpressionType.Or:
            case ExpressionType.And:
            case ExpressionType.OrElse:
            case ExpressionType.AndAlso:
                return(EvaluateLogical(expression));

            case ExpressionType.GreaterThan:
            case ExpressionType.GreaterThanOrEqual:
            case ExpressionType.LessThan:
            case ExpressionType.LessThanOrEqual:
                return(EvaluateCompare(expression));

            default:
                throw QueryExceptionExtensions.NotSupported(
                          "Binary operation {0} cannot be bound to Journal operation",
                          expression.NodeType);
            }
        }
Example #2
0
        private QueryRowsResult BindPostResult(IEnumerable <long> rowIds)
        {
            var hadNonTimestampOrder = false;

            foreach (var tranform in _directExpressions)
            {
                switch (tranform.Expression)
                {
                case EJournalExpressionType.Single:
                    return(new QueryRowsResult(rowIds.Single()));

                case EJournalExpressionType.First:
                    return(new QueryRowsResult(rowIds.First()));

                case EJournalExpressionType.Last:
                    return(new QueryRowsResult(rowIds.Last()));

                case EJournalExpressionType.Reverse:
                    if (hadNonTimestampOrder)
                    {
                        rowIds = rowIds.Reverse();
                    }
                    break;

                case EJournalExpressionType.LongCount:
                case EJournalExpressionType.Count:
                    return(new QueryRowsResult(rowIds, tranform.Expression));

                case EJournalExpressionType.OrderByDescending:
                case EJournalExpressionType.OrderBy:
                    if (tranform.Column.ColumnID != Metadata.TimestampColumnID)
                    {
                        hadNonTimestampOrder = true;
                        rowIds = BindOrderBy(rowIds, tranform);
                    }
                    break;

                case EJournalExpressionType.Take:
                    rowIds = rowIds.Take(tranform.Count);
                    break;

                case EJournalExpressionType.Skip:
                    rowIds = rowIds.Skip(tranform.Count);
                    break;

                case EJournalExpressionType.FirstOrDefault:
                    return(new QueryRowsResult(rowIds.FirstOrDefault()));

                case EJournalExpressionType.LastOrDefault:
                    return(new QueryRowsResult(rowIds.LastOrDefault()));

                default:
                    throw QueryExceptionExtensions.NotSupported(
                              "Expression {0} is not expected to be post operation", tranform.Expression);
                }
            }
            return(new QueryRowsResult(rowIds));
        }
Example #3
0
        public static string GetMemberName(MemberExpression memEx, Type journalType)
        {
            if (memEx.Member.DeclaringType == null || !memEx.Member.DeclaringType.IsAssignableFrom(journalType))
            {
                throw QueryExceptionExtensions.NotSupported("Expressions of type \"column\" == value "
                                                            + "where column is an NFSdb property "
                                                            + "name are supported only");
            }

            return(memEx.Member.Name);
        }
Example #4
0
        private Expression BindLatestBy(Expression ex1, LambdaExpression lambda)
        {
            var prop = lambda.Body as MemberExpression;

            if (prop != null)
            {
                return(new LatestBySymbolExpression(prop.Member.Name, Visit(ex1)));
            }
            throw QueryExceptionExtensions.NotSupported("LatestBy is only supported with property" +
                                                        " expression, but instead had '{0}'",
                                                        lambda);
        }
Example #5
0
        private TT GetConstant <TT>(Expression expression)
        {
            var c = expression as ConstantExpression;

            if (c != null)
            {
                if (c.Type == typeof(TT))
                {
                    return((TT)c.Value);
                }
            }
            throw QueryExceptionExtensions.NotSupported("Expected constant expression of type {0} but got {1}",
                                                        typeof(T).Name, expression);
        }
Example #6
0
        private Expression BindPostResult(Type resultType, ReadOnlyCollection <Expression> arguments, EJournalExpressionType expressionType)
        {
            if (resultType != typeof(T))
            {
                throw QueryExceptionExtensions.NotSupported("{0} operation canonly be bound to JournalQueryable of {1} but used on {2}",
                                                            expressionType, typeof(T).Name, resultType);
            }
            var source = arguments[0];

            if (arguments.Count > 1)
            {
                var lambda = GetLambda(arguments[1]);
                return(new PostResultExpression(new FilterExpression(Visit(lambda.Body), Visit(source)), expressionType));
            }
            return(new PostResultExpression(Visit(source), expressionType));
        }
Example #7
0
        private Expression BindContains(Expression source, Expression match)
        {
            var constSource = source as ConstantExpression;

            if (constSource != null && !IsQuery(constSource))
            {
                var stringEnum = constSource.Value as IEnumerable;
                if (stringEnum != null)
                {
                    match = Visit(match);
                    return(new SymbolContainsExpression(match, Expression.Constant(stringEnum)));
                }
            }

            throw QueryExceptionExtensions.NotSupported(
                      "List.Contains, Array.Contains allowed only. Unable to execute Contains on {0}.",
                      constSource);
        }
Example #8
0
 private Expression BindUnion(Type type, Expression expression1, Expression expression2)
 {
     if (typeof(IQueryable <T>).IsAssignableFrom(type))
     {
         var mc1 = expression1 as MethodCallExpression;
         var mc2 = expression2 as MethodCallExpression;
         if (mc1 != null && mc2 != null)
         {
             if (IsQuery(mc1.Arguments[0]) && IsQuery(mc2.Arguments[0]))
             {
                 return(new UnionExpression(Visit(mc1), Visit(mc2)));
             }
         }
     }
     throw QueryExceptionExtensions.NotSupported("Union of 2 journal queriables supported. " +
                                                 "Attempted to join '{0}' with '{1}' instead.",
                                                 expression1, expression2);
 }