Skip to content

Commit

Permalink
Merge pull request #9 from jshandorov1/m142
Browse files Browse the repository at this point in the history
Add aggregate sum function
  • Loading branch information
bgizdov authored Apr 18, 2024
2 parents 8ec2e65 + a84d5d5 commit ec99844
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 2 deletions.
4 changes: 2 additions & 2 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@

<groupId>in.kuros</groupId>
<artifactId>jFirebase</artifactId>
<version>1.4.0</version>
<version>1.5.0</version>


<description>This project aims at building a wrapper over nosql technologies - Firebase</description>
Expand Down Expand Up @@ -110,7 +110,7 @@
<dependency>
<groupId>com.google.cloud</groupId>
<artifactId>libraries-bom</artifactId>
<version>26.10.0</version>
<version>26.37.0</version>
<type>pom</type>
<scope>import</scope>
</dependency>
Expand Down
2 changes: 2 additions & 0 deletions src/main/java/in/kuros/jfirebase/PersistenceService.java
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,8 @@ public interface PersistenceService {

<T> long count(Query<T> query);

<T> Object sum(Query<T> query, String field);

static void init() {
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -307,6 +307,16 @@ public <T> long count(Query<T> query) {
}
}

public <T> Object sum(Query<T> query, String fieldName) {
try {
AggregateQuery aggregateQuery = QueryAdapter.toFirebaseQuery(firestore, query).aggregate(AggregateField.sum(fieldName));
final ApiFuture<AggregateQuerySnapshot> querySnapshot = aggregateQuery.get();
return querySnapshot.get().get(AggregateField.sum(fieldName));
} catch (final Exception e) {
throw new PersistenceException(e);
}
}

@SuppressWarnings("unchecked")
private <T> Class<T> getClass(final T entity) {
return (Class<T>) entity.getClass();
Expand Down

0 comments on commit ec99844

Please sign in to comment.