Database and dataholderobjects and performanceproblem
Gooood morning,
my problem is that: With using the db i must map the db with objects. At the moment i map 1 to 1 means:
The databasetable user exists as an class with colums as member.
I have a querymanager who contains all methods which interact with the db.If i have a method getAllUser(), then i need a dataobject who contains all colums but if i have a method getUserFirstNameOnly(), then i need only one member in the dataholderobject.
I made a benchmark with two classes. One contains 3 member and the other contains 8. After a 1 milion iteration the _small_object needs 1200 milliseconds and the _big_ object 1800!
And now i have a little problem by using the _big_ class if i dont need all members but on the outher side, i dont have fun to create for every query an extra dataholderclass :(
Ideas?
And know anybody a objectpoolmethod? I mean i can create a lot of objects in the ram and use it new and dont delete it. I must create a lot of time objects and i will optimize it!
[1038 byte] By [
Sicainea] at [2007-10-2 14:31:14]

Have one data object that holds one row of data. Then use an ArrayList to hold multiples of this one object (one for each row).
See: http://java.sun.com/j2se/1.5.0/docs/api/java/util/ArrayList.html
If you will usually be accessing the data in order of first -> next -> next (rather than randomly), then the LinkedList may be better.
See: http://java.sun.com/j2se/1.5.0/docs/api/java/util/LinkedList.html
But, of course, for the sake of keeping your code as general as possible, except for the initial instiation, you should refer to your xxxList as the general List interface:
See: http://java.sun.com/j2se/1.5.0/docs/api/java/util/List.html
The best part of the List is that it is as small as you define (set by the initialCapacity), and grows only as needed. So you can start small then get big, if needed, without extra work on your part.
As for the Object Pool method, doing a google search should lead to some nice demos. Be sure to check out Java World's bit on recyclers for object pools (helps prevent problems associated with re-using objects that have failed).