diff --git a/src/helma/framework/core/Application.java b/src/helma/framework/core/Application.java index 87da8865..1b35a503 100644 --- a/src/helma/framework/core/Application.java +++ b/src/helma/framework/core/Application.java @@ -407,7 +407,7 @@ public class Application extends UnicastRemoteObject implements IRemoteApp, IRep if (unode != null) return null; - unode = new Node (uname); + unode = users.createNode (uname); String usernameField = userMapping.getNameField (); String usernameProp = null; if (usernameField != null) { @@ -422,8 +422,9 @@ public class Application extends UnicastRemoteObject implements IRemoteApp, IRep unode.setString ("password", password); unode.setPrototype ("user"); unode.setDbMapping (userMapping); - users.setNode (uname, unode); - return users.getNode (uname, false); + // users.setNode (uname, unode); + // return users.getNode (uname, false); + return unode; } catch (Exception x) { logEvent ("Error registering User: "+x); return null; diff --git a/src/helma/framework/core/ESNode.java b/src/helma/framework/core/ESNode.java index 7a3da5a3..730c3cfc 100644 --- a/src/helma/framework/core/ESNode.java +++ b/src/helma/framework/core/ESNode.java @@ -5,6 +5,7 @@ package helma.framework.core; import helma.objectmodel.*; +import helma.objectmodel.db.NodeHandle; import helma.util.*; import FESI.Interpreter.*; import FESI.Exceptions.*; @@ -24,8 +25,8 @@ public class ESNode extends ObjectPrototype { INode node; INode cache; - // The ID of the wrapped Node. Makes ESNodes comparable without accessing the wrapped node. - String nodeID; + // The handle of the wrapped Node. Makes ESNodes comparable without accessing the wrapped node. + NodeHandle handle; DbMapping dbmap; ESObject cacheWrapper; Throwable lastError = null; @@ -37,10 +38,11 @@ public class ESNode extends ObjectPrototype { this.eval = eval; this.node = node; cache = null; - cacheWrapper = null; - nodeID = node.getID (); - dbmap = node.getDbMapping (); + + // set node handle to wrapped node + if (node instanceof helma.objectmodel.db.Node) + handle = ((helma.objectmodel.db.Node) node).getHandle (); } public ESNode (ESObject prototype, Evaluator evaluator, Object obj, RequestEvaluator eval) { @@ -55,9 +57,9 @@ public class ESNode extends ObjectPrototype { node = (INode) obj; else node = new Node (obj.toString ()); - // set nodeID to id of wrapped node - nodeID = node.getID (); - dbmap = node.getDbMapping (); + // set node handle to wrapped node + if (node instanceof helma.objectmodel.db.Node) + handle = ((helma.objectmodel.db.Node) node).getHandle (); // get transient cache Node cache = node.getCacheNode (); @@ -68,9 +70,9 @@ public class ESNode extends ObjectPrototype { * Check if the node has been invalidated. If so, it has to be re-fetched * from the db via the app's node manager. */ - private void checkNode () { + protected void checkNode () { if (node.getState () == INode.INVALID) try { - setNode (eval.app.nmgr.getNode (new Key (node.getDbMapping (), node.getID ()))); + node = handle.getNode (eval.app.nmgr.safe); } catch (Exception nx) {} } @@ -82,8 +84,9 @@ public class ESNode extends ObjectPrototype { public void setNode (INode node) { if (node != null) { this.node = node; - nodeID = node.getID (); - dbmap = node.getDbMapping (); + // set node handle to wrapped node + if (node instanceof helma.objectmodel.db.Node) + handle = ((helma.objectmodel.db.Node) node).getHandle (); eval.objectcache.put (node, this); // get transient cache Node cache = node.getCacheNode (); @@ -126,10 +129,6 @@ public class ESNode extends ObjectPrototype { if (what[i] instanceof ESNode) { ESNode esn = (ESNode) what[i]; INode added = node.addNode (esn.getNode ()); - // only rewrap if a transient node was addet to a persistent one. - if (esn.getNode () instanceof helma.objectmodel.Node && - !(node instanceof helma.objectmodel.Node)) - esn.rewrap (added); } return true; } @@ -159,51 +158,9 @@ public class ESNode extends ObjectPrototype { throw new EcmaScriptException ("Can ony add Node objects as subnodes"); ESNode esn = (ESNode) what[1]; INode added = node.addNode (esn.getNode (), (int) what[0].toInt32 ()); - // only rewrap if a transient node was addet to a persistent one. - if (esn.getNode () instanceof helma.objectmodel.Node && - !(node instanceof helma.objectmodel.Node)) - esn.rewrap (added); return true; } - /** - * This is necessary to remap ESNodes to their new peers - * when they go from transient to persistent state. - */ - protected void rewrap (INode newnode) { - eval.app.logEvent ("##### rewrapping "+this+" from "+node+" to "+newnode); - if (newnode == null) - throw new RuntimeException ("Non-consistent check-in detected in rewrap ()"); - INode oldnode = node; - if (oldnode == newnode) { - // eval.app.logEvent ("loop detected or new peers unchanged in rewrap"); - return; - } - // set node and nodeID to new node - node = newnode; - nodeID = node.getID (); - dbmap = node.getDbMapping (); - - int l = oldnode.numberOfNodes (); - for (int i=0; i "+esn); - if (esn != null) { - esn.rewrap (newnode.getSubnodeAt (i)); - } - } - for (Enumeration e=oldnode.properties (); e.hasMoreElements (); ) { - IProperty p = oldnode.get ((String) e.nextElement (), false); - if (p != null && p.getType () == IProperty.NODE) { - INode next = p.getNodeValue (); - ESNode esn = eval.getNodeWrapperFromCache (next); - if (esn != null) { - esn.rewrap (newnode.getNode (p.getName (), false)); - } - } - } - } /** * Remove one or more subnodes. @@ -296,11 +253,6 @@ public class ESNode extends ObjectPrototype { // long now = System.currentTimeMillis (); ESNode esn = (ESNode) propertyValue; node.setNode (propertyName, esn.getNode ()); - if (esn.getNode () instanceof helma.objectmodel.Node && - !(node instanceof helma.objectmodel.Node)) { - INode newnode = node.getNode (propertyName, false); - esn.rewrap (newnode); - } // eval.app.logEvent ("*** spent "+(System.currentTimeMillis () - now)+" ms to set property "+propertyName); } else { // eval.app.logEvent ("got "+propertyValue.getClass ()); @@ -463,7 +415,7 @@ public class ESNode extends ObjectPrototype { return true; if (what instanceof ESNode) { ESNode other = (ESNode) what; - return (other.nodeID.equals (nodeID) && other.dbmap == dbmap); + return (other.handle.equals (handle)); } return false; } diff --git a/src/helma/framework/core/ESUser.java b/src/helma/framework/core/ESUser.java index 5151605d..cf39a1ef 100644 --- a/src/helma/framework/core/ESUser.java +++ b/src/helma/framework/core/ESUser.java @@ -67,20 +67,22 @@ public class ESUser extends ESNode { // it will user the original transient cache node again. this.node = user.getNode (); } - nodeID = this.node.getID (); - dbmap = this.node.getDbMapping (); + // set node handle to wrapped node + if (node instanceof helma.objectmodel.db.Node) + handle = ((helma.objectmodel.db.Node) node).getHandle (); // we don't take over the transient cache from the node, // because we always use the one from the user object. } public void updateNodeFromUser () { node = user.getNode (); - nodeID = node.getID (); - dbmap = node.getDbMapping (); + // set node handle to wrapped node + if (node instanceof helma.objectmodel.db.Node) + handle = ((helma.objectmodel.db.Node) node).getHandle (); } public String toString () { - return ("UserObject "+node.getNameOrID ()); + return ("UserObject "+node.getName ()); } } diff --git a/src/helma/framework/core/HopExtension.java b/src/helma/framework/core/HopExtension.java index 31d3cc0a..a957b1ad 100644 --- a/src/helma/framework/core/HopExtension.java +++ b/src/helma/framework/core/HopExtension.java @@ -236,10 +236,11 @@ public class HopExtension { INode node = esn.getNode (); if (node instanceof helma.objectmodel.db.Node) { ((helma.objectmodel.db.Node) node).invalidate (); - try { + esn.checkNode (); + /* try { node = app.nmgr.getNode (new Key (node.getDbMapping (), node.getID ())); esn.setNode (node); - } catch (Exception x) {} + } catch (Exception x) {} */ } return ESBoolean.makeBoolean (true); } diff --git a/src/helma/framework/core/User.java b/src/helma/framework/core/User.java index b7a2fc07..942313f7 100644 --- a/src/helma/framework/core/User.java +++ b/src/helma/framework/core/User.java @@ -7,31 +7,32 @@ import java.io.*; import java.util.*; import java.net.URLEncoder; import helma.objectmodel.*; +import helma.objectmodel.db.NodeHandle; /** - * This represents a user who is currently using the HOP application. This does - * not just comprend registered users, but anybody who happens to surf the site. + * This represents a user who is currently using the Hop application. This does + * not just comprend registered users, but anybody who happens to surf the site. + * Depending on whether the user is logged in or not, the user object holds a + * persistent user node or just a transient cache node */ public class User implements Serializable { Application app; String sessionID; - String uid, nid; + String uid; // the unique id (login name) for the user, if logged in + NodeHandle nhandle; long onSince, lastTouched; Node cache; - DbMapping umap; String message; public User (String sid, Application app) { this.uid = null; - this.nid = null; + this.nhandle = null; this.app = app; setNode (null); - umap = app.getDbMapping ("user"); cache = new Node ("[session cache]"); cache.setPrototype ("user"); - cache.setDbMapping (umap); sessionID = sid; onSince = System.currentTimeMillis (); lastTouched = onSince; @@ -45,19 +46,19 @@ public class User implements Serializable { public void setNode (INode n) { // IServer.getLogger().log ("esn = "+esn); if (n == null) { - nid = null; + nhandle = null; uid = null; } else { uid = n.getNameOrID (); - nid = n.getID (); + nhandle = ((helma.objectmodel.db.Node) n).getHandle (); } } public INode getNode () { - if (uid == null) { + if (nhandle == null) { return cache; } else { - return app.nmgr.safe.getNode (nid, umap); + return nhandle.getNode (app.nmgr.safe); } }