Friday, June 18, 2010

EJB annotations and Stereotyping

Certainly for the EJB-related annotations, I would love to see @Stateless, @Stateful, @Singleton and @MessageDriven be used for stereotyping as well as all the other class level annotations for transactions, security, locking, timeouts and scheduling.

Great security example:

 @RolesAllowed({"SuperUser", "AccountAdmin", "SystemAdmin"})
 public @interface Admins {}
In one swoop all the security rolls become controlled in one spot and there's no need to go changing a million usages to modify the roll names.

Here's a couple great scheduling examples:

 @Schedule(second=”0”, minute=”0”, hour=”0”, month=”*”, dayOfWeek=”*”, year=”*”)
 public @interface Daily {}
 @Schedule(second=”0”, minute=”0”, hour=”0”, month=”*”, dayOfMonth=”15,Last”, year=”*”)
 public @interface BiMonthly {}
The list goes on and on. A much fuller example:
@RolesAllowed({"SuperUser", "AccountAdmin", "SystemAdmin"})
@Interceptors({LoggingInterceptor.class, StatisticsInterceptor.class})
public @interface SuperBean {}
And to use all that, just:
public class MyBean {

    public void doSomething() {


Heiko W. Rupp said...

This for sure looks interesting. Would you allow stereotypes to inherit from each other?

For the @Daily stereotype: I voted in the EJB3 cycle to directly have such keywords (basically what you have in newer cron implementations) within @Schedule

David Blevins said...

Sure, I would allow stereotypes to inherit from each other. Having a lot of levels will add indirection and potentially slow down your deployments, but I don't see any issues giving people that choice.

Definitely the cron built-in @hourly @daily, etc. were an inspiration for me as well and I did make this proposal in EJB 3.1 while we were talking about @Schedule. There was definitely interest and we might see it in a future EJB spec -- though likely after EJB 3.2.

I've worked on it in OpenEJB and am hoping to have a prototype in another week.

Narender Godara said...

Packers and movers Kanpur
Packers and movers Karnal
Packers and movers Kolkata
Packers and movers Lucknow