wood burning stoves 2.0*
The moose likes Developer Certification (SCJD/OCMJD) and the fly likes is this design OK? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Certification » Developer Certification (SCJD/OCMJD)
Bookmark "is this design OK?" Watch "is this design OK?" New topic
Author

is this design OK?

Yu Sun
Greenhorn

Joined: Nov 06, 2006
Posts: 29
Hi everyone,

In order to simplify the file reading / writing process, can I use a data cache Map <recordID, string[]>, and read all the data from the file into this Map in the beginning of the application, and write them back to the file in the end. All the operations in the middle are only performed in the cache. Is this OK?

If this is OK, we probably need to include the 1 Byte flag value in each String[] whenever needed, correct?

Thanks.

Yu
Carlos Morillo
Ranch Hand

Joined: Jun 06, 2009
Posts: 221

Hi Yu,

Yes, it is totally OK.
I took the same approach with
The exception of the byte flag
Which I do not store it in the
Map<Integer, String[]>.

Hope this helps,

Carlos.


SCSA, OCA, SCJP 5.0, SCJD http://www.linkedin.com/in/carlosamorillo
Yu Sun
Greenhorn

Joined: Nov 06, 2006
Posts: 29
Thanks a lot, Carlos.
Roel De Nijs
Bartender

Joined: Jul 19, 2004
Posts: 5139
    
  12

Hi Yu,

I used also a record cache approach. If you use search engine, you'll find tons of threads about this subject.

Do not include the "deleted" flag in your String[]. It doesn't make sense at all, I guarantee it will completely mess up your code,... More reasons why not to include it in String[] (or pojo) can be found here. You can simply store null in your map when the record is deleted.

Kind regards,
Roel


SCJA, SCJP (1.4 | 5.0 | 6.0), SCJD
http://www.javaroe.be/
Yu Sun
Greenhorn

Joined: Nov 06, 2006
Posts: 29
Hi Roel,

Thanks for the advice.

The only reason that I want to have deleted flag in String[] is to enable reusing deleted record when creating a new record, so that I can compare those deleted ones and see if I can reuse any of them. If we store null, how can we compare the records? Or we can store the flag info into a different structure, e.g., another Map <recNo, delelted flag>, right?

Thanks again.

Yu
Carlos Morillo
Ranch Hand

Joined: Jun 06, 2009
Posts: 221

Hi Yu,

I am using exactly the same approach.

There is no need to store the deleted flag, you just compare the stored value for an specific key
if it's equal to null or not.
If there are no null values once you iterate through all the keys, just create a new record.

When you write the cache to the file and you find a null value, write the deleted flag data record to the file.

HTH,

Carlos.
Yu Sun
Greenhorn

Joined: Nov 06, 2006
Posts: 29
Thanks Carlos. So, reusing deleted record only means reusing the deleted space, it is NOT necessary to have the same record content before reusing, correct? If that is the case, I am clear now.

Yu
Roel De Nijs
Bartender

Joined: Jul 19, 2004
Posts: 5139
    
  12

You just reuse the space of a deleted record when creating a new one, not the actual data of the deleted record. Should be obvious, because the create method has a String[] as parameter (which is the data for the new record). How would you reuse the same record content if the application used a RDBMS (instead of flat fil)e and delete from room where id = 1 actually deletes the record, no possibility to recover the actual field values of the deleted record.
Yu Sun
Greenhorn

Joined: Nov 06, 2006
Posts: 29
I see. Thanks Roel for my beginner question Now I am very clear about everything.
Roel De Nijs
Bartender

Joined: Jul 19, 2004
Posts: 5139
    
  12

Yu Sun wrote:Now I am very clear about everything.

So you finish the assignment without asking other questions
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: is this design OK?
 
Similar Threads
Data Validation
B&S 2.2.1 - dbAccess.findByCriteria method spec requires internal database?
desin issue
How do I know when I require synchronized access to cached data?
B&S: Opening database