aspose file tools*
The moose likes Servlets and the fly likes Servlets and PropertyResourceBundle Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Servlets
Bookmark "Servlets and PropertyResourceBundle" Watch "Servlets and PropertyResourceBundle" New topic
Author

Servlets and PropertyResourceBundle

Michael Szul
Ranch Hand

Joined: Sep 18, 2001
Posts: 57
My company is developing a Java Servlet based program. I came in about halfway through the initial bare-bones development, so some things were already in place.
I'm a little at odds with my technical lead over the issue of property files.
She doesn't want me to hardcode SQL Select statements in my code (exp: String query = "SELECT * FROM WHATEVER_FILE").
Instead she wants me to write the statement in an external properties file and do this:
PropertyResourceBundle prp = (PropertyResourceBundle) PropertyResourceBundle.getBundle("resources.whatever");
String query = prp.getString("WHATEVER_STATMENT");
I am under the impression that a PropertyResourceBundle creates a collection of Strings. Our properties file has over 110 key / value pairs.
Am I right in thinking that using a property file in this manner is creating a large chunk of objects that are memory-intensive, and it would be more efficient to just use a String in the code?
... and in actuality the properties file isn't even used in a dynamic manner. It's just her way of keeping all the select statements in one place.
thanks,
Beksy Kurian
Ranch Hand

Joined: Jul 11, 2001
Posts: 254
Why don't you use stored procedures instead? You can keep all the sql statements in one place that way.
Regards
Beksy
Michael Szul
Ranch Hand

Joined: Sep 18, 2001
Posts: 57
We do use some stored procedures, but that's not the issue. I was just giving a general example. We select from other things as well, using our own defined classes (which extend HashMap, etc).
I'm just interested in the comparison of speed and memory between the use of property files in this way as opposed to a simple string.

thanks,
achana chan
Ranch Hand

Joined: Jul 29, 2002
Posts: 277
Hi.
I use a combination of JNDI and .properties.
I find the properties file a much cleaner way to manage systems since my codes can access settings without recompiling e.g. database access.
You access the .properties like this :
mybundle = ResourceBundle.getBundle("bundleName");
I don't know whether you can get the program to reload the "bundle" on the fly without restarting, but, hey , it's worth a try.
Hope that helps.


humanum errare est.
Michael Szul
Ranch Hand

Joined: Sep 18, 2001
Posts: 57
Everybody is bringing up interesting points, but I'm still not coming across the answer I'd hope for.
What I need is somebody to explain to me briefy the memory allocation of a PropertyResourceBundle.
It seems to be a Collection of String objects, which would mean that a file with 110 key / value pairs would create an object containing 110 String objects, when the PropertyResourceBundle is initialized.
To me this seems less efficient than a simple string when we talk in concepts of my original example.
Does anyone know the answer?
thanks,
Maulin Vasavada
Ranch Hand

Joined: Nov 04, 2001
Posts: 1871
hi all,
i'm not that much experienced with anything like this. i've never used ResourceBundle and stuff (i'm scared of it :-))
i've used Properties instead. can't we use that here. of course we will have to look for escape sequence as we need to put sql in double quotes to get it as a single value.
e.g.
sql1 = "select * from abcd"
sql2 = "select * from abcd where name='myname'"
etc...
please thro more light if i sound totally out of synch here
regards
maulin
Thomas Mcfarrow
Ranch Hand

Joined: Jul 09, 2001
Posts: 137
my $.02. The only thing I ever used resource bundles for was for translation of strings. Isn't that the main use for it?
We used stored procedures for select statements.
TM
SCJP
SCWCD
Rick Hightower
Author
Ranch Hand

Joined: Feb 20, 2002
Posts: 350
110 strings does not seem like that much overhead.
make sure you only load the resource once, i.e., static.
no big deal.....
Why aren't you using JDO or EJB CMP/CMR?
Much nicer than straight SQL with JDBC.


Rick Hightower is CTO of Mammatus which focuses on Cloud Computing, EC2, etc. Rick is invovled in Java CDI and Java EE as well. linkedin,twitter,blog
zb cong
Ranch Hand

Joined: Jan 14, 2002
Posts: 416
hello
i think the advantage of using the properites file to store the sql statement is to decouple your application from your database,certainly using stored procedure provide such benefit too,and using procedure can be more efficient than using sql statemen.
as for if the 110-key properties files will exhausted much resource,i think it is not a deal to the application server,but if your server only have 32M memory,you should be careful.
summarilly,i think both of the stored procedure and properties file are good solution,and don't hard code your sql statement!
Ashok Mash
Ranch Hand

Joined: Oct 13, 2000
Posts: 1936
As I understand it, ResourceBundle mechanism in itself is maintaining a static instance of the bundle internally. That is, it is a singleton internally, and so we can safely assume that a couple of hundred keys in the memory wont be much of a overload.


[ flickr ]
John O'Hanley
Greenhorn

Joined: Oct 13, 2002
Posts: 24
I agree with your boss on this one. Keeping the
SQL as text, outside of the compiled code base, is
highly advantageous. The concern regarding performance seems like pre-mature optimization to me...
http://www.javapractices.com/Topic105.html
jayram
Ranch Hand

Joined: Oct 30, 2000
Posts: 94
why not keep all the SQLs in an interface as strings and the using them in classes which are actually querrying the database
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Servlets and PropertyResourceBundle