コード例 #1
0
        internal static DbExpression CompileFunctionView(
            string viewDef,
            StorageMappingItemCollection mappingItemCollection,
            ParserOptions.CompilationMode compilationMode,
            IEnumerable <DbParameterReferenceExpression> parameters)
        {
            DebugCheck.NotEmpty(viewDef);
            DebugCheck.NotNull(mappingItemCollection);

            Perspective perspective   = new TargetPerspective(mappingItemCollection.Workspace);
            var         parserOptions = new ParserOptions();

            parserOptions.ParserCompilationMode = compilationMode;

            // Parameters have to be accessible in the body as regular scope variables, not as command parameters.
            // Hence compile view as lambda with parameters as lambda vars, then invoke the lambda specifying
            // command parameters as values of the lambda vars.
            var functionBody = CqlQuery.CompileQueryCommandLambda(
                viewDef,
                perspective,
                parserOptions,
                null /* parameters */,
                parameters.Select(pInfo => pInfo.ResultType.Variable(pInfo.ParameterName)));

            Debug.Assert(functionBody != null, "functionBody != null");
            DbExpression expr = functionBody.Invoke(parameters);

            return(expr);
        }
コード例 #2
0
        internal static DbCommandTree CompileView(
            string viewDef,
            StorageMappingItemCollection mappingItemCollection,
            ParserOptions.CompilationMode compilationMode)
        {
            Perspective perspective = (Perspective) new TargetPerspective(mappingItemCollection.Workspace);

            return(CqlQuery.Compile(viewDef, perspective, new ParserOptions()
            {
                ParserCompilationMode = compilationMode
            }, (IEnumerable <DbParameterReferenceExpression>)null).CommandTree);
        }
コード例 #3
0
        internal static DbExpression CompileFunctionView(
            string viewDef,
            StorageMappingItemCollection mappingItemCollection,
            ParserOptions.CompilationMode compilationMode,
            IEnumerable <DbParameterReferenceExpression> parameters)
        {
            Perspective perspective = (Perspective) new TargetPerspective(mappingItemCollection.Workspace);

            return((DbExpression)CqlQuery.CompileQueryCommandLambda(viewDef, perspective, new ParserOptions()
            {
                ParserCompilationMode = compilationMode
            }, (IEnumerable <DbParameterReferenceExpression>)null, parameters.Select <DbParameterReferenceExpression, DbVariableReferenceExpression>((Func <DbParameterReferenceExpression, DbVariableReferenceExpression>)(pInfo => pInfo.ResultType.Variable(pInfo.ParameterName)))).Invoke((IEnumerable <DbExpression>)parameters));
        }
コード例 #4
0
 private static bool TryParseView(
     string eSQL,
     bool isUserSpecified,
     EntitySetBase extent,
     StorageMappingItemCollection mappingItemCollection,
     ConfigViewGenerator config,
     out DbQueryCommandTree commandTree,
     out DiscriminatorMap discriminatorMap,
     out Exception parserException)
 {
     commandTree      = (DbQueryCommandTree)null;
     discriminatorMap = (DiscriminatorMap)null;
     parserException  = (Exception)null;
     config.StartSingleWatch(PerfType.ViewParsing);
     try
     {
         ParserOptions.CompilationMode compilationMode = ParserOptions.CompilationMode.RestrictedViewGenerationMode;
         if (isUserSpecified)
         {
             compilationMode = ParserOptions.CompilationMode.UserViewGenerationMode;
         }
         commandTree = (DbQueryCommandTree)ExternalCalls.CompileView(eSQL, mappingItemCollection, compilationMode);
         commandTree = ViewSimplifier.SimplifyView(extent, commandTree);
         if (extent.BuiltInTypeKind == BuiltInTypeKind.EntitySet)
         {
             DiscriminatorMap.TryCreateDiscriminatorMap((EntitySet)extent, commandTree.Query, out discriminatorMap);
         }
     }
     catch (Exception ex)
     {
         if (ex.IsCatchableExceptionType())
         {
             parserException = ex;
         }
         else
         {
             throw;
         }
     }
     finally
     {
         config.StopSingleWatch(PerfType.ViewParsing);
     }
     return(parserException == null);
 }
コード例 #5
0
        internal static DbCommandTree CompileView(
            string viewDef,
            StorageMappingItemCollection mappingItemCollection,
            ParserOptions.CompilationMode compilationMode)
        {
            DebugCheck.NotEmpty(viewDef);
            DebugCheck.NotNull(mappingItemCollection);

            Perspective perspective   = new TargetPerspective(mappingItemCollection.Workspace);
            var         parserOptions = new ParserOptions();

            parserOptions.ParserCompilationMode = compilationMode;
            var expr = CqlQuery.Compile(viewDef, perspective, parserOptions, null).CommandTree;

            Debug.Assert(expr != null, "Compile returned empty tree?");

            return(expr);
        }
コード例 #6
0
        static internal DbCommandTree CompileView(
            string viewDef,
            StorageMappingItemCollection mappingItemCollection,
            ParserOptions.CompilationMode compilationMode)
        {
            Debug.Assert(!String.IsNullOrEmpty(viewDef), "!String.IsNullOrEmpty(viewDef)");
            Debug.Assert(mappingItemCollection != null, "mappingItemCollection != null");

            Perspective   perspective   = new TargetPerspective(mappingItemCollection.Workspace);
            ParserOptions parserOptions = new ParserOptions();

            parserOptions.ParserCompilationMode = compilationMode;
            DbCommandTree expr = CqlQuery.Compile(viewDef, perspective, parserOptions, null).CommandTree;

            Debug.Assert(expr != null, "Compile returned empty tree?");

            return(expr);
        }
コード例 #7
0
        /// <summary>
        /// Given an extent and its corresponding view, invokes the parser to check if the view definition is syntactically correct.
        /// Iff parsing succeeds: <paramref name="commandTree"/> and <paramref name="discriminatorMap"/> are set to the parse result and method returns true,
        /// otherwise if parser has thrown a catchable exception, it is returned via <paramref name="parserException"/> parameter,
        /// otherwise exception is re-thrown.
        /// </summary>
        private static bool TryParseView(string eSQL,
                                         bool isUserSpecified,
                                         EntitySetBase extent,
                                         StorageMappingItemCollection mappingItemCollection,
                                         ConfigViewGenerator config,
                                         out DbQueryCommandTree commandTree,
                                         out DiscriminatorMap discriminatorMap,
                                         out Exception parserException)
        {
            commandTree      = null;
            discriminatorMap = null;
            parserException  = null;

            // We do not catch any internal exceptions any more
            config.StartSingleWatch(PerfType.ViewParsing);
            try
            {
                // If it is a user specified view, allow all queries. Otherwise parse the view in the restricted mode.
                ParserOptions.CompilationMode compilationMode = ParserOptions.CompilationMode.RestrictedViewGenerationMode;
                if (isUserSpecified)
                {
                    compilationMode = ParserOptions.CompilationMode.UserViewGenerationMode;
                }

                Debug.Assert(!String.IsNullOrEmpty(eSQL), "eSQL query is not specified");
                commandTree = (DbQueryCommandTree)ExternalCalls.CompileView(eSQL, mappingItemCollection, compilationMode);

                // For non user-specified views, perform simplification.
                if (!isUserSpecified)
                {
                    commandTree = ViewSimplifier.SimplifyView(extent, commandTree);
                }

                // See if the view matches the "discriminated" pattern (allows simplification of generated store commands)
                if (extent.BuiltInTypeKind == BuiltInTypeKind.EntitySet)
                {
                    if (DiscriminatorMap.TryCreateDiscriminatorMap((EntitySet)extent, commandTree.Query, out discriminatorMap))
                    {
                        Debug.Assert(discriminatorMap != null, "discriminatorMap == null after it has been created");
                    }
                }
            }
            catch (Exception e)
            {
                // Catching all the exception types since Query parser seems to be throwing veriety of
                // exceptions - EntityException, ArgumentException, ArgumentNullException etc.
                if (EntityUtil.IsCatchableExceptionType(e))
                {
                    parserException = e;
                }
                else
                {
                    throw;
                }
            }
            finally
            {
                config.StopSingleWatch(PerfType.ViewParsing);
            }

            Debug.Assert(commandTree != null || parserException != null, "Either commandTree or parserException is expected.");
            // Note: m_commandTree might have been initialized by a previous call to this method, so in consequent calls it might occur that
            // both m_commandTree and parserException are not null - this would mean that the last parse attempt failed, but m_commandTree value is
            // preserved from the previous call.

            return(parserException == null);
        }