rearranged addNode method

This commit is contained in:
hns 2001-08-22 01:15:00 +00:00
parent 50fa6c0e73
commit 35ac6602bc

View file

@ -359,13 +359,9 @@ public final class Node implements INode, Serializable {
protected synchronized void clearWriteLock () { protected synchronized void clearWriteLock () {
lock = null; lock = null;
// check if the subnodes are relational.
// If so, clear the subnode vector.
// DbMapping smap = dbmap == null ? null : dbmap.getSubnodeMapping ();
// if (smap != null && smap.isRelational ())
// subnodes = null;
} }
protected void markAs (int s) { protected void markAs (int s) {
if (state == INVALID || state == VIRTUAL || state == TRANSIENT) if (state == INVALID || state == VIRTUAL || state == TRANSIENT)
return; return;
@ -487,24 +483,6 @@ public final class Node implements INode, Serializable {
return b.toString (); return b.toString ();
} }
/* public INode[] getPath () {
int pathSize = 1;
INode p = getParent ();
while (p != null) {
pathSize +=1;
p = p.getParent ();
if (pathSize > 100) // sanity check
break;
}
INode path[] = new INode[pathSize];
p = this;
for (int i = pathSize-1; i>=0; i--) {
path[i] = p;
p = p.getParent ();
}
return path;
} */
public String getPrototype () { public String getPrototype () {
if (prototype == null && propMap != null) { if (prototype == null && propMap != null) {
@ -704,19 +682,25 @@ public final class Node implements INode, Serializable {
node = (Node) elem; node = (Node) elem;
else else
throw new RuntimeException ("Can't add fixed-transient node to a persistent node"); throw new RuntimeException ("Can't add fixed-transient node to a persistent node");
// only lock node if it has to be modified for a change in subnodes
if (!ignoreSubnodeChange ())
checkWriteLock ();
node.checkWriteLock ();
// if subnodes are defined via realation, make sure its constraints are enforced.
if (dbmap != null && dbmap.getSubnodeRelation () != null)
dbmap.getSubnodeRelation ().setConstraints (this, node);
// if the new node is marked as TRANSIENT and this node is not, mark new node as NEW // if the new node is marked as TRANSIENT and this node is not, mark new node as NEW
if (state != TRANSIENT && node.state == TRANSIENT) if (state != TRANSIENT && node.state == TRANSIENT)
node.makePersistentCapable (); node.makePersistentCapable ();
String n = node.getName(); String n = node.getName();
// if (n.indexOf('/') > -1) // if (n.indexOf('/') > -1)
// throw new RuntimeException ("\"/\" found in Node name."); // throw new RuntimeException ("\"/\" found in Node name.");
// only lock node if it has to be modified for a change in subnodes
if (!ignoreSubnodeChange ())
checkWriteLock ();
node.checkWriteLock ();
// only mark this node as modified if subnodes are not in relational db // only mark this node as modified if subnodes are not in relational db
// pointing to this node. // pointing to this node.
if (!ignoreSubnodeChange () && (state == CLEAN || state == DELETED)) if (!ignoreSubnodeChange () && (state == CLEAN || state == DELETED))
@ -740,8 +724,6 @@ public final class Node implements INode, Serializable {
groupbyNode = getGroupbySubnode (groupbyValue, true); groupbyNode = getGroupbySubnode (groupbyValue, true);
groupbyNode.addNode (node); groupbyNode.addNode (node);
srel.setConstraints (this, node);
return node; return node;
} catch (Exception x) { } catch (Exception x) {
System.err.println ("Error adding groupby: "+x); System.err.println ("Error adding groupby: "+x);
@ -801,9 +783,6 @@ public final class Node implements INode, Serializable {
} }
} }
if (dbmap != null && dbmap.getSubnodeRelation () != null)
dbmap.getSubnodeRelation ().setConstraints (this, node);
lastmodified = System.currentTimeMillis (); lastmodified = System.currentTimeMillis ();
lastSubnodeChange = lastmodified; lastSubnodeChange = lastmodified;
// Server.throwNodeEvent (new NodeEvent (this, NodeEvent.SUBNODE_ADDED, node)); // Server.throwNodeEvent (new NodeEvent (this, NodeEvent.SUBNODE_ADDED, node));
@ -812,7 +791,8 @@ public final class Node implements INode, Serializable {
public INode createNode () { public INode createNode () {
return createNode (null, numberOfNodes ()); // create new node at end of subnode array // create new node at end of subnode array
return createNode (null, numberOfNodes ());
} }
public INode createNode (int where) { public INode createNode (int where) {