On Wed, 29 Nov 2000 09:47:28 +0100, Francesco Marchioni
<[EMAIL PROTECTED]> wrote:
>1) Is it a bad idea to put plain SQL queries in Session Beans ?
>
>I need somewhere in my code to make generic Sql queries to fill up
>some combos with values- since every combo has its own query
>I provided a config file in XML with the single query for every combo.
>
>Then I just wrote a method in my Session bean a method like this:
>
>Collection readSQL (String sql, params) {
>
>... execute query with params
>
>....fill up Collection with Resultset
>
>...return Collection
>}
>
>is it a clean solution- technically speaking? or do I need to
>contact Entity Beans and use their find methods ?
Seems like a good idea to me.
One additional thing you may want to do is if the data is fairly static
then cache the results in the session bean. I.e. keep a hashtable with
sql as key and result collection as value. If the sql string is in the
hashtable, then return the collection. If not then query the db and put
the result in the hashtable. If the data is semi-static you could also
use a timeout to refresh from the db. This will make your system much
speedier and you will put less strain on the db. If you use a static
hashtable make sure you use synchronized properly when updating the
hashtable.
/Rickard
--
Rickard �berg
Email: [EMAIL PROTECTED]
===========================================================================
To unsubscribe, send email to [EMAIL PROTECTED] and include in the body
of the message "signoff EJB-INTEREST". For general help, send email to
[EMAIL PROTECTED] and include in the body of the message "help".