getNode getProperty now does the right thing

for getting collection nodes on transient nodes
This commit is contained in:
hns 2001-08-25 19:58:26 +00:00
parent d3bc403bd4
commit 877405495d

View file

@ -390,22 +390,28 @@ public final class Node implements INode, Serializable {
this.state = s; this.state = s;
} }
/* Mark node as invalid so it is re-fetched from the database */ /**
* Mark node as invalid so it is re-fetched from the database
*/
public void invalidate () { public void invalidate () {
// This doesn't make sense for transient nodes
if (state == TRANSIENT || state == NEW)
return;
checkWriteLock (); checkWriteLock ();
nmgr.evictNode (this); nmgr.evictNode (this);
} }
/** /**
* navigation-related * Get the ID of this Node. This is the primary database key and used as part of the
* key for the internal node cache.
*/ */
public String getID () { public String getID () {
// if we are transient, we generate an id on demand. It's possible that we'll never need // if we are transient, we generate an id on demand. It's possible that we'll never need
// it, but if we do it's important to keep the one we have. // it, but if we do it's important to keep the one we have.
if (state == TRANSIENT && id == null) if (state == TRANSIENT && id == null) {
id = nmgr.generateID (dbmap); id = TransientNode.generateID ();
}
return id; return id;
} }
@ -1235,7 +1241,15 @@ public final class Node implements INode, Serializable {
prel = srel; prel = srel;
if (prel == null) if (prel == null)
prel = dbmap.getPropertyRelation (); prel = dbmap.getPropertyRelation ();
if (prel != null && (prel.accessor != null || prel.virtual || prel.groupby != null)) { if (prel != null) {
// if what we want is a virtual node, fetch anyway.
if (state == TRANSIENT && prel.virtual) {
INode node = new Node (propname, prel.getPrototype (), nmgr);
node.setDbMapping (prel.getVirtualMapping ());
setNode (propname, node);
prop = (Property) propMap.get (propname);
// if this is from relational database only fetch if this node is itself persistent.
} else if (state != TRANSIENT && (prel.accessor != null || prel.groupby != null)) {
// this may be a relational node stored by property name // this may be a relational node stored by property name
try { try {
Node pn = nmgr.getNode (this, propname, prel); Node pn = nmgr.getNode (this, propname, prel);
@ -1252,6 +1266,7 @@ public final class Node implements INode, Serializable {
} }
} }
} }
}
if (prop == null && inherit && getParent () != null && state != TRANSIENT) { if (prop == null && inherit && getParent () != null && state != TRANSIENT) {
prop = ((Node) getParent ()).getProperty (propname, inherit); prop = ((Node) getParent ()).getProperty (propname, inherit);
@ -1663,8 +1678,7 @@ public final class Node implements INode, Serializable {
protected void makePersistentCapable () { protected void makePersistentCapable () {
if (state == TRANSIENT) { if (state == TRANSIENT) {
state = NEW; state = NEW;
// generate a real, persistent ID for this object, if it doesn't have one already. // generate a real, persistent ID for this object
if (id == null)
id = nmgr.generateID (dbmap); id = nmgr.generateID (dbmap);
getHandle ().becomePersistent (); getHandle ().becomePersistent ();
Transactor current = (Transactor) Thread.currentThread (); Transactor current = (Transactor) Thread.currentThread ();