• 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 Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

B&S: Primary Key

 
Ranch Hand
Posts: 123
Hibernate Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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 Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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...
 
Ranch Hand
Posts: 58
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Ranch Hand
Posts: 100
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I am using the line numbers also.
 
Ranch Hand
Posts: 47
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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 https://coderanch.com/t/190046/java-developer-SCJD/certification/Concurrent-which-affects-ALL-algorithms
 
Ranch Hand
Posts: 54
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I am using the line numbers also.
 
Roman Yankin
Ranch Hand
Posts: 47
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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?
 
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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 Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Consider Paul's rocket mass heater.
reply
    Bookmark Topic Watch Topic
  • New Topic