public ExecutableProvider Compile(CompilableProvider provider, CompilerConfiguration configuration)
        {
            ArgumentValidator.EnsureArgumentNotNull(provider, "provider");
            ArgumentValidator.EnsureArgumentNotNull(configuration, "configuration");

            var preCompiler  = preCompilerProvider.Invoke(configuration);
            var compiler     = compilerProvider.Invoke(configuration);
            var postCompiler = postCompilerProvider.Invoke(configuration, compiler);

            if (compiler == null)
            {
                throw new InvalidOperationException(Strings.ExCanNotCompileNoCompiler);
            }

            var preprocessed = preCompiler.Process(provider);
            var compiled     = compiler.Compile(preprocessed);

            compiled = postCompiler.Process(compiled);

            if (compiled == null)
            {
                throw new InvalidOperationException(string.Format(Strings.ExCantCompileProviderX, provider));
            }

            return(compiled);
        }
        /// <summary>
        /// Creates the <see cref="IPostCompiler"/>.
        /// </summary>
        /// <param name="configuration">Compiler configuration to use.</param>
        /// <param name="compiler">Currently used compiler instance.</param>
        /// <returns>A new post-compiler.</returns>
        protected virtual IPostCompiler CreatePostCompiler(CompilerConfiguration configuration, ICompiler compiler)
        {
            var result = new CompositePostCompiler(new SqlSelectCorrector(Handlers.ProviderInfo));

            if (configuration.PrepareRequest)
            {
                result.Items.Add(new SqlProviderPreparer(Handlers));
            }
            return(result);
        }
        /// <summary>
        /// Creates the <see cref="IPreCompiler"/>.
        /// </summary>
        /// <param name="configuration">Compiler configuration to use.</param>
        /// <returns>A new pre-compiler.</returns>
        protected virtual IPreCompiler CreatePreCompiler(CompilerConfiguration configuration)
        {
            var providerInfo = Handlers.ProviderInfo;

            var applyCorrector = new ApplyProviderCorrector(
                !providerInfo.Supports(ProviderFeatures.Apply));
            var skipTakeCorrector = new SkipTakeCorrector(
                providerInfo.Supports(ProviderFeatures.NativeTake),
                providerInfo.Supports(ProviderFeatures.NativeSkip));

            return(new CompositePreCompiler(
                       applyCorrector,
                       skipTakeCorrector,
                       new RedundantColumnOptimizer(),
                       new OrderingCorrector(ResolveOrderingDescriptor)));
        }
        // Constructors

        /// <summary>
        /// Initializes a new instance of this class.
        /// </summary>
        public SqlCompiler(HandlerAccessor handlers, CompilerConfiguration configuration)
        {
            Handlers          = handlers;
            OuterReferences   = new BindingCollection <ApplyParameter, Pair <SqlProvider, bool> >();
            Mapping           = configuration.StorageNode.Mapping;
            TypeIdRegistry    = configuration.StorageNode.TypeIdRegistry;
            NodeConfiguration = configuration.StorageNode.Configuration;

            providerInfo             = Handlers.ProviderInfo;
            temporaryTablesSupported = DomainHandler.TemporaryTableManager.Supported;

            if (!providerInfo.Supports(ProviderFeatures.FullFeaturedBooleanExpressions))
            {
                booleanExpressionConverter = new BooleanExpressionConverter(Driver);
            }

            stubColumnMap = new Dictionary <SqlColumnStub, SqlExpression>();
        }
 /// <summary>
 /// Creates the compiler.
 /// </summary>
 /// <param name="configuration">Compiler configuration to use.</param>
 /// <returns>A new compiler.</returns>
 protected virtual ICompiler CreateCompiler(CompilerConfiguration configuration)
 {
     return(new SqlCompiler(Handlers, configuration));
 }