adopted to changes in DbMapping and Relation.
Relation is now smart enough to generate queries for groupby nodes.
This commit is contained in:
parent
18e3d82166
commit
ebecc37c29
2 changed files with 25 additions and 45 deletions
|
@ -443,8 +443,8 @@ public final class Node implements INode, Serializable {
|
||||||
DbMapping parentmap = p.getDbMapping ();
|
DbMapping parentmap = p.getDbMapping ();
|
||||||
Relation prel = parentmap.getPropertyRelation();
|
Relation prel = parentmap.getPropertyRelation();
|
||||||
if (prel != null && prel.subnodesAreProperties && !prel.usesPrimaryKey ()) {
|
if (prel != null && prel.subnodesAreProperties && !prel.usesPrimaryKey ()) {
|
||||||
Relation localrel = dbmap.columnNameToProperty (prel.getRemoteField ());
|
String propname = dbmap.columnNameToProperty (prel.getRemoteField ());
|
||||||
String propvalue = getString (localrel.propname, false);
|
String propvalue = getString (propname, false);
|
||||||
if (propvalue != null && propvalue.length() > 0) {
|
if (propvalue != null && propvalue.length() > 0) {
|
||||||
setName (propvalue);
|
setName (propvalue);
|
||||||
anonymous = false;
|
anonymous = false;
|
||||||
|
@ -769,7 +769,7 @@ public final class Node implements INode, Serializable {
|
||||||
if (dbmap != null && node.dbmap != null) {
|
if (dbmap != null && node.dbmap != null) {
|
||||||
Relation prel = dbmap.getPropertyRelation();
|
Relation prel = dbmap.getPropertyRelation();
|
||||||
if (prel != null && prel.subnodesAreProperties && !prel.usesPrimaryKey ()) {
|
if (prel != null && prel.subnodesAreProperties && !prel.usesPrimaryKey ()) {
|
||||||
Relation localrel = node.dbmap.columnNameToProperty (prel.getRemoteField ());
|
Relation localrel = node.dbmap.columnNameToRelation (prel.getRemoteField ());
|
||||||
// if no relation from db column to prop name is found, assume that both are equal
|
// if no relation from db column to prop name is found, assume that both are equal
|
||||||
String propname = localrel == null ? prel.getRemoteField() : localrel.propname;
|
String propname = localrel == null ? prel.getRemoteField() : localrel.propname;
|
||||||
String prop = node.getString (propname, false);
|
String prop = node.getString (propname, false);
|
||||||
|
@ -779,7 +779,6 @@ public final class Node implements INode, Serializable {
|
||||||
unset (prop);
|
unset (prop);
|
||||||
removeNode (old);
|
removeNode (old);
|
||||||
}
|
}
|
||||||
// throw new RuntimeException ("Property "+prop+" is already defined for "+this);
|
|
||||||
setNode (prop, node);
|
setNode (prop, node);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -816,7 +815,7 @@ public final class Node implements INode, Serializable {
|
||||||
if (dbmap != null) {
|
if (dbmap != null) {
|
||||||
Relation srel = dbmap.getSubnodeRelation ();
|
Relation srel = dbmap.getSubnodeRelation ();
|
||||||
if (srel != null && srel.direction == Relation.BACKWARD) {
|
if (srel != null && srel.direction == Relation.BACKWARD) {
|
||||||
Relation backlink = srel.other.columnNameToProperty (srel.getRemoteField());
|
Relation backlink = srel.other.columnNameToRelation (srel.getRemoteField());
|
||||||
if (backlink != null && backlink.propname != null) {
|
if (backlink != null && backlink.propname != null) {
|
||||||
if (node.get (backlink.propname, false) == null) {
|
if (node.get (backlink.propname, false) == null) {
|
||||||
if (this.state == VIRTUAL)
|
if (this.state == VIRTUAL)
|
||||||
|
@ -947,9 +946,8 @@ public final class Node implements INode, Serializable {
|
||||||
|
|
||||||
NodeHandle ghandle = new NodeHandle (new SyntheticKey (getKey(), sid));
|
NodeHandle ghandle = new NodeHandle (new SyntheticKey (getKey(), sid));
|
||||||
if (subnodes.contains (ghandle) || create) try {
|
if (subnodes.contains (ghandle) || create) try {
|
||||||
Relation srel = dbmap.getSubnodeRelation ();
|
DbMapping groupbyMapping = dbmap.getGroupbyMapping ();
|
||||||
Relation prel = dbmap.getPropertyRelation ();
|
boolean relational = groupbyMapping.getSubnodeMapping ().isRelational ();
|
||||||
boolean relational = srel.other != null && srel.other.isRelational ();
|
|
||||||
|
|
||||||
if (relational || create) {
|
if (relational || create) {
|
||||||
Node node = relational ? new Node (this, sid, nmgr, null) : new Node ("groupby-"+sid, null, nmgr);
|
Node node = relational ? new Node (this, sid, nmgr, null) : new Node ("groupby-"+sid, null, nmgr);
|
||||||
|
@ -957,33 +955,12 @@ public final class Node implements INode, Serializable {
|
||||||
node.setString ("groupname", sid);
|
node.setString ("groupname", sid);
|
||||||
|
|
||||||
if (relational) {
|
if (relational) {
|
||||||
DbMapping dbm = new DbMapping ();
|
node.setDbMapping (groupbyMapping);
|
||||||
Relation gsrel = srel.getGroupbySubnodeRelation();
|
|
||||||
dbm.setSubnodeMapping (srel.other);
|
|
||||||
dbm.setSubnodeRelation (gsrel);
|
|
||||||
if (prel != null) {
|
|
||||||
dbm.setPropertyMapping (prel.other);
|
|
||||||
dbm.setPropertyRelation (prel.getGroupbyPropertyRelation());
|
|
||||||
}
|
|
||||||
node.setDbMapping (dbm);
|
|
||||||
// one day, Relation should be smart enough to generate the subnode clause
|
|
||||||
// on the fly. Until then, we prepare it statically for each groupby node.
|
|
||||||
// This has the drawback that updates in the type definition won't affect already created
|
|
||||||
// groupby objects.
|
|
||||||
String snrel = "WHERE "+srel.groupby +"='"+sid+"'";
|
|
||||||
if (gsrel.direction == Relation.BACKWARD)
|
|
||||||
snrel += " AND "+gsrel.getRemoteField()+"='"+getNonVirtualHomeID()+"'";
|
|
||||||
if (gsrel.filter != null)
|
|
||||||
snrel += " AND "+gsrel.filter;
|
|
||||||
if (gsrel.order != null)
|
|
||||||
snrel += " ORDER BY "+gsrel.order;
|
|
||||||
node.setSubnodeRelation (snrel);
|
|
||||||
// set prototype of groupby-node
|
|
||||||
node.setPrototype (gsrel.prototype);
|
|
||||||
} else {
|
} else {
|
||||||
setNode (sid, node);
|
setNode (sid, node);
|
||||||
subnodes.add (node.getHandle ());
|
subnodes.add (node.getHandle ());
|
||||||
}
|
}
|
||||||
|
node.setPrototype (groupbyMapping.getTypeName ());
|
||||||
nmgr.evictKey (node.getKey ());
|
nmgr.evictKey (node.getKey ());
|
||||||
return node;
|
return node;
|
||||||
}
|
}
|
||||||
|
@ -1041,7 +1018,7 @@ public final class Node implements INode, Serializable {
|
||||||
if (dbmap != null) {
|
if (dbmap != null) {
|
||||||
Relation srel = dbmap.getSubnodeRelation ();
|
Relation srel = dbmap.getSubnodeRelation ();
|
||||||
if (srel != null && srel.direction == Relation.BACKWARD) {
|
if (srel != null && srel.direction == Relation.BACKWARD) {
|
||||||
Relation backlink = srel.other.columnNameToProperty (srel.getRemoteField ());
|
Relation backlink = srel.other.columnNameToRelation (srel.getRemoteField ());
|
||||||
if (backlink != null && id.equals (node.getString (backlink.propname, false)))
|
if (backlink != null && id.equals (node.getString (backlink.propname, false)))
|
||||||
node.unset (backlink.propname);
|
node.unset (backlink.propname);
|
||||||
}
|
}
|
||||||
|
@ -1051,7 +1028,7 @@ public final class Node implements INode, Serializable {
|
||||||
if (dbmap != null && node.dbmap != null) {
|
if (dbmap != null && node.dbmap != null) {
|
||||||
Relation prel = dbmap.getPropertyRelation();
|
Relation prel = dbmap.getPropertyRelation();
|
||||||
if (prel != null && prel.subnodesAreProperties && !prel.usesPrimaryKey ()) {
|
if (prel != null && prel.subnodesAreProperties && !prel.usesPrimaryKey ()) {
|
||||||
Relation localrel = node.dbmap.columnNameToProperty (prel.getRemoteField());
|
Relation localrel = node.dbmap.columnNameToRelation (prel.getRemoteField());
|
||||||
// if no relation from db column to prop name is found, assume that both are equal
|
// if no relation from db column to prop name is found, assume that both are equal
|
||||||
String propname = localrel == null ? prel.getRemoteField () : localrel.propname;
|
String propname = localrel == null ? prel.getRemoteField () : localrel.propname;
|
||||||
String prop = node.getString (propname, false);
|
String prop = node.getString (propname, false);
|
||||||
|
@ -1627,7 +1604,7 @@ public final class Node implements INode, Serializable {
|
||||||
if (rel != null && rel.direction == Relation.FORWARD && !rel.usesPrimaryKey ()) {
|
if (rel != null && rel.direction == Relation.FORWARD && !rel.usesPrimaryKey ()) {
|
||||||
// if the relation for this property doesn't use the primary key of the value object, make a
|
// if the relation for this property doesn't use the primary key of the value object, make a
|
||||||
// secondary key object with the proper db column
|
// secondary key object with the proper db column
|
||||||
String kval = n.getString (rel.other.columnNameToProperty (rel.getRemoteField ()).propname, false);
|
String kval = n.getString (rel.other.columnNameToProperty (rel.getRemoteField ()), false);
|
||||||
prop.nhandle = new NodeHandle (new DbKey (n.getDbMapping (), kval, rel.getRemoteField ()));
|
prop.nhandle = new NodeHandle (new DbKey (n.getDbMapping (), kval, rel.getRemoteField ()));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1643,8 +1620,6 @@ public final class Node implements INode, Serializable {
|
||||||
tx.visitCleanNode (secKey, n);
|
tx.visitCleanNode (secKey, n);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Server.throwNodeEvent (new NodeEvent (this, NodeEvent.SUBNODE_ADDED, n));
|
|
||||||
// Server.throwNodeEvent (new NodeEvent (this, NodeEvent.PROPERTIES_CHANGED));
|
|
||||||
lastmodified = System.currentTimeMillis ();
|
lastmodified = System.currentTimeMillis ();
|
||||||
if (state == CLEAN) markAs (MODIFIED);
|
if (state == CLEAN) markAs (MODIFIED);
|
||||||
if (n.state == DELETED) n.markAs (MODIFIED);
|
if (n.state == DELETED) n.markAs (MODIFIED);
|
||||||
|
|
|
@ -361,7 +361,7 @@ public final class NodeManager {
|
||||||
for (Enumeration e=dbm.getProp2DB ().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.propertyToRelation (propname);
|
||||||
|
|
||||||
if (p != null && rel != null) {
|
if (p != null && rel != null) {
|
||||||
switch (p.getType ()) {
|
switch (p.getType ()) {
|
||||||
|
@ -431,7 +431,7 @@ public final class NodeManager {
|
||||||
|
|
||||||
for (Enumeration e=dbm.getProp2DB ().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.propertyToRelation (propname);
|
||||||
|
|
||||||
// skip properties that don't need to be updated before fetching them
|
// skip properties that don't need to be updated before fetching them
|
||||||
if (rel != null && (rel.readonly || rel.virtual || (rel.direction != Relation.FORWARD && rel.direction != Relation.PRIMITIVE)))
|
if (rel != null && (rel.readonly || rel.virtual || (rel.direction != Relation.FORWARD && rel.direction != Relation.PRIMITIVE)))
|
||||||
|
@ -620,6 +620,8 @@ public final class NodeManager {
|
||||||
q += " WHERE "+subrel.getRemoteField()+" = '"+homeid+"'";
|
q += " WHERE "+subrel.getRemoteField()+" = '"+homeid+"'";
|
||||||
if (subrel.filter != null)
|
if (subrel.filter != null)
|
||||||
q += " AND "+subrel.filter;
|
q += " AND "+subrel.filter;
|
||||||
|
if (rel.dogroupby != null)
|
||||||
|
q += " AND " + rel.dogroupby + " = '" + home.getString ("groupname", false) +"'";
|
||||||
} else if (subrel.filter != null)
|
} else if (subrel.filter != null)
|
||||||
q += " WHERE "+subrel.filter;
|
q += " WHERE "+subrel.filter;
|
||||||
// set order, if specified and if not using subnode's relation
|
// set order, if specified and if not using subnode's relation
|
||||||
|
@ -766,6 +768,8 @@ public final class NodeManager {
|
||||||
String qstr = "SELECT count(*) FROM "+table+" WHERE "+subrel.getRemoteField()+" = '"+homeid+"'";
|
String qstr = "SELECT count(*) FROM "+table+" WHERE "+subrel.getRemoteField()+" = '"+homeid+"'";
|
||||||
if (subrel.filter != null)
|
if (subrel.filter != null)
|
||||||
qstr += " AND "+subrel.filter;
|
qstr += " AND "+subrel.filter;
|
||||||
|
if (rel.dogroupby != null)
|
||||||
|
qstr += " AND " + rel.dogroupby + " = '" + home.getString ("groupname", false) +"'";
|
||||||
qds = new QueryDataSet (con, qstr);
|
qds = new QueryDataSet (con, qstr);
|
||||||
} else {
|
} else {
|
||||||
String qstr = "SELECT count(*) FROM "+table;
|
String qstr = "SELECT count(*) FROM "+table;
|
||||||
|
@ -897,13 +901,7 @@ public final class NodeManager {
|
||||||
node.setPrototype (rel.prototype);
|
node.setPrototype (rel.prototype);
|
||||||
node.setDbMapping (app.getDbMapping (rel.prototype));
|
node.setDbMapping (app.getDbMapping (rel.prototype));
|
||||||
} else {
|
} else {
|
||||||
// make a db mapping good enough that the virtual node finds its subnodes
|
node.setDbMapping (rel.getVirtualMapping ());
|
||||||
DbMapping dbm = new DbMapping ();
|
|
||||||
dbm.setSubnodeMapping (rel.other);
|
|
||||||
dbm.setSubnodeRelation (rel.getVirtualSubnodeRelation());
|
|
||||||
dbm.setPropertyMapping (rel.other);
|
|
||||||
dbm.setPropertyRelation (rel.getVirtualPropertyRelation());
|
|
||||||
node.setDbMapping (dbm);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
} else if (rel != null && rel.groupby != null) {
|
} else if (rel != null && rel.groupby != null) {
|
||||||
|
@ -952,6 +950,13 @@ public final class NodeManager {
|
||||||
where.append (homeid);
|
where.append (homeid);
|
||||||
where.append ("'");
|
where.append ("'");
|
||||||
}
|
}
|
||||||
|
if (rel.dogroupby != null) {
|
||||||
|
where.append (" and ");
|
||||||
|
where.append (rel.dogroupby);
|
||||||
|
where.append (" = '");
|
||||||
|
where.append (home.getString ("groupname", false));
|
||||||
|
where.append ("'");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue