#1618 - ENH: Add @Sum ... as short hand for @Aggregation("sum(<property name>)")

This commit is contained in:
rob bygrave
2019-01-23 00:29:51 +13:00
parent a83896f1ff
commit 396fb49acd
3 changed files with 9 additions and 9 deletions
+1 -1
View File
@@ -117,7 +117,7 @@
<dependency>
<groupId>io.ebean</groupId>
<artifactId>ebean-annotation</artifactId>
<version>4.4</version>
<version>4.5</version>
</dependency>
<dependency>
@@ -25,6 +25,7 @@ import io.ebean.annotation.Index;
import io.ebean.annotation.JsonIgnore;
import io.ebean.annotation.Length;
import io.ebean.annotation.SoftDelete;
import io.ebean.annotation.Sum;
import io.ebean.annotation.TenantId;
import io.ebean.annotation.UnmappedJson;
import io.ebean.annotation.UpdatedTimestamp;
@@ -285,6 +286,10 @@ public class AnnotationFields extends AnnotationParser {
if (aggregation != null) {
prop.setAggregation(aggregation.value());
}
Sum sum = get(prop, Sum.class);
if (sum != null) {
prop.setAggregation("sum(" + prop.getName() + ")");
}
Version version = get(prop, Version.class);
if (version != null) {
@@ -1,6 +1,7 @@
package org.tests.model.aggregation;
import io.ebean.annotation.Aggregation;
import io.ebean.annotation.Sum;
import io.ebean.annotation.View;
import javax.persistence.Entity;
@@ -17,16 +18,10 @@ public class DMachineStatsAgg {
LocalDate date;
/**
* Matching with column underscore.
*/
@Aggregation("sum(totalKms)")
@Sum // which is the same as: @Aggregation("sum(totalKms)")
long totalKms;
/**
* Matching with no underscore.
*/
@Aggregation("sum(hours)")
@Aggregation("sum(hours)") // which is the same as: @Sum
long hours;
@Aggregation("max(rate)")