예제 #1
0
        /// <summary>
        /// Casts a <see cref="QueryScalarValue"/> to a <see cref="QueryScalarType"/>. The cast will return the value type cast to the new type.
        /// </summary>
        /// <param name="type">The type for the cast operation.</param>
        /// <returns><see cref="QueryScalarValue"/> which is cast to the appropriate type</returns>
        public override QueryValue Cast(QueryType type)
        {
            bool             wasNullBefore = this.IsNull;
            var              typeToCastTo  = type as QueryScalarType;
            var              clrType       = ((IQueryClrType)typeToCastTo).ClrType;
            QueryScalarValue result        = null;

            if ((clrType.GetGenericArguments().Length == 1 && clrType.GetGenericArguments()[0].IsEnum()) || clrType.IsEnum())
            {
                result = typeToCastTo.CreateValue(this.Value);
            }
            else
            {
                result = this.EvaluationStrategy.Cast(this, typeToCastTo);
            }

            // if the value wasn't null before, but is null now after the cast
            if (result.IsNull && !wasNullBefore)
            {
                return(type.CreateErrorValue(new QueryError("Invalid Cast : Cannot perform Cast to the specified type")));
            }

            result = result.MaterializeValueIfEnum(typeToCastTo);

            return(result);
        }
예제 #2
0
        /// <summary>
        /// Determines if two QueryKeyStructural values are equal or not
        /// </summary>
        /// <param name="obj">Object to compare to</param>
        /// <returns>true if keys are equal false if not</returns>
        public override bool Equals(object obj)
        {
            var otherKeyValue = obj as QueryKeyStructuralValue;

            if (otherKeyValue != null)
            {
                if (this.Type.IsAssignableFrom(otherKeyValue.Type))
                {
                    bool match = true;
                    foreach (QueryProperty keyProperty in this.keyProperties)
                    {
                        QueryScalarValue currentKeySubPartValue = this.GetScalarValue(keyProperty.Name);
                        QueryScalarValue otherKeySubPartValue   = otherKeyValue.GetScalarValue(keyProperty.Name);

                        if (!currentKeySubPartValue.Type.EvaluationStrategy.AreEqual(currentKeySubPartValue, otherKeySubPartValue))
                        {
                            match = false;
                            break;
                        }
                    }

                    if (match)
                    {
                        return(true);
                    }
                }
            }

            return(false);
        }
예제 #3
0
        /// <summary>
        /// Subtracts the specified value from this value.
        /// </summary>
        /// <param name="otherValue">The other value.</param>
        /// <returns>Result of the arithmetic operation.</returns>
        public QueryScalarValue Subtract(QueryScalarValue otherValue)
        {
            var evaluationResult = this.EvaluateBinaryOperation(otherValue, QueryBinaryOperation.Subtract);

            // Enums do not exist as a concept at the store level, so whenever we evaluate something on the store side, we have to
            // simulate the materialization of the result value to an enum.
            var materializedResult = evaluationResult.MaterializeValueIfEnum(this.Type);

            return(materializedResult);
        }
예제 #4
0
        private QueryScalarValue EvaluateBinaryOperation(QueryScalarValue otherValue, QueryBinaryOperation operation)
        {
            ExceptionUtilities.CheckArgumentNotNull(otherValue, "otherValue");

            var result = this.EvaluationStrategy.Evaluate(operation, this, otherValue);

            var error = QueryError.Combine(this.EvaluationError, otherValue.EvaluationError);

            if (error != null)
            {
                result.EvaluationError = error;
            }

            return(result);
        }
예제 #5
0
        private bool ScalarValuesAreEqual(QueryScalarValue firstValueScalar, QueryScalarValue secondValueScalar)
        {
            if (!this.ScalarTypesAreEqualComparable(firstValueScalar.Type, secondValueScalar.Type))
            {
                return(false);
            }

            if (firstValueScalar.IsNull)
            {
                return(secondValueScalar.IsNull);
            }

            if (secondValueScalar.IsNull)
            {
                return(false);
            }

            return((bool)firstValueScalar.EqualTo(secondValueScalar).Value);
        }
예제 #6
0
        /// <summary>
        /// Applies the Take operation on the given collection.
        /// </summary>
        /// <param name="takeCount">How many elements to take.</param>
        /// <returns>Collection with the applied Take operation.</returns>
        public QueryCollectionValue Take(QueryScalarValue takeCount)
        {
            ExceptionUtilities.CheckArgumentNotNull(takeCount, "takeCount");

            QueryError currentError = QueryError.Combine(this.EvaluationError, takeCount.EvaluationError);

            if (currentError != null)
            {
                return((QueryCollectionValue)this.Type.CreateErrorValue(currentError));
            }

            IEnumerable <QueryValue> result = null;

            if (!this.IsNull)
            {
                result = this.Elements.Take((int)takeCount.Value).ToList();
            }

            return(new QueryCollectionValue(this.Type, this.Type.EvaluationStrategy, QueryError.GetErrorFromValues(result), result, this.IsSorted));
        }
예제 #7
0
        /// <summary>
        /// Applies the Skip operation on the given collection.
        /// </summary>
        /// <param name="skipCount">How many elements to skip.</param>
        /// <returns>Collection with the applied Skip operation.</returns>
        public QueryCollectionValue Skip(QueryScalarValue skipCount)
        {
            ExceptionUtilities.CheckArgumentNotNull(skipCount, "skipCount");

            QueryError currentError = QueryError.Combine(this.EvaluationError, skipCount.EvaluationError);

            if (currentError != null)
            {
                return((QueryCollectionValue)this.Type.CreateErrorValue(currentError));
            }

            IEnumerable <QueryValue> result = null;

            if (!this.IsNull)
            {
                // perhaps this must be changed - moved to EvaluationStrategy
                result = this.Elements.Skip((int)skipCount.Value);
            }

            return(new QueryCollectionValue(this.Type, this.Type.EvaluationStrategy, QueryError.GetErrorFromValues(result), result, this.IsSorted));
        }
예제 #8
0
        /// <summary>
        /// Transforms a value from one scalar type to another.
        /// </summary>
        /// <param name="valueToTransform">The value to transform.</param>
        /// <param name="targetType">The target type of the value.</param>
        /// <returns>The value transformed to the target type.</returns>
        public static QueryScalarValue MaterializeValueIfEnum(this QueryScalarValue valueToTransform, QueryScalarType targetType)
        {
            ExceptionUtilities.CheckArgumentNotNull(targetType, "targetType");
            var clrType = ((IQueryClrType)targetType).ClrType;

            Type   clrEnumType;
            object enumValue = null;

            if (TryExtractEnumType(clrType, out clrEnumType))
            {
                if (valueToTransform.Value != null)
                {
                    enumValue = Enum.ToObject(clrEnumType, valueToTransform.Value);
                }

                return(targetType.CreateValue(enumValue));
            }
            else
            {
                return(valueToTransform);
            }
        }
예제 #9
0
        /// <summary>
        /// Builds a table of sorted orderby primitive values, where the rows by the size of result set, the columns by the number of orderby key selectors.
        /// </summary>
        /// <param name="ordering">query ordering of order by key selectors</param>
        /// <param name="elements">Elements used to get the table values.</param>
        /// <returns>the table of sorted orderby/thenby scalar values. </returns>
        private static QueryScalarValue[][] BuildSortedSelectorsTable(QueryOrdering ordering, IEnumerable <object> elements)
        {
            int orderingSelectorsCount = ordering.Selectors.Count();
            int selectorRowCount       = elements.Count();
            var orderingSelectorsTable = new QueryScalarValue[selectorRowCount][];

            for (int i = 0; i < selectorRowCount; i++)
            {
                orderingSelectorsTable[i] = new QueryScalarValue[orderingSelectorsCount];
            }

            for (int row = 0; row < selectorRowCount; row++)
            {
                var currentRow = elements.ElementAt(row);
                for (int col = 0; col < orderingSelectorsCount; col++)
                {
                    var selector = ordering.Selectors.ElementAt(col);
                    orderingSelectorsTable[row][col] = selector(currentRow);
                }
            }

            return(orderingSelectorsTable);
        }
예제 #10
0
 /// <summary>
 /// Gets the result of bitwise AND operation on this value and specified value.
 /// </summary>
 /// <param name="otherValue">The other value.</param>
 /// <returns>Result of the arithmetic operation.</returns>
 public QueryValue BitwiseAnd(QueryScalarValue otherValue)
 {
     return(this.EvaluateBinaryOperation(otherValue, QueryBinaryOperation.BitwiseAnd));
 }
 /// <summary>
 /// Do the specified BinaryOperation for the two values and returns the result.
 /// </summary>
 /// <param name="operation">The binary operation to perform.</param>
 /// <param name="firstValue">The first value.</param>
 /// <param name="secondValue">The second value.</param>
 /// <returns>Result of the operation.</returns>
 public QueryScalarValue Evaluate(QueryBinaryOperation operation, QueryScalarValue firstValue, QueryScalarValue secondValue)
 {
     throw new TaupoNotSupportedException("Attempt to use evaluation strategy from " + typeof(QueryUnresolvedType).Name + ". Please resolve expression first.");
 }
 /// <summary>
 /// Compares the primitive value to another value and returns their relative ordering.
 /// </summary>
 /// <param name="value">First value.</param>
 /// <param name="otherValue">Second value.</param>
 /// <returns>
 /// Integer which is less than zero if this value is less than the other value, 0 if they are equal,
 /// greater than zero if this value is greater than the other value
 /// </returns>
 public int Compare(QueryScalarValue value, QueryScalarValue otherValue)
 {
     throw new TaupoNotSupportedException("Attempt to use evaluation strategy from " + typeof(QueryUnresolvedType).Name + ". Please resolve expression first.");
 }
예제 #13
0
 /// <summary>
 /// Gets a <see cref="QueryScalarValue"/> value representing the result of boolean conjunction (AND) of two values.
 /// </summary>
 /// <param name="otherValue">The second boolean value.</param>
 /// <returns>
 /// Instance of <see cref="QueryScalarValue"/> which represents the result of boolean operation.
 /// </returns>
 public QueryScalarValue AndAlso(QueryScalarValue otherValue)
 {
     return(this.EvaluateBinaryOperation(otherValue, QueryBinaryOperation.LogicalAnd));
 }
예제 #14
0
 /// <summary>
 /// Gets a <see cref="QueryScalarValue"/> value indicating whether first value is greater than or equal to the second one.
 /// </summary>
 /// <param name="otherValue">The second value.</param>
 /// <returns>
 /// Instance of <see cref="QueryScalarValue"/> which represents the result of comparison.
 /// </returns>
 public QueryScalarValue GreaterThanOrEqual(QueryScalarValue otherValue)
 {
     return(this.EvaluateBinaryOperation(otherValue, QueryBinaryOperation.GreaterThanOrEqualTo));
 }
예제 #15
0
 /// <summary>
 /// Gets a <see cref="QueryScalarValue"/> value indicating whether two values are not equal.
 /// </summary>
 /// <param name="otherValue">The query scalar value.</param>
 /// <returns>
 /// Instance of <see cref="QueryScalarValue"/> which represents the result of comparison.
 /// </returns>
 public QueryScalarValue NotEqualTo(QueryScalarValue otherValue)
 {
     return(this.EvaluateBinaryOperation(otherValue, QueryBinaryOperation.NotEqualTo));
 }
예제 #16
0
 /// <summary>
 /// Gets a <see cref="QueryScalarValue"/> value indicating whether first value is less than the second one.
 /// </summary>
 /// <param name="otherValue">The second value.</param>
 /// <returns>
 /// Instance of <see cref="QueryScalarValue"/> which represents the result of comparison.
 /// </returns>
 public QueryScalarValue LessThan(QueryScalarValue otherValue)
 {
     return(this.EvaluateBinaryOperation(otherValue, QueryBinaryOperation.LessThan));
 }
예제 #17
0
        /// <summary>
        /// Compares the primitive value to another value and returns their relative ordering.
        /// </summary>
        /// <param name="otherValue">The other scalar value.</param>
        /// <returns>
        /// Integer which is less than zero if this value is less than the other value, 0 if they are equal,
        /// greater than zero if this value is greater than the other value
        /// </returns>
        private int CompareTo(QueryScalarValue otherValue)
        {
            ExceptionUtilities.CheckArgumentNotNull(otherValue, "otherValue");

            return(this.EvaluationStrategy.Compare(this, otherValue));
        }
예제 #18
0
 /// <summary>
 /// Gets a <see cref="QueryScalarValue"/> value representing the result of boolean alternative (OR) of two values.
 /// </summary>
 /// <param name="otherValue">The second boolean value.</param>
 /// <returns>
 /// Instance of <see cref="QueryScalarValue"/> which represents the result of boolean operation.
 /// </returns>
 public QueryScalarValue OrElse(QueryScalarValue otherValue)
 {
     return(this.EvaluateBinaryOperation(otherValue, QueryBinaryOperation.LogicalOr));
 }
예제 #19
0
 /// <summary>
 /// Divides the value by the the specified other value.
 /// </summary>
 /// <param name="otherValue">The other value.</param>
 /// <returns>Result of the arithmetic operation.</returns>
 public QueryScalarValue Divide(QueryScalarValue otherValue)
 {
     return(this.EvaluateBinaryOperation(otherValue, QueryBinaryOperation.Divide));
 }
예제 #20
0
 /// <summary>
 /// Gets the result of exclusive OR (XOR) operation on this value and specified value.
 /// </summary>
 /// <param name="otherValue">The other value.</param>
 /// <returns>Result of the arithmetic operation.</returns>
 public QueryValue ExclusiveOr(QueryScalarValue otherValue)
 {
     return(this.EvaluateBinaryOperation(otherValue, QueryBinaryOperation.BitwiseExclusiveOr));
 }
 /// <summary>
 /// Casts a <see cref="QueryScalarValue"/> to a <see cref="QueryScalarType"/>. The cast will return the value type cast to the new type.
 /// </summary>
 /// <param name="source">The source for the cast operation.</param>
 /// <param name="type">The type for the cast operation.</param>
 /// <returns><see cref="QueryScalarValue"/> which is cast to the appropriate type</returns>
 public QueryScalarValue Cast(QueryScalarValue source, QueryScalarType type)
 {
     throw new TaupoNotSupportedException("Attempt to use evaluation strategy from " + typeof(QueryUnresolvedType).Name + ". Please resolve expression first.");
 }
예제 #22
0
 /// <summary>
 /// Gets the result of modulo operation of the value by the the specified other value.
 /// </summary>
 /// <param name="otherValue">The other value.</param>
 /// <returns>Result of the arithmetic operation.</returns>
 public QueryScalarValue Modulo(QueryScalarValue otherValue)
 {
     return(this.EvaluateBinaryOperation(otherValue, QueryBinaryOperation.Modulo));
 }
예제 #23
0
 /// <summary>
 /// Multiplies the value by the the specified other value.
 /// </summary>
 /// <param name="otherValue">The other value.</param>
 /// <returns>Result of the arithmetic operation.</returns>
 public QueryScalarValue Multiply(QueryScalarValue otherValue)
 {
     return(this.EvaluateBinaryOperation(otherValue, QueryBinaryOperation.Multiply));
 }