|
From: Tim K. <tim...@gm...> - 2006-03-14 19:13:43
|
I was punting around this for a good while before taking five minutes to look at the source for the LocalSessionFactoryBean and having one of those 'oh-doh' moments. I now feel that the javadocs for those methods are misleading. What I was working on was a setup module for our webapp that would create/initialize the schema via a web-based UI.. and was using the LSFB methods to facilate that functionality. What I wanted to do was trap any exceptions that arose from the schema methods so that they could be displayed on the UI if there was a schema creation error. Looking at the javadocs for those schema methods, in particular the 'Throws' part in the javadoc where it says 'DataAccessException - in case of script execution errors' it seemed natural to assume that catching DataAccessException would do the trick. But no matter how many sacrifical lambs i put up, I was unable to trap *any* kind of exception, even though I could see the exception output in the logs. I was starting to question my competence as a programmer and my sanity. So after looking thru the source for the LSFB, I see that those schema methods call the 'executeSchemaStatement' and 'executeSchemaScript' methods internally. And to their credit to some degree, the javadocs for those methods do mention this: "Note that the default implementation will log unsuccessful statements and continue to execute. Override the executeSchemaStatement method to treat failures differently." So THAT explains why I wasn't able to trap the exception being thrown, and was seeing them in the logs. Simply by looking at the javadocs by itself, a programmer (or at least a simple one like me) wouldn't immediately make the association that those schema methods would call the executeSchemaStatements internally and that any schema errors would be logged and that DAE would not be thrown at all. That was only obvious after looking at the source code. 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. Also, slightly related, but is there a reason why 'updateDatabaseSchema' throws HibernateException while the other two 'create'/'dropDatabaseSchema' methods throw DataAccessException? Thanks! -tim |
|
From: Dmitriy K. <dko...@ru...> - 2006-03-15 02:38:56
|
> > 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... > Also, slightly related, but is there a reason why > 'updateDatabaseSchema' throws HibernateException while the other two > 'create'/'dropDatabaseSchema' methods throw DataAccessException? > I've fixed that in CVS. Regards, Dmitriy. |
|
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);
}
}
|
|
From: Tim K. <tim...@gm...> - 2006-03-17 19:47:33
|
Dmitriy,
Thanks for writing in with the suggestion. I will certainly give this a
try.
I still think, however, that it would be useful if the stock LSFB methods
would at least return some type of output regarding the operations that
occurred inside, or at least throw DAE.. since the javadocs are misleading
in that sense when they suggest that DAE will be thrown upon script
compilation errors. That's my view, at least.
Thanks again,
-tim
-----Original Message-----
From: spr...@li...
[mailto:spr...@li...] On Behalf Of
Dmitriy Kopylenko
Sent: Friday, March 17, 2006 1:52 PM
To: spr...@li...
Subject: Re: [Springframework-developer] somewhat confusing behavior w/ LSFB
create/update/dropSchema methods.
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);
}
}
-------------------------------------------------------
This SF.Net email is sponsored by xPML, a groundbreaking scripting language
that extends applications into web and mobile media. Attend the live webcast
and join the prime developer group breaking into this new coding territory!
http://sel.as-us.falkag.net/sel?cmd=lnk&kid=110944&bid=241720&dat=121642
_______________________________________________
Springframework-developer mailing list
Spr...@li...
https://lists.sourceforge.net/lists/listinfo/springframework-developer
|