aspose file tools*
The moose likes Developer Certification (SCJD/OCMJD) and the fly likes create, delete and locking 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 "create, delete and locking" Watch "create, delete and locking" New topic
Author

create, delete and locking

Keith Jones
Ranch Hand

Joined: Oct 30, 2006
Posts: 105
According to the specification of the lock method this method



Locks a record so that it can only be updated or deleted by this client.



In the case of delete, does this mean that we do the following:



Problem is if we lock, then delete then attempt to unlock then we should get a RecordNotFoundException in the unlock method as that is what the unlock method should return for a record that is marked as deleted. Anyone have any ideas as to how this should be written?


SCJP 1.4
Mark Smyth
Ranch Hand

Joined: Feb 04, 2004
Posts: 288
You could drop the exception from the unlock method in your data class.


SCJP<br />SCJD
Keith Jones
Ranch Hand

Joined: Oct 30, 2006
Posts: 105
Surely that's not possible since the specifcation for the unlock method says that we must throw an exception if we try to unlock a deleted record.
Jeroen T Wenting
Ranch Hand

Joined: Apr 21, 2006
Posts: 1847
mine doesn't state under which conditions RecordNotFoundException is thrown so I've decided to never throw it in unlock().
Would be pointless to throw it there anyway, you're trying to get rid of something that's not there, fine by me


42
Mark Smyth
Ranch Hand

Joined: Feb 04, 2004
Posts: 288
Originally posted by Keith Jones:
Surely that's not possible since the specification for the unlock method says that we must throw an exception if we try to unlock a deleted record.


I think that it is an easily defendable option to take with regards to this issue as is dropping DuplicateKeyException in the create method. If the RecordNotFound exception is thrown by the unlock method before the record is unlocked then the record will never be unlocked. But if you unlock the record before checking it exists then whats was the point of the check in the first place?

Mark.
Ken Boyd
Ranch Hand

Joined: Dec 10, 2003
Posts: 329
I would say if you are deleting record which is already make deleted (check using flag) then throw RecordNotFoundException since my assignment says clearly

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


[ February 12, 2007: Message edited by: Ken Boyd ]
[ February 12, 2007: Message edited by: Ken Boyd ]

SCJP, SCWCD, SCBCD, SCJD, BB Java2 and JSP1.1
Lucy Hummel
Ranch Hand

Joined: Apr 07, 2005
Posts: 232
Hi,

There exists also a different opinion than Ken's one.

If a record should be delete and it is already deleted, then the goal of deletion is already achieved in the client's view point. So that means for the client point of view, do not throw any exception.

Anyway, if in your assignment is mentioned to throw such an exception, then the client want such an exception and you have to throw it.

Br, Lucy


----------------------------------<br />| SCJP, SCWCD, SCBCD, SCEA, SCJD |<br />----------------------------------
Vincent Li
Greenhorn

Joined: Jan 12, 2007
Posts: 22
Originally posted by Keith Jones:
Surely that's not possible since the specifcation for the unlock method says that we must throw an exception if we try to unlock a deleted record.


Surely that can't be in your spec? This is what mine look like:



It only throws the SecurityException. There is also nothing that says I can't unlock a deleted record. You could prevent "locking" of a deleted record, but once it's locked, then you don't have to worry about its existence to unlock.

-- Vince
SJCP(1.4),SCWCD(1.4), SCJD(almost there)


Vince<br />SCJP(1.4), SCWCD(1.4), SCJD (5.0)
Mark Smyth
Ranch Hand

Joined: Feb 04, 2004
Posts: 288
The method signature is correct alright here is mine from the urlybird project.


I just dropped the Exception it in my Data implementation of unlock and justified it in my choices.txt by saying it made no sense .
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
 
subject: create, delete and locking