It's not a secret anymore!*
The moose likes Developer Certification (SCJD/OCMJD) and the fly likes Store records into collection Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Spring in Action this week in the Spring forum!
JavaRanch » Java Forums » Certification » Developer Certification (SCJD/OCMJD)
Bookmark "Store records into collection" Watch "Store records into collection" New topic
Author

Store records into collection

Richard Jackson
Ranch Hand

Joined: Jun 25, 2003
Posts: 128
Hi,all

I ever noticed that some candidates use collection (like Map or Set) to store locked record object.

But when I read records from the .db file, someone suggest me to put records into StringBuffer or Collection.

Is that suggestion available?
Please publish your experiences.Thanks in advance.

Regards,Richard


Regards, Richard
Steven Hoodless
Ranch Hand

Joined: Mar 23, 2004
Posts: 64
Richard,

I'm not sure I understand your question. Perhaps this might help?

Example: You have 6 records in your database and at this precise moment records 2 and 4 are locked. You need a way to associate the record number with the locking Client (Map) or you ignore who is locking the record and just store the locked records (Set).

I'll try and draw it diagramatically as a picture saves a thousand words..

Map

1
2 - Client Richard
3
4 - Client Steven
5
6

Set

1 - Record 2
2 - Record 4


I don't think a StringBuffer is much use here.

Regards,

Steven


SCJP, SCJD, SCWCD.
Hanna Habashy
Ranch Hand

Joined: Aug 20, 2003
Posts: 532
Richard,
This subject have been discussed many times in this forum. In general, there are two different methodlogy on how to read the db file.

The first method is to read the db file once, and then store all the information in a collection, so that all record will be available in memory. Of course, you have to make sure that it is in sync with the actual db file.

The second method is to leave everything in the db file, and access the file as needed. Similare to RDB access.

Both methods has its advantage and disadvantage. When the data is in memeory, you will have light speed performance. However, this approach in not scalable. If the data in the db file is too larg, the program will run out of memory. Also, you have to implement a good synchronizaiton technique to make sure that the data in memory is the same as in the db file.

When you access the db file on demand, i.e. search, update, delete, you have slower performance- not noticable for this project. However, this approach is more scalable, because one is not bound with the size of the db file.

YOu have to choose which method you are more comfortable with, because you have to explain it in you choice document.


SCJD 1.4<br />SCJP 1.4<br />-----------------------------------<br />"With regard to excellence, it is not enough to know, but we must try to have and use it.<br />" Aristotle
Richard Jackson
Ranch Hand

Joined: Jun 25, 2003
Posts: 128
Hi,Steven and Hanna

Thanks for your returns.

Steven:
I don't think a StringBuffer is much use here.

My friend said that he used StringBuffer to store records and return them in readRecords() method.And he used HashMap to store lock synchoronized records.

I am always confused about that.
Would please give me some methods to clarify that?


[B]Hanna[B/]
:-) The first method is to read the db file once, and then store all the information in a collection, so that all record will be available in memory. ...
:-) The second method is to leave everything in the db file, and access the file as needed. Similare to RDB access.

As you said,I want to select the first method to access the records into that .db file. So I am correct if I select Map to store them?

Regards, Richard
Hanna Habashy
Ranch Hand

Joined: Aug 20, 2003
Posts: 532
Richard,
I cannot tell you what did your friend do about using StringBuffer. Maybe he used different methodology.

Using a Map to store the data should be fine. Any collection should do as far as you know the limitation of each type of collection. If you are going with that approach, you should consider using value objects to represents each record.

Personally, I prefere the second approach-accessing the db file on demand. It is what I did in my project, but there were big debate about that, and many people prefere the first approach.
Eugenio Nassu
Greenhorn

Joined: Aug 09, 2004
Posts: 16
In my assignment:

"...They take bookings only within 48 hours of the start os room occupancy..."

I considered this indicates a not so big number of records, so the read all record approach makes sense for me...

I'm thinking the best way to store the records on client, not decided yet.


SCJP 1.4
Richard Jackson
Ranch Hand

Joined: Jun 25, 2003
Posts: 128
Thank you ,Hanna.

According what you said,I may store records to Map whenever operating data in "local" or "network" mode, isn't it?

There is still a problem.
I want to build a iterator for the new Map object (also above collection to put records).Are not any infections to data consistency?

Regards, Richard
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Store records into collection