Google
 
Web nishgoel.blogspot.com

Wednesday, November 16, 2005

JBoss classloading

From 4.0.2 Jboss has started using Tomcat classloader. (http://www.jboss.org/wiki/Wiki.jsp?page=ClassLoadingConfiguration)

Does anybody know if I still have to specify isolation in jboss-app.xml to achieve scoped classloading? IMO, if Tomcat classloader is used then different ear will be isolated from each other. Can someone verify this?

Friday, November 11, 2005

Spring AOP usage for logging purposes

Today we had some interesting discussion about Spring AOP usage.

In our project, we had a need for logging all the SQL statements executed in DAO’s.
We already had some custom logging framework built. Now we had to tie this framework to DAO’s.

Now since all the spring based DAO’s makes use of JDBCTemplate, all CRUD operation goes through JDBC template. So the first idea to popup was to define a point cut for JDBC template (field level interception) and then hook up our logging interceptor to it.

(Note: Spring doesn’t support it and we have to use AspectJ for it)

Whenever this field was accessed, we fired logging interceptor. In the interceptor, we iterate over method arguments. One of the arguments was of type SqlProvider. This provided sql statement being executed.

But here was a problem with above approach (apart from field interception). Let’s say we have DAO like this:


public class ProfileDaoImpl extends JDBCDaoSupport implements ProfileDao
{
private ProfileSQLquery profileSQLQuery = null;

public void initDao()
{
profileSQLQuery = new ProfileSQLQuery(getDataSource());
}

public Profile getProfile(String userId)
{
return profileSQLQuery.getProfile(userId);
}
class ProfileSQLQuery extends MappingSQLQuery
{
....
public Profile getProfile(String userId)
{
return (Profile)findObject(new Object[]{userId});
}
}

}

Point cut was defined for JDBC template field defined in ProfileDaoImpl.

But the query was executed on JDBC template field of ProfileSQLQuery object. So interceptor was never fired.

Until unless we externalize (as a separate spring bean) query objects like ProfileSQLQuery from DAO’s and then define point cut for JDBC template field in it, it will not work.

So field level interception didn’t help to keep these sql objects as inner classes. If we have to externalize, we can very well use method level interception. Just define point cut for execute* and update* methods of SQLQuery/SqlUpdate objects.


Not sure if we can do away with externalizing query objects.