• 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

B&S: How to create a new record, when identical record exist but marked as deleted?

 
Ranch Hand
Posts: 1855
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,

concerning the implementation of Data's create method my assignment says:

Creates a new record in the database (possibly reusing a deleted entry) ...



Now how do you handle it, when the same record you want to create already exist in the database (data file) with the deleted flag set.

Do you allow the new record to be created or do you throw a DuplicateKeyException?

Regards,
Darya
 
Ranch Hand
Posts: 357
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Darya,

This is an often asked question. Try searching the forum for other threads concerning this issue.

Personally, I choose to allow this. I defined the recordNumber as the primary key and since it can never be duplicate, my Data class would never throw a DuplicateKeyException.

Frans.

P.S. in case you choose to forbid duplicate records, think how you will implement the update method! It doesn't throw an DuplicateKeyException, but might update the record such that it will become identical to one that already exists.
[ June 08, 2005: Message edited by: Frans Janssen ]
 
Ranch Hand
Posts: 85
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by Frans Janssen:


Personally, I choose to allow this. I defined the recordNumber as the primary key and since it can never be duplicate, my Data class would never throw a DuplicateKeyException.



Frans,

If you used the record number as PK, how did you avoid the scenario where ClientB deletes and then creates a new record (reusing the space) and now ClientA has a recNo that references the new record created by clientB??
 
Darya Akbari
Ranch Hand
Posts: 1855
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Frans,

Honestly I didn't find topics that discuss my question .

So in this special case where a duplicate of my new record exist in the database but with its flag set to deleted you allow to create the new record and reuse the record number and don't throw a DuplicateException

In case the record's flag set to valid, you throw a DuplicateKeyException.

Did I understand you right?

Regards,
Darya
 
Ranch Hand
Posts: 329
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

// Creates a new record in the database (possibly reusing a
// deleted entry). Inserts the given data, and returns the record
// number of the new record.
public int create(String[] data) throws DuplicateKeyException;



If you delete record number 10 and wants to create record reuse that record (flag says deleted record) to create new record.
 
author and jackaroo
Posts: 12200
280
Mac IntelliJ IDE Firefox Browser Oracle C++ Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Darya

Now how do you handle [record creation], when the same record you want to create already exist in the database (data file) with the deleted flag set.

Do you allow the new record to be created or do you throw a DuplicateKeyException?



My personal belief is that if the deleted flag is set, then the record is deleted (that is, logically it no longer exists). So I have no problem with either overwritting the existing record or creating a brand new record. There is no problem with primary keys, since the original record does not exist any more.

Regards, Andrew
 
Darya Akbari
Ranch Hand
Posts: 1855
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I'm going to reuse this record.

Thanks,
Darya
 
Frans Janssen
Ranch Hand
Posts: 357
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by Jack Gold:
If you used the record number as PK, how did you avoid the scenario where ClientB deletes and then creates a new record (reusing the space) and now ClientA has a recNo that references the new record created by clientB??


Jack, I didn't. Since records in a concurrent environment can be changed all the time by other clients, I think it is justified to assume that clients can never assume that records have not been changed. That is, unless they lock the record.

I see little difference between the situation where a record is deleted and a new one is inserted and the one where a record is updated beyond recognition.

Frans.
 
If you were a tree, what sort of tree would you be? This tiny ad is a poop beast.
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic