Win a copy of Five Lines of Code this week in the OO, Patterns, UML and Refactoring forum!
  • 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 all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Bear Bibeault
  • Ron McLeod
  • Jeanne Boyarsky
  • Paul Clapham
Sheriffs:
  • Tim Cooke
  • Liutauras Vilda
  • Junilu Lacar
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • fred rosenberger
  • salvin francis
Bartenders:
  • Piet Souris
  • Frits Walraven
  • Carey Brown

NX: DuplicateKeyException

 
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
 
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
 
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.
 
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.
 
ranger
Posts: 17346
11
Mac IntelliJ IDE 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
 
Skool. Stay in. Smartness. Tiny ad:
Building a Better World in your Backyard by Paul Wheaton and Shawn Klassen-Koop
https://coderanch.com/wiki/718759/books/Building-World-Backyard-Paul-Wheaton
    Bookmark Topic Watch Topic
  • New Topic