• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

NX: Questions about deleted records

 
HaoZhe Xu
Ranch Hand
Posts: 222
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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?
 
Nicholas Cheung
Ranch Hand
Posts: 4982
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
George Marinkovich
Ranch Hand
Posts: 619
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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 ]
 
Javini Javono
Ranch Hand
Posts: 286
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Pie
Posts: 11915
209
C++ Firefox Browser IntelliJ IDE Java Mac Oracle
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
     
    Javini Javono
    Ranch Hand
    Posts: 286
    • Mark post as helpful
    • send pies
    • Quote
    • Report post to moderator
    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
    Posts: 619
    • Mark post as helpful
    • send pies
    • Quote
    • Report post to moderator
    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
    Posts: 286
    • Mark post as helpful
    • send pies
    • Quote
    • Report post to moderator
    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
    Posts: 286
    • Mark post as helpful
    • send pies
    • Quote
    • Report post to moderator
    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
     
    • Post Reply
    • Bookmark Topic Watch Topic
    • New Topic