Ejemplo n.º 1
0
 protected internal virtual void closeSessions(CommandInvocationContext commandInvocationContext)
 {
     foreach (Session session in sessionList)
     {
         try
         {
             session.close();
         }
         catch (Exception exception)
         {
             commandInvocationContext.trySetThrowable(exception);
         }
     }
 }
Ejemplo n.º 2
0
        public virtual void close(CommandInvocationContext commandInvocationContext)
        {
            // the intention of this method is that all resources are closed properly,
            // even
            // if exceptions occur in close or flush methods of the sessions or the
            // transaction context.

            try
            {
                try
                {
                    try
                    {
                        if (commandInvocationContext.Throwable == null)
                        {
                            fireCommandContextClose();
                            flushSessions();
                        }
                    }
                    catch (Exception exception)
                    {
                        commandInvocationContext.trySetThrowable(exception);
                    }
                    finally
                    {
                        try
                        {
                            if (commandInvocationContext.Throwable == null)
                            {
                                transactionContext.commit();
                            }
                        }
                        catch (Exception exception)
                        {
                            commandInvocationContext.trySetThrowable(exception);
                        }

                        if (commandInvocationContext.Throwable != null)
                        {
                            // fire command failed (must not fail itself)
                            fireCommandFailed(commandInvocationContext.Throwable);

                            if (shouldLogInfo(commandInvocationContext.Throwable))
                            {
                                LOG.infoException(commandInvocationContext.Throwable);
                            }
                            else if (shouldLogFine(commandInvocationContext.Throwable))
                            {
                                LOG.debugException(commandInvocationContext.Throwable);
                            }
                            else
                            {
                                LOG.errorException(commandInvocationContext.Throwable);
                            }
                            transactionContext.rollback();
                        }
                    }
                }
                catch (Exception exception)
                {
                    commandInvocationContext.trySetThrowable(exception);
                }
                finally
                {
                    closeSessions(commandInvocationContext);
                }
            }
            catch (Exception exception)
            {
                commandInvocationContext.trySetThrowable(exception);
            }

            // rethrow the original exception if there was one
            commandInvocationContext.rethrow();
        }
Ejemplo n.º 3
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));
        }