The transition needs to happen in ConfigRegistry so it can reserialize the object in its new format, otherwise we're just writing the same String back out to the db

git-svn-id: svn+ssh://src.earth.threerings.net/narya/trunk@4982 542714f4-19e9-0310-aa3c-eee0fc999fb1
This commit is contained in:
Charlie Groves
2008-03-27 21:18:26 +00:00
parent c50e78030c
commit c7126f07d5
3 changed files with 34 additions and 13 deletions
@@ -67,6 +67,26 @@ import com.threerings.presents.dobj.SetListener;
*/
public abstract class ConfigRegistry
{
/**
* Creates a ConfigRegistry that isn't transitioning.
*/
public ConfigRegistry ()
{
this(false);
}
/**
* Creates a ConfigRegistry.
*
* @param transitioning if true, serialized Streamable instances stored in the registry will
* be written back out immediately to allow them to be transitioned to new class names.
*/
public ConfigRegistry (boolean transitioning)
{
_transitioning = transitioning;
}
/**
* Registers the supplied configuration object with the system.
*
@@ -286,7 +306,13 @@ public abstract class ConfigRegistry
ByteArrayInputStream bin =
new ByteArrayInputStream(StringUtil.unhexlate(value));
ObjectInputStream oin = createObjectInputStream(bin);
field.set(object, oin.readObject());
Object deserializedValue = oin.readObject();
field.set(object, deserializedValue);
if (_transitioning) {
// Use serialize rather than serializeAttribute so we don't get
// ObjectAccessExceptions
serialize(key, nameToKey(key), deserializedValue);
}
} catch (Exception e) {
Log.warning("Failure decoding config value [type=" + type +
", field=" + field + ", exception=" + e + "].");
@@ -378,4 +404,7 @@ public abstract class ConfigRegistry
/** A mapping from identifying key to config object. */
protected HashMap<String,ObjectRecord> _configs = new HashMap<String,ObjectRecord>();
/** If we need to transition serialized Streamables to a new class format in init.. */
protected boolean _transitioning;
}