From 20af506b7560432abc14e7daf08813d893240da9 Mon Sep 17 00:00:00 2001 From: hns Date: Wed, 8 Aug 2001 10:57:47 +0000 Subject: [PATCH] overwrite hashCode to depend on prototype make prototype switchable for prototypes with same storage --- src/helma/objectmodel/db/Node.java | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) diff --git a/src/helma/objectmodel/db/Node.java b/src/helma/objectmodel/db/Node.java index 55020622..811558e9 100644 --- a/src/helma/objectmodel/db/Node.java +++ b/src/helma/objectmodel/db/Node.java @@ -1418,6 +1418,23 @@ public final class Node implements INode, Serializable { } } + // check if the property we're setting specifies the prototype of this object. + if (dbmap != null && dbmap.getPrototypeField () != null) { + String pn = dbmap.columnNameToProperty (dbmap.getPrototypeField ()); + if (propname.equals (pn)) { + DbMapping newmap = nmgr.getDbMapping (value); + if (newmap != null) { + // see if old and new prototypes have same storage - otherwise type change is ignored + String oldStorage = dbmap.getStorageTypeName (); + String newStorage = newmap.getStorageTypeName (); + if ((oldStorage == null && newStorage == null) || + (oldStorage != null && oldStorage.equals (newStorage))) { + this.dbmap = newmap; + this.prototype = value; + } + } + } + } // Server.throwNodeEvent (new NodeEvent (this, NodeEvent.PROPERTIES_CHANGED)); lastmodified = System.currentTimeMillis (); @@ -1786,6 +1803,18 @@ public final class Node implements INode, Serializable { return nmgr == null; } + /** + * We overwrite hashCode to make it dependant from the prototype. That way, when the prototype + * changes, the node will automatically get a new ESNode wrapper, since they're cached in a hashtable. + * You gotta love these hash code tricks ;-) + */ + public int hashCode () { + if (prototype == null) + return super.hashCode (); + else + return super.hashCode () + prototype.hashCode (); + } + public void dump () { System.err.println ("subnodes: "+subnodes); System.err.println ("properties: "+propMap);