A CQL Selector (element in select clause)
Наследование: System.Linq.Expressions.Expression
Пример #1
0
        /// <summary>
        /// replaces selectors (column references) expressions, with an expression that reads the corresponding
        /// value from DataReader
        /// </summary>
        /// <param name="selector"></param>
        /// <returns></returns>
        public override Expression VisitSelector(SelectorExpression selector)
        {
            Expression value;

            //check if it is a token (of which we don't know it's type)
            if (selector.Type == typeof(CqlToken))
                return Expression.New(TokenConstructor,
                                      Expression.MakeIndex(_reader, Indexer, new[] { Expression.Constant(selector.Ordinal) }));

            //normal case
            value = Expression.Call(_reader, "GetFieldValue", new [] { selector.Type }, Expression.Constant(selector.Ordinal));

            
            //check for null values in case of a Nullable type
            if (selector.Type.IsGenericType && selector.Type.GetGenericTypeDefinition() == typeof(Nullable<>))
            {
                value = Expression.Condition(
                    Expression.Call(_reader, "IsDBNull", null, Expression.Constant(selector.Ordinal)),
                    Expression.Constant(null, selector.Type),
                    Expression.Convert(value, selector.Type)
                    );
            }

            return value;
        }
Пример #2
0
        public OrderingExpression(SelectorExpression selector, CqlExpressionType orderType)
        {
            if (selector == null)
                throw new ArgumentNullException("selector");

            if (orderType != CqlExpressionType.OrderAscending && orderType != CqlExpressionType.OrderDescending)
                throw new ArgumentException("ExpressionType must be OrderAscending or OrderDescending", "orderType");

            _selector = selector;
            _order = orderType;
        }
Пример #3
0
        /// <summary>
        ///   Initializes a new instance of the <see cref="RelationExpression" /> class.
        /// </summary>
        /// <param name="selector"> The selector. </param>
        /// <param name="relation"> The relation. </param>
        /// <param name="term"> The term. </param>
        /// <exception cref="System.ArgumentNullException">selector
        ///   or
        ///   term</exception>
        public RelationExpression(SelectorExpression selector, CqlExpressionType relation, TermExpression term)
        {
            if (selector == null) throw new ArgumentNullException("selector");

            if (term == null)
                throw new ArgumentNullException("term");

            _selector = selector;
            _relation = relation;
            _term = term;
        }
Пример #4
0
        protected override Expression VisitChildren(ExpressionVisitor visitor)
        {
            if (_selectors != null)
            {
                bool changed = false;
                int count = _selectors.Count;
                var selectors = new SelectorExpression[count];
                for (int i = 0; i < count; i++)
                {
                    selectors[i] = (SelectorExpression) visitor.Visit(_selectors[i]);
                    changed |= selectors[i] != _selectors[i];
                }

                if (changed)
                {
                    return new SelectClauseExpression(selectors, _distinct);
                }
            }

            return this;
        }
Пример #5
0
 public override Expression VisitSelector(SelectorExpression selector)
 {
     _selectors.Add(selector);
     return selector;
 }
Пример #6
0
        public override Expression VisitSelector(SelectorExpression selector)
        {
            base.VisitSelector(selector);

            string value;

            switch ((CqlExpressionType)selector.NodeType)
            {
                case CqlExpressionType.IdentifierSelector:
                    value = "\"" + selector.Identifier.Replace("\"", "\"\"") + "\"";
                    break;
                case CqlExpressionType.FunctionSelector:
                    var builder = new StringBuilder();
                    builder.Append(selector.Function.Name.ToLower());
                    builder.Append("(");
                    var argsAsString = selector.Arguments.Select(arg => _translations[arg]);
                    builder.Append(string.Join(",", argsAsString));
                    builder.Append(")");
                    value = builder.ToString();
                    break;
                default:
                    throw new CqlLinqException("Unexpected Selector type encountered");
            }

            _translations[selector] = value;

            return selector;
        }
Пример #7
0
 public virtual Expression VisitSelector(SelectorExpression selector)
 {
     return base.VisitExtension(selector);
 }
Пример #8
0
        /// <summary>
        /// replaces selectors (column references) expressions, with an expression that reads the corresponding
        /// value from DataReader
        /// </summary>
        /// <param name="selector"></param>
        /// <returns></returns>
        public override Expression VisitSelector(SelectorExpression selector)
        {
            Expression value;

            //check if it is a token (of which we don't know it's type)
            if (selector.Type == typeof(CqlToken))
                return Expression.New(TokenConstructor,
                                      Expression.MakeIndex(_reader, Indexer, new[] { Expression.Constant(selector.Ordinal) }));

            switch (selector.Type.ToCqlType())
            {
                case CqlType.Set:
                    value = Expression.Call(_reader,
                                            "GetSet",
                                            new[] { TypeSystem.GetElementType(selector.Type) },
                                            Expression.Constant(selector.Ordinal));
                    break;

                case CqlType.List:
                    value = Expression.Call(_reader,
                                            "GetList",
                                            selector.Type.GetGenericArguments(),
                                            Expression.Constant(selector.Ordinal));
                    break;

                case CqlType.Map:
                    value = Expression.Call(_reader,
                                            "GetDictionary",
                                            selector.Type.GetGenericArguments(),
                                            Expression.Constant(selector.Ordinal));
                    break;

                case CqlType.Varchar:
                case CqlType.Text:
                case CqlType.Ascii:
                    value = Expression.Call(_reader,
                                            "GetString",
                                            null,
                                            Expression.Constant(selector.Ordinal));
                    break;

                case CqlType.Int:
                    value = Expression.Call(_reader,
                                            "GetInt32",
                                            null,
                                            Expression.Constant(selector.Ordinal));
                    break;

                case CqlType.Counter:
                case CqlType.Bigint:
                    value = Expression.Call(_reader,
                                            "GetInt64",
                                            null,
                                            Expression.Constant(selector.Ordinal));
                    break;

                case CqlType.Varint:
                    value = Expression.Call(_reader,
                                            "GetBigInteger",
                                            null,
                                            Expression.Constant(selector.Ordinal));
                    break;

                case CqlType.Blob:
                    value = Expression.Call(_reader,
                                            "GetBytes",
                                            null,
                                            Expression.Constant(selector.Ordinal));
                    break;

                case CqlType.Boolean:
                    value = Expression.Call(_reader,
                                            "GetBoolean",
                                            null,
                                            Expression.Constant(selector.Ordinal));
                    break;

                case CqlType.Decimal:
                    value = Expression.Call(_reader,
                                            "GetDecimal",
                                            null,
                                            Expression.Constant(selector.Ordinal));
                    break;

                case CqlType.Double:
                    value = Expression.Call(_reader,
                                            "GetDouble",
                                            null,
                                            Expression.Constant(selector.Ordinal));
                    break;

                case CqlType.Float:
                    value = Expression.Call(_reader,
                                           "GetFloat",
                                           null,
                                           Expression.Constant(selector.Ordinal));
                    break;

                case CqlType.Inet:
                    value = Expression.Call(_reader,
                                           "GetIPAddress",
                                           null,
                                           Expression.Constant(selector.Ordinal));
                    break;

                case CqlType.Timestamp:
                    value = Expression.Call(_reader,
                                           "GetDateTime",
                                           null,
                                           Expression.Constant(selector.Ordinal));
                    break;

                case CqlType.Uuid:
                case CqlType.Timeuuid:
                    value = Expression.Call(_reader,
                                           "GetGuid",
                                           null,
                                           Expression.Constant(selector.Ordinal));
                    break;

                default:
                    value = Expression.Convert(
                        Expression.MakeIndex(_reader, Indexer, new[] { Expression.Constant(selector.Ordinal) }),
                        selector.Type);
                    break;

            }

            //check for null values in case of a Nullable type
            if (selector.Type.IsGenericType && selector.Type.GetGenericTypeDefinition() == typeof(Nullable<>))
            {
                value = Expression.Condition(
                    Expression.Call(_reader, "IsDBNull", null, Expression.Constant(selector.Ordinal)),
                    Expression.Constant(null, selector.Type),
                    Expression.Convert(value, selector.Type)
                    );
            }

            return value;
        }