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

B&S cookie value

Lek Olof
Greenhorn

Joined: Jan 03, 2007
Posts: 10
Hi,

When using the

public long lock(int recNo) throws RecordNotFoundException {

method of B&S assignemnt the assignment says that it should return a cookie value.

Can the recNo be the cookievalue, and if not, why?

regards
Baran
Song Jing Lim
Ranch Hand

Joined: Feb 11, 2003
Posts: 56
I also doing B&S assignmnet, but nothing related to cookies value (beside the magic cookies value on first 4 byte to identify it is a data file).

The locking method I need implement as instruct as below:
// 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;

So our requiremenet may be difference even both doing B&S


Rgds,<br />Song Jing
Mihai Radulescu
Ranch Hand

Joined: Sep 18, 2003
Posts: 918

Hi guys,


I also don't have cookies, but as far as I understand the cookies are some form to identify the client. If a client looks a record it becomes a cookie (sugar free). Because if the looking methodology(a record can be releases only by the client which lock the record) you need to use this cookie to identify your client when you need to release the record.
If you use the record index like cookie, this will be the same for all the clients - and this collides with the looking methodology(explained above).

Regards M


SCJP, SCJD, SCWCD, OCPJBCD
Lek Olof
Greenhorn

Joined: Jan 03, 2007
Posts: 10
hi,

Ok I understand.

So what are you guys mapping the recNo to?

I guess you have some kind of map where you map the recNo to some kind of clientnumber? Or what object to do map the recNo to?
Mark Smyth
Ranch Hand

Joined: Feb 04, 2004
Posts: 288
Originally posted by Lek Olof:
hi,

Ok I understand.

So what are you guys mapping the recNo to?

I guess you have some kind of map where you map the recNo to some kind of clientnumber? Or what object to do map the recNo to?


My version did not have lock cookies for client identification so I don't know much about cookie generation I used thread references to identify the client. With regards to mapping the lock swhat you probably want is a HashMap where the key is an Integer object representing the record number and the value is a Long object representing the generated client cookie value.

Regards,
Mark


SCJP<br />SCJD
Mihai Radulescu
Ranch Hand

Joined: Sep 18, 2003
Posts: 918

Hi Lek,


So what are you guys mapping the recNo to?


If this question is in the cookies context then take care you don't need to care about the records here, what you need is a unique id for the your client(s). This id can be everything.

Regards M.
Song Jing Lim
Ranch Hand

Joined: Feb 11, 2003
Posts: 56
For locking related to client thread, you can refer to:
http://www.coderanch.com/t/184117/java-developer-SCJD/certification/Single-table-Simple-Locking-WeakHashMap
Song Jing Lim
Ranch Hand

Joined: Feb 11, 2003
Posts: 56
I have a seek method that pass in recNo and get the record from database using below fomula.

RandomAccessFile RAF = new RandomAccessFile(dbpath, "rw");

public void seek(recNo){
long filePositionToSeek = headerLen
+ (recordLen() * (recNo - 1));
RAF.seek(filePositionToSeek);
}


So no need map recNo to anything
Song Jing Lim
Ranch Hand

Joined: Feb 11, 2003
Posts: 56
The problem with server side locking is 'diry read', eg.

User A: Read Rec1
User B: Edit and Update Rec1
User A: Edit and Update Rec1

Where b4 user A update the record, the contain already change by UserB without notice.

Still got problem to solve this... Anyone can help?
Mihai Radulescu
Ranch Hand

Joined: Sep 18, 2003
Posts: 918

Well, you can build some checks and before you alter a record you check if its content is still the same(or was changed).
But I think that this has nothing to do with the thread topic "Regards MB&S cookie value".

Regards M.
Lek Olof
Greenhorn

Joined: Jan 03, 2007
Posts: 10
thanks for the help, I think I understand how to solve it now!

regards
Baran
Song Jing Lim
Ranch Hand

Joined: Feb 11, 2003
Posts: 56
Discussion for 'dirty data', I post a new topic:
http://www.coderanch.com/t/188886/java-developer-SCJD/certification/timestamp-prevent-dirty-data
PaulSeldon07
Greenhorn

Joined: Jan 24, 2007
Posts: 4
Lek, I think I have the same assignment as you do.
I don't understand well about this cookie.

And in my database, if you print out, location and name,
has to be as a primary key. because the same name in the different location.
Please check.

Bye --

Paul
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: B&S cookie value