DeveelDB  20151217
complete SQL database system, primarly developed for .NET/Mono frameworks
FunctionConfigurationExtensions.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.Routines;
20 using Deveel.Data.Types;
21 
22 namespace Deveel.Data.Sql.Fluid {
23  public static class FunctionConfigurationExtensions {
24  public static IFunctionConfiguration Named(this IFunctionConfiguration configuration, string name) {
25  var routineConfig = configuration as IRoutineConfiguration;
26  if (routineConfig == null)
27  throw new InvalidOperationException();
28 
29  return configuration.Named(new ObjectName(new ObjectName(routineConfig.Context.SchemaName), name));
30  }
31 
32  public static IFunctionConfiguration WithAlias(this IFunctionConfiguration configuration, string alias) {
33  var routineConfig = configuration as IRoutineConfiguration;
34  if (routineConfig == null)
35  throw new InvalidOperationException();
36 
37  return configuration.WithAlias(new ObjectName(new ObjectName(routineConfig.Context.SchemaName), alias));
38  }
39 
41  configuration.OfType(FunctionType.Aggregate);
42  return configuration;
43  }
44 
45  public static IFunctionConfiguration WithParameter(this IFunctionConfiguration configuration, string name,
46  SqlType type) {
47  return configuration.WithParameter(config => config.Named(name).OfType(type));
48  }
49 
50  public static IFunctionConfiguration WithNumericParameter(this IFunctionConfiguration configuration, string name) {
51  return configuration.WithParameter(name, PrimitiveTypes.Numeric());
52  }
53 
54  public static IFunctionConfiguration WithStringParameter(this IFunctionConfiguration configuration, string name) {
55  return configuration.WithParameter(name, PrimitiveTypes.String());
56  }
57 
58  public static IFunctionConfiguration WithDynamicParameter(this IFunctionConfiguration configuration, string name) {
59  return configuration.WithParameter(name, Function.DynamicType);
60  }
61 
62  public static IFunctionConfiguration WithBooleanParameter(this IFunctionConfiguration configuration, string name) {
63  return configuration.WithParameter(name, PrimitiveTypes.Boolean());
64  }
65 
66  public static IFunctionConfiguration WithDateTimeParameter(this IFunctionConfiguration configuration, string name) {
67  return configuration.WithParameter(name, PrimitiveTypes.DateTime());
68  }
69 
70  public static IFunctionConfiguration WithUnoundedParameter(this IFunctionConfiguration configuration, string name,
71  SqlType type) {
72  return configuration.WithParameter(config => config.Named(name).OfType(type).Unbounded());
73  }
74 
75  public static IFunctionConfiguration ReturnsType(this IFunctionConfiguration configuration, SqlType type) {
76  return configuration.ReturnsType(context => type);
77  }
78 
79  public static IFunctionConfiguration ReturnsString(this IFunctionConfiguration configuration) {
80  return configuration.ReturnsType(PrimitiveTypes.String());
81  }
82 
83  public static IFunctionConfiguration ReturnsNumeric(this IFunctionConfiguration configuration) {
84  return configuration.ReturnsType(PrimitiveTypes.Numeric());
85  }
86 
87  public static IFunctionConfiguration ReturnsBoolean(this IFunctionConfiguration configuration) {
88  return configuration.ReturnsType(PrimitiveTypes.Boolean());
89  }
90 
91  public static IFunctionConfiguration ReturnsBinary(this IFunctionConfiguration configuration) {
92  return configuration.ReturnsType(PrimitiveTypes.Binary());
93  }
94 
96  return configuration.ReturnsType(PrimitiveTypes.DateTime());
97  }
98  }
99 }
Provides some helper functions for resolving and creating SqlType instances that are primitive to the...
static IFunctionConfiguration ReturnsBinary(this IFunctionConfiguration configuration)
static IFunctionConfiguration WithStringParameter(this IFunctionConfiguration configuration, string name)
static IFunctionConfiguration ReturnsBoolean(this IFunctionConfiguration configuration)
static IFunctionConfiguration WithAlias(this IFunctionConfiguration configuration, string alias)
static readonly SqlType DynamicType
A special SqlType that is used to mark an argument of a function as dynamic.
Definition: Function.cs:39
IFunctionConfiguration Named(ObjectName name)
IFunctionConfiguration OfType(FunctionType functionType)
A system routine that returns a value at the end of its execution.
Definition: Function.cs:31
static BooleanType Boolean()
IFunctionConfiguration WithAlias(ObjectName alias)
static IFunctionConfiguration ReturnsNumeric(this IFunctionConfiguration configuration)
static IFunctionConfiguration Named(this IFunctionConfiguration configuration, string name)
static BinaryType Binary(int maxSize)
Describes the name of an object within a database.
Definition: ObjectName.cs:44
static IFunctionConfiguration WithParameter(this IFunctionConfiguration configuration, string name, SqlType type)
static IFunctionConfiguration WithBooleanParameter(this IFunctionConfiguration configuration, string name)
static IFunctionConfiguration WithUnoundedParameter(this IFunctionConfiguration configuration, string name, SqlType type)
static IFunctionConfiguration ReturnsDateTime(this IFunctionConfiguration configuration)
static NumericType Numeric()
static IFunctionConfiguration ReturnsString(this IFunctionConfiguration configuration)
FunctionType
The different type of a function.
Definition: FunctionType.cs:25
Defines the properties of a specific SQL Type and handles the values compatible.
Definition: SqlType.cs:33
IFunctionConfiguration ReturnsType(Func< InvokeContext, SqlType > returns)
static IFunctionConfiguration WithDateTimeParameter(this IFunctionConfiguration configuration, string name)
static IFunctionConfiguration WithDynamicParameter(this IFunctionConfiguration configuration, string name)
static IFunctionConfiguration OfAggregateType(this IFunctionConfiguration configuration)
static IFunctionConfiguration WithNumericParameter(this IFunctionConfiguration configuration, string name)
IFunctionConfiguration WithParameter(Action< IFunctionParameterConfiguration > config)
static IFunctionConfiguration ReturnsType(this IFunctionConfiguration configuration, SqlType type)