aspose file tools*
The moose likes Developer Certification (SCJD/OCMJD) and the fly likes NX: Questions about deleted records Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Certification » Developer Certification (SCJD/OCMJD)
Bookmark "NX: Questions about deleted records" Watch "NX: Questions about deleted records" New topic
Author

NX: Questions about deleted records

HaoZhe Xu
Ranch Hand

Joined: Nov 03, 2003
Posts: 222
1.Can the find(String [] criteria) method return a deleted record?
2.Can the update(int recNo, String [] data) method update a deleted record?
if not, should I throw RecordNotFoundException?


[url]Olnex.net[/url]
[SCJP 1.2, SCJD, SCWCD]
Nicholas Cheung
Ranch Hand

Joined: Nov 07, 2003
Posts: 4982
Hi HaoZhe,

1.Can the find(String [] criteria) method return a deleted record?

NO.

2.Can the update(int recNo, String [] data) method update a deleted record?

Definitely NO. The function should throw RecordNotFoundException in this case.
Nick.


SCJP 1.2, OCP 9i DBA, SCWCD 1.3, SCJP 1.4 (SAI), SCJD 1.4, SCWCD 1.4 (Beta), ICED (IBM 287, IBM 484, IBM 486), SCMAD 1.0 (Beta), SCBCD 1.3, ICSD (IBM 288), ICDBA (IBM 700, IBM 701), SCDJWS, ICSD (IBM 348), OCP 10g DBA (Beta), SCJP 5.0 (Beta), SCJA 1.0 (Beta), MCP(70-270), SCBCD 5.0 (Beta), SCJP 6.0, SCEA for JEE5 (in progress)
George Marinkovich
Ranch Hand

Joined: Apr 15, 2003
Posts: 619
Nick posted his answer while I was still composing mine. It's the same answer, pick your favorite flavor: consise above, verbose below.
1.Can the find(String [] criteria) method return a deleted record?
No
if not, should I throw RecordNotFoundException?
Q: What does the RecordNotFoundException mean?
A: I think it means we were looking for a record and couldn't find it.
Q: What is the purpose of the find method?
A: To return an array of record numbers that match the criteria.
Q: Does the searching algorithm consider deleted records?
A: I don't think it should. Deleted records don't exist.
Q: So does the find method ever try to match a deleted record?
A: No.
Q: So, since we would never try to "find" a deleted record, would we ever need to throw the RecordNotFoundException for a deleted record?
A: No.
2.Can the update(int recNo, String [] data) method update a deleted record?
No
if not, should I throw RecordNotFoundException?
Q: In an update are we looking to update a specific record number?
A: Yes
Q: If that record number doesn't exist (perhaps because it's been marked for deletion) what should happen?
A: Seems like an appropriate time to throw the RecordNotFoundException.
Hope this helps,
George
[ January 06, 2004: Message edited by: George Marinkovich ]

Regards, George
SCJP, SCJD, SCWCD, SCBCD
Javini Javono
Ranch Hand

Joined: Dec 03, 2003
Posts: 286
Originally posted by HaoZhe XU:
1.Can the find(String [] criteria) method return a deleted record?
2.Can the update(int recNo, String [] data) method update a deleted record?
if not, should I throw RecordNotFoundException?

Hi,
I may not be the best person to respond, as often my ideas are considered
far from mainstream; and, if I implement my ideas, it has been suggested,
and perhaps quite validly, that I might fail or get an automatic failure.
I think you are asking the correct questions. That is, I went through my
DBMain interface thoroughly, looking at all the cases, and all the exceptions
to see if the DBMain interface made sense and was consistent.
2.Can the update(int recNo, String [] data) method update a deleted record?
It depends how you end up defining your method, and how all the methods
will make sense together. My ideas are presumably not mainstream, but
theoretically, I would think it could, as it might change the deleted flag
to undeleted or vice versa. If this is your interpretation, then you have
to define the data array to contain both physical and logical record data--
an idea which presumably is not mainstream, and some might think,
correctly, that it could lead to automatic failure.
Others might have other ways of handling how a record is deleted and
undeleted (either they don't implement it, perhaps, or they add additional
methods to carry out this function).
So, I personally think it good to ask thorough questions about this DBMain
interface, and to be guided by a principle: that it be consistent and perform
the functions you need while at the same time fitting into your over-all design.
But, my impression is that my ideas are not mainstream, so consider them
at your own risk.
But, putting aside risk, one of the most enjoyable aspects of this assignment
was asking myself questions about DBMain and finding solutions.
Thanks,
Javini Javono
Andrew Monkhouse
author and jackaroo
Marshal Commander

Joined: Mar 28, 2003
Posts: 11525
    
100

Hi Javini,
You are definately non mainstream

Originally posted by HaoZhe XU:
2.Can the update(int recNo, String [] data) method update a deleted record?
Originally posted by Javini Javono:
It depends how you end up defining your method, and how all the methods will make sense together. My ideas are presumably not mainstream, but theoretically, I would think it could, as it might change the deleted flag to undeleted or vice versa.

Once the record is deleted it is gone permanently. I think you may even have an instruction telling you that the space occupied by the deleted record may be used by the next record that is created.
To give you an impossible question:
  • Record number 5 contains the value "Sams business"
  • Client 1 deletes record number 5
  • Client 2 adds a new record "Bills business" which happens to overwrite record 5
  • Client 3 searches for all records matching "Bill" and gets record number 5
  • Client 1 does an update which is designed to "undelete" record 5


  • Now what happens? Client 1 believes it is working with record 5 = "Sams business" and client 3 believes it is working with record 5 = "Bills Business". Who is right?
    It is only if a record is totally discarded when it is deleted that you can avoid that conundrum.
    It does raise the question though, of what you should check when you do a booking - since in that scenario you could be booking the wrong record.
    Regards, Andrew


    The Sun Certified Java Developer Exam with J2SE 5: paper version from Amazon, PDF from Apress, Online reference: Books 24x7 Personal blog
    Javini Javono
    Ranch Hand

    Joined: Dec 03, 2003
    Posts: 286
    Hi,
    I think your addressing me?
    To give you an impossible question:
    Record number 5 contains the value "Sams business"
    Client 1 deletes record number 5
    Client 2 adds a new record "Bills business" which happens to overwrite record 5
    Client 3 searches for all records matching "Bill" and gets record number 5
    Client 1 does an update which is designed to "undelete" record 5
    Now what happens? Client 1 believes it is working with record 5 = "Sams business" and client 3 believes it is working with record 5 = "Bills Business". Who is right?
    It is only if a record is totally discarded when it is deleted that you can avoid that conundrum

    To give you an impossible question:
    Record number 5 contains the value "Sams business"
    5: Active: "Sams business"
    Client 1 deletes record number 5
    5: Inactive: "Sams business"
    Client 2 adds a new record "Bills business" which happens to overwrite record 5
    5: Active: "Bills business"
    Client 3 searches for all records matching "Bill" and gets record number 5
    Agreed.
    Client 1 does an update which is designed to "undelete" record 5
    Illegal: record 5 is already "undeleted".
    Now what happens? Client 1 believes it is working with record 5 = "Sams business" and client 3 believes it is working with record 5 = "Bills Business". Who is right?
    Again, I'm not sure you are addressing me or people in general.
    Assuming that you use some of the methods to read and update
    both physical (the active/inactive flag) and logical data,
    then you need another layer on top of this to carry out
    more logical types of questions: such as: you can't undelete
    a record which is not deleted.
    It is only if a record is totally discarded when it is deleted that you can avoid that conundrum

    thanks,
    Javini Javono
    George Marinkovich
    Ranch Hand

    Joined: Apr 15, 2003
    Posts: 619
    It is only if a record is totally discarded when it is deleted that you can avoid that conundrum.
    I think that's true. The alternative leads to serious problems as you outline.
    It does raise the question though, of what you should check when you do a booking - since in that scenario you could be booking the wrong record.
    If booking is conducted as follows:
    1. lock(recNo);
    2. String[] record = read(recNo);
    3. allow user to edit the record
    4. update(recNo, record);
    5. unlock(recNo)
    Any mistaken notions as to the record that is being updated are resolved in step 2. The user in step 3 is seeing the true contents of recNo. I think this handles the problem you raise.
    Javini Javono
    Ranch Hand

    Joined: Dec 03, 2003
    Posts: 286
    Hi,
    Thanks for your impossible question; clearly, there are
    subtleties of logic involved in this, so I find this
    quite interesting.

    To give you an impossible question:
    Record number 5 contains the value "Sams business"
    5: Active: "Sams business"
    Client 1 deletes record number 5
    5: Inactive: "Sams business"
    Client 2 adds a new record "Bills business" which happens to overwrite record 5
    5: Active: "Bills business"
    Client 3 searches for all records matching "Bill" and gets record number 5
    Agreed.
    Client 1 does an update which is designed to "undelete" record 5
    Illegal: record 5 is already "undeleted".
    Now what happens? Client 1 believes it is working with record 5 = "Sams business" and client 3 believes it is working with record 5 = "Bills Business". Who is right?

    I sort of answered this before, but it may have been unclear;
    furthermore, by answering again and clarifying, I learn also
    and may prove my own assertions wrong (which is fine).
    In my design, the client will never request that any operation
    be performed on the database that involves physical database data
    (such as handling whether the record is inactive or active). The
    client can only ask for a task involving the logical data (name,
    address, zip, et cetera): 1) read physical record N; 2) create
    a new record, 3) update physical record M.
    This is why the client can't say,
    "Client 1 does an update which is designed to "undelete" record 5."
    Because the client simply has no authority in my
    design to modify physical database attributes such
    as whether the record is active or inactive.
    The client can only say things like, "add this
    new record to the database" Then the server
    is responsible for creating a new record.
    However, your "impossible question" is indeed very
    tricky, and I thank you much for presenting it.
    Furthermore, it is unclear that my response even
    addresses this tricky question's subtleties.
    So, in my initial draft, I will never set the
    inactive flag from inactive to active; instead, when a new
    record is created, it must be appended to the end
    of the file.
    I will then attach your "impossible question" to my
    software comments (non JavaDoc). And, if at some
    future time I decide to get fancy and let the server
    re-use an inactive record, I will think twice (or for me
    I may need to think five times!) while reviewing your
    impossible question. For my requirements allow the
    create method to "Create a new record in the database
    (possibly reusing a deleted entry)." Thus, I'm not
    forced to re-use a deleted entry.
    Again, I'm not sure that my response logically and
    correctly addresses your impossible question, but
    I appreciate much your presentation.
    Thanks,
    Javini Javono
    Javini Javono
    Ranch Hand

    Joined: Dec 03, 2003
    Posts: 286
    Hi,
    And, it just occurred to me, when my server starts
    up either in alone mode or as a real networked server,
    it will
    1. Check the database for consistency.
    2. Compact the database.
    3. Recheck the database for consistency.
    4. Start accepting client request.
    Thanks,
    Javini Javono
     
    I agree. Here's the link: http://aspose.com/file-tools
     
    subject: NX: Questions about deleted records