made max the default method of key generation for relational databases

cleanup in ESNode on while searching comic node manager bug
set baseuri when using embedded web server
This commit is contained in:
hns 2001-02-23 18:07:24 +00:00
parent 9c058a3a02
commit 35d118c43c
8 changed files with 52 additions and 30 deletions

View file

@ -34,6 +34,8 @@ public class Application extends UnicastRemoteObject implements IRemoteApp, Runn
protected static WebServer xmlrpc; protected static WebServer xmlrpc;
protected XmlRpcAccess xmlrpcAccess; protected XmlRpcAccess xmlrpcAccess;
private String baseURI;
public boolean debug; public boolean debug;
TypeManager typemgr; TypeManager typemgr;
@ -376,6 +378,8 @@ public class Application extends UnicastRemoteObject implements IRemoteApp, Runn
String uid = u.user.uid; String uid = u.user.uid;
if (uid != null) if (uid != null)
activeUsers.remove (uid); activeUsers.remove (uid);
// switch back to the non-persistent user node as cache
u.user.setNode (null); u.user.setNode (null);
u.setNode (u.user.getNode ()); u.setNode (u.user.getNode ());
} }
@ -390,17 +394,26 @@ public class Application extends UnicastRemoteObject implements IRemoteApp, Runn
} }
public String getNodeHref (INode n, String tmpname) { public String getNodeHref (INode n, String tmpname) {
boolean linkByQuery = "query".equalsIgnoreCase (props.getProperty ("linkmethod", ""));
INode root = getDataRoot (); INode root = getDataRoot ();
INode users = getUserRoot (); INode users = getUserRoot ();
String connector = linkByQuery ? "?path=" : "/"; // check base uri from app.properties
String req = props.getProperty ("baseURI", "") + connector; String base = props.getProperty ("baseURI");
String href = n.getHref (root, users, tmpname, req); if (base != null)
setBaseURI (base);
String href = n.getHref (root, users, tmpname, baseURI);
// add cache teaser // add cache teaser
// href = href + "&tease="+((int) (Math.random ()*999)); // href = href + "&tease="+((int) (Math.random ()*999));
return href; return href;
} }
public void setBaseURI (String uri) {
if (uri == null)
this.baseURI = "/";
else if (!uri.endsWith ("/"))
this.baseURI = uri+"/";
else
this.baseURI = uri;
}
public void run () { public void run () {
long cleanupSleep = 60000; // thread sleep interval (fixed) long cleanupSleep = 60000; // thread sleep interval (fixed)

View file

@ -26,6 +26,7 @@ public class ESNode extends ObjectPrototype {
// The ID of the wrapped Node. Makes ESNodes comparable without accessing the wrapped node. // The ID of the wrapped Node. Makes ESNodes comparable without accessing the wrapped node.
String nodeID; String nodeID;
DbMapping dbmap;
ESObject cacheWrapper; ESObject cacheWrapper;
Throwable lastError = null; Throwable lastError = null;
RequestEvaluator eval; RequestEvaluator eval;
@ -39,6 +40,7 @@ public class ESNode extends ObjectPrototype {
cacheWrapper = null; cacheWrapper = null;
nodeID = node.getID (); nodeID = node.getID ();
dbmap = node.getDbMapping ();
} }
public ESNode (ESObject prototype, Evaluator evaluator, Object obj, RequestEvaluator eval) { public ESNode (ESObject prototype, Evaluator evaluator, Object obj, RequestEvaluator eval) {
@ -55,6 +57,7 @@ public class ESNode extends ObjectPrototype {
node = new Node (obj.toString ()); node = new Node (obj.toString ());
// set nodeID to id of wrapped node // set nodeID to id of wrapped node
nodeID = node.getID (); nodeID = node.getID ();
dbmap = node.getDbMapping ();
// get transient cache Node // get transient cache Node
cache = node.getCacheNode (); cache = node.getCacheNode ();
@ -79,6 +82,8 @@ 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 ();
dbmap = node.getDbMapping ();
eval.objectcache.put (node, this); eval.objectcache.put (node, this);
// get transient cache Node // get transient cache Node
cache = node.getCacheNode (); cache = node.getCacheNode ();
@ -221,6 +226,7 @@ public class ESNode extends ObjectPrototype {
// set node and nodeID to new node // set node and nodeID to new node
node = newnode; node = newnode;
nodeID = node.getID (); nodeID = node.getID ();
dbmap = node.getDbMapping ();
int l = oldnode.numberOfNodes (); int l = oldnode.numberOfNodes ();
for (int i=0; i<l; i++) { for (int i=0; i<l; i++) {
@ -363,7 +369,8 @@ public class ESNode extends ObjectPrototype {
public ESValue getProperty (int i) throws EcmaScriptException { public ESValue getProperty (int i) throws EcmaScriptException {
checkNode (); checkNode ();
INode n = node.getSubnodeAt (i); INode n = node.getSubnodeAt (i);
if (n == null) return ESNull.theNull; if (n == null)
return ESNull.theNull;
return eval.getNodeWrapper (n); return eval.getNodeWrapper (n);
} }
@ -500,10 +507,13 @@ public class ESNode extends ObjectPrototype {
* or the wrapped INode itself. FIXME: doesen't check dbmapping/type! * or the wrapped INode itself. FIXME: doesen't check dbmapping/type!
*/ */
public boolean equals (Object what) { public boolean equals (Object what) {
if (what == null) return false; if (what == null)
if (what == this) return true; return false;
if (what == this)
return true;
if (what instanceof ESNode) { if (what instanceof ESNode) {
return (((ESNode) what).nodeID.equals (this.nodeID)); ESNode other = (ESNode) what;
return (other.nodeID.equals (nodeID) && other.dbmap == dbmap);
} }
return false; return false;
} }

View file

@ -64,6 +64,8 @@ public class ESUser extends ESNode {
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 ();
dbmap = node.getDbMapping ();
eval.objectcache.put (node, this); eval.objectcache.put (node, this);
// 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.

View file

@ -40,10 +40,9 @@ public class DbMapping {
String idField; String idField;
String nameField; String nameField;
// id generator via sequence // descriptor for key generation method
private String idgen; private String idgen;
// id generator for dbs that don't support sequences // remember last key generated for this table
private String sqlidgen;
public long lastID; public long lastID;
@ -96,15 +95,13 @@ public class DbMapping {
this.table = props.getProperty ("_tablename"); this.table = props.getProperty ("_tablename");
this.idgen = props.getProperty ("_idgen"); this.idgen = props.getProperty ("_idgen");
this.sqlidgen = props.getProperty ("_sqlidgen");
String sourceName = props.getProperty ("_datasource"); String sourceName = props.getProperty ("_datasource");
if (sourceName != null) if (sourceName != null)
source = (DbSource) IServer.dbSources.get (sourceName.toLowerCase ()); source = (DbSource) IServer.dbSources.get (sourceName.toLowerCase ());
idField = props.getProperty ("_id"); // id field must not be null, default is "id"
// id field must not be null idField = props.getProperty ("_id", "id");
if (idField == null)
idField = "id";
nameField = props.getProperty ("_name"); nameField = props.getProperty ("_name");
@ -331,10 +328,6 @@ public class DbMapping {
return idgen; return idgen;
} }
public String getSQLIDgen () {
return sqlidgen;
}
public WrappedNodeManager getWrappedNodeManager () { public WrappedNodeManager getWrappedNodeManager () {
if (app == null) if (app == null)

View file

@ -72,6 +72,9 @@ public class ApplicationManager {
try { try {
Application app = new Application (appName, dbHome, appHome); Application app = new Application (appName, dbHome, appHome);
applications.put (appName, app); applications.put (appName, app);
// if we're running with the embedded web server, set app base uri to /appname
if (server.websrv != null)
app.setBaseURI ("/"+java.net.URLEncoder.encode (appName));
app.start (); app.start ();
} catch (Exception x) { } catch (Exception x) {
IServer.getLogger().log ("Error creating application "+appName+": "+x); IServer.getLogger().log ("Error creating application "+appName+": "+x);

View file

@ -1743,7 +1743,7 @@ public class Node implements INode, Serializable {
} }
public String toString () { public String toString () {
return "Node " + name; return "HopObject " + name;
} }

View file

@ -478,7 +478,7 @@ public final class NodeManager {
/** /**
* Generates an ID for the table by finding out the maximum current value * Generates an ID for the table by finding out the maximum current value
*/ */
public synchronized String generateSQLID (DbMapping map) throws Exception { public synchronized String generateMaxID (DbMapping map) throws Exception {
Transactor tx = (Transactor) Thread.currentThread (); Transactor tx = (Transactor) Thread.currentThread ();
// tx.timer.beginEvent ("generateID "+map); // tx.timer.beginEvent ("generateID "+map);

View file

@ -116,14 +116,15 @@ import java.util.Vector;
public String generateID (DbMapping map) { public String generateID (DbMapping map) {
try { try {
if (map == null || (map.getIDgen() == null && map.getSQLIDgen() == null)) // check if we use internal id generator
if (map == null || !map.isRelational () || "[hop]".equalsIgnoreCase (map.getIDgen()))
return nmgr.idgen.newID (); return nmgr.idgen.newID ();
else { // or if we query max key value
if ("true".equalsIgnoreCase (map.getSQLIDgen())) else if (map.getIDgen() == null || "[max]".equalsIgnoreCase (map.getIDgen()))
return nmgr.generateSQLID (map); return nmgr.generateMaxID (map);
else else
return nmgr.generateID (map); return nmgr.generateID (map);
} // otherwise, we use an oracle sequence
} catch (Exception x) { } catch (Exception x) {
throw new RuntimeException (x.toString ()); throw new RuntimeException (x.toString ());
} }