aspose file tools*
The moose likes Developer Certification (SCJD/OCMJD) and the fly likes Deleted Items 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 "Deleted Items" Watch "Deleted Items" New topic
Author

Deleted Items

Kevin Broderick
Ranch Hand

Joined: Jul 19, 2009
Posts: 39
I've being revisiting a method readRecord, and one thing that escaped me was deleted items. should this function return deleted items?

Thanks
Roberto Perillo
Bartender

Joined: Dec 28, 2007
Posts: 2266
    
    3

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.


Cheers, Bob "John Lennon" Perillo
SCJP, SCWCD, SCJD, SCBCD - Daileon: A Tool for Enabling Domain Annotations
Kevin Broderick
Ranch Hand

Joined: Jul 19, 2009
Posts: 39
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
Jeffry Kristianto Yanuar
Ranch Hand

Joined: Oct 01, 2007
Posts: 759
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

Joined: Oct 01, 2007
Posts: 759
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
Ehsan Rahman
Ranch Hand

Joined: Feb 16, 2009
Posts: 59

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?


SCJP 1.5, SCJD 1.6
Roberto Perillo
Bartender

Joined: Dec 28, 2007
Posts: 2266
    
    3

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

Joined: Feb 16, 2009
Posts: 59

Howdy all & thanks Roberto.
Kevin Broderick
Ranch Hand

Joined: Jul 19, 2009
Posts: 39
Hey all, thanks Roberto, Jefy, Ehsan - thank you all
Carlos Morillo
Ranch Hand

Joined: Jun 06, 2009
Posts: 221

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.


SCSA, OCA, SCJP 5.0, SCJD, CCDH, CCAH http://www.linkedin.com/in/carlosamorillo
Nicolas Kal
Ranch Hand

Joined: Sep 09, 2009
Posts: 69
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


[Thumbnail for deleted entries.jpg]



SCJP 6.0 , SBCD (Preparing..),
MSc Enterprise Systems Development, BSc Computer Science
Roel De Nijs
Bartender

Joined: Jul 19, 2004
Posts: 5407
    
  13

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


SCJA, SCJP (1.4 | 5.0 | 6.0), SCJD
http://www.javaroe.be/
Carlos Morillo
Ranch Hand

Joined: Jun 06, 2009
Posts: 221

Hi Roel,


Thanks a lot!


Definitely I need to simplify my assumptions.



Best Regards,


Carlos.
 
 
subject: Deleted Items