DeveelDB  20151217
complete SQL database system, primarly developed for .NET/Mono frameworks
RoutineResolverExtensions.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.Sql;
22 
23 namespace Deveel.Data.Routines {
27  public static class RoutineResolverExtensions {
40  public static bool IsAggregateFunction(this IRoutineResolver resolver, Invoke request, IQuery query) {
41  var routine = resolver.ResolveRoutine(request, query);
42 
43  var function = routine as IFunction;
44  if (function == null)
45  return false;
46 
47  return function.FunctionType == FunctionType.Aggregate;
48  }
49 
50  public static IFunction ResolveFunction(this FunctionProvider resolver, string name) {
51  return ResolveFunction(resolver, null, name);
52  }
53 
54  public static IFunction ResolveFunction(this FunctionProvider resolver, IQuery context, string name) {
55  return ResolveFunction(resolver, context, name, new SqlExpression[0]);
56  }
57 
58  public static IFunction ResolveFunction(this FunctionProvider resolver, string name, params SqlExpression[] args) {
59  return ResolveFunction(resolver, null, name, args);
60  }
61 
62  public static IFunction ResolveFunction(this FunctionProvider resolver, string name, params DataObject[] args) {
63  return ResolveFunction(resolver, null, name, args);
64  }
65 
66  public static IFunction ResolveFunction(this FunctionProvider resolver, IQuery context, string name, params DataObject[] args) {
67  var exps = new SqlExpression[0];
68  if (args != null && args.Length > 0) {
69  exps = new SqlExpression[args.Length];
70  for (int i = 0; i < args.Length; i++) {
71  exps[i] = SqlExpression.Constant(args[i]);
72  }
73  }
74 
75  return resolver.ResolveFunction(context, name, exps);
76  }
77 
78  public static IFunction ResolveFunction(this FunctionProvider resolver, IQuery query, string name, SqlExpression[] args) {
79  var funName = new ObjectName(new ObjectName(resolver.SchemaName), name);
80  var routine = ((IRoutineResolver) resolver).ResolveRoutine(new Invoke(funName, args), query);
81  if (!(routine is IFunction))
82  throw new InvalidOperationException();
83 
84  return routine as IFunction;
85  }
86  }
87 }
The system uses instances of this interface to resolve routines given a user invocation.
Defines a routine that is a function, that means it returns a value after its execution.
Definition: IFunction.cs:26
static IFunction ResolveFunction(this FunctionProvider resolver, IQuery context, string name)
Describes the name of an object within a database.
Definition: ObjectName.cs:44
static IFunction ResolveFunction(this FunctionProvider resolver, string name, params DataObject[] args)
FunctionType FunctionType
Gets the type of function.
Definition: IFunction.cs:30
Extension methods to any IRoutineResolver
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
FunctionType
The different type of a function.
Definition: FunctionType.cs:25
static IFunction ResolveFunction(this FunctionProvider resolver, IQuery context, string name, params DataObject[] args)
static IFunction ResolveFunction(this FunctionProvider resolver, IQuery query, string name, SqlExpression[] args)
IFunction ResolveFunction(Invoke invoke, IQuery query)
static IFunction ResolveFunction(this FunctionProvider resolver, string name, params SqlExpression[] args)
IRoutine ResolveRoutine(Invoke request, IQuery query)
Resolves a routine that matches the given invocation within the context provided. ...
static IFunction ResolveFunction(this FunctionProvider resolver, string name)
Defines the base class for instances that represent SQL expression tree nodes.
static SqlConstantExpression Constant(object value)
static bool IsAggregateFunction(this IRoutineResolver resolver, Invoke request, IQuery query)
Checks if a function matched against the given request represents an aggregate function.