the getNode(Key) method now does the same cache consistency
checks as the getNode-by-relation. This is necessary due to the introduction of secondary DbKeys - we need to check if a node is in the cache with its primary key after getting it via secondary key.
This commit is contained in:
parent
a22bde81ad
commit
210a4530b6
1 changed files with 26 additions and 9 deletions
|
@ -179,14 +179,24 @@ public final class NodeManager {
|
||||||
else
|
else
|
||||||
node = null;
|
node = null;
|
||||||
} else
|
} else
|
||||||
node = getNodeByKey (tx.txn, key);
|
node = getNodeByKey (tx.txn, (DbKey) key);
|
||||||
|
|
||||||
if (node != null) {
|
if (node != null) {
|
||||||
|
Key primKey = node.getKey ();
|
||||||
|
boolean keyIsPrimary = primKey.equals (key);
|
||||||
synchronized (cache) {
|
synchronized (cache) {
|
||||||
Node oldnode = (Node) cache.put (node.getKey (), node);
|
// check if node is already in cache with primary key
|
||||||
if (oldnode != null && oldnode.getState () != Node.INVALID && !oldnode.isNullNode ()) {
|
Node oldnode = (Node) cache.put (primKey, node);
|
||||||
cache.put (node.getKey (), oldnode);
|
// no need to check for oldnode != node because we fetched a new node from db
|
||||||
|
if (oldnode != null && !oldnode.isNullNode() && oldnode.getState () != Node.INVALID) {
|
||||||
|
cache.put (primKey, oldnode);
|
||||||
|
if (!keyIsPrimary) {
|
||||||
|
cache.put (key, oldnode);
|
||||||
|
}
|
||||||
node = oldnode;
|
node = oldnode;
|
||||||
|
} else if (!keyIsPrimary) {
|
||||||
|
// cache node with secondary key
|
||||||
|
cache.put (key, node);
|
||||||
}
|
}
|
||||||
} // synchronized
|
} // synchronized
|
||||||
}
|
}
|
||||||
|
@ -216,7 +226,8 @@ public final class NodeManager {
|
||||||
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
|
||||||
key = new DbKey (rel.other, rel.getKeyID (home, kstr));
|
// FIXME: This should never apply, since for every relation-based loading Synthetic Keys are used. Right?
|
||||||
|
key = new DbKey (rel.other, 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);
|
||||||
|
@ -624,7 +635,8 @@ public final class NodeManager {
|
||||||
|
|
||||||
qds.fetchRecords ();
|
qds.fetchRecords ();
|
||||||
|
|
||||||
Key k = home.getKey ();
|
// problem: how do we derive a SyntheticKey from a not-yet-persistent Node?
|
||||||
|
Key k = rel.groupby != null ? home.getKey (): null;
|
||||||
for (int i=0; i<qds.size (); i++) {
|
for (int i=0; i<qds.size (); i++) {
|
||||||
Record rec = qds.getRecord (i);
|
Record rec = qds.getRecord (i);
|
||||||
String kstr = rec.getValue (1).asString ();
|
String kstr = rec.getValue (1).asString ();
|
||||||
|
@ -832,10 +844,11 @@ public final class NodeManager {
|
||||||
// private getNode methods
|
// private getNode methods
|
||||||
///////////////////////////////////////////////////////////////////////////////////////
|
///////////////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
private Node getNodeByKey (DbTxn txn, Key key) throws Exception {
|
private Node getNodeByKey (DbTxn txn, DbKey key) throws Exception {
|
||||||
|
// Note: Key must be a DbKey, otherwise will not work for relational objects
|
||||||
Node node = null;
|
Node node = null;
|
||||||
String kstr = key.getID ();
|
|
||||||
DbMapping dbm = app.getDbMapping (key.getStorageName ());
|
DbMapping dbm = app.getDbMapping (key.getStorageName ());
|
||||||
|
String kstr = key.getID ();
|
||||||
|
|
||||||
if (dbm == null || !dbm.isRelational ()) {
|
if (dbm == null || !dbm.isRelational ()) {
|
||||||
node = db.getNode (txn, kstr);
|
node = db.getNode (txn, kstr);
|
||||||
|
@ -843,10 +856,14 @@ public final class NodeManager {
|
||||||
if (node != null && dbm != null)
|
if (node != null && dbm != null)
|
||||||
node.setDbMapping (dbm);
|
node.setDbMapping (dbm);
|
||||||
} else {
|
} else {
|
||||||
|
String idfield = key.getIDField ();
|
||||||
|
if (idfield == null)
|
||||||
|
idfield =dbm.getIDField ();
|
||||||
|
|
||||||
TableDataSet tds = null;
|
TableDataSet tds = null;
|
||||||
try {
|
try {
|
||||||
tds = new TableDataSet (dbm.getConnection (), dbm.getSchema (), dbm.getKeyDef ());
|
tds = new TableDataSet (dbm.getConnection (), dbm.getSchema (), dbm.getKeyDef ());
|
||||||
tds.where (dbm.getIDField ()+" = '"+kstr+"'");
|
tds.where (idfield+" = '"+kstr+"'");
|
||||||
|
|
||||||
if (logSql)
|
if (logSql)
|
||||||
app.logEvent ("### getNodeByKey: "+tds.getSelectString());
|
app.logEvent ("### getNodeByKey: "+tds.getSelectString());
|
||||||
|
|
Loading…
Add table
Reference in a new issue