Encapsulates the
Inheritance: IDisposable
コード例 #1
0
ファイル: RoutineExtensions.cs プロジェクト: deveel/deveeldb
        public static InvokeResult Execute(this IRoutine routine, InvokeArgument[] args, IRequest request, IVariableResolver resolver, IGroupResolver group)
        {
            var invoke = new Invoke(routine.ObjectInfo.FullName, args);

            var executeContext = new InvokeContext(invoke, routine, resolver, group, request);
            return routine.Execute(executeContext);
        }
コード例 #2
0
        public override SqlType ReturnType(InvokeContext context)
        {
            if (method == null)
                method = DiscoverMethod();

            return base.ReturnType(context);
        }
コード例 #3
0
ファイル: Routine.cs プロジェクト: deveel/deveeldb
        public virtual InvokeResult Execute(InvokeContext context)
        {
            var args = context.Arguments;
            InvokeResult invokeResult = null;

            try {
                context.Request.Context.OnEvent(new RoutineEvent(Name, args, RoutineInfo.RoutineType));

                var block = context.Request.CreateBlock();
                PrepareBlock(context.Arguments, block);

                var result = ExecuteRoutine(block);

                if (RoutineInfo.RoutineType == RoutineType.Function) {
                    invokeResult = context.Result(result);
                } else {
                    invokeResult = context.Result();
                }

                var output = CollectOutput(block);

                if (output.Count > 0) {
                    foreach (var pair in output) {
                        context.SetOutput(pair.Key, pair.Value);
                    }
                }

                return invokeResult;
            } catch (Exception) {
                throw;
            } finally {
                context.Request.Context.OnEvent(new RoutineEvent(Name, args, RoutineInfo.RoutineType, invokeResult));
            }
        }
コード例 #4
0
        /// <summary>
        /// Executes the function given the cintext provided.
        /// </summary>
        /// <param name="function">The function to execute.</param>
        /// <param name="request">The invocation information that was used to resolve 
        /// the function.</param>
        /// <param name="group"></param>
        /// <param name="resolver"></param>
        /// <param name="query"></param>
        /// <returns></returns>
        public static DataObject Execute(this IFunction function, Invoke request, IGroupResolver group,
			IVariableResolver resolver,
			IRequest query)
        {
            var execContext = new InvokeContext(request, function, resolver, group, query);
            var result = function.Execute(execContext);
            return result.ReturnValue;
        }
コード例 #5
0
ファイル: ExternalFunction.cs プロジェクト: deveel/deveeldb
        public override SqlType ReturnType(InvokeContext context)
        {
            var returnType = FunctionInfo.ReturnType;
            if (returnType == null) {
                var methodReturnType = ExternalRef.GetMethod().ReturnType;
                returnType = PrimitiveTypes.FromType(methodReturnType);
            }

            return returnType;
        }
コード例 #6
0
        public static InvokeResult Execute(this IRoutine routine, SqlExpression[] args, IQuery query, IVariableResolver resolver, IGroupResolver group)
        {
            var request = new Invoke(routine.FullName, args);

            if (query != null &&
                !query.UserCanExecuteFunction(request))
                throw new InvalidOperationException();

            var executeContext = new InvokeContext(request, routine, resolver, group, query);
            return routine.Execute(executeContext);
        }
コード例 #7
0
ファイル: ExternalFunction.cs プロジェクト: deveel/deveeldb
        public override InvokeResult Execute(InvokeContext context)
        {
            var args = context.EvaluatedArguments;

            var method = ExternalRef.GetMethod();

            var methodArgs = ConvertArguments(method, context.Request, args);
            var result = method.Invoke(null, methodArgs);

            return context.Result(ConvertValue(result, ReturnType()));
        }
コード例 #8
0
ファイル: InvokeResult.cs プロジェクト: deveel/deveeldb
 private InvokeResult(InvokeContext context, object returnValue, bool hasReturn)
 {
     Context = context;
     if (returnValue is ITable) {
         var table = (ITable) returnValue;
         ReturnTable = table;
         HasReturnTable = hasReturn;
     } else if (returnValue is Field) {
         var field = (Field) returnValue;
         ReturnValue = field;
         HasReturnValue = hasReturn;
     }
 }
コード例 #9
0
        public override InvokeResult Execute(InvokeContext context)
        {
            if (method == null)
                method = DiscoverMethod();

            if (method == null)
                throw new InvalidOperationException();

            var args = context.EvaluatedArguments;

            try {
                var methodArgs = ConvertArguments(method, args);
                var result = method.Invoke(null, methodArgs);

                return  context.Result(ConvertValue(result, ReturnType()));
            } catch (Exception) {
                throw;
            }
        }
コード例 #10
0
        public override InvokeResult Execute(InvokeContext context)
        {
            if (context == null)
                throw new ArgumentNullException("context");

            var group = context.GroupResolver;

            if (group == null)
                throw new Exception(String.Format("'{0}' can only be used as an aggregate function.", FunctionName));

            DataObject result = null;
            // All aggregates functions return 'null' if group size is 0
            int size = group.Count;
            if (size == 0) {
                // Return a NULL of the return type
                return context.Result(DataObject.Null(ReturnType(context)));
            }

            DataObject val;
            ObjectName v = context.Arguments[0].AsReferenceName();
            // If the aggregate parameter is a simple variable, then use optimal
            // routine,
            if (v != null) {
                for (int i = 0; i < size; ++i) {
                    val = group.Resolve(v, i);
                    result = Evaluate(result, val, context.Request, group);
                }
            } else {
                // Otherwise we must resolve the expression for each entry in group,
                // This allows for expressions such as 'sum(quantity * price)' to
                // work for a group.
                var exp = context.Arguments[0];
                for (int i = 0; i < size; ++i) {
                    val = exp.EvaluateToConstant(context.Request, group.GetVariableResolver(i));
                    result = Evaluate(result, val, context.Request, group);
                }
            }

            // Post method.
            result = PostEvaluate(result, context.Request, group);

            return context.Result(result);
        }
コード例 #11
0
ファイル: PlSqlFunction.cs プロジェクト: deveel/deveeldb
        public override InvokeResult Execute(InvokeContext context)
        {
            using (var execContext = new ExecutionContext(context.Request, Body)) {
                Body.Execute(execContext);

                if (!execContext.HasResult)
                    throw new InvalidOperationException("The execution of the function has no returns");

                var result = execContext.Result;
                var returnType = ReturnType(context);

                if (returnType is TabularType)
                    return context.Result(result);

                if (result.RowCount == 0)
                    throw new InvalidOperationException("The execution of the function has no returns");

                var retunValue = result.GetValue(0, 0);
                return context.Result(retunValue);
            }
        }
コード例 #12
0
ファイル: TypeManager.cs プロジェクト: deveel/deveeldb
 SqlType IFunction.ReturnType(InvokeContext context)
 {
     return Type;
 }
コード例 #13
0
ファイル: TypeManager.cs プロジェクト: deveel/deveeldb
            public InvokeResult Execute(InvokeContext context)
            {
                // Rewrite the function to the object initialization

                var sourceArgs = context.Arguments == null ? new InvokeArgument[1] : context.Arguments;
                var args = new InvokeArgument[sourceArgs.Length + 1];
                Array.Copy(sourceArgs, 0, args, 1, sourceArgs.Length);
                args[0] = new InvokeArgument(SqlExpression.Constant(FunctionInfo.RoutineName.FullName));

                var initFunction = context.Request.Access().ResolveObjectName(DbObjectType.Routine, ObjectName.Parse("SYSTEM.NEW_OBJECT"));
                if (initFunction == null)
                    throw new InvalidOperationException("The object initialization function was not defined.");

                var invoke = new Invoke(initFunction, args);
                return invoke.Execute(context.Request, context.VariableResolver, context.GroupResolver);
            }
コード例 #14
0
ファイル: FunctionExtensions.cs プロジェクト: deveel/deveeldb
 public static SqlType ReturnType(this IFunction function, Invoke request, IRequest query, IVariableResolver resolver)
 {
     var execContext = new InvokeContext(request, function, resolver, null, query);
     return function.ReturnType(execContext);
 }
コード例 #15
0
ファイル: Invoke.cs プロジェクト: ArsenShnurkov/deveeldb
 public InvokeResult Execute(IRequest query, IVariableResolver resolver, IGroupResolver group)
 {
     var routine = ResolveRoutine(query);
     var executeContext = new InvokeContext(this, routine, resolver, group, query);
     return routine.Execute(executeContext);
 }
コード例 #16
0
 private static InvokeResult Simple(InvokeContext context, Func<DataObject[], DataObject> func)
 {
     var args = context.EvaluatedArguments;
     var funcResult = func(args);
     return context.Result(funcResult);
 }
コード例 #17
0
ファイル: InvokeResult.cs プロジェクト: deveel/deveeldb
 internal InvokeResult(InvokeContext context, Field returnValue)
     : this(context, returnValue, true)
 {
 }
コード例 #18
0
            public override SqlType ReturnType(InvokeContext context)
            {
                if (returnType == null)
                    return FunctionInfo.ReturnType;

                return returnType(context);
            }
コード例 #19
0
 internal InvokeResult(InvokeContext context, DataObject returnValue)
     : this(context, returnValue, true)
 {
 }
コード例 #20
0
        internal static InvokeResult Iif(InvokeContext context)
        {
            var result = DataObject.Null();

            var evalContext = new EvaluateContext(context.Request, context.VariableResolver, context.GroupResolver);

            var condition = context.Arguments[0].EvaluateToConstant(evalContext);
            if (condition.Type is BooleanType) {
                if (condition.Equals(DataObject.BooleanTrue)) {
                    result = context.Arguments[1].EvaluateToConstant(evalContext);
                } else if (condition.Equals(DataObject.BooleanFalse)) {
                    result = context.Arguments[2].EvaluateToConstant(evalContext);
                }
            }

            return context.Result(result);
        }
コード例 #21
0
ファイル: InvokeResult.cs プロジェクト: deveel/deveeldb
 internal InvokeResult(InvokeContext context, ITable table)
     : this(context, table, true)
 {
 }
コード例 #22
0
 public override InvokeResult Execute(InvokeContext context)
 {
     throw new NotImplementedException();
 }
コード例 #23
0
 private InvokeResult(InvokeContext context, DataObject returnValue, bool hasReturn)
 {
     Context = context;
     ReturnValue = returnValue;
     HasReturnValue = hasReturn;
 }
コード例 #24
0
ファイル: InvokeResult.cs プロジェクト: deveel/deveeldb
 internal InvokeResult(InvokeContext context)
     : this(context, Field.Null(), false)
 {
 }
コード例 #25
0
 public override InvokeResult Execute(InvokeContext context)
 {
     return functionBody(context);
 }
コード例 #26
0
 internal InvokeResult(InvokeContext context)
     : this(context, DataObject.Null(), false)
 {
 }