Defines the metadata for a routine that are used to resolve within a context.
상속: IObjectInfo
예제 #1
0
파일: Routine.cs 프로젝트: deveel/deveeldb
        protected Routine(RoutineInfo routineInfo)
        {
            if (routineInfo == null)
                throw new ArgumentNullException("routineInfo");

            RoutineInfo = routineInfo;
        }
예제 #2
0
        internal void CheckReference(RoutineInfo routineInfo)
        {
            var method = GetMethod();

            if (method == null)
            {
                throw new ArgumentException(String.Format("The reference '{0}' does not resolve to any method.", this));
            }

            if (routineInfo is FunctionInfo &&
                method.ReturnType == typeof(void))
            {
                throw new ArgumentException(String.Format("The method '{0}.{1}' is not a function.", Type.FullName, method.Name));
            }
            else if (routineInfo is ProcedureInfo &&
                     method.ReturnType != typeof(void))
            {
                throw new ArgumentException(String.Format("The method '{0}.{1}' is not a procedure.", Type.FullName, method.Name));
            }

            var methodParams = method.GetParameters();

            if (!CheckParametersMatch(routineInfo, methodParams))
            {
                throw new ArgumentException("The parameters of this function and the reference do not match.");
            }
        }
예제 #3
0
        internal RoutineBody(RoutineInfo routineInfo)
        {
            if (routineInfo == null)
                throw new ArgumentNullException("routineInfo");

            RoutineInfo = routineInfo;
            declarations = new List<SqlStatement>();
            statements = new List<SqlStatement>();
        }
예제 #4
0
        protected Routine(RoutineInfo routineInfo)
        {
            if (routineInfo == null)
            {
                throw new ArgumentNullException("routineInfo");
            }

            RoutineInfo = routineInfo;
        }
예제 #5
0
        public bool ReplaceRoutine(RoutineInfo routineInfo)
        {
            if (!RemoveRoutine(routineInfo.RoutineName))
            {
                return(false);
            }

            CreateRoutine(routineInfo);
            return(true);
        }
예제 #6
0
        private bool CheckParametersMatch(RoutineInfo routineInfo, ParameterInfo[] parameters)
        {
            var routineParameters = routineInfo.Parameters;

            if ((routineParameters == null || routineParameters.Length == 0) &&
                (parameters == null || parameters.Length == 0))
            {
                return(true);
            }

            if (routineParameters == null || routineParameters.Length == 0)
            {
                return(false);
            }

            var offset = 0;

            if (parameters[0].ParameterType == typeof(ISession))
            {
                offset = 1;
            }

            if (routineParameters.Length != parameters.Length - offset)
            {
                return(false);
            }

            for (int i = offset; i < parameters.Length; i++)
            {
                var param = parameters[i];

                var paramType = param.ParameterType;
                if (paramType.IsByRef)
                {
                    paramType = paramType.GetElementType();
                }


                var argType          = PrimitiveTypes.FromType(paramType);
                var routineParameter = routineParameters[i];

                if (!routineParameter.Type.CanCastTo(argType))
                {
                    return(false);
                }
            }

            return(true);
        }
예제 #7
0
        public void CreateRoutine(RoutineInfo routineInfo)
        {
            try {
                string routineType = null;

                if (routineInfo is FunctionInfo)
                {
                    if (routineInfo is ExternalFunctionInfo)
                    {
                        routineType = ExtrernalFunctionType;
                    }
                    else if (routineInfo is PlSqlFunctionInfo)
                    {
                        routineType = FunctionType;
                    }
                }
                else if (routineInfo is ProcedureInfo)
                {
                    if (routineInfo is PlSqlProcedureInfo)
                    {
                        routineType = ProcedureType;
                    }
                    else if (routineInfo is ExternalProcedureInfo)
                    {
                        routineType = ExternalProcedureType;
                    }
                }
                else
                {
                    throw new ArgumentException();
                }

                if (String.IsNullOrEmpty(routineType))
                {
                    throw new InvalidOperationException("Could not determine the kind of routine.");
                }

                var id = transaction.NextTableId(RoutineTableName);

                var routine       = transaction.GetMutableTable(RoutineTableName);
                var routineParams = transaction.GetMutableTable(RoutineParameterTableName);

                var row = routine.NewRow();
                row.SetValue(0, id);
                row.SetValue(1, routineInfo.RoutineName.ParentName);
                row.SetValue(2, routineInfo.RoutineName.Name);
                row.SetValue(3, routineType);

                if (routineType == ExternalProcedureType)
                {
                    var extProcedure = (ExternalProcedureInfo)routineInfo;
                    var location     = extProcedure.ExternalRef.ToString();
                    row.SetValue(4, location);
                }
                else if (routineType == ExtrernalFunctionType)
                {
                    var extFunction = (ExternalFunctionInfo)routineInfo;
                    var location    = extFunction.ExternalRef.ToString();
                    row.SetValue(4, location);
                }
                else if (routineType == ProcedureType)
                {
                    var plsqlProcedure = (PlSqlProcedureInfo)routineInfo;
                    var bin            = SqlBinary.ToBinary(plsqlProcedure.Body);
                    row.SetValue(5, bin);
                }
                else if (routineType == FunctionType)
                {
                    var plsqlFunction = (PlSqlFunctionInfo)routineInfo;
                    var bin           = SqlBinary.ToBinary(plsqlFunction.Body);
                    row.SetValue(5, bin);
                }

                if (routineInfo is FunctionInfo)
                {
                    var returnType = ((FunctionInfo)routineInfo).ReturnType.ToString();
                    row.SetValue(6, returnType);
                }

                row.SetValue(7, routineInfo.Owner);
                routine.AddRow(row);

                if (routineInfo.Parameters != null)
                {
                    foreach (var parameter in routineInfo.Parameters)
                    {
                        var prow = routineParams.NewRow();
                        prow.SetValue(0, id);
                        prow.SetValue(1, parameter.Name);

                        var argType = parameter.Type.ToString();
                        prow.SetValue(2, argType);

                        var attrs = new SqlNumber((int)parameter.Attributes);
                        prow.SetValue(3, attrs);

                        var dir = new SqlNumber((int)parameter.Direction);
                        prow.SetValue(4, dir);

                        prow.SetValue(5, parameter.Offset);

                        routineParams.AddRow(prow);
                    }
                }

                transaction.OnObjectCreated(DbObjectType.Routine, routineInfo.RoutineName);
            } finally {
                routinesCache.Clear();
            }
        }
예제 #8
0
 public bool AlterRoutine(RoutineInfo routineInfo)
 {
     // TODO: implement
     return(false);
 }
예제 #9
0
 public void CreateRoutine(RoutineInfo routineInfo)
 {
     throw new NotImplementedException();
 }
예제 #10
0
 public bool AlterRoutine(RoutineInfo routineInfo)
 {
     // TODO: implement
     return false;
 }
예제 #11
0
 public void CreateRoutine(RoutineInfo routineInfo)
 {
     throw new NotImplementedException();
 }
예제 #12
0
        public void CreateRoutine(RoutineInfo routineInfo)
        {
            try {
                string routineType = null;

                if (routineInfo is FunctionInfo) {
                    if (routineInfo is ExternalFunctionInfo) {
                        routineType = ExtrernalFunctionType;
                    } else if (routineInfo is PlSqlFunctionInfo) {
                        routineType = FunctionType;
                    }
                } else if (routineInfo is ProcedureInfo) {
                    if (routineInfo is PlSqlProcedureInfo) {
                        routineType = ProcedureType;
                    } else if (routineInfo is ExternalProcedureInfo) {
                        routineType = ExternalProcedureType;
                    }
                } else {
                    throw new ArgumentException();
                }

                if (String.IsNullOrEmpty(routineType))
                    throw new InvalidOperationException("Could not determine the kind of routine.");

                var id = transaction.NextTableId(RoutineTableName);

                var routine = transaction.GetMutableTable(RoutineTableName);
                var routineParams = transaction.GetMutableTable(RoutineParameterTableName);

                var row = routine.NewRow();
                row.SetValue(0, id);
                row.SetValue(1, routineInfo.RoutineName.ParentName);
                row.SetValue(2, routineInfo.RoutineName.Name);
                row.SetValue(3, routineType);

                if (routineType == ExternalProcedureType) {
                    var extProcedure = (ExternalProcedureInfo)routineInfo;
                    var location = extProcedure.ExternalRef.ToString();
                    row.SetValue(4, location);
                } else if (routineType == ExtrernalFunctionType) {
                    var extFunction = (ExternalFunctionInfo)routineInfo;
                    var location = extFunction.ExternalRef.ToString();
                    row.SetValue(4, location);
                } else if (routineType == ProcedureType) {
                    var plsqlProcedure = (PlSqlProcedureInfo)routineInfo;
                    var bin = SqlBinary.ToBinary(plsqlProcedure.Body);
                    row.SetValue(5, bin);
                } else if (routineType == FunctionType) {
                    var plsqlFunction = (PlSqlFunctionInfo)routineInfo;
                    var bin = SqlBinary.ToBinary(plsqlFunction.Body);
                    row.SetValue(5, bin);
                }

                if (routineInfo is FunctionInfo) {
                    var returnType = ((FunctionInfo)routineInfo).ReturnType.ToString();
                    row.SetValue(6, returnType);
                }

                row.SetValue(7, routineInfo.Owner);
                routine.AddRow(row);

                if (routineInfo.Parameters != null) {
                    foreach (var parameter in routineInfo.Parameters) {
                        var prow = routineParams.NewRow();
                        prow.SetValue(0, id);
                        prow.SetValue(1, parameter.Name);

                        var argType = parameter.Type.ToString();
                        prow.SetValue(2, argType);

                        var attrs = new SqlNumber((int)parameter.Attributes);
                        prow.SetValue(3, attrs);

                        var dir = new SqlNumber((int)parameter.Direction);
                        prow.SetValue(4, dir);

                        prow.SetValue(5, parameter.Offset);

                        routineParams.AddRow(prow);
                    }
                }

                transaction.OnObjectCreated(DbObjectType.Routine, routineInfo.RoutineName);
            } finally {
                routinesCache.Clear();
            }
        }
예제 #13
0
        public bool ReplaceRoutine(RoutineInfo routineInfo)
        {
            if (!RemoveRoutine(routineInfo.RoutineName))
                return false;

            CreateRoutine(routineInfo);
            return true;
        }
예제 #14
0
 public bool AlterRoutine(RoutineInfo routineInfo)
 {
     throw new NotImplementedException();
 }
예제 #15
0
        private bool CheckParametersMatch(RoutineInfo routineInfo, ParameterInfo[] parameters)
        {
            var routineParameters = routineInfo.Parameters;
            if ((routineParameters == null || routineParameters.Length == 0) &&
                (parameters == null || parameters.Length == 0))
                return true;

            if (routineParameters == null || routineParameters.Length == 0)
                return false;

            var offset = 0;
            if (parameters[0].ParameterType == typeof(ISession))
                offset = 1;

            if (routineParameters.Length != parameters.Length - offset)
                return false;

            for (int i = offset; i < parameters.Length; i++) {
                var param = parameters[i];

                var paramType = param.ParameterType;
                if (paramType.IsByRef)
                    paramType = paramType.GetElementType();

                var argType = PrimitiveTypes.FromType(paramType);
                var routineParameter = routineParameters[i];

                if (!routineParameter.Type.CanCastTo(argType))
                    return false;
            }

            return true;
        }
예제 #16
0
        internal void CheckReference(RoutineInfo routineInfo)
        {
            var method = GetMethod();
            if (method == null)
                throw new ArgumentException(String.Format("The reference '{0}' does not resolve to any method.", this));

            if (routineInfo is FunctionInfo &&
                method.ReturnType == typeof (void)) {
                throw new ArgumentException(String.Format("The method '{0}.{1}' is not a function.", Type.FullName, method.Name));
            } else if (routineInfo is ProcedureInfo &&
                       method.ReturnType != typeof (void)) {
                throw new ArgumentException(String.Format("The method '{0}.{1}' is not a procedure.", Type.FullName, method.Name));
            }

            var methodParams = method.GetParameters();
            if (!CheckParametersMatch(routineInfo, methodParams))
                throw new ArgumentException("The parameters of this function and the reference do not match.");
        }