Win a copy of Design for the Mind this week in the Design forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

is this design OK?

 
Yu Sun
Greenhorn
Posts: 29
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 221
Java Python Scala
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Yu Sun
Greenhorn
Posts: 29
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks a lot, Carlos.
 
Roel De Nijs
Sheriff
Posts: 9929
113
AngularJS Chrome Eclipse IDE Hibernate Java jQuery MySQL Database Spring Tomcat Server
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
Yu Sun
Greenhorn
Posts: 29
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 221
Java Python Scala
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 29
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Sheriff
Posts: 9929
113
AngularJS Chrome Eclipse IDE Hibernate Java jQuery MySQL Database Spring Tomcat Server
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 29
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I see. Thanks Roel for my beginner question Now I am very clear about everything.
 
Roel De Nijs
Sheriff
Posts: 9929
113
AngularJS Chrome Eclipse IDE Hibernate Java jQuery MySQL Database Spring Tomcat Server
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Yu Sun wrote:Now I am very clear about everything.

So you finish the assignment without asking other questions
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic