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:
@@ -67,6 +67,26 @@ import com.threerings.presents.dobj.SetListener;
|
|||||||
*/
|
*/
|
||||||
public abstract class ConfigRegistry
|
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.
|
* Registers the supplied configuration object with the system.
|
||||||
*
|
*
|
||||||
@@ -286,7 +306,13 @@ public abstract class ConfigRegistry
|
|||||||
ByteArrayInputStream bin =
|
ByteArrayInputStream bin =
|
||||||
new ByteArrayInputStream(StringUtil.unhexlate(value));
|
new ByteArrayInputStream(StringUtil.unhexlate(value));
|
||||||
ObjectInputStream oin = createObjectInputStream(bin);
|
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) {
|
} catch (Exception e) {
|
||||||
Log.warning("Failure decoding config value [type=" + type +
|
Log.warning("Failure decoding config value [type=" + type +
|
||||||
", field=" + field + ", exception=" + e + "].");
|
", field=" + field + ", exception=" + e + "].");
|
||||||
@@ -378,4 +404,7 @@ public abstract class ConfigRegistry
|
|||||||
|
|
||||||
/** A mapping from identifying key to config object. */
|
/** A mapping from identifying key to config object. */
|
||||||
protected HashMap<String,ObjectRecord> _configs = new HashMap<String,ObjectRecord>();
|
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;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -99,10 +99,10 @@ public class DatabaseConfigRegistry extends ConfigRegistry
|
|||||||
boolean transitioning)
|
boolean transitioning)
|
||||||
throws PersistenceException
|
throws PersistenceException
|
||||||
{
|
{
|
||||||
|
super(transitioning);
|
||||||
_repo = new ConfigRepository(ctx);
|
_repo = new ConfigRepository(ctx);
|
||||||
_invoker = invoker;
|
_invoker = invoker;
|
||||||
_node = StringUtil.isBlank(node) ? "" : node;
|
_node = StringUtil.isBlank(node) ? "" : node;
|
||||||
_transitioning = transitioning;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override // from ConfigRegistry
|
@Override // from ConfigRegistry
|
||||||
@@ -119,6 +119,7 @@ public class DatabaseConfigRegistry extends ConfigRegistry
|
|||||||
_path = path;
|
_path = path;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
public void init ()
|
public void init ()
|
||||||
{
|
{
|
||||||
// load up our persistent data synchronously because we should be in the middle of
|
// load up our persistent data synchronously because we should be in the middle of
|
||||||
@@ -126,7 +127,7 @@ public class DatabaseConfigRegistry extends ConfigRegistry
|
|||||||
// be completely initialized when we return from this call so that subsequent systems
|
// be completely initialized when we return from this call so that subsequent systems
|
||||||
// can predictably make use of the configuration information that we load
|
// can predictably make use of the configuration information that we load
|
||||||
try {
|
try {
|
||||||
_data = _repo.loadConfig(_node, _path, _transitioning);
|
_data = _repo.loadConfig(_node, _path);
|
||||||
} catch (PersistenceException pe) {
|
} catch (PersistenceException pe) {
|
||||||
Log.warning("Failed to load object configuration [path=" + _path + "].");
|
Log.warning("Failed to load object configuration [path=" + _path + "].");
|
||||||
Log.logStackTrace(pe);
|
Log.logStackTrace(pe);
|
||||||
@@ -305,7 +306,6 @@ public class DatabaseConfigRegistry extends ConfigRegistry
|
|||||||
protected HashMap<String,String> _data;
|
protected HashMap<String,String> _data;
|
||||||
}
|
}
|
||||||
|
|
||||||
protected boolean _transitioning;
|
|
||||||
protected ConfigRepository _repo;
|
protected ConfigRepository _repo;
|
||||||
protected Invoker _invoker;
|
protected Invoker _invoker;
|
||||||
protected String _node;
|
protected String _node;
|
||||||
|
|||||||
@@ -46,21 +46,15 @@ public class ConfigRepository extends DepotRepository
|
|||||||
/**
|
/**
|
||||||
* Loads up the configuration data for the specified object.
|
* Loads up the configuration data for the specified object.
|
||||||
*
|
*
|
||||||
* @param transitioning - if true, the read in value will be written out again immediately to
|
|
||||||
* transition the stored data to a new format
|
|
||||||
*
|
|
||||||
* @return a map containing field/value pairs for all stored configuration data.
|
* @return a map containing field/value pairs for all stored configuration data.
|
||||||
*/
|
*/
|
||||||
public HashMap<String,String> loadConfig (String node, String object, boolean transitioning)
|
public HashMap<String,String> loadConfig (String node, String object)
|
||||||
throws PersistenceException
|
throws PersistenceException
|
||||||
{
|
{
|
||||||
HashMap<String, String> data = new HashMap<String, String>();
|
HashMap<String, String> data = new HashMap<String, String>();
|
||||||
Where where = new Where(ConfigRecord.OBJECT_C, object, ConfigRecord.NODE_C, node);
|
Where where = new Where(ConfigRecord.OBJECT_C, object, ConfigRecord.NODE_C, node);
|
||||||
for (ConfigRecord record : findAll(ConfigRecord.class, where)) {
|
for (ConfigRecord record : findAll(ConfigRecord.class, where)) {
|
||||||
data.put(record.field, record.value);
|
data.put(record.field, record.value);
|
||||||
if (transitioning) {
|
|
||||||
updateConfig(node, object, record.field, record.value);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
return data;
|
return data;
|
||||||
}
|
}
|
||||||
@@ -79,6 +73,4 @@ public class ConfigRepository extends DepotRepository
|
|||||||
{
|
{
|
||||||
classes.add(ConfigRecord.class);
|
classes.add(ConfigRecord.class);
|
||||||
}
|
}
|
||||||
|
|
||||||
protected boolean _transitioning;
|
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user