Ejemplo n.º 1
0
        public override EntitySet Load(Evaluant.NLinq.NLinqQuery query, string[] attributes, string orderby, int first, int max)
        {
            if (first <= 0)
                throw new ArgumentException("first must be greater than 0");

            if (max < 0)
                throw new ArgumentException("max must be none negative");

            XPathTransformer transformer = new XPathTransformer(Factory.Model);
            string xpath = transformer.ConvertToXPath(query);
            EntitySet result = LoadWithXPath(xpath);

            LoadAttribute(result, attributes);

            // sort
            if (orderby != null)
                result.Sort(orderby.Split(','));

            // page
            EntitySet pageResult = new EntitySet();
            Utils.TruncateList(result, pageResult, first, max);

            return pageResult;
        }
Ejemplo n.º 2
0
        public override object LoadScalar(NLinqQuery query)
        {
            XPathTransformer transformer = new XPathTransformer(false, this.Model);
            string xpath = transformer.Visit(query);

            object result = null;
            result = _Document.CreateNavigator().Evaluate(xpath);

            // Ensure the result in an Int32 in cas of a count()
            if (query.Expression.Operands[0] is OPath.Expressions.Function)
                result = Convert.ToInt32(result);

            return result;
        }
Ejemplo n.º 3
0
		public override void Visit(Call call) 
		{
            _ExprLevel.Push((int)_ExprLevel.Peek());

			if(call.Name == "id")
			{
				XPathTransformer transformer = new XPathTransformer(false, _Model, _ExprLevel);
				call.Operands[0].Accept(transformer);

				string strQuote = transformer.Result.IndexOf("'") > 0 ? "\"" : "'"; // if id contains ' limiter is " else '
				_Result = String.Concat(" @Id = concat( @Type, ':', ", strQuote, transformer.Result, strQuote, ")");

				for(int i=1; i<call.Operands.Count; i++)
				{
					call.Operands[i].Accept(transformer);
					strQuote = transformer.Result.IndexOf("'") > 0 ? "\"" : "'"; // if id contains ' limiter is " else '
					_Result += String.Concat(" or @Id = concat( @Type, ':', ", strQuote, transformer.Result, strQuote, ")");
				}

			}

            _ExprLevel.Pop();
		} 
Ejemplo n.º 4
0
        public override object LoadScalar(string opath)
        {
            XPathTransformer transformer = new XPathTransformer(false, this.Model);
            string query = string.Format("eval({0})", opath);
            string xpath = transformer.ConvertToScalarXPath(query);

            object result = null;
            result = _Document.CreateNavigator().Evaluate(xpath);

            // Ensure the result in an Int32 in cas of a count()
            if (opath.Trim().StartsWith("count"))
                result = Convert.ToInt32(result);

            return result;
        }
Ejemplo n.º 5
0
		public override void Visit(UnaryOperator unaryop) 
		{
            _ExprLevel.Push((int)_ExprLevel.Peek());

			XPathTransformer transformer = new XPathTransformer(true, _Model, _ExprLevel);
			unaryop.Operand.Accept(transformer);

			_Result = UnaryOperatorToString(unaryop.Type) + "(" + transformer.Result + " )";

            _ExprLevel.Pop();
		}
Ejemplo n.º 6
0
		public override void Visit(BinaryOperator binaryop) 
		{
            _ExprLevel.Push((int)_ExprLevel.Peek());

			XPathTransformer transformer = new XPathTransformer(true, _Model, _ExprLevel);
			
			binaryop.LeftOperand.Accept(transformer);

			string leftValue = String.Empty, rightValue = String.Empty;

			if(binaryop.LeftOperand is Value)
			{
				if(binaryop.RightOperand is Function)
					leftValue = transformer.Result;
				else
					leftValue = FormatValue(transformer.Result);
			}
			else
				leftValue = transformer.Result;

			binaryop.RightOperand.Accept(transformer);

			if(binaryop.RightOperand is Value)
			{
				if(binaryop.LeftOperand is Function)
					rightValue = transformer.Result;
				else
					rightValue = FormatValue(transformer.Result);
			}
			else
				rightValue = transformer.Result;


			_Result = String.Format("({0})", BinaryOperatorToString(binaryop.Type, leftValue, rightValue));

            _ExprLevel.Pop();
		}
Ejemplo n.º 7
0
		public override void Visit(Function function) 
		{
            _ExprLevel.Push((int)_ExprLevel.Peek());

			XPathTransformer transformer;

			switch(function.Type)
			{
				case FunctionEnum.Average : 
                    transformer = new XPathTransformer(true, _Model, _ExprLevel);
                    function.Path.Accept(transformer);
                    _Result = String.Concat(" sum( ", transformer.Result, " ) div count( ", transformer.Result ," )");
                    break;
				
				case FunctionEnum.Count :
				    transformer = new XPathTransformer(false, _Model, _ExprLevel);
					function.Path.Accept(transformer);
					_Result = String.Concat(" count( ", transformer.Result, " )");
					break;

				case FunctionEnum.Exists :
                    transformer = new XPathTransformer(false, _Model, _ExprLevel);
					function.Path.Accept(transformer);
					_Result = String.Concat(" count( ", transformer.Result, " ) > 0");
					break;

				case FunctionEnum.IsNull :
                    transformer = new XPathTransformer(true, _Model, _ExprLevel);
					function.Path.Accept(transformer);
					_Result = String.Concat(" count( ", transformer.Result, " ) = 0");
					break;

				case FunctionEnum.Max : 
					/// TODO: Needs exslt extensions
                    throw new NotImplementedException("The max() function is not implemented for this engine");

				case FunctionEnum.Min :
                    /// TODO: Needs exslt extensions					
                    throw new NotImplementedException("The min() function is not implemented for this engine");

				case FunctionEnum.Sum : 
                    transformer = new XPathTransformer(true, _Model, _ExprLevel);
					function.Path.Accept(transformer);
					_Result = String.Concat(" sum( ", transformer.Result, " )");
					break;

			}

            _ExprLevel.Pop();
		}
Ejemplo n.º 8
0
        /// <summary>
        /// Converts the Expression to a xpath expression.
        /// </summary>
        /// <param name="path">Expression.</param>
        /// <param name="firstIsType">True if the first identifer is a type.</param>
        /// <param name="lastIsAttribute">True if the latest identifer is an attribute.</param>
        /// <param name="isInConstraint"><see langword="true"/> if [is in constraint]; otherwise, <see langword="false"/>.</param>
        /// <returns></returns>
        private string ConvertToXPath(Call call, bool firstIsType, bool lastIsAttribute, bool isInConstraint)
        {
            // eval(count(...) + 3 + 2 * sum(...))

            string xpath = String.Empty;

            if (call.Name == "eval")
            {
                // evaluate a scalar expression
		        XPathTransformer transformer = new XPathTransformer(true, _Model, _ExprLevel);
		        call.Operands[0].Accept(transformer);
                xpath = transformer.Result;
            }

            return xpath;
        }
Ejemplo n.º 9
0
		/// <summary>
		/// Converts a Constraint to the corresponding xpath.
		/// </summary>
		/// <param name="constraint">Constraint.</param>
		/// <param name="attributeAtEnd"></param>
		/// <returns></returns>
		private string ConvertToXPath(Constraint constraint, bool attributeAtEnd)
		{
            _ExprLevel.Push((int)_ExprLevel.Peek());

			// We must do as if the first identifier is not a Type but a reference or attribute's name.
			// The first case is taken into account by the same method's Query overload
			
			XPathTransformer transformer = new XPathTransformer(attributeAtEnd, _Model, _ExprLevel);
			constraint.Accept(transformer);

            _ExprLevel.Pop();
			return transformer.Result;
		}