Win a copy of Functional Reactive Programming this week in the Other Languages forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Store records into collection

 
Richard Jackson
Ranch Hand
Posts: 128
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
Steven Hoodless
Ranch Hand
Posts: 64
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
Hanna Habashy
Ranch Hand
Posts: 532
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Richard Jackson
Ranch Hand
Posts: 128
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 532
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 16
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Richard Jackson
Ranch Hand
Posts: 128
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic