|
From: Dmitriy K. <dko...@ru...> - 2006-03-17 18:52:10
|
Dmitriy Kopylenko wrote:
>>
>> So it would seem that my only option is to subclass LSFB and modify
>> the behavior of those to collect the error messages and pass them on
>> up. I would think, however that those methods could benefit from
>> clearer javadoc comments on what I've just covered, and it would be
>> nice to be able to obtain that output (or to at least know somehow) to
>> be able to determine if any errors were generated, and have some sort
>> of output on the reasons why, since there is no way to accomplish that
>> right now without subclassing the LSFB itself (as far as I can see) -
>> and I'm somewhat leery of having to maintain a subclass of LSFB for
>> the entire foreseeable future of the application since it is such a
>> critical part of the spring/hibernate functionality. If I'm mistaken
>> on this, I'd greatly appreciate a point in the right direction.
>>
>
> If you call *DatabaseSchema() methods directly on LSFB instance, I
> think there could be more modular, cleaner, etc. solution than
> extending LSFB, by using AspectJ with Inter-Type declaration and
> "handler" pointcut designator...
>
>
Here's how you could possibly do it:
public aspect DatabaseShemaOperationsErrorsCollector {
private List<SQLException> LocalSessionFactoryBean.exceptions = new
ArrayList<SQLException>();
public List<SQLException>
LocalSessionFactoryBean.getDatabaseShemaErrors() {
return this.exceptions;
}
private void
LocalSessionFactoryBean.recordDatabaseSchemaException(SQLException
sqlException) {
this.exceptions.add(sqlException);
}
public pointcut databaseSchemaOperationExceptionHandler(SQLException
sqlException, LocalSessionFactoryBean localSessionFactoryBean):
handler(SQLException) &&
args(sqlException) &&
this(localSessionFactoryBean);
before(SQLException sqlException, LocalSessionFactoryBean
localSessionFactoryBean) :
databaseSchemaOperationExceptionHandler(sqlException,
localSessionFactoryBean) {
localSessionFactoryBean.recordDatabaseSchemaException(sqlException);
}
}
|