• 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

RNFE in update /delete method

 
Ranch Hand
Posts: 88
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Hi All,

Should we throw RNFE in update/delete method ?

but signature of update /delete is in instruction like :


public void update(int recNo, String [] data)
throws RecordNotFoundException;


// Deletes a record, making the record number and associated disk
// storage available for reuse.
public void delete(int recNo) throws RecordNotFoundException;



but signature of lock method

// Locks a record so that it can only be updated or deleted by this client.
// If the specified record is already locked, the current thread gives up
// the CPU and consumes no CPU cycles until the record is unlocked.
public void lock(int recNo) throws RecordNotFoundException;
// Releases the lock on a record.

so I think lock method will always be called before update/delete , correct?

So lock method is already throwing RNFE so no need to throw RNFE in update/delete .

correct?

Please reply .


Regards,
Pramod
 
Bartender
Posts: 3648
16
Android Mac OS X Firefox Browser Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
No need to throw rnfe for update delete if you do it in lock
 
Sheriff
Posts: 11604
178
Hibernate jQuery Eclipse IDE Spring MySQL Database AngularJS Tomcat Server Chrome Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi pramod,

You don't even have to throw one in unlock-method.

Kind regards,
Roel
 
Bartender
Posts: 2292
3
Eclipse IDE Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Indeed, if you do everything correctly (calling lock()/update()/delete()/unlock()), it isn't really necessary to throw it... but it could make sense throwing it when you call, for instance, the update() method isolately. This way, the client could know that the record to be updated doesn't even exist.
 
Roel De Nijs
Sheriff
Posts: 11604
178
Hibernate jQuery Eclipse IDE Spring MySQL Database AngularJS Tomcat Server Chrome Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Roberto Perillo wrote:but it could make sense throwing it when you call, for instance, the update() method isolately


If you try this, you should get a SecurityException (or an IllegalStateException or another exception), because you are not using the API correctly. Each call to update/delete should be surrounded with a call to lock and unlock. That's my opinion about it (and explained it in dept in my choices.txt)

Kind regards,
Roel
 
Roberto Perillo
Bartender
Posts: 2292
3
Eclipse IDE Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Roel De Nijs wrote:If you try this, you should get a SecurityException (or an IllegalStateException or another exception)...



Maybe it could make sense to throw the exception before it. I myself throw the RNFE if the record to be locked doesn't exist. Then I proceed and verify if the record is locked. It it isn't locked, then I throw the IllegalStateException.
 
Ranch Hand
Posts: 147
IntelliJ IDE Java Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
You should only throw exception that are checked if the user is not doing something abusive to the API. Any API abuse is RuntimeException candidate because a user cant be expected to recover seeing as they already violated the API. Hope you understand better now.
reply
    Bookmark Topic Watch Topic
  • New Topic