very carefully introduced use of NodeHandle instead of key+dbmapping
This commit is contained in:
parent
6ce443b2ed
commit
7231ec6224
1 changed files with 50 additions and 35 deletions
|
@ -24,7 +24,7 @@ public final class Property implements IProperty, Serializable, Cloneable {
|
|||
protected long lvalue;
|
||||
protected double dvalue;
|
||||
protected String nvalueID;
|
||||
private transient DbMapping dbm;
|
||||
private transient NodeHandle nhandle;
|
||||
protected Object jvalue;
|
||||
|
||||
protected int type;
|
||||
|
@ -65,9 +65,6 @@ public final class Property implements IProperty, Serializable, Cloneable {
|
|||
}
|
||||
|
||||
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.writeObject (node);
|
||||
out.writeInt (type);
|
||||
|
@ -89,6 +86,9 @@ public final class Property implements IProperty, Serializable, Cloneable {
|
|||
out.writeUTF (nvalueID);
|
||||
break;
|
||||
case JAVAOBJECT:
|
||||
if (jvalue != null && !(jvalue instanceof Serializable))
|
||||
out.writeObject (null);
|
||||
else
|
||||
out.writeObject (jvalue);
|
||||
break;
|
||||
}
|
||||
|
@ -194,8 +194,10 @@ public final class Property implements IProperty, Serializable, Cloneable {
|
|||
unregisterNode ();
|
||||
if (type == JAVAOBJECT)
|
||||
this.jvalue = null;
|
||||
|
||||
registerNode (value);
|
||||
type = NODE;
|
||||
|
||||
if (node.dbmap != null) {
|
||||
Relation rel = node.dbmap.getPropertyRelation (propname);
|
||||
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.usesPrimaryKey ()) {
|
||||
this.nvalueID = value.getID ();
|
||||
nhandle = new NodeHandle (value);
|
||||
} else try {
|
||||
this.nvalueID = value.getString (vmap.columnNameToProperty (rel.getRemoteField()).propname, false);
|
||||
nhandle = null;
|
||||
} catch (Exception x) {
|
||||
throw new RuntimeException ("Can't set "+propname+" to "+value+": error retrieving target property");
|
||||
}
|
||||
this.dbm = null;
|
||||
dirty = true;
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
nhandle = new NodeHandle (value);
|
||||
this.nvalueID = value == null ? null : value.getID ();
|
||||
this.dbm = value == null ? null : value.getDbMapping ();
|
||||
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.
|
||||
*/
|
||||
protected void unregisterNode () {
|
||||
if (nvalueID != null) {
|
||||
Node nvalue = null;
|
||||
if (nhandle != null)
|
||||
nvalue = nhandle.getNode ();
|
||||
|
||||
DbMapping nvmap = null;
|
||||
Relation nvrel = null;
|
||||
if (node.dbmap != null) {
|
||||
nvmap = node.dbmap.getPropertyMapping (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)
|
||||
return;
|
||||
|
||||
nvalue.checkWriteLock ();
|
||||
// check if the property node is also a subnode
|
||||
// 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 () {
|
||||
|
||||
if (nhandle != null) {
|
||||
Node n = nhandle.getNode ();
|
||||
if (n != null) return n;
|
||||
}
|
||||
DbMapping dbm = null;
|
||||
//// PROVISIONAL
|
||||
if (type == NODE && nvalueID != null) {
|
||||
Relation rel = null;
|
||||
if (dbm == null && node.dbmap != null) {
|
||||
|
|
Loading…
Add table
Reference in a new issue