From be1dd61a1961e3f371f7b482bcf55d8695024233 Mon Sep 17 00:00:00 2001 From: hns Date: Fri, 13 Sep 2002 13:28:00 +0000 Subject: [PATCH] Do not set write locks when adding a node or setting a node to a transient parent. --- src/helma/objectmodel/db/Node.java | 39 ++++++++++++++++++------------ 1 file changed, 23 insertions(+), 16 deletions(-) diff --git a/src/helma/objectmodel/db/Node.java b/src/helma/objectmodel/db/Node.java index 3233b9ac..0eeb444b 100644 --- a/src/helma/objectmodel/db/Node.java +++ b/src/helma/objectmodel/db/Node.java @@ -737,16 +737,19 @@ public final class Node implements INode, Serializable { public INode addNode (INode elem, int where) { - Node node = null; - if (elem instanceof Node) + Node node = null; + if (elem instanceof Node) node = (Node) elem; - else + else throw new RuntimeException ("Can't add fixed-transient node to a persistent node"); - - // only lock node if it has to be modified for a change in subnodes - if (!ignoreSubnodeChange ()) - checkWriteLock (); - node.checkWriteLock (); + + // only lock nodes if parent node is not transient + if (state != TRANSIENT) { + // only lock parent if it has to be modified for a change in subnodes + if (!ignoreSubnodeChange ()) + checkWriteLock (); + node.checkWriteLock (); + } // if subnodes are defined via realation, make sure its constraints are enforced. if (dbmap != null && dbmap.getSubnodeRelation () != null) @@ -1640,19 +1643,21 @@ public final class Node implements INode, Serializable { throw new RuntimeException ("Can't set "+propname+" to object with prototype "+value.getPrototype()+", was expecting "+nmap.getTypeName()); } - checkWriteLock (); + if (state != TRANSIENT) + checkWriteLock (); - Node n = null; - if (value instanceof Node) + Node n = null; + if (value instanceof Node) n = (Node) value; - else + else throw new RuntimeException ("Can't add fixed-transient node to a persistent node"); // if the new node is marked as TRANSIENT and this node is not, mark new node as NEW if (state != TRANSIENT && n.state == TRANSIENT) n.makePersistentCapable (); - n.checkWriteLock (); + if (state != TRANSIENT) + n.checkWriteLock (); // check if the main identity of this node is as a named property // or as an anonymous node in a collection @@ -1700,10 +1705,12 @@ public final class Node implements INode, Serializable { // this is done anyway when the node becomes persistent. if (n.state != TRANSIENT) { // check node in with transactor cache - String nID = n.getID(); - DbMapping dbm = n.getDbMapping (); + // String nID = n.getID(); + // DbMapping dbm = n.getDbMapping (); Transactor tx = (Transactor) Thread.currentThread (); - tx.visitCleanNode (new DbKey (dbm, nID), n); + // tx.visitCleanNode (new DbKey (dbm, nID), n); + // UPDATE: using n.getKey() instead of manually constructing key. HW 2002/09/13 + tx.visitCleanNode (n.getKey(), n); // if the field is not the primary key of the property, also register it if (rel != null && rel.accessor != null && state != TRANSIENT) { Key secKey = new SyntheticKey (getKey (), propname);