first implementation of inheritable data mappings
This commit is contained in:
parent
b64c59dd8a
commit
bfd3c0ae6a
2 changed files with 39 additions and 20 deletions
|
@ -147,8 +147,24 @@ public class Node implements INode, Serializable {
|
||||||
* Constructor used for nodes being stored in a relational database table.
|
* Constructor used for nodes being stored in a relational database table.
|
||||||
*/
|
*/
|
||||||
public Node (DbMapping dbmap, Record rec, WrappedNodeManager nmgr) throws DataSetException {
|
public Node (DbMapping dbmap, Record rec, WrappedNodeManager nmgr) throws DataSetException {
|
||||||
|
|
||||||
|
// see what prototype/DbMapping this object should use
|
||||||
|
DbMapping m = dbmap;
|
||||||
|
String protoField= dbmap.getPrototypeField ();
|
||||||
|
if (protoField != null) {
|
||||||
|
Value val = rec.getValue (protoField);
|
||||||
|
if (val != null && !val.isNull ()) {
|
||||||
|
String protoName = val.asString ();
|
||||||
|
m = nmgr.getDbMapping (protoName);
|
||||||
|
if (m == null) {
|
||||||
|
// invalid prototype name!
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
setPrototype (m.getTypeName ());
|
||||||
|
this.dbmap = m;
|
||||||
|
|
||||||
this.nmgr = nmgr;
|
this.nmgr = nmgr;
|
||||||
this.dbmap = dbmap;
|
|
||||||
id = rec.getValue (dbmap.getIDField ()).asString ();
|
id = rec.getValue (dbmap.getIDField ()).asString ();
|
||||||
checkWriteLock ();
|
checkWriteLock ();
|
||||||
String nameField = dbmap.getNameField ();
|
String nameField = dbmap.getNameField ();
|
||||||
|
@ -156,8 +172,8 @@ public class Node implements INode, Serializable {
|
||||||
if (name == null || name.length() == 0)
|
if (name == null || name.length() == 0)
|
||||||
name = id;
|
name = id;
|
||||||
created = lastmodified = System.currentTimeMillis ();
|
created = lastmodified = System.currentTimeMillis ();
|
||||||
setPrototype (dbmap.getTypeName ());
|
|
||||||
for (Enumeration e=dbmap.db2prop.elements (); e.hasMoreElements(); ) {
|
for (Enumeration e=dbmap.getDB2Prop ().elements (); e.hasMoreElements(); ) {
|
||||||
|
|
||||||
Relation rel = (Relation) e.nextElement ();
|
Relation rel = (Relation) e.nextElement ();
|
||||||
// NOTE: this should never be the case, since we're just looping through
|
// NOTE: this should never be the case, since we're just looping through
|
||||||
|
@ -595,7 +611,7 @@ public class Node implements INode, Serializable {
|
||||||
// reverse look up property used to access this via parent
|
// reverse look up property used to access this via parent
|
||||||
String dbfield = prel.getRemoteField ();
|
String dbfield = prel.getRemoteField ();
|
||||||
if (dbfield != null) {
|
if (dbfield != null) {
|
||||||
Relation proprel = (Relation) dbmap.db2prop.get (dbfield);
|
Relation proprel = (Relation) dbmap.getDB2Prop ().get (dbfield);
|
||||||
if (proprel != null && proprel.propname != null)
|
if (proprel != null && proprel.propname != null)
|
||||||
newname = getString (proprel.propname, false);
|
newname = getString (proprel.propname, false);
|
||||||
}
|
}
|
||||||
|
@ -642,7 +658,7 @@ public class Node implements INode, Serializable {
|
||||||
try {
|
try {
|
||||||
if (dbm != null && dbm.getSubnodeGroupby () != null) {
|
if (dbm != null && dbm.getSubnodeGroupby () != null) {
|
||||||
// check for groupby
|
// check for groupby
|
||||||
Relation rel = (Relation) dbmap.db2prop.get (dbm.getSubnodeGroupby());
|
Relation rel = (Relation) dbmap.getDB2Prop ().get (dbm.getSubnodeGroupby());
|
||||||
pn = pn.getSubnode (getString (rel.propname, false));
|
pn = pn.getSubnode (getString (rel.propname, false));
|
||||||
}
|
}
|
||||||
if (pn != null) {
|
if (pn != null) {
|
||||||
|
@ -715,7 +731,7 @@ public class Node implements INode, Serializable {
|
||||||
if (dbmap != null) {
|
if (dbmap != null) {
|
||||||
Relation srel = dbmap.getSubnodeRelation ();
|
Relation srel = dbmap.getSubnodeRelation ();
|
||||||
if (srel != null && srel.groupby != null) try {
|
if (srel != null && srel.groupby != null) try {
|
||||||
Relation groupbyRel = (Relation) srel.other.db2prop.get (srel.groupby);
|
Relation groupbyRel = (Relation) srel.other.getDB2Prop ().get (srel.groupby);
|
||||||
String groupbyProp = (groupbyRel != null) ?
|
String groupbyProp = (groupbyRel != null) ?
|
||||||
groupbyRel.propname : srel.groupby;
|
groupbyRel.propname : srel.groupby;
|
||||||
String groupbyValue = node.getString (groupbyProp, false);
|
String groupbyValue = node.getString (groupbyProp, false);
|
||||||
|
@ -1124,7 +1140,7 @@ public class Node implements INode, Serializable {
|
||||||
Relation subRel = dbmap.getSubnodeRelation ();
|
Relation subRel = dbmap.getSubnodeRelation ();
|
||||||
if (subRel.aggressiveLoading) {
|
if (subRel.aggressiveLoading) {
|
||||||
// we don't want to load *all* nodes if we just want to count them
|
// we don't want to load *all* nodes if we just want to count them
|
||||||
long lastChange = subRel.aggressiveCaching ? lastSubnodeChange : smap.lastDataChange;
|
long lastChange = subRel.aggressiveCaching ? lastSubnodeChange : smap.getLastDataChange ();
|
||||||
// also reload if the type mapping has changed.
|
// also reload if the type mapping has changed.
|
||||||
lastChange = Math.max (lastChange, dbmap.getLastTypeChange ());
|
lastChange = Math.max (lastChange, dbmap.getLastTypeChange ());
|
||||||
if (lastChange < lastSubnodeFetch && subnodes != null) {
|
if (lastChange < lastSubnodeFetch && subnodes != null) {
|
||||||
|
@ -1154,7 +1170,7 @@ public class Node implements INode, Serializable {
|
||||||
// check if subnodes need to be reloaded
|
// check if subnodes need to be reloaded
|
||||||
Relation subRel = dbmap.getSubnodeRelation ();
|
Relation subRel = dbmap.getSubnodeRelation ();
|
||||||
synchronized (this) {
|
synchronized (this) {
|
||||||
long lastChange = subRel.aggressiveCaching ? lastSubnodeChange : smap.lastDataChange;
|
long lastChange = subRel.aggressiveCaching ? lastSubnodeChange : smap.getLastDataChange ();
|
||||||
// also reload if the type mapping has changed.
|
// also reload if the type mapping has changed.
|
||||||
lastChange = Math.max (lastChange, dbmap.getLastTypeChange ());
|
lastChange = Math.max (lastChange, dbmap.getLastTypeChange ());
|
||||||
if (lastChange >= lastSubnodeFetch || subnodes == null) {
|
if (lastChange >= lastSubnodeFetch || subnodes == null) {
|
||||||
|
@ -1194,9 +1210,9 @@ public class Node implements INode, Serializable {
|
||||||
*/
|
*/
|
||||||
public Enumeration properties () {
|
public Enumeration properties () {
|
||||||
|
|
||||||
if (dbmap != null && dbmap.prop2db.size() > 0)
|
if (dbmap != null && dbmap.getProp2DB ().size() > 0)
|
||||||
// return the properties defined in type.properties, if there are any
|
// return the properties defined in type.properties, if there are any
|
||||||
return dbmap.prop2db.keys();
|
return dbmap.getProp2DB ().keys();
|
||||||
|
|
||||||
Relation prel = dbmap == null ? null : dbmap.getPropertyRelation ();
|
Relation prel = dbmap == null ? null : dbmap.getPropertyRelation ();
|
||||||
if (prel != null && prel.direction == Relation.DIRECT && !prel.subnodesAreProperties
|
if (prel != null && prel.direction == Relation.DIRECT && !prel.subnodesAreProperties
|
||||||
|
|
|
@ -224,7 +224,7 @@ public final class NodeManager {
|
||||||
if (rel.subnodesAreProperties && node != null && node.getState() != Node.INVALID) {
|
if (rel.subnodesAreProperties && node != null && node.getState() != Node.INVALID) {
|
||||||
// check if node is null node (cached null)
|
// check if node is null node (cached null)
|
||||||
if (node instanceof NullNode) {
|
if (node instanceof NullNode) {
|
||||||
if (node.created() < rel.other.lastDataChange)
|
if (node.created() < rel.other.getLastDataChange ())
|
||||||
node = null; // cached null not valid anymore
|
node = null; // cached null not valid anymore
|
||||||
} else if (app.doesSubnodeChecking () && home.contains (node) < 0) {
|
} else if (app.doesSubnodeChecking () && home.contains (node) < 0) {
|
||||||
node = null;
|
node = null;
|
||||||
|
@ -345,7 +345,7 @@ public final class NodeManager {
|
||||||
if (nameField != null)
|
if (nameField != null)
|
||||||
rec.setValue (nameField, node.getName ());
|
rec.setValue (nameField, node.getName ());
|
||||||
|
|
||||||
for (Enumeration e=dbm.prop2db.keys(); e.hasMoreElements(); ) {
|
for (Enumeration e=dbm.getProp2DB ().keys(); e.hasMoreElements(); ) {
|
||||||
String propname = (String) e.nextElement ();
|
String propname = (String) e.nextElement ();
|
||||||
Property p = node.getProperty (propname, false);
|
Property p = node.getProperty (propname, false);
|
||||||
Relation rel = dbm.propertyToColumnName (propname);
|
Relation rel = dbm.propertyToColumnName (propname);
|
||||||
|
@ -381,6 +381,10 @@ public final class NodeManager {
|
||||||
rec.setValueNull (rel.getDbField());
|
rec.setValueNull (rel.getDbField());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (dbm.getPrototypeField () != null) {
|
||||||
|
rec.setValue (dbm.getPrototypeField (), node.getPrototype ());
|
||||||
|
}
|
||||||
rec.markForInsert ();
|
rec.markForInsert ();
|
||||||
tds.save ();
|
tds.save ();
|
||||||
} finally {
|
} finally {
|
||||||
|
@ -388,7 +392,7 @@ public final class NodeManager {
|
||||||
tds.close ();
|
tds.close ();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
dbm.lastDataChange = System.currentTimeMillis ();
|
dbm.notifyDataChange ();
|
||||||
}
|
}
|
||||||
// tx.timer.endEvent ("insertNode "+node);
|
// tx.timer.endEvent ("insertNode "+node);
|
||||||
}
|
}
|
||||||
|
@ -412,7 +416,7 @@ public final class NodeManager {
|
||||||
|
|
||||||
int updated = 0;
|
int updated = 0;
|
||||||
|
|
||||||
for (Enumeration e=dbm.prop2db.keys(); e.hasMoreElements(); ) {
|
for (Enumeration e=dbm.getProp2DB ().keys(); e.hasMoreElements(); ) {
|
||||||
String propname = (String) e.nextElement ();
|
String propname = (String) e.nextElement ();
|
||||||
Relation rel = dbm.propertyToColumnName (propname);
|
Relation rel = dbm.propertyToColumnName (propname);
|
||||||
|
|
||||||
|
@ -476,7 +480,7 @@ public final class NodeManager {
|
||||||
tds.close ();
|
tds.close ();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
dbm.lastDataChange = System.currentTimeMillis ();
|
dbm.notifyDataChange ();
|
||||||
}
|
}
|
||||||
// update may cause changes in the node's parent subnode array
|
// update may cause changes in the node's parent subnode array
|
||||||
if (node.isAnonymous()) {
|
if (node.isAnonymous()) {
|
||||||
|
@ -506,7 +510,7 @@ public final class NodeManager {
|
||||||
if (st != null)
|
if (st != null)
|
||||||
st.close ();
|
st.close ();
|
||||||
}
|
}
|
||||||
dbm.lastDataChange = System.currentTimeMillis ();
|
dbm.notifyDataChange ();
|
||||||
}
|
}
|
||||||
// node may still be cached via non-primary keys. mark as invalid
|
// node may still be cached via non-primary keys. mark as invalid
|
||||||
node.setState (Node.INVALID);
|
node.setState (Node.INVALID);
|
||||||
|
@ -532,8 +536,7 @@ public final class NodeManager {
|
||||||
if (qds.size () == 0)
|
if (qds.size () == 0)
|
||||||
return "0";
|
return "0";
|
||||||
long currMax = qds.getRecord (0).getValue (1).asLong ();
|
long currMax = qds.getRecord (0).getValue (1).asLong ();
|
||||||
currMax = Math.max (currMax+1, map.lastID+1);
|
currMax = map.getNewID (currMax);
|
||||||
map.lastID = currMax;
|
|
||||||
retval = Long.toString (currMax);
|
retval = Long.toString (currMax);
|
||||||
} finally {
|
} finally {
|
||||||
// tx.timer.endEvent ("generateID "+map);
|
// tx.timer.endEvent ("generateID "+map);
|
||||||
|
@ -985,7 +988,7 @@ public final class NodeManager {
|
||||||
Node n = (Node) en.nextElement ();
|
Node n = (Node) en.nextElement ();
|
||||||
DbMapping dbm = app.getDbMapping (n.getPrototype ());
|
DbMapping dbm = app.getDbMapping (n.getPrototype ());
|
||||||
if (dbm != null)
|
if (dbm != null)
|
||||||
dbm.lastDataChange = System.currentTimeMillis ();
|
dbm.notifyDataChange ();
|
||||||
n.lastParentSet = -1;
|
n.lastParentSet = -1;
|
||||||
n.setDbMapping (dbm);
|
n.setDbMapping (dbm);
|
||||||
n.nmgr = safe;
|
n.nmgr = safe;
|
||||||
|
@ -995,7 +998,7 @@ public final class NodeManager {
|
||||||
Node n = (Node) en.nextElement ();
|
Node n = (Node) en.nextElement ();
|
||||||
DbMapping dbm = app.getDbMapping (n.getPrototype ());
|
DbMapping dbm = app.getDbMapping (n.getPrototype ());
|
||||||
if (dbm != null)
|
if (dbm != null)
|
||||||
dbm.lastDataChange = System.currentTimeMillis ();
|
dbm.notifyDataChange ();
|
||||||
n.setDbMapping (dbm);
|
n.setDbMapping (dbm);
|
||||||
n.nmgr = safe;
|
n.nmgr = safe;
|
||||||
cache.put (n.getKey(), n);
|
cache.put (n.getKey(), n);
|
||||||
|
|
Loading…
Add table
Reference in a new issue