getting an object via key now directly takes a Key object

instead of the key string and dbmapping.
This commit is contained in:
hns 2001-08-01 00:06:41 +00:00
parent a62cad8555
commit 6ce443b2ed

View file

@ -103,6 +103,7 @@ public final class NodeManager {
node.nmgr = safe; node.nmgr = safe;
} catch (ObjectNotFoundException notfound) { } catch (ObjectNotFoundException notfound) {
node = new Node ("root", "0", "root", safe); node = new Node ("root", "0", "root", safe);
node.setDbMapping (app.getDbMapping ("root"));
db.save (txn, node.getID (), node); db.save (txn, node.getID (), node);
registerNode (node); // register node with nodemanager cache registerNode (node); // register node with nodemanager cache
} }
@ -112,6 +113,7 @@ public final class NodeManager {
node.nmgr = safe; node.nmgr = safe;
} catch (ObjectNotFoundException notfound) { } catch (ObjectNotFoundException notfound) {
node = new Node ("users", "1", null, safe); node = new Node ("users", "1", null, safe);
node.setDbMapping (app.getDbMapping ("__userroot__"));
db.save (txn, node.getID (), node); db.save (txn, node.getID (), node);
registerNode (node); // register node with nodemanager cache registerNode (node); // register node with nodemanager cache
} }
@ -145,16 +147,16 @@ public final class NodeManager {
} }
public Node getNode (String kstr, DbMapping dbmap) throws Exception { public Node getNode (Key key) throws Exception {
if (kstr == null) // if (kstr == null)
return null; // return null;
Transactor tx = (Transactor) Thread.currentThread (); Transactor tx = (Transactor) Thread.currentThread ();
// tx.timer.beginEvent ("getNode "+kstr); // tx.timer.beginEvent ("getNode "+kstr);
// it would be a good idea to reuse key objects one day. // it would be a good idea to reuse key objects one day.
Key key = new Key (dbmap, kstr); // Key key = new Key (dbmap, kstr);
// See if Transactor has already come across this node // See if Transactor has already come across this node
Node node = tx.getVisitedNode (key); Node node = tx.getVisitedNode (key);
@ -170,7 +172,7 @@ public final class NodeManager {
// The requested node isn't in the shared cache. Synchronize with key to make sure only one // The requested node isn't in the shared cache. Synchronize with key to make sure only one
// version is fetched from the database. // version is fetched from the database.
node = getNodeByKey (db, tx.txn, kstr, dbmap); node = getNodeByKey (tx.txn, key);
if (node != null) { if (node != null) {
synchronized (cache) { synchronized (cache) {
Node oldnode = (Node) cache.put (node.getKey (), node); Node oldnode = (Node) cache.put (node.getKey (), node);
@ -262,18 +264,8 @@ public final class NodeManager {
// node fetched from db is null, cache result using nullNode // node fetched from db is null, cache result using nullNode
synchronized (cache) { synchronized (cache) {
Node oldnode = (Node) cache.put (key, new NullNode ()); Node oldnode = (Node) cache.put (key, new NullNode ());
// for the rare case that some other thread created the node in the meantime // we ignore the case that onother thread has created the node in the meantime
/* if (oldnode != null && !(oldnode instanceof NullNode) && oldnode.getState () != Node.INVALID) {
Key primKey = oldnode.getKey ();
boolean keyIsPrimary = primKey.equals (key);
cache.put (oldnode.getKey (), oldnode);
if (!keyIsPrimary) {
cache.put (key, oldnode);
}
node = oldnode;
} else { */
return null; return null;
// }
} }
} }
} else if (node instanceof NullNode) { } else if (node instanceof NullNode) {
@ -825,8 +817,11 @@ public final class NodeManager {
// private getNode methods // private getNode methods
/////////////////////////////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////////////////////////////
private Node getNodeByKey (DbWrapper db, DbTxn txn, String kstr, DbMapping dbm) throws Exception { private Node getNodeByKey (DbTxn txn, Key key) throws Exception {
Node node = null; Node node = null;
String kstr = key.getID ();
DbMapping dbm = app.getDbMapping (key.getType ());
if (dbm == null || !dbm.isRelational ()) { if (dbm == null || !dbm.isRelational ()) {
node = db.getNode (txn, kstr); node = db.getNode (txn, kstr);
node.nmgr = safe; node.nmgr = safe;