* Fully implement simple object references that don't use the primary key on either side.

Fixes bug 218.
This commit is contained in:
hns 2007-09-20 10:39:31 +00:00
parent 4648a7eee2
commit e9fbe01c68
4 changed files with 15 additions and 6 deletions

View file

@ -1781,7 +1781,7 @@ public final class Node implements INode, Serializable {
if (rel != null) { if (rel != null) {
// Is a relational node stored by id but things it's a string or int. Fix it. // Is a relational node stored by id but things it's a string or int. Fix it.
if (rel.otherType != null && prop.getType() != Property.NODE) { if (rel.otherType != null && prop.getType() != Property.NODE) {
prop.convertToNodeReference(rel.otherType); prop.convertToNodeReference(rel);
} }
if (rel.isVirtual()) { if (rel.isVirtual()) {
// property was found in propMap and is a collection - this is // property was found in propMap and is a collection - this is

View file

@ -303,7 +303,7 @@ public final class NodeManager {
return null; return null;
} else { } else {
// update primary key in cache to keep it from being flushed, see above // update primary key in cache to keep it from being flushed, see above
if (!rel.usesPrimaryKey()) { if (!rel.usesPrimaryKey() && node.getState() != Node.TRANSIENT) {
synchronized (cache) { synchronized (cache) {
Node old = (Node) cache.put(node.getKey(), node); Node old = (Node) cache.put(node.getKey(), node);
@ -1870,7 +1870,7 @@ public final class NodeManager {
// if the property is a pointer to another node, change the property type to NODE // if the property is a pointer to another node, change the property type to NODE
if (rel.isReference() && rel.usesPrimaryKey()) { if (rel.isReference() && rel.usesPrimaryKey()) {
// FIXME: References to anything other than the primary key are not supported // FIXME: References to anything other than the primary key are not supported
prop.convertToNodeReference(rel.otherType); prop.convertToNodeReference(rel);
} }
propMap.put(rel.propName.toLowerCase(), prop); propMap.put(rel.propName.toLowerCase(), prop);
} }

View file

@ -311,11 +311,15 @@ public final class Property implements IProperty, Serializable, Cloneable, Compa
/** /**
* *
* *
* @param dbm ... * @param rel the Relation
*/ */
public void convertToNodeReference(DbMapping dbm) { public void convertToNodeReference(Relation rel) {
if ((value != null) && !(value instanceof NodeHandle)) { if ((value != null) && !(value instanceof NodeHandle)) {
value = new NodeHandle(new DbKey(dbm, value.toString())); if (rel.usesPrimaryKey()) {
value = new NodeHandle(new DbKey(rel.otherType, value.toString()));
} else {
value = new NodeHandle(new MultiKey(rel.otherType, rel.getKeyParts(node)));
}
} }
type = NODE; type = NODE;

View file

@ -1207,6 +1207,11 @@ public final class Relation {
Property prop = home.getProperty(cnst.localProperty()); Property prop = home.getProperty(cnst.localProperty());
if (prop != null) { if (prop != null) {
child.set(crel.propName, prop.getValue(), prop.getType()); child.set(crel.propName, prop.getValue(), prop.getType());
} else {
prop = child.getProperty(cnst.foreignProperty(child.getDbMapping()));
if (prop != null) {
home.set(cnst.localProperty(), prop.getValue(), prop.getType());
}
} }
} }
} }