SQLErrorCodesExceptionTranslator using database table for exception translation
Hi all,
I have a custom SQLErrorCodesExceptionTranslator set into a JdbcTemplate. This template will help me execute stored procedures, which are part of a legacy system I wish to integrate. These stored procedures take their error codes and messages from a database table. What would be the correct way to have my custom error translator read the table, look for an error code and throw a custom app exception with the message specified in the table?
I was thinking of setting the same jdbcTemplate property for my custom translator, so I can use it to execute the queries that will manage my error codes, but I do not know if it is a good idea.
Any suggestions or best-practice advice will help.
Regards.
J.
if you'll se the same jdbcTemplate you'll get a circular dependency (both code and logic). The most efficient way would be to get the code from the database inside the XML file so you don't have to query the db. If however you have to query the db simply use an inner bean with a new jdbcTemplate so in case quering for the exception fails you'll get a generic exception (which is not translated).
Thank you, costin, I'll try both approaches and post any results I come up with. One other thing...what exactly do you mean by 'pouring' the table data to the XML file? do you mean the appCtx file? or a custom properties xml file for the translator to read?
Regards.
J.
'pouring' the table data to the XML file?
I meant instead of quering the database to store the codes somewhere on the disk. In most of the types the list is not that big and storing this information inside a configuration can be a lot more efficient as you can load the file only once at application startup and then cache them - basically what the SQL translator does with the xml file. |