Win a copy of Functional Reactive Programming this week in the Other Languages forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

B&S Data => Create method "pseudo"

 
Alex Belisle Turcot
Ranch Hand
Posts: 516
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 114
Eclipse IDE Java Tomcat Server
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

- 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 .
 
Xabier Martija
Ranch Hand
Posts: 40
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 516
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 14
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Alex Belisle Turcot
Ranch Hand
Posts: 516
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 114
Eclipse IDE Java Tomcat Server
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 169
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 516
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic