DeveelDB  20151217
complete SQL database system, primarly developed for .NET/Mono frameworks
Function.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.Sql;
21 using Deveel.Data.Sql.Objects;
22 using Deveel.Data.Types;
23 
24 namespace Deveel.Data.Routines {
31  public abstract class Function : IFunction {
39  public static readonly SqlType DynamicType = new DynamicSqlType();
40 
41  protected Function(FunctionInfo functionInfo) {
42  if (functionInfo == null)
43  throw new ArgumentNullException("functionInfo");
44 
45  FunctionInfo = functionInfo;
46  }
47 
48  protected Function(ObjectName name, RoutineParameter[] parameters, FunctionType functionType)
49  : this(name, parameters, null, functionType) {
50  }
51 
52  protected Function(ObjectName name, RoutineParameter[] parameters, SqlType returnType)
53  : this(name, parameters, returnType, FunctionType.Static) {
54  }
55 
56  protected Function(ObjectName name, RoutineParameter[] parameters, SqlType returnType, FunctionType functionType)
57  : this(new FunctionInfo(name, parameters, returnType, functionType)) {
58  }
59 
61  get { return FunctionInfo.FunctionType; }
62  }
63 
64  public FunctionInfo FunctionInfo { get; private set; }
65 
66  public ObjectName FunctionName {
67  get { return FunctionInfo.RoutineName; }
68  }
69 
71  get { return FunctionInfo; }
72  }
73 
75  get { return RoutineType.Function; }
76  }
77 
79  get { return DbObjectType.Routine; }
80  }
81 
83  get { return FunctionName; }
84  }
85 
95  public abstract InvokeResult Execute(InvokeContext context);
96 
104  public SqlType ReturnType() {
105  if (FunctionInfo.ReturnType != null)
106  return FunctionInfo.ReturnType;
107 
108  return ReturnType(null);
109  }
110 
121  public virtual SqlType ReturnType(InvokeContext context) {
122  return FunctionInfo.ReturnType;
123  }
124 
125  #region DynamicType
126 
128  public DynamicSqlType()
129  : base("DYNAMIC", SqlTypeCode.Object) {
130  }
131 
132  public override bool IsComparable(SqlType type) {
133  return true;
134  }
135 
136  public override int Compare(ISqlObject x, ISqlObject y) {
137  throw new NotSupportedException();
138  }
139  }
140 
141  #endregion
142  }
143 }
Defines a routine that is a function, that means it returns a value after its execution.
Definition: IFunction.cs:26
A system routine that returns a value at the end of its execution.
Definition: Function.cs:31
Represents a database object, such as a table, a trigger, a type or a column.
Definition: IDbObject.cs:24
ObjectName FullName
Gets the fully qualified name of the object used to resolve it uniquely within the database...
Definition: IDbObject.cs:30
Function(ObjectName name, RoutineParameter[] parameters, FunctionType functionType)
Definition: Function.cs:48
Describes the name of an object within a database.
Definition: ObjectName.cs:44
The contract to define a program routine that can interact with database objects. ...
Definition: IRoutine.cs:26
A type that represents a static function.
override int Compare(ISqlObject x, ISqlObject y)
Definition: Function.cs:136
Defines the contract for a valid SQL Object
Definition: ISqlObject.cs:23
RoutineType
The type of routine program.
Definition: RoutineType.cs:23
Function(FunctionInfo functionInfo)
Definition: Function.cs:41
ObjectName RoutineName
Gets the name of the routine that uniquely identifies it in a system context.
Definition: RoutineInfo.cs:65
Function(ObjectName name, RoutineParameter[] parameters, SqlType returnType)
Definition: Function.cs:52
override bool IsComparable(SqlType type)
Verifies if a given SqlType is comparable to this data-type.
Definition: Function.cs:132
Represents the result of the execution of a routine.
Definition: InvokeResult.cs:25
FunctionType FunctionType
Gets the kind of function.
Definition: FunctionInfo.cs:96
FunctionType
The different type of a function.
Definition: FunctionType.cs:25
DbObjectType ObjectType
Gets the type of database object that the implementation is for
Definition: IDbObject.cs:35
Defines the properties of a specific SQL Type and handles the values compatible.
Definition: SqlType.cs:33
virtual SqlType ReturnType(InvokeContext context)
Resolves the function return type against the given context.
Definition: Function.cs:121
The function signature information that are used to resolve a function within a context.
Definition: FunctionInfo.cs:30
SqlTypeCode
Enumerates the codes of all SQL types handled by the system.
Definition: SqlTypeCode.cs:23
Defines the metadata for a routine that are used to resolve within a context.
Definition: RoutineInfo.cs:28
SqlType ReturnType()
Gets the function static return type
Definition: Function.cs:104
RoutineType Type
Gets the type of routine that will be executed.
Definition: IRoutine.cs:31
Function(ObjectName name, RoutineParameter[] parameters, SqlType returnType, FunctionType functionType)
Definition: Function.cs:56
DbObjectType
The kind of objects that can be handled by a database system and its managers
Definition: DbObjectType.cs:27