Make sure nodes created by HopObject.getCollection have a valid id. Fixes bug 663.

This commit is contained in:
hns 2009-07-30 09:48:58 +00:00
parent 507da18a8b
commit 66eb754564
3 changed files with 18 additions and 2 deletions

View file

@ -45,6 +45,9 @@ public final class DbKey implements Key, Serializable {
* make a key for a persistent Object, describing its datasource and id.
*/
public DbKey(DbMapping dbmap, String id) {
if (id == null) {
throw new IllegalArgumentException("id null in DbKey");
}
this.id = id;
this.storageName = (dbmap == null) ? null : dbmap.getStorageTypeName();
}

View file

@ -144,6 +144,14 @@ public final class DbMapping {
}
}
/**
* Create a DbMapping from a type.properties property file
*/
public DbMapping(Application app, String typename, Properties props, boolean virtual) {
this(app, typename, props);
isVirtual = virtual;
}
/**
* Create a DbMapping from a type.properties property file
*/

View file

@ -23,6 +23,7 @@ import helma.objectmodel.INode;
import helma.objectmodel.db.DbMapping;
import helma.objectmodel.db.DbKey;
import helma.objectmodel.db.Node;
import helma.objectmodel.db.WrappedNodeManager;
import org.mozilla.javascript.*;
@ -36,6 +37,8 @@ public class HopObjectCtor extends FunctionObject {
static Method hopObjCtor;
static long collectionId = 0;
static {
try {
hopObjCtor = HopObjectCtor.class.getMethod("jsConstructor", new Class[] {
@ -203,11 +206,13 @@ public class HopObjectCtor extends FunctionObject {
childmapping.put("collection", HopObjectCtor.this.getFunctionName());
}
Node node = new Node("HopQuery", null, core.app.getWrappedNodeManager());
Properties props = new Properties();
props.put("_children", childmapping);
DbMapping dbmap = new DbMapping(core.app, null, props);
DbMapping dbmap = new DbMapping(core.app, null, props, true);
dbmap.update();
WrappedNodeManager nmgr = core.app.getWrappedNodeManager();
Node node = new Node("HopQuery", Long.toString(collectionId++), null, nmgr);
node.setDbMapping(dbmap);
node.setState(Node.VIRTUAL);
return new HopObject("HopQuery", core, node, core.hopObjectProto);