18 using System.Collections.Generic;
28 namespace Deveel.Data.Routines {
31 private const string ExternalProcedureType =
"ext_procedure";
33 private const string ExtrernalFunctionType =
"ext_function";
38 if (transaction == null)
39 throw new ArgumentNullException(
"transaction");
41 this.transaction = transaction;
49 using (var context = session.CreateQuery()) {
52 t = t.ExhaustiveSelect(context,
58 throw new Exception(
"Assert failed: multiple procedure names for " + routineName);
83 transaction.CreateTable(tableInfo);
93 transaction.CreateTable(tableInfo);
95 var fkCol =
new[] {
"routine_schema",
"routine_name"};
96 var refCol =
new[] {
"schema",
"name"};
101 onDelete, onUpdate,
"ROUTINE_PARAMS_FK");
106 throw new ArgumentNullException(
"objInfo");
109 if (routineInfo == null)
110 throw new ArgumentException();
112 CreateRoutine(routineInfo);
116 throw new NotImplementedException();
120 return RoutineExists(objName);
124 return RoutineExists(objName);
133 return GetRoutine(objName);
143 if (routineInfo == null)
144 throw new ArgumentException();
146 return AlterRoutine(routineInfo);
150 return DropRoutine(objName);
164 throw new NotImplementedException();
172 #region RoutinesTableContainer
190 return info.AsReadOnly();
194 var tableName = GetTableName(offset);
195 if (tableName == null)
196 throw new ArgumentOutOfRangeException(
"offset");
198 return CreateTableInfo(tableName.ParentName, tableName.Name);
202 var table = GetTable(offset);
204 throw new ArgumentOutOfRangeException(
"offset");
206 var typeString = table.GetValue(0, 0).Value.ToString();
207 if (
String.Equals(typeString, FunctionType, StringComparison.OrdinalIgnoreCase) ||
208 String.Equals(typeString, ExternalProcedureType, StringComparison.OrdinalIgnoreCase))
211 if (
String.Equals(typeString, ProcedureType, StringComparison.OrdinalIgnoreCase) ||
212 String.Equals(typeString, ExternalProcedureType, StringComparison.OrdinalIgnoreCase))
215 throw new InvalidOperationException(
String.Format(
"The type {0} is invalid as routine table type.", typeString));
220 var rowE = table.GetEnumerator();
224 while (rowE.MoveNext()) {
225 i = rowE.Current.RowId.RowNumber;
234 throw new ArgumentOutOfRangeException(
"offset");
236 string schema = table.GetValue(rowI, 0).Value.ToString();
237 string name = table.GetValue(rowI, 1).Value.ToString();
239 var paramTypes = GetParameterTypes(schema, name);
241 var tableInfo = CreateTableInfo(schema, name);
242 var type = table.GetValue(rowI, 2);
243 var location = table.GetValue(rowI, 3);
244 var returnType = table.GetValue(rowI, 4);
245 var owner = table.GetValue(rowI, 5);
250 ReturnType = returnType,
251 ParameterTypes = paramTypes,
259 var types =
new List<string>();
261 foreach (var rowIndex
in rows) {
262 var argName = table.GetValue(rowIndex, 1);
263 var argType = table.GetValue(rowIndex, 2);
264 var inOut = table.GetValue(rowIndex, 3);
266 var paramString = BuildParameterString(argName, argType, inOut);
268 types.Add(paramString);
271 var args =
String.Join(
", ", types.ToArray());
276 var sb =
new StringBuilder();
277 sb.Append(argName.ToString());
279 sb.Append(argType.ToString());
283 .Append(inOut.
Value);
285 return sb.ToString();
295 this.tableInfo = tableInfo;
299 get {
return tableInfo; }
312 public override int RowCount {
317 if (rowNumber < 0 || rowNumber >= 1)
318 throw new ArgumentOutOfRangeException(
"rowNumber");
320 switch (columnOffset) {
328 return ParameterTypes;
332 throw new ArgumentOutOfRangeException(
"columnOffset");
Provides some helper functions for resolving and creating SqlType instances that are primitive to the...
The system uses instances of this interface to resolve routines given a user invocation.
bool IsNull
Gets a value that indicates if this object is materialized as null.
bool AlterObject(IObjectInfo objInfo)
Modifies an existing object managed, identified by IObjectInfo.FullName component of the given specif...
bool DropObject(ObjectName objName)
Deletes a database object handled by this manager from the system.
Defines the contract to access the data contained into a table of a database.
ITable FindEntry(Table table, ObjectName routineName)
A long string in the system.
The context of a single database within a system.
override DataObject GetValue(long rowNumber, int columnOffset)
Gets a single cell within the table that is located at the given column offset and row...
The system implementation of a transaction model that handles isolated operations within a database c...
bool RealObjectExists(ObjectName objName)
Checks if an object really exists in the system.
IDatabase ITransaction. Database
bool AlterRoutine(RoutineInfo routineInfo)
static TableInfo CreateTableInfo(string schema, string name)
Represents a database object, such as a table, a trigger, a type or a column.
static NumericType Integer()
IRoutine ResolveRoutine(Invoke request, IQuery context)
Resolves a routine that matches the given invocation within the context provided. ...
static SqlBinaryExpression Equal(SqlExpression left, SqlExpression right)
Describes the name of an object within a database.
The contract to define a program routine that can interact with database objects. ...
ISqlObject Value
Gets the underlined value that is handled.
static DataObject String(string s)
override string GetTableType(int offset)
Gets the type of the table at the given offset.
SqlExpressionType
All the possible type of SqlExpression supported
ObjectName ResolveName(ObjectName objName, bool ignoreCase)
Normalizes the input object name using the case sensitivity specified.
override ITable GetTable(int offset)
Gets the table contained at the given offset within the context.
virtual ObjectName GetResolvedColumnName(int column)
ForeignKeyAction
Enumerates the foreign key referential trigger actions.
DataObject GetParameterTypes(string schema, string name)
new IDatabaseContext Context
Gets the context that contains this database.
A user-defined TYPE that holds complex objects in a database column.
static readonly ObjectName RoutineTableName
void CreateObject(IObjectInfo objInfo)
Create a new object of the ObjectType given the specifications given.
Provides the constant names of the types of tables in a database system.
string BuildParameterString(DataObject argName, DataObject argType, DataObject inOut)
void CreateRoutine(RoutineInfo routineInfo)
Represents a dynamic object that encapsulates a defined SqlType and a compatible constant ISqlObject ...
bool DropRoutine(ObjectName objName)
readonly TableInfo tableInfo
The information about the invocation of a routine, including the full name and arguments (as SqlExpre...
FunctionType
The different type of a function.
IRoutine GetRoutine(ObjectName routineName)
Provides utilities and properties for handling the SYSTEN schema of a database.
bool RoutineExists(ObjectName objName)
DbObjectType ObjectType
Gets the type of objects managed by this instance.
string Name
Gets the name of the object being referenced.
static SqlReferenceExpression Reference(ObjectName objectName)
static StringType String()
RoutineTable(IDatabaseContext dbContext, TableInfo tableInfo)
IDbObject GetObject(ObjectName objName)
Gets a database object managed by this manager.
bool ObjectExists(ObjectName objName)
Checks if an object identified by the given name is managed by this instance.
Defines the metadata for a routine that are used to resolve within a context.
RoutinesTableContainer(ITransaction transaction)
override TableInfo GetTableInfo(int offset)
Gets the information of the table at the given offset in this container.
Defines the base class for instances that represent SQL expression tree nodes.
Defines the contract for the business managers of database objects of a given type.
static SqlConstantExpression Constant(object value)
void Create()
Initializes the manager into the underlying system.
The simplest implementation of a transaction.
DbObjectType
The kind of objects that can be handled by a database system and its managers
Defines the metadata properties of a table existing within a database.
ProcedureType
The form of a database stored PROCEDURE.
static readonly ObjectName RoutineParameterTableName
RoutineManager(ITransaction transaction)