public IRoutine GetRoutine(ObjectName routineName) { IRoutine result; if (!routinesCache.TryGet(routineName, out result)) { var t = FindEntry(routineName); if (t == null || t.RowCount == 0) { return(null); } var id = t.GetValue(0, 0); var schemaName = t.GetValue(0, 1).Value.ToString(); var name = t.GetValue(0, 2).Value.ToString(); var fullName = new ObjectName(ObjectName.Parse(schemaName), name); var t2 = GetParameters(id); var parameters = CreateParameters(t2); var routineType = t.GetValue(0, 3).Value.ToString(); var returnTypeString = t.GetValue(0, 6).Value.ToString(); var owner = t.GetValue(0, 7).Value.ToString(); RoutineInfo info; SqlType returnType = null; if (routineType == FunctionType || routineType == ExtrernalFunctionType) { returnType = transaction.Context.ResolveType(returnTypeString); } SqlStatement body = null; ExternalRef externalRef = null; if (routineType == FunctionType || routineType == ProcedureType) { var bodyBin = (SqlBinary)t.GetValue(0, 5).Value; body = bodyBin.ToObject <PlSqlBlockStatement>(); } else if (routineType == ExtrernalFunctionType || routineType == ExternalProcedureType) { var location = t.GetValue(0, 4).Value.ToString(); if (!ExternalRef.TryParse(location, out externalRef)) { throw new InvalidOperationException(String.Format("The location stored for function '{0}' is invalid: {1}.", routineName, location)); } } if (routineType == FunctionType) { info = new PlSqlFunctionInfo(fullName, parameters, returnType, body); } else if (routineType == ProcedureType) { info = new PlSqlProcedureInfo(fullName, parameters, body); } else if (routineType == ExtrernalFunctionType) { info = new ExternalFunctionInfo(fullName, parameters, returnType, externalRef); } else if (routineType == ExternalProcedureType) { info = new ExternalProcedureInfo(fullName, parameters, externalRef); } else { throw new InvalidOperationException(String.Format("Invalid routine type '{0}' found in database", routineType)); } info.Owner = owner; if (info is PlSqlFunctionInfo) { result = new PlSqlFunction((PlSqlFunctionInfo)info); } else if (info is PlSqlProcedureInfo) { result = new PlSqlProcedure((PlSqlProcedureInfo)info); } else if (info is ExternalFunctionInfo) { result = new ExternalFunction((ExternalFunctionInfo)info); } else { result = new ExternalProcedure((ExternalProcedureInfo)info); } routinesCache.Set(fullName, result); } return(result); }
public IRoutine GetRoutine(ObjectName routineName) { IRoutine result; if (!routinesCache.TryGet(routineName, out result)) { var t = FindEntry(routineName); if (t == null || t.RowCount == 0) return null; var id = t.GetValue(0, 0); var schemaName = t.GetValue(0, 1).Value.ToString(); var name = t.GetValue(0, 2).Value.ToString(); var fullName = new ObjectName(ObjectName.Parse(schemaName), name); var t2 = GetParameters(id); var parameters = CreateParameters(t2); var routineType = t.GetValue(0, 3).Value.ToString(); var returnTypeString = t.GetValue(0, 6).Value.ToString(); var owner = t.GetValue(0, 7).Value.ToString(); RoutineInfo info; SqlType returnType = null; if (routineType == FunctionType || routineType == ExtrernalFunctionType) { returnType = transaction.Context.ResolveType(returnTypeString); } SqlStatement body = null; ExternalRef externalRef = null; if (routineType == FunctionType || routineType == ProcedureType) { var bodyBin = (SqlBinary) t.GetValue(0, 5).Value; body = bodyBin.ToObject<PlSqlBlockStatement>(); } else if (routineType == ExtrernalFunctionType || routineType == ExternalProcedureType) { var location = t.GetValue(0, 4).Value.ToString(); if (!ExternalRef.TryParse(location, out externalRef)) throw new InvalidOperationException(String.Format("The location stored for function '{0}' is invalid: {1}.", routineName, location)); } if (routineType == FunctionType) { info = new PlSqlFunctionInfo(fullName, parameters, returnType, body); } else if (routineType == ProcedureType) { info = new PlSqlProcedureInfo(fullName, parameters, body); } else if (routineType == ExtrernalFunctionType) { info = new ExternalFunctionInfo(fullName, parameters, returnType, externalRef); } else if (routineType == ExternalProcedureType) { info = new ExternalProcedureInfo(fullName, parameters, externalRef); } else { throw new InvalidOperationException(String.Format("Invalid routine type '{0}' found in database", routineType)); } info.Owner = owner; if (info is PlSqlFunctionInfo) { result = new PlSqlFunction((PlSqlFunctionInfo) info); } else if (info is PlSqlProcedureInfo) { result = new PlSqlProcedure((PlSqlProcedureInfo) info); } else if (info is ExternalFunctionInfo) { result = new ExternalFunction((ExternalFunctionInfo) info); } else { result = new ExternalProcedure((ExternalProcedureInfo) info); } routinesCache.Set(fullName, result); } return result; }