示例#1
0
        public override T execute <T>(Command <T> command)
        {
            CommandContext context = null;

            if (!alwaysOpenNew)
            {
                // check whether we can reuse the command context
                CommandContext existingCommandContext = Context.CommandContext;
                if (existingCommandContext != null && isFromSameEngine(existingCommandContext))
                {
                    context = existingCommandContext;
                }
            }

            bool openNew = (context == null);

            CommandInvocationContext commandInvocationContext = new CommandInvocationContext(command);

            Context.CommandInvocationContext = commandInvocationContext;

            try
            {
                if (openNew)
                {
                    LOG.debugOpeningNewCommandContext();
                    context = commandContextFactory.createCommandContext();
                }
                else
                {
                    LOG.debugReusingExistingCommandContext();
                }

                Context.CommandContext             = context;
                Context.ProcessEngineConfiguration = processEngineConfiguration;

                // delegate to next interceptor in chain
                return(next.execute(command));
            }
            catch (Exception t)
            {
                commandInvocationContext.trySetThrowable(t);
            }
            finally
            {
                try
                {
                    if (openNew)
                    {
                        LOG.closingCommandContext();
                        context.close(commandInvocationContext);
                    }
                    else
                    {
                        commandInvocationContext.rethrow();
                    }
                }
                finally
                {
                    Context.removeCommandInvocationContext();
                    Context.removeCommandContext();
                    Context.removeProcessEngineConfiguration();
                }
            }

            return(default(T));
        }