This week's book giveaway is in the Java 8 forum.
We're giving away four copies of Java 8 in Action and have Raoul-Gabriel Urma, Mario Fusco, and Alan Mycroft on-line!
See this thread for details.
The moose likes Developer Certification (SCJD/OCMJD) and the fly likes B&S: Primary Key Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Java 8 in Action this week in the Java 8 forum!
JavaRanch » Java Forums » Certification » Developer Certification (SCJD/OCMJD)
Bookmark "B&S: Primary Key" Watch "B&S: Primary Key" New topic
Author

B&S: Primary Key

Bhavik Patel
Ranch Hand

Joined: Jul 12, 2004
Posts: 155
In my assignment , the spec says clearly that if the method declares DuplicateKeyException to be thrown then it should do so if DuplicateKey found.

so i can not avoid this requirement and not throw DuplicateKeyException as i saw some people have just ignored this requirement in the past.

Now the question is what should be the primary key ..

recNo as primary key may create problem in case of create-delete sequence but locking should avoid this..

I have implemented name & location combination as composite key.
I am setting the primary key object with keys(int[] keys) as member variable which sets the index of array fields which are primary key elements ..
so in my case


In create method i check for duplicateEntry by comparing the name & location.and if its valid then just create new record,

in the update i am trying to check the new values will not violate the name& location(composite key) and if its all valid then & then update.

My concern is that if in any case primary key constraint is violated then the operationis failed throwing the DKE and message is logged .Does it fullfill the requirement ??any drawbacks of this decision ?? just wanted some views on this design ...

Thanks.


SCJP 1.4<br />SCWCD 1.4(91%)<br />Working on SCJD -Bodgitt & Scrapper Constructions...<br /> <br />"It takes 43 muscles to frown & 17 to smile but it doen't take any to just sit there with a dumb look on your face .. Keep Smiling "
Jeremy Botha
Ranch Hand

Joined: Feb 16, 2005
Posts: 125
Pretty much what I did.

I've also documented around referential integrity in the user documentation, explaining what conditions will cause the exception to occur.

Jeremy


McFinnigan? Never heard of him. Nobody here but us chickens...<br /> <br />SCJP for Java 1.4<br />SCJD for Java 5.0
Jeroen T Wenting
Ranch Hand

Joined: Apr 21, 2006
Posts: 1847
Yes, the requirements say to throw a duplicatekeyexception if there's an attempt to generate a duplicate key.
But as the requirements don't specify a key, there's no way (unless you, like you did, specify your own) to ever generate a duplicate key as there's no key at all

All depends on how you explain the requirements I guess, just make sure you (as always) document your decisions.


42
Bhavik Patel
Ranch Hand

Joined: Jul 12, 2004
Posts: 155
thanks for the information .. I will document my decisions about it.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: B&S: Primary Key
 
Similar Threads
@deprecated DuplicateKeyException
Nx: Documenting DuplicateKeyException
nx: All of URLy Bird 1.1.3 read/write lock(2)
DuplicateKeyException - B&S
updating a primary key field