wood burning stoves 2.0*
The moose likes Beginning Java and the fly likes how to know if the object is updated ? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "how to know if the object is updated ?" Watch "how to know if the object is updated ?" New topic
Author

how to know if the object is updated ?

ilias basha
Ranch Hand

Joined: Nov 27, 2008
Posts: 55

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

Joined: Mar 13, 2009
Posts: 492

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


"If the facts don't fit the theory, get new facts" --Albert Einstein
David Newton
Author
Rancher

Joined: Sep 29, 2008
Posts: 12617

@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

Joined: Nov 27, 2008
Posts: 55

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

Joined: Mar 13, 2009
Posts: 492

My mistake, I thought the question was about the changing values of an object.

-Hunter
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: how to know if the object is updated ?
 
Similar Threads
Object to Jar
getting NonUniqueObjectException exception
Struts 2, OGNL and data abstraction
JSON Object
Servlet: Multithreading Issues