getNameOrID will now honor anonymous flag and not try to override it

setNode throws an exception when trying to set an object with wrong type
minor fixes in getParent()
This commit is contained in:
hns 2001-03-07 21:55:30 +00:00
parent 2a08d8150f
commit 7d49b8b673

View file

@ -411,17 +411,19 @@ public class Node implements INode, Serializable {
public String getNameOrID () { public String getNameOrID () {
// if subnodes are also mounted as properties, try to get the "nice" prop value // if subnodes are also mounted as properties, try to get the "nice" prop value
// instead of the id by turning the anonymous flag off. // instead of the id by turning the anonymous flag off.
if (anonymous && parentmap != null) { if (parentmap != null) {
Relation prel = parentmap.getPropertyRelation(); Relation prel = parentmap.getPropertyRelation();
if (prel != null && prel.subnodesAreProperties && !prel.usesPrimaryKey ()) try { if (prel != null && prel.subnodesAreProperties && !prel.usesPrimaryKey ()) try {
Relation localrel = dbmap.columnNameToProperty (prel.getRemoteField ()); Relation localrel = dbmap.columnNameToProperty (prel.getRemoteField ());
String propvalue = getString (localrel.propname, false); String propvalue = getString (localrel.propname, false);
if (propvalue != null && propvalue.length() > 0) { if (propvalue != null && propvalue.length() > 0) {
setName (propvalue); setName (propvalue);
anonymous = false; // anonymous = false;
// nameProp = localrel.propname; // nameProp = localrel.propname;
} }
} catch (Exception ignore) {} // just fall back to ID } catch (Exception ignore) {
// just fall back to ID
}
} }
return anonymous || name == null || name.length() == 0 ? id : name; return anonymous || name == null || name.length() == 0 ? id : name;
} }
@ -610,22 +612,22 @@ public class Node implements INode, Serializable {
pn = nmgr.getNode ("0", nmgr.getDbMapping ("root")); pn = nmgr.getNode ("0", nmgr.getDbMapping ("root"));
if (pn != null) { if (pn != null) {
// see if dbmapping specifies anonymity for this node // see if dbmapping specifies anonymity for this node
anonymous = !pinfo.named;
if (pinfo.virtualname != null) if (pinfo.virtualname != null)
pn = pn.getNode (pinfo.virtualname, false); pn = pn.getNode (pinfo.virtualname, false);
DbMapping dbm = pn == null ? null : pn.getDbMapping (); DbMapping dbm = pn == null ? null : pn.getDbMapping ();
try {
if (dbm != null && dbm.getSubnodeGroupby () != null) { if (dbm != null && dbm.getSubnodeGroupby () != null) {
// check for groupby // check for groupby
try {
Relation rel = (Relation) dbmap.db2prop.get (dbm.getSubnodeGroupby()); Relation rel = (Relation) dbmap.db2prop.get (dbm.getSubnodeGroupby());
pn = pn.getSubnode (getString (rel.propname, false)); pn = pn.getSubnode (getString (rel.propname, false));
} catch (Exception ignore) {}
} }
if (pn != null) { if (pn != null) {
setParent ((Node) pn); setParent ((Node) pn);
anonymous = !pinfo.named;
lastParentSet = System.currentTimeMillis (); lastParentSet = System.currentTimeMillis ();
return pn; return pn;
} }
} catch (Exception ignore) {}
} }
} }
} }
@ -1473,6 +1475,13 @@ public class Node implements INode, Serializable {
public void setNode (String propname, INode value) { public void setNode (String propname, INode value) {
// nmgr.logEvent ("setting node prop"); // nmgr.logEvent ("setting node prop");
// check if types match, otherwise throw exception
DbMapping nmap = dbmap == null ? null : dbmap.getPropertyMapping (propname);
if (nmap != null && nmap != value.getDbMapping()) {
throw new RuntimeException ("Can't set "+propname+" to object with prototype "+value.getPrototype()+", was expecting "+nmap.getTypeName());
}
checkWriteLock (); checkWriteLock ();
Node n = null; Node n = null;
@ -1500,12 +1509,6 @@ public class Node implements INode, Serializable {
propname = propname.trim (); propname = propname.trim ();
String p2 = propname.toLowerCase (); String p2 = propname.toLowerCase ();
DbMapping nmap = dbmap == null ? null : dbmap.getPropertyMapping (propname);
if (nmap != null && nmap != n.getDbMapping()) {
n.setDbMapping (nmap);
n.setPrototype (nmap.getTypeName ());
}
Property prop = (Property) propMap.get (p2); Property prop = (Property) propMap.get (p2);
if (prop != null) { if (prop != null) {
if (prop.type == IProperty.NODE && n.getID ().equals (prop.nvalueID)) { if (prop.type == IProperty.NODE && n.getID ().equals (prop.nvalueID)) {