#1408 - Incorrect SQL when @Aggregation formula matches the property - sum(t0.sum(totalKms))

This commit is contained in:
rob bygrave
2018-06-08 17:38:15 +12:00
parent 42f0b419e8
commit f031bb72b6
5 changed files with 389 additions and 0 deletions
@@ -647,11 +647,35 @@ public class DeployBeanProperty {
*/
public String parseAggregation() {
if (aggregation != null) {
int pos = aggregation.indexOf('(');
if (pos > -1) {
// check for recursive property name and formula
String maybePropertyName = aggregation.substring(pos + 1, aggregation.length() - 1);
if (name.equals(maybePropertyName)) {
// e.g. bean property cost mapped to sum(cost)
return aggregationJoin(pos, dbColumn);
} else {
DeployBeanProperty other = desc.getBeanProperty(maybePropertyName);
if (other != null) {
// e.g. bean property maxKms mapped to sum(totalKms) where totalKms is another property
return aggregationJoin(pos, other.getDbColumnRaw());
}
}
}
aggregationParsed = desc.parse(aggregation);
}
return aggregationParsed;
}
/**
* Simple aggregation parsing like sum(someProperty)
*/
private String aggregationJoin(int pos, String dbColumn) {
String p0 = aggregation.substring(0, pos + 1);
aggregationParsed = p0 + "${ta}." + dbColumn + aggregation.substring(aggregation.length() - 1);
return aggregationParsed;
}
public void setAggregation(String aggregation) {
this.aggregation = aggregation;
this.dbRead = true;
@@ -702,6 +726,13 @@ public class DeployBeanProperty {
return dbColumn;
}
/**
* Return the DB column without any aggregation parsing.
*/
private String getDbColumnRaw() {
return dbColumn;
}
/**
* Set the database column name this is mapped to.
*/