aspose file tools*
The moose likes Developer Certification (SCJD/OCMJD) and the fly likes B&S Data => Create method 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 "B&S Data => Create method "pseudo"" Watch "B&S Data => Create method "pseudo"" New topic
Author

B&S Data => Create method "pseudo"

Alex Belisle Turcot
Ranch Hand

Joined: Apr 26, 2005
Posts: 516
Hi,

what do you think about this high level pseudo for the create method:


When you call create, there is no way to know the recNo, so you cannot previously lock the record, it has to be done by the create method itself!.

Alex
[ November 07, 2007: Message edited by: Alex Turcot ]
Naveen Narayanan
Ranch Hand

Joined: Sep 11, 2007
Posts: 114


- Loop until find identical key
. DuplicateKeyException


Here comes a doubt for me , create throws a DuplicateKeyException when finds an identical key ,

If the key is recNo , then its to be auto-generated (probably previous max + 1) , so there is no chance of a duplicate key comes here .


SCJP 5.0, SCJD, SCWCD
Xabier Martija
Ranch Hand

Joined: Jul 18, 2007
Posts: 40
Originally posted by Naveen Narayanan:


Here comes a doubt for me , create throws a DuplicateKeyException when finds an identical key ,

If the key is recNo , then its to be auto-generated (probably previous max + 1) , so there is no chance of a duplicate key comes here .


I agree. DuplicateKeyException will never be thrown. Don't forget to document it in your choices and method docs.
Alex Belisle Turcot
Ranch Hand

Joined: Apr 26, 2005
Posts: 516
Thanks..


I will actually throw the exception, for the sake of future maintenance..
Lets say the "delete" method is modified and deletes records for real.
Added records would then use duplicateKeys.

So, I'm throwing it and documenting that is should never happen, unless code is modified in the future by a junior programmer

Alex
Calum Ludwig
Greenhorn

Joined: Oct 01, 2007
Posts: 14
Originally posted by Naveen Narayanan:


Here comes a doubt for me , create throws a DuplicateKeyException when finds an identical key ,

If the key is recNo , then its to be auto-generated (probably previous max + 1) , so there is no chance of a duplicate key comes here .


I�m not sure what the requirements state for your assignment but does the key have to be the recNo?

Can you run a search for through the records for similar fields of the newly created record?

Name
Name + Location
Name + Location + Size

As just a few examples that could act as the DuplicateKey to check when the user has created a new record.


SCJP 1.4<br />SCJD
Alex Belisle Turcot
Ranch Hand

Joined: Apr 26, 2005
Posts: 516
H,

you're right, it does not have to be recNo but I liked the suggestion, a lot less error prone I would think.
No funny situation, update and create at the same time, updating the keys of 2 different records.. (update reuse the same recNo and create will use another one or the one from a deleted record.)
[ November 08, 2007: Message edited by: Alex Belisle Turcot ]
Naveen Narayanan
Ranch Hand

Joined: Sep 11, 2007
Posts: 114

Probably I assumed our assignments have common framework

Originally posted by Calum Ludwig

I�m not sure what the requirements state for your assignment but does the key have to be the recNo?

Can you run a search for through the records for similar fields of the newly created record?

Name
Name + Location
Name + Location + Size

In my assignment
-ReadRecord is based on recNo
-UpdateRecord is based on recNo

So is most of the other methods .

That is why I have strong reason to think recNo is the key . I am not sure with a Name + Location key the above methods could be performed.

I would rather like to call it a DuplicateRecordException in create if a Name + Location + size + �..(till all fields) already exist in the db.
mohamed sulibi
Ranch Hand

Joined: Sep 04, 2005
Posts: 169
hi all;
about this :

Loop until find a deleted record
. Lock the record
. if still deleted
. Update the record
. unlock


i think it is better to replace with:
-Lock the DBFile
Loop until find a deleted rcord.
update the recrod
-unlock

best regards.
M_darim
SCJP, SCJD in progress ...
Alex Belisle Turcot
Ranch Hand

Joined: Apr 26, 2005
Posts: 516
ok... I changed it quite a bit...

In fact, my lock method does not allow locking on a deleted record (it throws RecordNotFound)

And, only 1 thread is allowed to create (synchronized block).
So, there is no need to lock at the record-level when creating a new record.
Create will either reuse a delete record or insert a new one, it's all the same since only 1 thread is allowed at once there.

Thanks for all your advice/tips/comments.

Alex
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: B&S Data => Create method "pseudo"