Fixed multiple bugs related to the embedded database:

* Do not test ElementName for objects from embedded db
* Do set DbMapping for embedded db collection nodes
* Do not fetch embedded db objects onDemand by NodeManager

http://helma.org/bugs/show_bug.cgi?id=251
This commit is contained in:
hns 2003-07-03 11:12:57 +00:00
parent c48346b4bb
commit c08395ae39
3 changed files with 53 additions and 37 deletions

View file

@ -429,8 +429,9 @@ public final class Node implements INode, Serializable {
public String getElementName() { public String getElementName() {
// if subnodes are also mounted as properties, try to get the "nice" prop value // if subnodes are also mounted as properties, try to get the "nice" prop value
// instead of the id by turning the anonymous flag off. // instead of the id by turning the anonymous flag off.
if ((parentHandle != null) && long lastmod = Math.max(dbmap.getLastTypeChange(), lastmodified);
(lastNameCheck < Math.max(dbmap.getLastTypeChange(), lastmodified))) { if ((parentHandle != null) && (lastNameCheck < lastmod) &&
(dbmap != null) && (dbmap.isRelational())) {
try { try {
Node p = parentHandle.getNode(nmgr); Node p = parentHandle.getNode(nmgr);
DbMapping parentmap = p.getDbMapping(); DbMapping parentmap = p.getDbMapping();
@ -1648,9 +1649,12 @@ public final class Node implements INode, Serializable {
// the property does not exist in our propmap - see if we should create it on the fly, // the property does not exist in our propmap - see if we should create it on the fly,
// either because it is mapped to an object from relational database or defined as // either because it is mapped to an object from relational database or defined as
// collection aka virtual node // collection aka virtual node
if ((prop == null) && (dbmap != null)) { if (dbmap != null) {
// the explicitly defined property mapping
Relation propRel = dbmap.getPropertyRelation(propname); Relation propRel = dbmap.getPropertyRelation(propname);
// property was not found in propmap
if (prop == null) {
// if no property relation is defined for this specific property name, // if no property relation is defined for this specific property name,
// use the generic property relation, if one is defined. // use the generic property relation, if one is defined.
if (propRel == null) { if (propRel == null) {
@ -1675,7 +1679,6 @@ public final class Node implements INode, Serializable {
// is itself persistent. // is itself persistent.
else if ((state != TRANSIENT) && propRel.createOnDemand()) { else if ((state != TRANSIENT) && propRel.createOnDemand()) {
// this may be a relational node stored by property name // this may be a relational node stored by property name
// try {
Node pn = nmgr.getNode(this, propname, propRel); Node pn = nmgr.getNode(this, propname, propRel);
if (pn != null) { if (pn != null) {
@ -1688,9 +1691,14 @@ public final class Node implements INode, Serializable {
prop = new Property(propname, this, pn); prop = new Property(propname, this, pn);
} }
// } catch (RuntimeException nonode) { }
// wasn't a node after all }
// } } else if (propRel != null && propRel.isVirtual()) {
// prop was found and explicit property relation is collection -
// this is a collection node containing objects stored in the embedded db
INode pn = prop.getNodeValue();
if (pn != null) {
pn.setDbMapping(propRel.getVirtualMapping());
} }
} }
} }

View file

@ -274,13 +274,16 @@ public final class NodeManager {
if (rel.isComplexReference()) { if (rel.isComplexReference()) {
// a key for a complex reference // a key for a complex reference
key = new MultiKey(rel.otherType, rel.getKeyParts(home)); key = new MultiKey(rel.otherType, rel.getKeyParts(home));
} else if (rel.virtual || (rel.groupby != null) || !rel.usesPrimaryKey()) { // } else if (rel.virtual || (rel.groupby != null) || !rel.usesPrimaryKey()) {
} else if (rel.createOnDemand()) {
// a key for a virtually defined object that's never actually stored in the db // a key for a virtually defined object that's never actually stored in the db
// or a key for an object that represents subobjects grouped by some property, generated on the fly // or a key for an object that represents subobjects grouped by some property,
// generated on the fly
key = new SyntheticKey(home.getKey(), kstr); key = new SyntheticKey(home.getKey(), kstr);
} else { } else {
// if a key for a node from within the DB // if a key for a node from within the DB
// FIXME: This should never apply, since for every relation-based loading Synthetic Keys are used. Right? // FIXME: This should never apply, since for every relation-based loading
// Synthetic Keys are used. Right?
key = new DbKey(rel.otherType, kstr); key = new DbKey(rel.otherType, kstr);
} }

View file

@ -370,12 +370,17 @@ public final class Relation {
/** /**
* Returns true if the object represented by this Relation has to be * Returns true if the object represented by this Relation has to be
* created dynamically by the Helma objectmodel runtime as a virtual * created on demand at runtime by the NodeManager. This is true for:
* node. Virtual nodes are objects which are only generated on demand *
* and never stored to a persistent storage. * - collection (aka virtual) nodes
* - nodes accessed via accessname
* - group nodes
* - complex reference nodes
*/ */
public boolean createOnDemand() { public boolean createOnDemand() {
return virtual || (accessName != null) || (groupby != null) || isComplexReference(); return virtual ||
(otherType.isRelational() && accessName != null) ||
(groupby != null) || isComplexReference();
} }
/** /**