aspose file tools*
The moose likes Developer Certification (SCJD/OCMJD) and the fly likes NX: DuplicateKeyException Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Soft Skills this week in the Jobs Discussion forum!
JavaRanch » Java Forums » Certification » Developer Certification (SCJD/OCMJD)
Bookmark "NX: DuplicateKeyException" Watch "NX: DuplicateKeyException" New topic
Author

NX: DuplicateKeyException

David Chan
Ranch Hand

Joined: Jun 11, 2003
Posts: 30
// 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

Joined: Aug 29, 2003
Posts: 67
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


SCJP (1.4), SCWCD, SCJD
Philippe Maquet
Bartender

Joined: Jun 02, 2003
Posts: 1872
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

Joined: Mar 29, 2002
Posts: 10
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

Joined: Feb 05, 2001
Posts: 17260
    
    6

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


Perfect World Programming, LLC - Two Laptop Bag - Tube Organizer
How to Ask Questions the Smart Way FAQ
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: NX: DuplicateKeyException