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 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,7 +86,10 @@ public final class Property implements IProperty, Serializable, Cloneable {
|
||||||
out.writeUTF (nvalueID);
|
out.writeUTF (nvalueID);
|
||||||
break;
|
break;
|
||||||
case JAVAOBJECT:
|
case JAVAOBJECT:
|
||||||
out.writeObject (jvalue);
|
if (jvalue != null && !(jvalue instanceof Serializable))
|
||||||
|
out.writeObject (null);
|
||||||
|
else
|
||||||
|
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,33 +242,38 @@ 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;
|
||||||
DbMapping nvmap = null;
|
if (nhandle != null)
|
||||||
Relation nvrel = null;
|
nvalue = nhandle.getNode ();
|
||||||
if (node.dbmap != null) {
|
|
||||||
nvmap = node.dbmap.getPropertyMapping (propname);
|
DbMapping nvmap = null;
|
||||||
nvrel = node.dbmap.getPropertyRelation (propname);
|
Relation nvrel = null;
|
||||||
}
|
if (node.dbmap != null) {
|
||||||
Node nvalue = node.nmgr.getNode (nvalueID, nvmap);
|
nvmap = node.dbmap.getPropertyMapping (propname);
|
||||||
if (nvalue == null)
|
nvrel = node.dbmap.getPropertyRelation (propname);
|
||||||
return;
|
}
|
||||||
nvalue.checkWriteLock ();
|
if (nvalue == null)
|
||||||
// check if the property node is also a subnode
|
nvalue = node.nmgr.getNode (nvalueID, nvmap);
|
||||||
// BUG: this doesn't work because properties for subnode/properties are never stored and therefore
|
|
||||||
// never reused.
|
if (nvalue == null)
|
||||||
if (nvrel != null && nvrel.subnodesAreProperties) {
|
return;
|
||||||
node.removeNode (nvalue);
|
|
||||||
}
|
nvalue.checkWriteLock ();
|
||||||
// only need to call unregisterPropLink if the value node is not stored in a relational db
|
// check if the property node is also a subnode
|
||||||
// also, getParent is heuristical/implicit for relational nodes, so we don't do deepRemoveNode
|
// BUG: this doesn't work because properties for subnode/properties are never stored and therefore
|
||||||
// based on that for relational nodes.
|
// never reused.
|
||||||
if (nvmap == null || !nvmap.isRelational()) {
|
if (nvrel != null && nvrel.subnodesAreProperties) {
|
||||||
if (!nvalue.isAnonymous() && propname.equals (nvalue.getName()) && this.node == nvalue.getParent()) {
|
node.removeNode (nvalue);
|
||||||
// this is the "main" property of a named node, so handle this as a cascading delete.
|
}
|
||||||
nvalue.deepRemoveNode ();
|
// only need to call unregisterPropLink if the value node is not stored in a relational db
|
||||||
} else {
|
// also, getParent is heuristical/implicit for relational nodes, so we don't do deepRemoveNode
|
||||||
nvalue.unregisterPropLink (this.node);
|
// based on that for relational nodes.
|
||||||
}
|
if (nvmap == null || !nvmap.isRelational()) {
|
||||||
|
if (!nvalue.isAnonymous() && propname.equals (nvalue.getName()) && this.node == nvalue.getParent()) {
|
||||||
|
// this is the "main" property of a named node, so handle this as a cascading delete.
|
||||||
|
nvalue.deepRemoveNode ();
|
||||||
|
} else {
|
||||||
|
nvalue.unregisterPropLink (this.node);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -331,7 +340,13 @@ 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) {
|
||||||
|
|
Loading…
Add table
Reference in a new issue