From 7bdcdcd65f6dec93f209fd24f9e005920bdcd669 Mon Sep 17 00:00:00 2001 From: hns Date: Fri, 3 Aug 2001 14:53:42 +0000 Subject: [PATCH] increased the capabilities of the NodeManager to get nodes by key to groupby nodes. always use getNonVirtualHomeID to retrieve id of the db node a virtual or groupby node belongs to Some tweaks based on new Key schema --- src/helma/objectmodel/db/NodeManager.java | 92 ++++++++++++----------- 1 file changed, 48 insertions(+), 44 deletions(-) diff --git a/src/helma/objectmodel/db/NodeManager.java b/src/helma/objectmodel/db/NodeManager.java index f0e56f01..8b6e9b7c 100644 --- a/src/helma/objectmodel/db/NodeManager.java +++ b/src/helma/objectmodel/db/NodeManager.java @@ -149,9 +149,6 @@ public final class NodeManager { public Node getNode (Key key) throws Exception { - // if (kstr == null) - // return null; - Transactor tx = (Transactor) Thread.currentThread (); // tx.timer.beginEvent ("getNode "+kstr); @@ -172,7 +169,19 @@ public final class NodeManager { // The requested node isn't in the shared cache. Synchronize with key to make sure only one // version is fetched from the database. - node = getNodeByKey (tx.txn, key); + if (key instanceof SyntheticKey) { + System.err.println ("SPLITTING SYNTHETIC KEY: "+key); + Node parent = getNode (key.getParentKey ()); + Relation rel = parent.dbmap.getPropertyRelation (key.getID()); + if (rel == null || rel.groupby != null) + node = parent.getGroupbySubnode (key.getID (), true); + else if (rel != null) + node = getNode (parent, key.getID (), rel); + else + node = null; + } else + node = getNodeByKey (tx.txn, key); + if (node != null) { synchronized (cache) { Node oldnode = (Node) cache.put (node.getKey (), node); @@ -201,12 +210,14 @@ public final class NodeManager { Transactor tx = (Transactor) Thread.currentThread (); Key key = null; - // If what we want is a virtual node create a "synthetic" key - if (rel.virtual || rel.groupby != null) - key = new Key ((String) null, home.getKey ().getVirtualID (kstr)); - // if a key for a node from within the DB + // check what kind of object we're looking for and make an apropriate key + if (rel.virtual || rel.groupby != null || !rel.usesPrimaryKey()) + // 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 + key = new SyntheticKey (home.getKey (), kstr); else - key = new Key (rel.other, rel.getKeyID (home, kstr)); + // if a key for a node from within the DB + key = new DbKey (rel.other, rel.getKeyID (home, kstr)); // See if Transactor has already come across this node Node node = tx.getVisitedNode (key); @@ -224,12 +235,14 @@ public final class NodeManager { // check if we can use the cached node without further checks. // we need further checks for subnodes fetched by name if the subnodes were changed. - if (rel.subnodesAreProperties && node != null && node.getState() != Node.INVALID) { + if (!rel.virtual && rel.subnodesAreProperties && node != null && node.getState() != Node.INVALID) { // check if node is null node (cached null) if (node instanceof NullNode) { if (node.created() < rel.other.getLastDataChange ()) node = null; // cached null not valid anymore } else if (app.doesSubnodeChecking () && home.contains (node) < 0) { + System.err.println ("NULLING SUBNODE: "+key); + System.err.println ("REL = "+rel); node = null; } } @@ -238,8 +251,8 @@ public final class NodeManager { // The requested node isn't in the shared cache. Synchronize with key to make sure only one // version is fetched from the database. - - node = getNodeByRelation (db, tx.txn, home, kstr, rel); +if (key instanceof SyntheticKey && node == null) System.err.println ("GETTING BY REL: "+key+" > "+node); + node = getNodeByRelation (tx.txn, home, kstr, rel); if (node != null) { @@ -596,7 +609,7 @@ public final class NodeManager { } else { String q = "SELECT "+idfield+" FROM "+table; if (subrel.direction == Relation.BACKWARD) { - String homeid = home.getNonVirtualHomeID (); // home.getState() == Node.VIRTUAL ? home.parentID : home.getID (); + String homeid = home.getNonVirtualHomeID (); q += " WHERE "+subrel.getRemoteField()+" = '"+homeid+"'"; if (subrel.filter != null) q += " AND "+subrel.filter; @@ -614,16 +627,20 @@ public final class NodeManager { app.logEvent ("### getNodeIDs: "+qds.getSelectString()); qds.fetchRecords (); + + Key k = home.getKey (); for (int i=0; i 5) { @@ -977,7 +981,7 @@ public final class NodeManager { if (str.indexOf ("'") < 0) return str; int l = str.length(); - StringBuffer sbuf = new StringBuffer (l + 10); + StringBuffer sbuf = new StringBuffer (l + 10); for (int i=0; i