Win a copy of Java Mock Exams (software) this week in the Programmer Certification (OCPJP) forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

id of a record

 
Daniel Vogt
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
in my database interface i have the following method-declaration:

//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;

and my databasedefinition has no "primary key". the only thing what i have is a unique name. and which one should be the record number? should i generate a map with the id's and the unique name? or maybe a map with the id of the record and with the start-position in the db-file?

regards,
[ April 09, 2007: Message edited by: Daniel Vogt ]
 
Lucy Hummel
Ranch Hand
Posts: 232
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

May I ask you to read the



naming guideline again and update you display name accordingly?

Furthermore, if you have a kind of primary key, that is great. I do not have it. So mapping that key to the file position sounds a pretty good idea/solution.

Why do I not have a primary key?!
 
Mihai Radulescu
Ranch Hand
Posts: 918
IntelliJ IDE Java Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Daniel,

The DuplicateKeyException can be throw if you can define a unicity criteria, and this depend on your database structure. Even if this sound strange there are some situation where you can not define a reliable unicity criteria and in this case you can not throw the DuplicateKeyException, but you need to document your decision.


regards M.
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!