Added the necessary machinations to make getOldValue() and getOldEntry()
work on the server. git-svn-id: svn+ssh://src.earth.threerings.net/narya/trunk@2510 542714f4-19e9-0310-aa3c-eee0fc999fb1
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
//
|
||||
// $Id: AttributeChangedEvent.java,v 1.14 2002/12/20 23:29:04 mdb Exp $
|
||||
// $Id: AttributeChangedEvent.java,v 1.15 2003/04/30 22:32:04 mdb Exp $
|
||||
|
||||
package com.threerings.presents.dobj;
|
||||
|
||||
@@ -26,10 +26,12 @@ public class AttributeChangedEvent extends NamedEvent
|
||||
* primitive types, the reflection-defined object-alternative is
|
||||
* used).
|
||||
*/
|
||||
public AttributeChangedEvent (int targetOid, String name, Object value)
|
||||
public AttributeChangedEvent (int targetOid, String name,
|
||||
Object value, Object oldValue)
|
||||
{
|
||||
super(targetOid, name);
|
||||
_value = value;
|
||||
_oldValue = oldValue;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -108,8 +110,10 @@ public class AttributeChangedEvent extends NamedEvent
|
||||
public boolean applyToObject (DObject target)
|
||||
throws ObjectAccessException
|
||||
{
|
||||
// grab the previous value
|
||||
_oldValue = target.getAttribute(_name);
|
||||
// grab the previous value (if we're on the client)
|
||||
if (_oldValue == UNSET_OLD_VALUE) {
|
||||
_oldValue = target.getAttribute(_name);
|
||||
}
|
||||
// pass the new value on to the object
|
||||
target.setAttribute(_name, _value);
|
||||
return true;
|
||||
@@ -133,5 +137,5 @@ public class AttributeChangedEvent extends NamedEvent
|
||||
}
|
||||
|
||||
protected Object _value;
|
||||
protected transient Object _oldValue;
|
||||
protected transient Object _oldValue = UNSET_OLD_VALUE;
|
||||
}
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
//
|
||||
// $Id: DEvent.java,v 1.12 2002/12/20 23:41:26 mdb Exp $
|
||||
// $Id: DEvent.java,v 1.13 2003/04/30 22:32:04 mdb Exp $
|
||||
|
||||
package com.threerings.presents.dobj;
|
||||
|
||||
@@ -115,4 +115,16 @@ public abstract class DEvent implements Streamable
|
||||
|
||||
/** The oid of the client that generated this event. */
|
||||
protected transient int _soid = -1;
|
||||
|
||||
/** Used to differentiate between null meaning we haven't initialized
|
||||
* our old value and null being the actual old value. */
|
||||
protected static final Object UNSET_OLD_VALUE = new Object();
|
||||
|
||||
/** Used to differentiate between null meaning we haven't initialized
|
||||
* our old entry and null being the actual old entry. */
|
||||
protected static final DSet.Entry UNSET_OLD_ENTRY = new DSet.Entry() {
|
||||
public Comparable getKey () {
|
||||
return null;
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
@@ -1,8 +1,9 @@
|
||||
//
|
||||
// $Id: DObject.java,v 1.62 2003/04/10 17:48:42 mdb Exp $
|
||||
// $Id: DObject.java,v 1.63 2003/04/30 22:32:04 mdb Exp $
|
||||
|
||||
package com.threerings.presents.dobj;
|
||||
|
||||
import java.lang.reflect.Array;
|
||||
import java.lang.reflect.Field;
|
||||
import java.util.ArrayList;
|
||||
|
||||
@@ -723,8 +724,15 @@ public class DObject implements Streamable
|
||||
*/
|
||||
protected void requestAttributeChange (String name, Object value)
|
||||
{
|
||||
// dispatch an attribute changed event
|
||||
postEvent(new AttributeChangedEvent(_oid, name, value));
|
||||
try {
|
||||
// dispatch an attribute changed event
|
||||
postEvent(new AttributeChangedEvent(
|
||||
_oid, name, value, getAttribute(name)));
|
||||
|
||||
} catch (ObjectAccessException oae) {
|
||||
Log.warning("Unable to request attributeChange [name=" + name +
|
||||
", value=" + value + ", error=" + oae + "].");
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -733,8 +741,17 @@ public class DObject implements Streamable
|
||||
*/
|
||||
protected void requestElementUpdate (String name, Object value, int index)
|
||||
{
|
||||
// dispatch an attribute changed event
|
||||
postEvent(new ElementUpdatedEvent(_oid, name, value, index));
|
||||
try {
|
||||
// dispatch an attribute changed event
|
||||
Object oldValue = Array.get(getAttribute(name), index);
|
||||
postEvent(new ElementUpdatedEvent(
|
||||
_oid, name, value, oldValue, index));
|
||||
|
||||
} catch (ObjectAccessException oae) {
|
||||
Log.warning("Unable to request elementUpdate [name=" + name +
|
||||
", value=" + value + ", index=" + index +
|
||||
", error=" + oae + "].");
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -766,8 +783,6 @@ public class DObject implements Streamable
|
||||
// immediately
|
||||
boolean alreadyApplied = false;
|
||||
if (_omgr != null && _omgr.isManager(this)) {
|
||||
// Log.info("Immediately adding [name=" + name +
|
||||
// ", entry=" + entry + "].");
|
||||
set.add(entry);
|
||||
alreadyApplied = true;
|
||||
}
|
||||
@@ -791,8 +806,6 @@ public class DObject implements Streamable
|
||||
// immediately
|
||||
DSet.Entry oldEntry = null;
|
||||
if (_omgr != null && _omgr.isManager(this)) {
|
||||
// Log.info("Immediately removing [name=" + name +
|
||||
// ", key=" + key + "].");
|
||||
oldEntry = set.get(key);
|
||||
set.removeKey(key);
|
||||
}
|
||||
@@ -816,8 +829,6 @@ public class DObject implements Streamable
|
||||
// immediately
|
||||
DSet.Entry oldEntry = null;
|
||||
if (_omgr != null && _omgr.isManager(this)) {
|
||||
// Log.info("Immediately updating [name=" + name +
|
||||
// ", entry=" + entry + "].");
|
||||
oldEntry = set.get(entry.getKey());
|
||||
set.update(entry);
|
||||
}
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
//
|
||||
// $Id: ElementUpdatedEvent.java,v 1.4 2002/12/20 23:29:04 mdb Exp $
|
||||
// $Id: ElementUpdatedEvent.java,v 1.5 2003/04/30 22:32:04 mdb Exp $
|
||||
|
||||
package com.threerings.presents.dobj;
|
||||
|
||||
@@ -29,13 +29,17 @@ public class ElementUpdatedEvent extends NamedEvent
|
||||
* element has changed.
|
||||
* @param value the new value of the element (in the case of primitive
|
||||
* types, the reflection-defined object-alternative is used).
|
||||
* @param oldValue the previous value of the element (in the case of
|
||||
* primitive types, the reflection-defined object-alternative is
|
||||
* used).
|
||||
* @param index the index in the array of the updated element.
|
||||
*/
|
||||
public ElementUpdatedEvent (
|
||||
int targetOid, String name, Object value, int index)
|
||||
int targetOid, String name, Object value, Object oldValue, int index)
|
||||
{
|
||||
super(targetOid, name);
|
||||
_value = value;
|
||||
_oldValue = oldValue;
|
||||
_index = index;
|
||||
}
|
||||
|
||||
@@ -135,7 +139,9 @@ public class ElementUpdatedEvent extends NamedEvent
|
||||
}
|
||||
|
||||
// grab the previous value to provide to interested parties
|
||||
_oldValue = Array.get(field.get(target), _index);
|
||||
if (_oldValue != UNSET_OLD_VALUE) {
|
||||
_oldValue = Array.get(field.get(target), _index);
|
||||
}
|
||||
|
||||
// we don't do any magical expansion or any funny business;
|
||||
// the array should be big enough to contain the value being
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
//
|
||||
// $Id: EntryRemovedEvent.java,v 1.14 2003/03/10 18:29:54 mdb Exp $
|
||||
// $Id: EntryRemovedEvent.java,v 1.15 2003/04/30 22:32:04 mdb Exp $
|
||||
|
||||
package com.threerings.presents.dobj;
|
||||
|
||||
@@ -22,15 +22,7 @@ public class EntryRemovedEvent extends NamedEvent
|
||||
* @param name the name of the attribute from which to remove the
|
||||
* specified entry.
|
||||
* @param key the entry key that identifies the entry to remove.
|
||||
*/
|
||||
public EntryRemovedEvent (int targetOid, String name, Comparable key)
|
||||
{
|
||||
this(targetOid, name, key, null);
|
||||
}
|
||||
|
||||
/**
|
||||
* Used when the distributed object already removed the entry before
|
||||
* generating the event.
|
||||
* @param oldEntry the previous value of the entry.
|
||||
*/
|
||||
public EntryRemovedEvent (int targetOid, String name, Comparable key,
|
||||
DSet.Entry oldEntry)
|
||||
@@ -70,7 +62,7 @@ public class EntryRemovedEvent extends NamedEvent
|
||||
public boolean applyToObject (DObject target)
|
||||
throws ObjectAccessException
|
||||
{
|
||||
if (_oldEntry == null) {
|
||||
if (_oldEntry == UNSET_OLD_ENTRY) {
|
||||
DSet set = (DSet)target.getAttribute(_name);
|
||||
// fetch the previous value for interested callers
|
||||
_oldEntry = set.get(_key);
|
||||
@@ -97,5 +89,5 @@ public class EntryRemovedEvent extends NamedEvent
|
||||
}
|
||||
|
||||
protected Object _key;
|
||||
protected transient DSet.Entry _oldEntry;
|
||||
protected transient DSet.Entry _oldEntry = UNSET_OLD_ENTRY;
|
||||
}
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
//
|
||||
// $Id: EntryUpdatedEvent.java,v 1.10 2003/03/10 18:29:54 mdb Exp $
|
||||
// $Id: EntryUpdatedEvent.java,v 1.11 2003/04/30 22:32:04 mdb Exp $
|
||||
|
||||
package com.threerings.presents.dobj;
|
||||
|
||||
@@ -25,15 +25,7 @@ public class EntryUpdatedEvent extends NamedEvent
|
||||
* @param name the name of the attribute in which to update the
|
||||
* specified entry.
|
||||
* @param entry the entry to update.
|
||||
*/
|
||||
public EntryUpdatedEvent (int targetOid, String name, DSet.Entry entry)
|
||||
{
|
||||
this(targetOid, name, entry, null);
|
||||
}
|
||||
|
||||
/**
|
||||
* Used when the distributed object already updated the entry before
|
||||
* generating the event.
|
||||
* @param oldEntry the previous value of the entry.
|
||||
*/
|
||||
public EntryUpdatedEvent (int targetOid, String name, DSet.Entry entry,
|
||||
DSet.Entry oldEntry)
|
||||
@@ -77,7 +69,9 @@ public class EntryUpdatedEvent extends NamedEvent
|
||||
DSet set = (DSet)target.getAttribute(_name);
|
||||
|
||||
// fetch the previous value for interested callers
|
||||
_oldEntry = set.get(_entry.getKey());
|
||||
if (_oldEntry != UNSET_OLD_ENTRY) {
|
||||
_oldEntry = set.get(_entry.getKey());
|
||||
}
|
||||
|
||||
// update the entry
|
||||
if (!set.update(_entry)) {
|
||||
@@ -108,5 +102,5 @@ public class EntryUpdatedEvent extends NamedEvent
|
||||
}
|
||||
|
||||
protected DSet.Entry _entry;
|
||||
protected transient DSet.Entry _oldEntry;
|
||||
protected transient DSet.Entry _oldEntry = UNSET_OLD_ENTRY;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user