Completely rewrite getSubnode().
Aded isNullNode method
This commit is contained in:
parent
8ef0a8c4e6
commit
157f7bba7f
1 changed files with 45 additions and 36 deletions
|
@ -23,7 +23,7 @@ import com.workingdogs.village.*;
|
||||||
* an external relational database.
|
* an external relational database.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
public class Node implements INode, Serializable {
|
public final class Node implements INode, Serializable {
|
||||||
|
|
||||||
// The handle to the node's parent
|
// The handle to the node's parent
|
||||||
protected NodeHandle parentHandle;
|
protected NodeHandle parentHandle;
|
||||||
|
@ -127,10 +127,11 @@ public class Node implements INode, Serializable {
|
||||||
static final long serialVersionUID = -3740339688506633675L;
|
static final long serialVersionUID = -3740339688506633675L;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* This constructor is only used for instances of the NullNode subclass. Do not use for ordinary Nodes!<
|
* This constructor is only used for instances of the NullNode subclass. Do not use for ordinary Nodes.
|
||||||
*/
|
*/
|
||||||
Node () {
|
Node () {
|
||||||
created = lastmodified = System.currentTimeMillis ();
|
created = lastmodified = System.currentTimeMillis ();
|
||||||
|
nmgr = null;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -838,51 +839,52 @@ public class Node implements INode, Serializable {
|
||||||
links.add (fromHandle);
|
links.add (fromHandle);
|
||||||
}
|
}
|
||||||
|
|
||||||
public INode getSubnode (String path) {
|
public INode getSubnode (String subid) {
|
||||||
StringTokenizer st = new StringTokenizer (path, "/");
|
// System.err.println ("GETSUBNODE : "+this+" > "+subid);
|
||||||
Node retval = this, runner;
|
Node retval = null;
|
||||||
|
if ("".equals (subid)) {
|
||||||
while (st.hasMoreTokens () && retval != null) {
|
return this;
|
||||||
runner = retval;
|
} else if (subid != null) {
|
||||||
String next = st.nextToken().trim().toLowerCase ();
|
loadNodes ();
|
||||||
|
if (subnodes == null || subnodes.size() == 0)
|
||||||
if ("".equals (next)) {
|
return null;
|
||||||
retval = this;
|
|
||||||
} else {
|
|
||||||
runner.loadNodes ();
|
|
||||||
Relation srel = null;
|
|
||||||
DbMapping smap = null;
|
|
||||||
if (runner.dbmap != null) {
|
|
||||||
srel = runner.dbmap.getSubnodeRelation ();
|
|
||||||
smap = runner.dbmap.getSubnodeMapping ();
|
|
||||||
}
|
|
||||||
|
|
||||||
// check if there is a group-by relation
|
// check if there is a group-by relation
|
||||||
NodeHandle nhandle = null;
|
NodeHandle nhandle = null;
|
||||||
if (srel != null && srel.groupby != null)
|
int l = subnodes.size ();
|
||||||
|
for (int i=0; i<l; i++) try {
|
||||||
|
NodeHandle shandle = (NodeHandle) subnodes.get (i);
|
||||||
|
if (subid.equals (shandle.getID ())) {
|
||||||
|
// System.err.println ("FOUND SUBNODE: "+shandle);
|
||||||
|
nhandle = shandle;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
} catch (Exception x) {
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
/* if (srel != null && srel.groupby != null)
|
||||||
nhandle = new NodeHandle (new SyntheticKey (runner.getKey (), next));
|
nhandle = new NodeHandle (new SyntheticKey (runner.getKey (), next));
|
||||||
else
|
else
|
||||||
nhandle = new NodeHandle (new DbKey (smap, next));
|
nhandle = new NodeHandle (new DbKey (smap, next));
|
||||||
boolean found = runner.subnodes == null ? false : runner.subnodes.contains (nhandle);
|
boolean found = runner.subnodes == null ? false : runner.subnodes.contains (nhandle); */
|
||||||
|
|
||||||
if (!found) {
|
if (nhandle != null) {
|
||||||
retval = null;
|
retval = nhandle.getNode (nmgr);
|
||||||
} else {
|
|
||||||
retval = nhandle.getNode (nmgr);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (retval != null && retval.parentHandle == null && !"root".equalsIgnoreCase (retval.getPrototype ())) {
|
|
||||||
retval.setParent (runner);
|
|
||||||
retval.anonymous = true;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
if (retval == null) {
|
|
||||||
retval = (Node) runner.getNode (next, false);
|
if (retval != null && retval.parentHandle == null && !"root".equalsIgnoreCase (retval.getPrototype ())) {
|
||||||
|
retval.setParent (this);
|
||||||
|
retval.anonymous = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* if (retval == null) {
|
||||||
|
retval = (Node) getNode (subid, false);
|
||||||
|
} */
|
||||||
}
|
}
|
||||||
return retval;
|
return retval;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public INode getSubnodeAt (int index) {
|
public INode getSubnodeAt (int index) {
|
||||||
loadNodes ();
|
loadNodes ();
|
||||||
|
|
||||||
|
@ -1160,6 +1162,9 @@ public class Node implements INode, Serializable {
|
||||||
if (smap != null && smap.isRelational ()) {
|
if (smap != null && smap.isRelational ()) {
|
||||||
// check if subnodes need to be reloaded
|
// check if subnodes need to be reloaded
|
||||||
Relation subRel = dbmap.getSubnodeRelation ();
|
Relation subRel = dbmap.getSubnodeRelation ();
|
||||||
|
// can't do backward relation on transient subnodes
|
||||||
|
if (state == TRANSIENT && subRel.direction == Relation.BACKWARD)
|
||||||
|
return;
|
||||||
synchronized (this) {
|
synchronized (this) {
|
||||||
long lastChange = subRel.aggressiveCaching ? lastSubnodeChange : smap.getLastDataChange ();
|
long lastChange = subRel.aggressiveCaching ? lastSubnodeChange : smap.getLastDataChange ();
|
||||||
// also reload if the type mapping has changed.
|
// also reload if the type mapping has changed.
|
||||||
|
@ -1766,6 +1771,10 @@ public class Node implements INode, Serializable {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public boolean isNullNode () {
|
||||||
|
return nmgr == null;
|
||||||
|
}
|
||||||
|
|
||||||
public void dump () {
|
public void dump () {
|
||||||
System.err.println ("subnodes: "+subnodes);
|
System.err.println ("subnodes: "+subnodes);
|
||||||
System.err.println ("properties: "+propMap);
|
System.err.println ("properties: "+propMap);
|
||||||
|
|
Loading…
Add table
Reference in a new issue