• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Deleted Items

 
Ranch Hand
Posts: 39
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I've being revisiting a method readRecord, and one thing that escaped me was deleted items. should this function return deleted items?

Thanks
 
Bartender
Posts: 2292
3
Eclipse IDE Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hum... no. And here's what I did: if you try to read a record whose number is marked as deleted, a RecordNotFoundException is thrown. Take a look at the interface that was provided to you; if your readRecord throws RecordNotFoundException, then you can throw it.
 
Kevin Broderick
Ranch Hand
Posts: 39
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks Roberto...but NOW heres another question. Looking at the deleteRecord and createRecord methods, their comments led me to believe that the record is physically removed, for instance:



But if we are setting a flag on our field to mean a record is deleted AND the data is to be manipulated for reports, then surly we should not delete the record physically from disk.

Would my assumptions be correct?

Many Thanks
 
Ranch Hand
Posts: 759
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Here's what I did.

When I delete the record, I just set the flag byte and put that deleted record number to a Map. When I add new record, I check the Map for the deleted record. If any, I use that record number and overwrite the bytes on that record number (I think it is what the specification means on "making the record number and associated disk storage available for reuse."). If not any, I use the last record number + 1.

Whatever your choice, just make sure it is not against the specification and make sure that you document it. Please consider the other's opinion too.


Jeffry Kristianto Yanuar SCJP, SCJA, SCJD
 
Jeffry Kristianto Yanuar
Ranch Hand
Posts: 759
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Good luck on your exam. Don't forget to post on the wall of fame once you pass the exam.

Jeffry Kristianto Yanuar SCJP, SCJA, SCJD
 
Ranch Hand
Posts: 59
Netbeans IDE VI Editor Chrome
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Not to put a spanner in the works, I've been considering a logical delete rather than a physical delete.

Advantages include:
- a clear trace of deleted records if any disputes arise (either by the customer or contractor company)
- a clear trace for any legal auditing
- clearer code for a junior programmer
- a more open implementation (in the case client really does want a physical delete in the future)

As far as the must requirements, here is my take:



I read this as "marking the record's storage bits for reuse".


Here is the open part: by using the words 'possibly reusing a deleted entry', does this mean:

A) In the case that there are deleted records, you must reuse them (the physical bits).
or
B) In the case there are deleted records, you may wish to consider reusing a deleted entry (the physical bits).

There is also another interpretation: C) Reuse a deleted entry in the sense of making a deleted item active again.

Do you think logical deletion is violating the requirements?
 
Roberto Perillo
Bartender
Posts: 2292
3
Eclipse IDE Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Howdy, y'all.

The "status" flag tells us whether the record is valid or not. So, if a record is marked as "deleted", then it only exists in the file and this entry can be reused. For instance, in the case of the URLyBird assignment, it shouldn't be possible to book a room whose record is deleted. The records to be displayed in the JTable should only be valid records. So, Ehsan is correct by only considering it as a logical delete.

Ehsan Rahman wrote:A) In the case that there are deleted records, you must reuse them (the physical bits).
or
B) In the case there are deleted records, you may wish to consider reusing a deleted entry (the physical bits).



Some people chose not to reuse deleted entries and justified this choice. I myself chose to reuse deleted entries.

Ehsan Rahman wrote:There is also another interpretation: C) Reuse a deleted entry in the sense of making a deleted item active again.



This is not a requirement, that is, making a deleted record active again. So, once it is deleted, it is deleted (and deleting a record is not also a requirement of the assignment). A new record can fit this position in the .db file, overwriting the old record (and creating a record is not also a requirement). But even though creating or deleting records are not a requirement, these methods must have valid implementations.
 
Ehsan Rahman
Ranch Hand
Posts: 59
Netbeans IDE VI Editor Chrome
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Howdy all & thanks Roberto.
 
Kevin Broderick
Ranch Hand
Posts: 39
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hey all, thanks Roberto, Jefy, Ehsan - thank you all
 
Ranch Hand
Posts: 221
Scala Python Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,


I've been following these threads and reading them carefully before I start coding my Data Class implementing the Sun interface for URLyBird 1.1.3.

I am still slightly confused using a Cache approach loading all the hotel records in a Map if when I read the file for the first time about what should I do:


1. Load in the Cache only valid records with 00 (in my assignment deleted record have 0xFF).

2. Either in my Room class containing a String[] and another member variable for the status or have a separate Status Map<Record Number, Valid Status of that Hotel Room>.


I am considering these options just in terms of possibly reusing a Deleted Record in the File when I create a New Record according to my interface.


Hopefully I am not getting too complicated with the Assumptions I am making or perhaps there is a more simpler, easier and more elegant way to accomplish this.


Your Thoughts?


Thanks,


Carlos.
 
Ranch Hand
Posts: 69
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Heellloo everyone!

In my approach I have chosen to display deleted entries. If the user wants can then undelete the hotels records. The deleted records are marked with red colour in the JTable in order to distinguish from the other. According to my opinion its up to the developer and how the solution will be justified on the choices.txt in order to be acceptable..

Regards,
Nicolas
deleted-entries.jpg
[Thumbnail for deleted-entries.jpg]
 
Sheriff
Posts: 11604
178
Hibernate jQuery Eclipse IDE Spring MySQL Database AngularJS Tomcat Server Chrome Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Carlos,

I used also a map as record cache and when I read the file for the first time I store the recNo with the String array or null (if the record has deleted flag). And that's it!
When I need a record number for a new record I just iterate over my map and if I encounter a null-value I use that recNo as the new record number, otherwise just the size of the map (+ 1 if your recNo is 1-based)

I don't think it gets any easier than this.

Kind regards,
Roel
 
Carlos Morillo
Ranch Hand
Posts: 221
Scala Python Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Roel,


Thanks a lot!


Definitely I need to simplify my assumptions.



Best Regards,


Carlos.
 
Don't get me started about those stupid light bulbs.
reply
    Bookmark Topic Watch Topic
  • New Topic