Skip to main content

Javapolis 2004 University Day 1: AspectJ in Action

Posted by vbrabant on December 13, 2004 at 9:08 AM PST

Javapolis 2004 started today.

Today, it was the first day of the University.
The morning, during 3 hours, I listen to Adrian Colyer explaining AspectJ and explain us how it worked and why we would use it.

He wins. I will certainly try AspectJ one of those next days.

The demo he does that convinces me is his demo concerning Hibernate.

He had a class called Address with somes fields. And without modifying one line of his existing Address class, thanks to Aspects, he was able to add persistance via Hibernate mechanism.

All the stuffs concerning the management of session and transaction
like the following piece of code

Transaction tx = null;
Session s = null;
try {
s = sessionFactory.openSession();
tx = s.beginTransaction();
somes code concerning Address here
tx.commit();
return address;
} catch (HibernateException e) {
e.printStackTrace();
tx.rollback();
} finally {
s.close;
}

was contained not in a java class, but in a aspect. And the part that appears in bold were in a dao java class, but not linked to Hibernate, and was high level, so the code could be reusable for the save, update or delete of the object.

By the way, he also shows how to encapsulate all HibernateException into DAOException (required by his virtual architecht), and also how to preserve people to directly call Hibernate oriented methods appearing in your DAO class after compilation by AspectJ.

As a demo, It was really incredible.

Many Thanks, Mr Colyer.

Now, I really hope that somes next version of NetBeans will include a module to manage aspects like the eclipse one.

Related Topics >>