DeveelDB  20151217
complete SQL database system, primarly developed for .NET/Mono frameworks
RoutineExtensions.cs
Go to the documentation of this file.
1 //
2 // Copyright 2010-2015 Deveel
3 //
4 // Licensed under the Apache License, Version 2.0 (the "License");
5 // you may not use this file except in compliance with the License.
6 // You may obtain a copy of the License at
7 //
8 // http://www.apache.org/licenses/LICENSE-2.0
9 //
10 // Unless required by applicable law or agreed to in writing, software
11 // distributed under the License is distributed on an "AS IS" BASIS,
12 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 // See the License for the specific language governing permissions and
14 // limitations under the License.
15 //
16 
17 using System;
18 
19 using Deveel.Data;
20 using Deveel.Data.Security;
21 using Deveel.Data.Sql;
23 
24 namespace Deveel.Data.Routines {
25  public static class RoutineExtensions {
26  public static InvokeResult Execute(this IRoutine routine) {
27  return Execute(routine, new SqlExpression[0]);
28  }
29 
30  public static InvokeResult Execute(this IRoutine routine, SqlExpression[] args) {
31  return Execute(routine, args, null);
32  }
33 
34  public static InvokeResult Execute(this IRoutine routine, SqlExpression[] args, IQuery context) {
35  return Execute(routine, args, context, null);
36  }
37 
38  public static InvokeResult Execute(this IRoutine routine, SqlExpression[] args, IQuery query, IVariableResolver resolver) {
39  return Execute(routine, args, query, resolver, null);
40  }
41 
42  public static InvokeResult Execute(this IRoutine routine, IQuery query) {
43  return Execute(routine, query, null);
44  }
45 
46  public static InvokeResult Execute(this IRoutine routine, IQuery query, IVariableResolver resolver) {
47  return Execute(routine, query, resolver, null);
48  }
49 
50  public static InvokeResult Execute(this IRoutine routine, IQuery query, IVariableResolver resolver, IGroupResolver group) {
51  return Execute(routine, new SqlExpression[0], query, resolver, group);
52  }
53 
54  public static InvokeResult Execute(this IRoutine routine, SqlExpression[] args, IQuery query, IVariableResolver resolver, IGroupResolver group) {
55  var request = new Invoke(routine.FullName, args);
56 
57  if (query != null &&
58  !query.UserCanExecuteFunction(request))
59  throw new InvalidOperationException();
60 
61  var executeContext = new InvokeContext(request, routine, resolver, group, query);
62  return routine.Execute(executeContext);
63  }
64 
65  public static InvokeResult Execute(this IRoutine routine, DataObject[] args) {
66  var exps = new SqlExpression[0];
67  if (args != null && args.Length > 0) {
68  exps = new SqlExpression[args.Length];
69 
70  for (int i = 0; i < args.Length; i++) {
71  exps[i] = SqlExpression.Constant(args[i]);
72  }
73  }
74 
75  return routine.Execute(exps);
76  }
77  }
78 }
InvokeResult Execute(InvokeContext context)
ObjectName FullName
Gets the fully qualified name of the object used to resolve it uniquely within the database...
Definition: IDbObject.cs:30
The contract to define a program routine that can interact with database objects. ...
Definition: IRoutine.cs:26
static InvokeResult Execute(this IRoutine routine, SqlExpression[] args, IQuery context)
static InvokeResult Execute(this IRoutine routine, IQuery query, IVariableResolver resolver, IGroupResolver group)
static InvokeResult Execute(this IRoutine routine, SqlExpression[] args, IQuery query, IVariableResolver resolver)
static InvokeResult Execute(this IRoutine routine, IQuery query, IVariableResolver resolver)
Defines a contract used by grouping functions to find information about the current group being evalu...
Represents the result of the execution of a routine.
Definition: InvokeResult.cs:25
Represents a dynamic object that encapsulates a defined SqlType and a compatible constant ISqlObject ...
Definition: DataObject.cs:35
The information about the invocation of a routine, including the full name and arguments (as SqlExpre...
Definition: Invoke.cs:30
static InvokeResult Execute(this IRoutine routine, SqlExpression[] args)
An interface to resolve a variable name to a constant object.
static InvokeResult Execute(this IRoutine routine, IQuery query)
static InvokeResult Execute(this IRoutine routine, SqlExpression[] args, IQuery query, IVariableResolver resolver, IGroupResolver group)
static InvokeResult Execute(this IRoutine routine)
Defines the base class for instances that represent SQL expression tree nodes.
static SqlConstantExpression Constant(object value)
static InvokeResult Execute(this IRoutine routine, DataObject[] args)