• Post Reply Bookmark Topic Watch Topic
  • New Topic

B&S: Database file  RSS feed

 
Mickey Mulligan
Greenhorn
Posts: 20
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi there, the schema for my database file looks like this:

subcontractor name, location, specialties, size, rate, owner

My question is, do folks generally use the subcontractor name as a primary key? I've chosen not to do this (you might have subcontractors with the same name in different locations), and I use the record's position in the file (ie. its number) as the primary key.

Problem is, my interface demands this method:



Seeing as I don't pass the primary key into the String [] data array above, (my record is assigned a key by its location in the file) how can I check for a DuplicateKeyException? It's pretty much impossible to get duplicate keys the way I'm doing things.

Perhaps I should interpret this as "Duplicate Record"?

If so, what's the best way to check for dupes? I would assume it's to keep an array of the hashes of each record and check against that, rather than digging through the database file.

Any suggestions?
 
Kristof Janssens
Greenhorn
Posts: 23
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I don't use that exception. I mentioned in my choices.txt file that this exception cannot be thrown because I also use the record position as primary key. I placed the exception in my methods so it is available for future enhancements, but it is never thrown.
 
Mickey Mulligan
Greenhorn
Posts: 20
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Cool, methinks I will do the same, thanks!
 
Ed Tse
Ranch Hand
Posts: 183
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I saw the same problem but have ignored it since I am working on other areas. from my impression, you can't change the interface that was provided by the assignment, I don't think you can remove the throw from the interface.
 
B Chen
Ranch Hand
Posts: 89
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You cannot remove the exception specification from createRecord in the interface provided by Sun. But you can remove it from createRecord in your implementation class.
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!