How volatile is this list? If you can avoid the filter entirely, that would simplify things.
[ November 01, 2008: Message edited by: Bear Bibeault ]
[ November 02, 2008: Message edited by: John Schretz ]
If the list isn't different for every user, it's a simple matter to establish it once at app startup in application context using a context listener. If it's user-specific, it's also a simple matter to use the session and only load the list when it's not already there.
Does it not seem like incredible overkill to hit the DB at each and every request just to grab a list that doesn't often change?
[ November 02, 2008: Message edited by: Bear Bibeault ]
Originally posted by John Schretz:
you are absolutely right. the list is the same for all users. i will look into the context listener. if the list ever changed in the db and had to be updated would i just have to restart tomcat in order to refresh the list?
That'd be an easy way. But in most production environments, restarting the server is something that's avoided as much as possible so you could also have an admin servlet that you could hit (authenticated, please) to trigger a manual reload of the application-scoped variable whenever you update the database.
Or, you could even make the application-scoped variable "smart enough" to periodically check to see if it need to update its list -- but that's a more advanced topic.
You can include a check into the getVendors() method for ex. if the static list has been initialized, if not retrieve the data from the db otherwise get the content of the already populated data. If you need to reloaded call the other method (getVendorsFromDb() for ex)
It works for me for countries, currencies etc.
And you will inject all the serices and db logic there somehow (Spring or else)
Note: that the vendors attribute is private so you can access it only via the getter.
[ November 03, 2008: Message edited by: Tamas Jano ]