I added the following code to the Address class included with JBossCacheAop:
int id = -1;
| public int getId() {
| return this.id;
| }
| public void setId(int id) {
| this.id = id;
| }
| public boolean equals(Object o) {
| if(!(o instanceof Address)) return false;
| return ((Address)o).getId() == this.getId();
| }
| public int hashCode() {
| return id;
| }
Basically it's just an extra ID property that is used to determine equality. With this
extra code, I was expecting JBossCacheAop to be intelligent about maintaining my
object graph for me:
bsh % import org.jboss.cache.aop.*;
| bsh % import org.jboss.test.cache.test.standAloneAop.*;
| bsh % TreeCacheAop tree = new TreeCacheAop();
| bsh % tree.startService();
| bsh % Person joe = new Person();
| bsh % Person mary = new Person();
| bsh % Address addr = new Address();
| bsh % addr.setId(1);
| bsh % joe.setAddress(addr);
| bsh % mary.setAddress(addr);
| bsh % System.out.println(joe.getAddress() == mary.getAddress());
| true
| bsh % Address addr2 = new Address();
| bsh % addr2.setId(1);
| bsh % joe.setAddress(addr2);
| bsh % System.out.println(joe.getAddress() == mary.getAddress());
| false
I was expecting that last false to be true.
Basically, I make two Person instances, joe and mary, both using the same Address
instance. If I modify that Address instance, the modification is visible from both joe
and mary, as expected. However, if I create a new Address with the same ID as the
first one, such that addr.equals(addr2) returns true, and assign it to one of the two
people, then the other person still references the old address.
I had expected the object as a whole to be replaced throughout the object graph, given
that they are "equal". Am I doing something wrong, or is this functionality not
implemented?
Thanks in advance,
Daniel
View the original post :
http://www.jboss.org/index.html?module=bb&op=viewtopic&p=3854140#3854140
Reply to the post :
http://www.jboss.org/index.html?module=bb&op=posting&mode=reply&p=3854140
-------------------------------------------------------
This SF.Net email is sponsored by:
Sybase ASE Linux Express Edition - download now for FREE
LinuxWorld Reader's Choice Award Winner for best database on Linux.
http://ads.osdn.com/?ad_id=5588&alloc_id=12065&op=click
_______________________________________________
JBoss-Development mailing list
[EMAIL PROTECTED]
https://lists.sourceforge.net/lists/listinfo/jboss-development