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:
parent
9c058a3a02
commit
35d118c43c
8 changed files with 52 additions and 30 deletions
|
@ -34,6 +34,8 @@ public class Application extends UnicastRemoteObject implements IRemoteApp, Runn
|
|||
protected static WebServer xmlrpc;
|
||||
protected XmlRpcAccess xmlrpcAccess;
|
||||
|
||||
private String baseURI;
|
||||
|
||||
public boolean debug;
|
||||
|
||||
TypeManager typemgr;
|
||||
|
@ -376,6 +378,8 @@ public class Application extends UnicastRemoteObject implements IRemoteApp, Runn
|
|||
String uid = u.user.uid;
|
||||
if (uid != null)
|
||||
activeUsers.remove (uid);
|
||||
|
||||
// switch back to the non-persistent user node as cache
|
||||
u.user.setNode (null);
|
||||
u.setNode (u.user.getNode ());
|
||||
}
|
||||
|
@ -390,17 +394,26 @@ public class Application extends UnicastRemoteObject implements IRemoteApp, Runn
|
|||
}
|
||||
|
||||
public String getNodeHref (INode n, String tmpname) {
|
||||
boolean linkByQuery = "query".equalsIgnoreCase (props.getProperty ("linkmethod", ""));
|
||||
INode root = getDataRoot ();
|
||||
INode users = getUserRoot ();
|
||||
String connector = linkByQuery ? "?path=" : "/";
|
||||
String req = props.getProperty ("baseURI", "") + connector;
|
||||
String href = n.getHref (root, users, tmpname, req);
|
||||
// check base uri from app.properties
|
||||
String base = props.getProperty ("baseURI");
|
||||
if (base != null)
|
||||
setBaseURI (base);
|
||||
String href = n.getHref (root, users, tmpname, baseURI);
|
||||
// add cache teaser
|
||||
// href = href + "&tease="+((int) (Math.random ()*999));
|
||||
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 () {
|
||||
long cleanupSleep = 60000; // thread sleep interval (fixed)
|
||||
|
|
|
@ -26,6 +26,7 @@ public class ESNode extends ObjectPrototype {
|
|||
|
||||
// The ID of the wrapped Node. Makes ESNodes comparable without accessing the wrapped node.
|
||||
String nodeID;
|
||||
DbMapping dbmap;
|
||||
ESObject cacheWrapper;
|
||||
Throwable lastError = null;
|
||||
RequestEvaluator eval;
|
||||
|
@ -39,6 +40,7 @@ public class ESNode extends ObjectPrototype {
|
|||
|
||||
cacheWrapper = null;
|
||||
nodeID = node.getID ();
|
||||
dbmap = node.getDbMapping ();
|
||||
}
|
||||
|
||||
public ESNode (ESObject prototype, Evaluator evaluator, Object obj, RequestEvaluator eval) {
|
||||
|
@ -55,6 +57,7 @@ public class ESNode extends ObjectPrototype {
|
|||
node = new Node (obj.toString ());
|
||||
// set nodeID to id of wrapped node
|
||||
nodeID = node.getID ();
|
||||
dbmap = node.getDbMapping ();
|
||||
|
||||
// get transient cache Node
|
||||
cache = node.getCacheNode ();
|
||||
|
@ -79,6 +82,8 @@ public class ESNode extends ObjectPrototype {
|
|||
public void setNode (INode node) {
|
||||
if (node != null) {
|
||||
this.node = node;
|
||||
nodeID = node.getID ();
|
||||
dbmap = node.getDbMapping ();
|
||||
eval.objectcache.put (node, this);
|
||||
// get transient cache Node
|
||||
cache = node.getCacheNode ();
|
||||
|
@ -221,6 +226,7 @@ public class ESNode extends ObjectPrototype {
|
|||
// 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++) {
|
||||
|
@ -363,7 +369,8 @@ public class ESNode extends ObjectPrototype {
|
|||
public ESValue getProperty (int i) throws EcmaScriptException {
|
||||
checkNode ();
|
||||
INode n = node.getSubnodeAt (i);
|
||||
if (n == null) return ESNull.theNull;
|
||||
if (n == null)
|
||||
return ESNull.theNull;
|
||||
return eval.getNodeWrapper (n);
|
||||
}
|
||||
|
||||
|
@ -500,10 +507,13 @@ public class ESNode extends ObjectPrototype {
|
|||
* or the wrapped INode itself. FIXME: doesen't check dbmapping/type!
|
||||
*/
|
||||
public boolean equals (Object what) {
|
||||
if (what == null) return false;
|
||||
if (what == this) return true;
|
||||
if (what == null)
|
||||
return false;
|
||||
if (what == this)
|
||||
return true;
|
||||
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;
|
||||
}
|
||||
|
|
|
@ -64,6 +64,8 @@ public class ESUser extends ESNode {
|
|||
public void setNode (INode node) {
|
||||
if (node != null) {
|
||||
this.node = node;
|
||||
nodeID = node.getID ();
|
||||
dbmap = node.getDbMapping ();
|
||||
eval.objectcache.put (node, this);
|
||||
// we don't take over the transient cache from the node,
|
||||
// because we always use the one from the user object.
|
||||
|
|
|
@ -40,10 +40,9 @@ public class DbMapping {
|
|||
String idField;
|
||||
String nameField;
|
||||
|
||||
// id generator via sequence
|
||||
// descriptor for key generation method
|
||||
private String idgen;
|
||||
// id generator for dbs that don't support sequences
|
||||
private String sqlidgen;
|
||||
// remember last key generated for this table
|
||||
public long lastID;
|
||||
|
||||
|
||||
|
@ -96,15 +95,13 @@ public class DbMapping {
|
|||
|
||||
this.table = props.getProperty ("_tablename");
|
||||
this.idgen = props.getProperty ("_idgen");
|
||||
this.sqlidgen = props.getProperty ("_sqlidgen");
|
||||
|
||||
String sourceName = props.getProperty ("_datasource");
|
||||
if (sourceName != null)
|
||||
source = (DbSource) IServer.dbSources.get (sourceName.toLowerCase ());
|
||||
|
||||
idField = props.getProperty ("_id");
|
||||
// id field must not be null
|
||||
if (idField == null)
|
||||
idField = "id";
|
||||
// id field must not be null, default is "id"
|
||||
idField = props.getProperty ("_id", "id");
|
||||
|
||||
nameField = props.getProperty ("_name");
|
||||
|
||||
|
@ -331,10 +328,6 @@ public class DbMapping {
|
|||
return idgen;
|
||||
}
|
||||
|
||||
public String getSQLIDgen () {
|
||||
return sqlidgen;
|
||||
}
|
||||
|
||||
|
||||
public WrappedNodeManager getWrappedNodeManager () {
|
||||
if (app == null)
|
||||
|
|
|
@ -72,6 +72,9 @@ public class ApplicationManager {
|
|||
try {
|
||||
Application app = new Application (appName, dbHome, appHome);
|
||||
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 ();
|
||||
} catch (Exception x) {
|
||||
IServer.getLogger().log ("Error creating application "+appName+": "+x);
|
||||
|
|
|
@ -1743,7 +1743,7 @@ public class Node implements INode, Serializable {
|
|||
}
|
||||
|
||||
public String toString () {
|
||||
return "Node " + name;
|
||||
return "HopObject " + name;
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -478,7 +478,7 @@ public final class NodeManager {
|
|||
/**
|
||||
* 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 ();
|
||||
// tx.timer.beginEvent ("generateID "+map);
|
||||
|
|
|
@ -116,14 +116,15 @@ import java.util.Vector;
|
|||
|
||||
public String generateID (DbMapping map) {
|
||||
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 ();
|
||||
else {
|
||||
if ("true".equalsIgnoreCase (map.getSQLIDgen()))
|
||||
return nmgr.generateSQLID (map);
|
||||
// or if we query max key value
|
||||
else if (map.getIDgen() == null || "[max]".equalsIgnoreCase (map.getIDgen()))
|
||||
return nmgr.generateMaxID (map);
|
||||
else
|
||||
return nmgr.generateID (map);
|
||||
}
|
||||
// otherwise, we use an oracle sequence
|
||||
} catch (Exception x) {
|
||||
throw new RuntimeException (x.toString ());
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue