Win a copy of Mesos in Action this week in the Cloud/Virtualizaton forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

how to know if the object is updated ?

 
ilias basha
Ranch Hand
Posts: 55
Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Can anybody explain me how to know if any java object gets updated/re-loaded.

Consider if i have java object which will be loaded only if it meets certain conditions. and i need to check if that object is actually updated or not.
 
Hunter McMillen
Ranch Hand
Posts: 492
Firefox Browser Linux VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You can use print statements to determine the value of an object at a specific point in time.

Ex:



in this case if newStudent didn't meet the condition all of the student fields(i.e. gpa, name, student id) would be empty.

-Hunter
 
David Newton
Author
Rancher
Posts: 12617
IntelliJ IDE Ruby
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
@Hunter: what?

@Ilias: Loaded from where? In any case, one of the easiest ways to detect changes would be to compute a hash code, store it, and check against it later. This, of course, depends on having a good hash function, and may not always be appropriate. You could also instrument getters/setters to set a "modified" flag if their values actually cause a change--there are a number of ways this could be implemented.

I'm not sure how Hibernate determines dirtiness, but you could look into that and see what their implementation does.
 
ilias basha
Ranch Hand
Posts: 55
Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
David Newton wrote:
@Ilias: Loaded from where? In any case, one of the easiest ways to detect changes would be to compute a hash code, store it, and check against it later. This, of course, depends on having a good hash function, and may not always be appropriate. You could also instrument getters/setters to set a "modified" flag if their values actually cause a change--there are a number of ways this could be implemented.

I'm not sure how Hibernate determines dirtiness, but you could look into that and see what their implementation does.


I have written code that will load the property file, which will load only time stamp of previous instance differs with current one. I want to know if the object has got updated of the said class or not.
 
Hunter McMillen
Ranch Hand
Posts: 492
Firefox Browser Linux VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
My mistake, I thought the question was about the changing values of an object.

-Hunter
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic