very carefully introduced use of NodeHandle instead of key+dbmapping

This commit is contained in:
hns 2001-08-01 00:07:31 +00:00
parent 6ce443b2ed
commit 7231ec6224

View file

@ -24,7 +24,7 @@ public final class Property implements IProperty, Serializable, Cloneable {
protected long lvalue; protected long lvalue;
protected double dvalue; protected double dvalue;
protected String nvalueID; protected String nvalueID;
private transient DbMapping dbm; private transient NodeHandle nhandle;
protected Object jvalue; protected Object jvalue;
protected int type; protected int type;
@ -65,9 +65,6 @@ public final class Property implements IProperty, Serializable, Cloneable {
} }
private void writeObject (ObjectOutputStream out) throws IOException { private void writeObject (ObjectOutputStream out) throws IOException {
// don't even start if this is a non-serializable Java object
if (type == JAVAOBJECT && jvalue != null && !(jvalue instanceof Serializable))
return;
out.writeUTF (propname); out.writeUTF (propname);
out.writeObject (node); out.writeObject (node);
out.writeInt (type); out.writeInt (type);
@ -89,6 +86,9 @@ public final class Property implements IProperty, Serializable, Cloneable {
out.writeUTF (nvalueID); out.writeUTF (nvalueID);
break; break;
case JAVAOBJECT: case JAVAOBJECT:
if (jvalue != null && !(jvalue instanceof Serializable))
out.writeObject (null);
else
out.writeObject (jvalue); out.writeObject (jvalue);
break; break;
} }
@ -194,8 +194,10 @@ public final class Property implements IProperty, Serializable, Cloneable {
unregisterNode (); unregisterNode ();
if (type == JAVAOBJECT) if (type == JAVAOBJECT)
this.jvalue = null; this.jvalue = null;
registerNode (value); registerNode (value);
type = NODE; type = NODE;
if (node.dbmap != null) { if (node.dbmap != null) {
Relation rel = node.dbmap.getPropertyRelation (propname); Relation rel = node.dbmap.getPropertyRelation (propname);
if (rel != null && rel.other != null) { if (rel != null && rel.other != null) {
@ -209,19 +211,21 @@ public final class Property implements IProperty, Serializable, Cloneable {
if (!rel.virtual && rel.direction == Relation.FORWARD) { if (!rel.virtual && rel.direction == Relation.FORWARD) {
if (rel.usesPrimaryKey ()) { if (rel.usesPrimaryKey ()) {
this.nvalueID = value.getID (); this.nvalueID = value.getID ();
nhandle = new NodeHandle (value);
} else try { } else try {
this.nvalueID = value.getString (vmap.columnNameToProperty (rel.getRemoteField()).propname, false); this.nvalueID = value.getString (vmap.columnNameToProperty (rel.getRemoteField()).propname, false);
nhandle = null;
} catch (Exception x) { } catch (Exception x) {
throw new RuntimeException ("Can't set "+propname+" to "+value+": error retrieving target property"); throw new RuntimeException ("Can't set "+propname+" to "+value+": error retrieving target property");
} }
this.dbm = null;
dirty = true; dirty = true;
return; return;
} }
} }
} }
nhandle = new NodeHandle (value);
this.nvalueID = value == null ? null : value.getID (); this.nvalueID = value == null ? null : value.getID ();
this.dbm = value == null ? null : value.getDbMapping ();
dirty = true; dirty = true;
} }
@ -238,16 +242,22 @@ public final class Property implements IProperty, Serializable, Cloneable {
* If this was the "main" property for the node, also remove all other references. * If this was the "main" property for the node, also remove all other references.
*/ */
protected void unregisterNode () { protected void unregisterNode () {
if (nvalueID != null) { Node nvalue = null;
if (nhandle != null)
nvalue = nhandle.getNode ();
DbMapping nvmap = null; DbMapping nvmap = null;
Relation nvrel = null; Relation nvrel = null;
if (node.dbmap != null) { if (node.dbmap != null) {
nvmap = node.dbmap.getPropertyMapping (propname); nvmap = node.dbmap.getPropertyMapping (propname);
nvrel = node.dbmap.getPropertyRelation (propname); nvrel = node.dbmap.getPropertyRelation (propname);
} }
Node nvalue = node.nmgr.getNode (nvalueID, nvmap); if (nvalue == null)
nvalue = node.nmgr.getNode (nvalueID, nvmap);
if (nvalue == null) if (nvalue == null)
return; return;
nvalue.checkWriteLock (); nvalue.checkWriteLock ();
// check if the property node is also a subnode // check if the property node is also a subnode
// BUG: this doesn't work because properties for subnode/properties are never stored and therefore // BUG: this doesn't work because properties for subnode/properties are never stored and therefore
@ -267,7 +277,6 @@ public final class Property implements IProperty, Serializable, Cloneable {
} }
} }
} }
}
/** /**
@ -332,6 +341,12 @@ public final class Property implements IProperty, Serializable, Cloneable {
public INode getNodeValue () { public INode getNodeValue () {
if (nhandle != null) {
Node n = nhandle.getNode ();
if (n != null) return n;
}
DbMapping dbm = null;
//// PROVISIONAL
if (type == NODE && nvalueID != null) { if (type == NODE && nvalueID != null) {
Relation rel = null; Relation rel = null;
if (dbm == null && node.dbmap != null) { if (dbm == null && node.dbmap != null) {