You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@tomee.apache.org by David Blevins <da...@visi.com> on 2010/06/20 19:57:37 UTC

@SystemException

As mentioned in the "JCDI Sandbox" discussion, one of the things that is part of EJB that is not necessarily configurable is if a bean should be discarded if a system exception is thrown.  As of EJB 3.0 the @ApplicationException can flag certain exceptions as not causing the bean to be discarded and the transaction rolled back.

The problem with it though is annotating every possible exception is a leaky approach.  As well if the desire is simply to shut this behavior off for one bean or method of a bean without affecting other beans/methods, there is no solution.

So thinking to add support for counterpart to @ApplicationException that gets closer to the real problem and simply lets users dictate how they want us to handle system exceptions.  Should we rollback as the spec says, should we discard your bean as the spec says?

    import static java.lang.annotation.ElementType.TYPE;
    import static java.lang.annotation.ElementType.METHOD;
    import java.lang.annotation.Retention;
    import static java.lang.annotation.RetentionPolicy.RUNTIME;
    import java.lang.annotation.Target;
    
    @Target({TYPE, METHOD})
    @Retention(RUNTIME)
    public @interface SystemException {
    
        /**
         * Should the bean instance be discarded
         */
        boolean discard() default true;
    
        /**
         * Should the transaction rollback
         */
        boolean rollback() default true;
    
        /**
         * Same as @ApplicationException
         */
        boolean inherited() default true;
    }

This would be applied to the bean itself or methods of a bean to dictate how unchecked exceptions should be handled.  As well it could be applied to individual exceptions, like @ApplicationException, to turn even checked exceptions into a SystemException.  So a user could even use it to throw checked exceptions and have them cause both rollback and instance removal.

What I imagine is that for @ManagedBean the default would be SystemException(discard=false, rollback=false), and for all other bean types it would be of course SystemException(discard=true, rollback=true)

Thoughts?


-David


Re: @SystemException

Posted by Jacek Laskowski <ja...@laskowski.net.pl>.
On Sun, Jun 20, 2010 at 7:57 PM, David Blevins <da...@visi.com> wrote:

> Thoughts?

Good idea.

Would there be a complimentary XML element? I believe there would.
What will happen to a SFSB when a system exception has been thrown and
@SystemException(discard=false) is set? I can't envision any troubles
atm, but that's where we should look for some if any, isn't it?

Jacek

-- 
Jacek Laskowski
Notatnik Projektanta Java EE - http://jaceklaskowski.pl
KapituĊ‚a Javarsovia 2010 - http://javarsovia.pl