Win a copy of The Little Book of Impediments (e-book only) this week in the Agile and Other Processes forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

B&S: Primary Key

 
Justin Rundle
Ranch Hand
Posts: 123
Hibernate Java Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
G'day fellow ranchers,

Quick question just wanted to get your feedback about primary key for each record in the data file. The instructions which reveals the data file structure does not specify a unique identifier.

More so I was thinking of you using the actual line number as the unique identifier.

Thanks
 
Justin Rundle
Ranch Hand
Posts: 123
Hibernate Java Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Furthermore to add to the topic I realize after reading a few other posts than other developers are using the name or concatenating the name and the location... and yes you sould as the guidelines suggests keep the assignment simple but i think there's a fine line between simple and not realistic.

More so using the hashcode of the name or concatenating the name and location doesnt seem feasible in real world scenarios, what stops two sub contrators living in the same town with the same name. (Consider how many different countries there are they share the same city name...?)

I guess the problem I'm constantly facing is distinguishing when deciding to code a simple solution or realistic solution...
 
Kah Tang
Ranch Hand
Posts: 58
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I think the most simplest thing to do is indeed using the line numbers. That's how I solved it.
 
Jethro Borsje
Ranch Hand
Posts: 100
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I am using the line numbers also.
 
Roman Yankin
Ranch Hand
Posts: 47
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
This solution has a potential bug with no workaround, unless you are not reusing the deleted records lines, but appending new records to the end of file. For details see http://www.coderanch.com/t/190046/java-developer-SCJD/certification/Concurrent-which-affects-ALL-algorithms
 
Iván Párraga
Ranch Hand
Posts: 54
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

I'm using [Name + Location]. I think it is simple enough and quite realistic. I took this choice because I wanted to have a logical primary key from the point of view of the human user. Furthermore, I don�t know exactly what your instructions are but in mine is explicitly said that the record numbers can be reused when removing a record (so perhaps it is not a great idea use them as primary keys).

Cheers,

Iv�n
 
Jethro Borsje
Ranch Hand
Posts: 100
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I am using the line numbers also.
 
Roman Yankin
Ranch Hand
Posts: 47
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Iv�n P�rraga:
Hi,
(so perhaps it is not a great idea use them as primary keys).


Why not? Once the record has been deleted you can reuse its unique ID thats the whole point.

BTW, Iv�n, did you go about navigation in your data file? For instance if user has requested to delete a certain record how would you find out which record you have to delete?
 
Zlatan Hajric
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
How do you solve this if you use only record number?

public int create(String [] data) throws DuplicateKeyException;

it doesn't matter if you use a deleted record or append one.
if you append you'll never get DuplicateKeyExeption , and if you reuse you do so only if record is deleted so no chance of getting Duplicate there either.

so DuplicateKeyException is never to be thrown and the question is does that compile with a specification.
 
Justin Rundle
Ranch Hand
Posts: 123
Hibernate Java Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Anything can "compile" with the specification, as long as you can justify your decisions in your choices.txt document.
 
Jethro Borsje
Ranch Hand
Posts: 100
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Zlatan Hajric:
How do you solve this if you use only record number?

public int create(String [] data) throws DuplicateKeyException;

it doesn't matter if you use a deleted record or append one.
if you append you'll never get DuplicateKeyExeption , and if you reuse you do so only if record is deleted so no chance of getting Duplicate there either.

so DuplicateKeyException is never to be thrown and the question is does that compile with a specification.

In my implementation the DuplicateKeyException is indeed never thrown.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic