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,20 +1241,29 @@ 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) {
// this may be a relational node stored by property name // if what we want is a virtual node, fetch anyway.
try { if (state == TRANSIENT && prel.virtual) {
Node pn = nmgr.getNode (this, propname, prel); INode node = new Node (propname, prel.getPrototype (), nmgr);
if (pn != null) { node.setDbMapping (prel.getVirtualMapping ());
if (pn.parentHandle == null && !"root".equalsIgnoreCase (pn.getPrototype ())) { setNode (propname, node);
pn.setParent (this); prop = (Property) propMap.get (propname);
pn.name = propname; // if this is from relational database only fetch if this node is itself persistent.
pn.anonymous = false; } else if (state != TRANSIENT && (prel.accessor != null || prel.groupby != null)) {
// this may be a relational node stored by property name
try {
Node pn = nmgr.getNode (this, propname, prel);
if (pn != null) {
if (pn.parentHandle == null && !"root".equalsIgnoreCase (pn.getPrototype ())) {
pn.setParent (this);
pn.name = propname;
pn.anonymous = false;
}
prop = new Property (propname, this, pn);
} }
prop = new Property (propname, this, pn); } catch (RuntimeException nonode) {
// wasn't a node after all
} }
} catch (RuntimeException nonode) {
// wasn't a node after all
} }
} }
} }
@ -1663,9 +1678,8 @@ 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 ();
current.visitNode (this); current.visitNode (this);