* Make setParent() return boolean true if the argument was accepted as new parent
* Use setParentHandle() wherever we don't need the new parent to be checked * Backpedal from change in previous commit to only set parent for non-relational nodes in addNode() and setNode().
This commit is contained in:
parent
b565d6a166
commit
b173eb0200
1 changed files with 35 additions and 45 deletions
|
@ -113,7 +113,7 @@ public final class Node implements INode, Serializable {
|
||||||
*/
|
*/
|
||||||
public Node(Node home, String propname, WrappedNodeManager nmgr, String prototype) {
|
public Node(Node home, String propname, WrappedNodeManager nmgr, String prototype) {
|
||||||
this.nmgr = nmgr;
|
this.nmgr = nmgr;
|
||||||
setParent(home);
|
setParentHandle(home.getHandle());
|
||||||
|
|
||||||
// this.dbmap = null;
|
// this.dbmap = null;
|
||||||
// generate a key for the virtual node that can't be mistaken for a Database Key
|
// generate a key for the virtual node that can't be mistaken for a Database Key
|
||||||
|
@ -624,10 +624,11 @@ public final class Node implements INode, Serializable {
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Register a node as parent of the present node. We can't refer to the node directly, so we use
|
* Register a node as parent of the present node. This performs a check
|
||||||
* the ID + DB map combo.
|
* to prevent cyclic parent paths. If the argument is accepted as parent,
|
||||||
|
* the method returns true. Otherwise, false is returned.
|
||||||
*/
|
*/
|
||||||
protected void setParent(Node parent) {
|
protected boolean setParent(Node parent) {
|
||||||
// walk down parent node to see if we are in its parent chain.
|
// walk down parent node to see if we are in its parent chain.
|
||||||
// this is to prevent cyclic parent chains.
|
// this is to prevent cyclic parent chains.
|
||||||
Node p = parent;
|
Node p = parent;
|
||||||
|
@ -636,14 +637,18 @@ public final class Node implements INode, Serializable {
|
||||||
if (p == this) {
|
if (p == this) {
|
||||||
// we found ourself in the argument node's parent chain -
|
// we found ourself in the argument node's parent chain -
|
||||||
// ignore request to make it our parent.
|
// ignore request to make it our parent.
|
||||||
return;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
parentHandle = (parent == null) ? null : parent.getHandle();
|
parentHandle = (parent == null) ? null : parent.getHandle();
|
||||||
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Set the parent handle which can be used to get the actual parent node.
|
* Set the parent handle which can be used to get the actual parent node.
|
||||||
|
* In contrast to <code>getParent()</code> this does not perform any
|
||||||
|
* cyclic parent chain checks, so it should only be used when one is sure
|
||||||
|
* the argument handle doesn't refer to a Node we are a parent of.
|
||||||
*/
|
*/
|
||||||
public void setParentHandle(NodeHandle parent) {
|
public void setParentHandle(NodeHandle parent) {
|
||||||
parentHandle = parent;
|
parentHandle = parent;
|
||||||
|
@ -653,6 +658,8 @@ public final class Node implements INode, Serializable {
|
||||||
* This version of setParent additionally marks the node as anonymous or non-anonymous,
|
* This version of setParent additionally marks the node as anonymous or non-anonymous,
|
||||||
* depending on the string argument. This is the version called from the scripting framework,
|
* depending on the string argument. This is the version called from the scripting framework,
|
||||||
* while the one argument version is called from within the objectmodel classes only.
|
* while the one argument version is called from within the objectmodel classes only.
|
||||||
|
*
|
||||||
|
* @deprecated use Helma _parent mapping instead
|
||||||
*/
|
*/
|
||||||
public void setParent(Node parent, String propertyName) {
|
public void setParent(Node parent, String propertyName) {
|
||||||
// we only do that for relational nodes.
|
// we only do that for relational nodes.
|
||||||
|
@ -760,7 +767,7 @@ public final class Node implements INode, Serializable {
|
||||||
}
|
}
|
||||||
|
|
||||||
if (pn != null && pn.isParentOf(this)) {
|
if (pn != null && pn.isParentOf(this)) {
|
||||||
setParent(pn);
|
setParentHandle(pn.getHandle());
|
||||||
lastParentSet = System.currentTimeMillis();
|
lastParentSet = System.currentTimeMillis();
|
||||||
|
|
||||||
return pn;
|
return pn;
|
||||||
|
@ -915,7 +922,7 @@ public final class Node implements INode, Serializable {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!node.isRelational() && node != this && !"root".equalsIgnoreCase(node.getPrototype())) {
|
if (node != this && !"root".equalsIgnoreCase(node.getPrototype())) {
|
||||||
// avoid calling getParent() because it would return bogus results
|
// avoid calling getParent() because it would return bogus results
|
||||||
// for the not-anymore transient node
|
// for the not-anymore transient node
|
||||||
Node nparent = (node.parentHandle == null) ? null
|
Node nparent = (node.parentHandle == null) ? null
|
||||||
|
@ -925,11 +932,12 @@ public final class Node implements INode, Serializable {
|
||||||
// transient while we are persistent, make this the nodes new parent.
|
// transient while we are persistent, make this the nodes new parent.
|
||||||
if ((nparent == null) ||
|
if ((nparent == null) ||
|
||||||
((state != TRANSIENT) && (nparent.getState() == TRANSIENT))) {
|
((state != TRANSIENT) && (nparent.getState() == TRANSIENT))) {
|
||||||
node.setParent(this);
|
if (node.setParent(this)) {
|
||||||
node.anonymous = true;
|
node.anonymous = true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
lastmodified = System.currentTimeMillis();
|
lastmodified = System.currentTimeMillis();
|
||||||
registerSubnodeChange();
|
registerSubnodeChange();
|
||||||
|
@ -1095,10 +1103,11 @@ public final class Node implements INode, Serializable {
|
||||||
|
|
||||||
if ((retval != null) && (retval.parentHandle == null) &&
|
if ((retval != null) && (retval.parentHandle == null) &&
|
||||||
!"root".equalsIgnoreCase(retval.getPrototype())) {
|
!"root".equalsIgnoreCase(retval.getPrototype())) {
|
||||||
retval.setParent(this);
|
if (retval.setParent(this)) {
|
||||||
retval.anonymous = true;
|
retval.anonymous = true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
return retval;
|
return retval;
|
||||||
}
|
}
|
||||||
|
@ -1125,10 +1134,11 @@ public final class Node implements INode, Serializable {
|
||||||
|
|
||||||
if ((retval != null) && (retval.parentHandle == null) &&
|
if ((retval != null) && (retval.parentHandle == null) &&
|
||||||
!"root".equalsIgnoreCase(retval.getPrototype())) {
|
!"root".equalsIgnoreCase(retval.getPrototype())) {
|
||||||
retval.setParent(this);
|
if (retval.setParent(this)) {
|
||||||
retval.anonymous = true;
|
retval.anonymous = true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
return retval;
|
return retval;
|
||||||
}
|
}
|
||||||
|
@ -1320,7 +1330,7 @@ public final class Node implements INode, Serializable {
|
||||||
}
|
}
|
||||||
|
|
||||||
// mark the node as deleted
|
// mark the node as deleted
|
||||||
setParent(null);
|
setParentHandle(null);
|
||||||
markAs(DELETED);
|
markAs(DELETED);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1648,7 +1658,7 @@ public final class Node implements INode, Serializable {
|
||||||
// consulting the NodeManager about it.
|
// consulting the NodeManager about it.
|
||||||
Node n = new Node(propname, rel.getPrototype(), nmgr);
|
Node n = new Node(propname, rel.getPrototype(), nmgr);
|
||||||
n.setDbMapping(rel.getVirtualMapping());
|
n.setDbMapping(rel.getVirtualMapping());
|
||||||
n.setParent(this);
|
n.setParentHandle(this.getHandle());
|
||||||
setNode(propname, n);
|
setNode(propname, n);
|
||||||
return (Property) propMap.get(propname.toLowerCase());
|
return (Property) propMap.get(propname.toLowerCase());
|
||||||
}
|
}
|
||||||
|
@ -1661,37 +1671,16 @@ public final class Node implements INode, Serializable {
|
||||||
if (n != null) {
|
if (n != null) {
|
||||||
if ((n.parentHandle == null) &&
|
if ((n.parentHandle == null) &&
|
||||||
!"root".equalsIgnoreCase(n.getPrototype())) {
|
!"root".equalsIgnoreCase(n.getPrototype())) {
|
||||||
n.setParent(this);
|
if (n.setParent(this)) {
|
||||||
n.name = propname;
|
n.name = propname;
|
||||||
n.anonymous = false;
|
n.anonymous = false;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
return new Property(propname, this, n);
|
return new Property(propname, this, n);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// 3) try to get the property from the database via accessname, if defined
|
|
||||||
// (only do this if accessname or groupby is specified)
|
|
||||||
/* if (rel == null && dbmap != null && state != TRANSIENT) {
|
|
||||||
rel = dbmap.getSubnodeRelation();
|
|
||||||
|
|
||||||
if (rel != null && rel.createOnDemand()) {
|
|
||||||
Node n = nmgr.getNode(this, propname, rel);
|
|
||||||
|
|
||||||
if (n != null) {
|
|
||||||
if ((n.parentHandle == null) &&
|
|
||||||
!"root".equalsIgnoreCase(n.getPrototype())) {
|
|
||||||
n.setParent(this);
|
|
||||||
n.name = propname;
|
|
||||||
n.anonymous = false;
|
|
||||||
}
|
|
||||||
|
|
||||||
return new Property(propname, this, n);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
} */
|
|
||||||
|
|
||||||
// 4) nothing to be found - return null
|
// 4) nothing to be found - return null
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
@ -2187,7 +2176,7 @@ public final class Node implements INode, Serializable {
|
||||||
|
|
||||||
// check if the main identity of this node is as a named property
|
// check if the main identity of this node is as a named property
|
||||||
// or as an anonymous node in a collection
|
// or as an anonymous node in a collection
|
||||||
if (!n.isRelational() && n != this && !"root".equalsIgnoreCase(n.getPrototype())) {
|
if (n != this && !"root".equalsIgnoreCase(n.getPrototype())) {
|
||||||
// avoid calling getParent() because it would return bogus results
|
// avoid calling getParent() because it would return bogus results
|
||||||
// for the not-anymore transient node
|
// for the not-anymore transient node
|
||||||
Node nparent = (n.parentHandle == null) ? null
|
Node nparent = (n.parentHandle == null) ? null
|
||||||
|
@ -2197,11 +2186,12 @@ public final class Node implements INode, Serializable {
|
||||||
// transient while we are persistent, make this the nodes new parent.
|
// transient while we are persistent, make this the nodes new parent.
|
||||||
if ((nparent == null) ||
|
if ((nparent == null) ||
|
||||||
((state != TRANSIENT) && (nparent.getState() == TRANSIENT))) {
|
((state != TRANSIENT) && (nparent.getState() == TRANSIENT))) {
|
||||||
n.setParent(this);
|
if (n.setParent(this)) {
|
||||||
n.setName(propname);
|
n.setName(propname);
|
||||||
n.anonymous = false;
|
n.anonymous = false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
propname = propname.trim();
|
propname = propname.trim();
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue