updated the complete helma.framework.core package to use

NodeHandle instead of ID/DbMapping.
This commit is contained in:
hns 2001-08-03 14:39:17 +00:00
parent aba59483ee
commit 2baa845dfe
5 changed files with 42 additions and 85 deletions

View file

@ -407,7 +407,7 @@ public class Application extends UnicastRemoteObject implements IRemoteApp, IRep
if (unode != null) if (unode != null)
return null; return null;
unode = new Node (uname); unode = users.createNode (uname);
String usernameField = userMapping.getNameField (); String usernameField = userMapping.getNameField ();
String usernameProp = null; String usernameProp = null;
if (usernameField != null) { if (usernameField != null) {
@ -422,8 +422,9 @@ public class Application extends UnicastRemoteObject implements IRemoteApp, IRep
unode.setString ("password", password); unode.setString ("password", password);
unode.setPrototype ("user"); unode.setPrototype ("user");
unode.setDbMapping (userMapping); unode.setDbMapping (userMapping);
users.setNode (uname, unode); // users.setNode (uname, unode);
return users.getNode (uname, false); // return users.getNode (uname, false);
return unode;
} catch (Exception x) { } catch (Exception x) {
logEvent ("Error registering User: "+x); logEvent ("Error registering User: "+x);
return null; return null;

View file

@ -5,6 +5,7 @@
package helma.framework.core; package helma.framework.core;
import helma.objectmodel.*; import helma.objectmodel.*;
import helma.objectmodel.db.NodeHandle;
import helma.util.*; import helma.util.*;
import FESI.Interpreter.*; import FESI.Interpreter.*;
import FESI.Exceptions.*; import FESI.Exceptions.*;
@ -24,8 +25,8 @@ public class ESNode extends ObjectPrototype {
INode node; INode node;
INode cache; INode cache;
// The ID of the wrapped Node. Makes ESNodes comparable without accessing the wrapped node. // The handle of the wrapped Node. Makes ESNodes comparable without accessing the wrapped node.
String nodeID; NodeHandle handle;
DbMapping dbmap; DbMapping dbmap;
ESObject cacheWrapper; ESObject cacheWrapper;
Throwable lastError = null; Throwable lastError = null;
@ -37,10 +38,11 @@ public class ESNode extends ObjectPrototype {
this.eval = eval; this.eval = eval;
this.node = node; this.node = node;
cache = null; cache = null;
cacheWrapper = 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) { public ESNode (ESObject prototype, Evaluator evaluator, Object obj, RequestEvaluator eval) {
@ -55,9 +57,9 @@ public class ESNode extends ObjectPrototype {
node = (INode) obj; node = (INode) obj;
else else
node = new Node (obj.toString ()); node = new Node (obj.toString ());
// set nodeID to id of wrapped node // set node handle to wrapped node
nodeID = node.getID (); if (node instanceof helma.objectmodel.db.Node)
dbmap = node.getDbMapping (); handle = ((helma.objectmodel.db.Node) node).getHandle ();
// get transient cache Node // get transient cache Node
cache = node.getCacheNode (); 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 * Check if the node has been invalidated. If so, it has to be re-fetched
* from the db via the app's node manager. * from the db via the app's node manager.
*/ */
private void checkNode () { protected void checkNode () {
if (node.getState () == INode.INVALID) try { 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) {} } catch (Exception nx) {}
} }
@ -82,8 +84,9 @@ public class ESNode extends ObjectPrototype {
public void setNode (INode node) { public void setNode (INode node) {
if (node != null) { if (node != null) {
this.node = node; this.node = node;
nodeID = node.getID (); // set node handle to wrapped node
dbmap = node.getDbMapping (); if (node instanceof helma.objectmodel.db.Node)
handle = ((helma.objectmodel.db.Node) node).getHandle ();
eval.objectcache.put (node, this); eval.objectcache.put (node, this);
// get transient cache Node // get transient cache Node
cache = node.getCacheNode (); cache = node.getCacheNode ();
@ -126,10 +129,6 @@ public class ESNode extends ObjectPrototype {
if (what[i] instanceof ESNode) { if (what[i] instanceof ESNode) {
ESNode esn = (ESNode) what[i]; ESNode esn = (ESNode) what[i];
INode added = node.addNode (esn.getNode ()); 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; return true;
} }
@ -159,51 +158,9 @@ public class ESNode extends ObjectPrototype {
throw new EcmaScriptException ("Can ony add Node objects as subnodes"); throw new EcmaScriptException ("Can ony add Node objects as subnodes");
ESNode esn = (ESNode) what[1]; ESNode esn = (ESNode) what[1];
INode added = node.addNode (esn.getNode (), (int) what[0].toInt32 ()); 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; 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<l; i++) {
INode next = oldnode.getSubnodeAt (i);
ESNode esn = eval.getNodeWrapperFromCache (next);
// eval.app.logEvent ("rewrapping node: "+next+" -> "+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. * Remove one or more subnodes.
@ -296,11 +253,6 @@ public class ESNode extends ObjectPrototype {
// long now = System.currentTimeMillis (); // long now = System.currentTimeMillis ();
ESNode esn = (ESNode) propertyValue; ESNode esn = (ESNode) propertyValue;
node.setNode (propertyName, esn.getNode ()); 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); // eval.app.logEvent ("*** spent "+(System.currentTimeMillis () - now)+" ms to set property "+propertyName);
} else { } else {
// eval.app.logEvent ("got "+propertyValue.getClass ()); // eval.app.logEvent ("got "+propertyValue.getClass ());
@ -463,7 +415,7 @@ public class ESNode extends ObjectPrototype {
return true; return true;
if (what instanceof ESNode) { if (what instanceof ESNode) {
ESNode other = (ESNode) what; ESNode other = (ESNode) what;
return (other.nodeID.equals (nodeID) && other.dbmap == dbmap); return (other.handle.equals (handle));
} }
return false; return false;
} }

View file

@ -67,20 +67,22 @@ public class ESUser extends ESNode {
// it will user the original transient cache node again. // it will user the original transient cache node again.
this.node = user.getNode (); this.node = user.getNode ();
} }
nodeID = this.node.getID (); // set node handle to wrapped node
dbmap = this.node.getDbMapping (); 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, // we don't take over the transient cache from the node,
// because we always use the one from the user object. // because we always use the one from the user object.
} }
public void updateNodeFromUser () { public void updateNodeFromUser () {
node = user.getNode (); node = user.getNode ();
nodeID = node.getID (); // set node handle to wrapped node
dbmap = node.getDbMapping (); if (node instanceof helma.objectmodel.db.Node)
handle = ((helma.objectmodel.db.Node) node).getHandle ();
} }
public String toString () { public String toString () {
return ("UserObject "+node.getNameOrID ()); return ("UserObject "+node.getName ());
} }
} }

View file

@ -236,10 +236,11 @@ public class HopExtension {
INode node = esn.getNode (); INode node = esn.getNode ();
if (node instanceof helma.objectmodel.db.Node) { if (node instanceof helma.objectmodel.db.Node) {
((helma.objectmodel.db.Node) node).invalidate (); ((helma.objectmodel.db.Node) node).invalidate ();
try { esn.checkNode ();
/* try {
node = app.nmgr.getNode (new Key (node.getDbMapping (), node.getID ())); node = app.nmgr.getNode (new Key (node.getDbMapping (), node.getID ()));
esn.setNode (node); esn.setNode (node);
} catch (Exception x) {} } catch (Exception x) {} */
} }
return ESBoolean.makeBoolean (true); return ESBoolean.makeBoolean (true);
} }

View file

@ -7,31 +7,32 @@ import java.io.*;
import java.util.*; import java.util.*;
import java.net.URLEncoder; import java.net.URLEncoder;
import helma.objectmodel.*; import helma.objectmodel.*;
import helma.objectmodel.db.NodeHandle;
/** /**
* This represents a user who is currently using the HOP application. This does * 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. * 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 { public class User implements Serializable {
Application app; Application app;
String sessionID; String sessionID;
String uid, nid; String uid; // the unique id (login name) for the user, if logged in
NodeHandle nhandle;
long onSince, lastTouched; long onSince, lastTouched;
Node cache; Node cache;
DbMapping umap;
String message; String message;
public User (String sid, Application app) { public User (String sid, Application app) {
this.uid = null; this.uid = null;
this.nid = null; this.nhandle = null;
this.app = app; this.app = app;
setNode (null); setNode (null);
umap = app.getDbMapping ("user");
cache = new Node ("[session cache]"); cache = new Node ("[session cache]");
cache.setPrototype ("user"); cache.setPrototype ("user");
cache.setDbMapping (umap);
sessionID = sid; sessionID = sid;
onSince = System.currentTimeMillis (); onSince = System.currentTimeMillis ();
lastTouched = onSince; lastTouched = onSince;
@ -45,19 +46,19 @@ public class User implements Serializable {
public void setNode (INode n) { public void setNode (INode n) {
// IServer.getLogger().log ("esn = "+esn); // IServer.getLogger().log ("esn = "+esn);
if (n == null) { if (n == null) {
nid = null; nhandle = null;
uid = null; uid = null;
} else { } else {
uid = n.getNameOrID (); uid = n.getNameOrID ();
nid = n.getID (); nhandle = ((helma.objectmodel.db.Node) n).getHandle ();
} }
} }
public INode getNode () { public INode getNode () {
if (uid == null) { if (nhandle == null) {
return cache; return cache;
} else { } else {
return app.nmgr.safe.getNode (nid, umap); return nhandle.getNode (app.nmgr.safe);
} }
} }