aspose file tools*
The moose likes Developer Certification (SCJD/OCMJD) and the fly likes DB.unlock() vs. RecordNotFoundException Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Certification » Developer Certification (SCJD/OCMJD)
Bookmark "DB.unlock() vs. RecordNotFoundException" Watch "DB.unlock() vs. RecordNotFoundException" New topic
Author

DB.unlock() vs. RecordNotFoundException

Andy Jung
Ranch Hand

Joined: Feb 07, 2010
Posts: 150
Hi,

the DB method unlock() specifies a RecordNotFoundException in its throws-clause,
whereas the assignment says:

Any methods that throw RecordNotFoundException should do so
if a specified record does not exist or is marked as deleted
in the database file


Implementing the methods in this way, I always receive a RecordNotFoundException
when performing the following tasks in my business model:



How did you resolve this problem?

Regards,
Andy


SCJP, SCJD
Carlos Morillo
Ranch Hand

Joined: Jun 06, 2009
Posts: 221

Hi Andy,


I do check first for x to be in my map of locked records and also if the cookie that was passed is the same stored in my map for x,
if this is true I do remove the value in my map for x and call notifyAll().
If not if x is in my map but the cookie passed as argument is not
I throw a SecurityException.
if not I check if the record x does not exist
and if this the case I throw RecordNotFoundException.


Hope this helps,


Carlos.


SCSA, OCA, SCJP 5.0, SCJD, CCDH, CCAH http://www.linkedin.com/in/carlosamorillo
Andy Jung
Ranch Hand

Joined: Feb 07, 2010
Posts: 150
Hi Carlos,

that's it !
Thanks for that hint, the problem was, that I firstly validated the recNo with the possible consequence of a RNFE being thrown and after that I did cookie matching. Reversing validation logic will resolve this.

Kind regards,
Andy
Roel De Nijs
Bartender

Joined: Jul 19, 2004
Posts: 5408
    
  13

Hi Andy,

In my own created interface update, delete and unlock methods don't throw the RNFE anymore, because it makes no sense at all. You have to always lock the record prior to updating/deleting/unlocking, so when record doesn't exist anymore you will get the RNFE when you lock the record. When you successfully have locked a record, it can't disappear mysteriously
This approach simplifies again my code: I don't have to catch any RNFE which will never happen. But you won't be a fan, because you are a Beckenrandschwimmer and are afraid of the automatic failure ghost ;)

Kind regards,
Roel


SCJA, SCJP (1.4 | 5.0 | 6.0), SCJD
http://www.javaroe.be/
Andy Jung
Ranch Hand

Joined: Feb 07, 2010
Posts: 150
Hi Roel,

you're right, RNFE in those methods don't make much sense anymore having logical locking.
After a record is locked, a record shouldn't vanish mysteriously, except
that a mean guy accesses and manipulates the database file meanwhile or
due to some magnetic or mechanical failure the record flag on hard disk turns to an invalid one.
But that's actually a stupid "Beckenrandschwimmer" argument ;-).
You like that word, don't you ?
To improve your German further, I'll tell you some more synonyms for that, i.e. :
  • Turnbeutelvergesser
  • Warmduscher
  • Weichei

  • regards,
    Andy
    Roel De Nijs
    Bartender

    Joined: Jul 19, 2004
    Posts: 5408
        
      13

    Andy Jung wrote:To improve your German further, I'll tell you some more synonyms for that, i.e.
    Because in Belgium there are 3 official languages (dutch, french and german) I had to learn 4 languages (the 3 official ones + english of course). In our 1st German lesson we learnt the word "Tempotaschentucher". I never forgot that one, so funny After all Dutch and German are closely related to each other.

    Kind regards,
    Roel
    Andy Jung
    Ranch Hand

    Joined: Feb 07, 2010
    Posts: 150
    Hi Roel,

    I know, the best foreign language speakers in Europe are people from small countries like Belgium, Denmark, Holland ...
    Germans are a little bit like the English: There's actually no really need to learn a foreign language.
    This is why most Germans are pretty bad in the English language (like me).

    Kind regards,
    Andy
     
    I agree. Here's the link: http://aspose.com/file-tools
     
    subject: DB.unlock() vs. RecordNotFoundException