This week's book giveaways are in the Java EE and JavaScript forums.
We're giving away four copies each of The Java EE 7 Tutorial Volume 1 or Volume 2(winners choice) and jQuery UI in Action and have the authors on-line!
See this thread and this one for details.
The moose likes Developer Certification (SCJD/OCMJD) and the fly likes Using timestamp to prevent 'dirty data' Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of The Java EE 7 Tutorial Volume 1 or Volume 2 this week in the Java EE forum
or jQuery UI in Action in the JavaScript forum!
JavaRanch » Java Forums » Certification » Developer Certification (SCJD/OCMJD)
Bookmark "Using timestamp to prevent Watch "Using timestamp to prevent New topic
Author

Using timestamp to prevent 'dirty data'

Song Jing Lim
Ranch Hand

Joined: Feb 11, 2003
Posts: 56
Hi...

To prevent 'dirty data' as show below:

User1 View RecNo1
User2 Del RecNo1
User3 Add new record (as RecNo will be reuse, user 3 will use back RecNo1 for difference data)
Back to user1 he decide to edit/delete the RecNo1 after view...

Problem came as the RecNo1 expected by User1 are not the one in database now.

To prevent that problem, I will using timestamp as below:

- Read the database during system startup and build a hashtable contain recNo and assign each with a timestamp value.
- When user get the Record (will return as JavaBean object), timestamp associate with that recNo (from hashtable) will be set.
- That timestamp will be use to compare the current timestamp associate wit h that record during edit/delete.

There for:
User1 View RecNo1 (current db, RecNo1 have timestamp x)
User2 Del RecNo1 (current db, RecNo1 had remove)
User3 Add new record (as RecNo will be reuse, user 3 will use back RecNo1 for difference data) (current db, RecNo1 have timestamp y)
so when User1 want to edit/delete, system will alert user that timestamp in the object are difference from database.

My approach is ok? Anyone have a better suggestion or alternative approach?

Note: I using service side locking as lock() method implement didn't return any value (it is void), so not able implement client side locking.

:roll:


Rgds,<br />Song Jing
Roy Mallard
Ranch Hand

Joined: Jul 14, 2005
Posts: 53
I am using timestamps for this and it works fine.


SCJP 1.4<br />SCJD
Song Jing Lim
Ranch Hand

Joined: Feb 11, 2003
Posts: 56
Thanks for reply, make me more confidence on that.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Using timestamp to prevent 'dirty data'