Win a copy of Design for the Mind this week in the Design forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

NX: DuplicateKeyException

 
David Chan
Ranch Hand
Posts: 30
  • Mark post as helpful
  • send pies
  • 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 long createRecord(String [] data)
throws DuplicateKeyException;
*/
1. Is it OK not to reuse the deleted entry for new record? I think putting new records append to the end of db file is more simple.
2. When to throw DuplicateKeyException in the createRecord method? It looks the method does not have chance to get duplicated key.

Regards,
David
 
Arun Kumar
Ranch Hand
Posts: 67
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by David Chan:
// 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 long createRecord(String [] data)
throws DuplicateKeyException;
*/
1. Is it OK not to reuse the deleted entry for new record? I think putting new records append to the end of db file is more simple.
2. When to throw DuplicateKeyException in the createRecord method? It looks the method does not have chance to get duplicated key.

Regards,
David


If i were you, i would give them what they expect. By their comments for the create method they are expecting to reuse deleted records for new entries.
I did the contractor assignment. So i treated the name and location of the contractor as a combined primary key. If the new entry violates this primary key i threw DuplicateKeyException.
Arun
 
Philippe Maquet
Bartender
Posts: 1872
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi David,
1. Is it OK not to reuse the deleted entry for new record? I think putting new records append to the end of db file is more simple.

I agree with Arun, just do it. As a non-english speaker, I understood "possibly" as "if possible". Then someone (Andrew and/or Jim ?) told me that it means "perhaps" or "maybe" ...and it's confirmed by my english-french dictionary.
But why would they mention reuse of deleted entries if they didn't expect you to do it ?!
Anyway, the requirement is not explicit, so it seems that you may choose not to implement that feature.
Yesterday, Vlad wrote in another thread "(an) IT developer MUST strictly follow the specification and only do what is EXPLICITELY required.". It's a design choice per se, probably one of the top main ones.
2. When to throw DuplicateKeyException in the createRecord method? It looks the method does not have chance to get duplicated key.

For the DuplicateKeyException, look at this thread.
Best,
Phil.
 
Horst Dehmer
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi David!
Considering that DB/Data stand for arbitary database files, assuming/defining a implicit primary key which suits the needs for the assignment would be wrong in my opinion.
Considering further that DB has no mechanism to define/handle primary key meta data, I'd suggest that the DuplicateKeyException is just reserved for later use. It might only part of the methods signature because client code may be adopted smoother if such functionality is some day provided by DB.
What ya thinkin?
Regards, Horst.
 
Mark Spritzler
ranger
Sheriff
Posts: 17278
6
IntelliJ IDE Mac Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Also, if you do a search on this forum, you will see many threads on this same question with some very good answers.
Pay particular atention to my answers. Just Kidding.
Read all opinions and form your own, based on them.
Mark
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic