Skip to content

Commit c84ba6b

Browse files
authored
Merge pull request #7 from jshandorov1/v132
Add count to PersistenceService
2 parents 6b9da10 + b810f9b commit c84ba6b

File tree

3 files changed

+14
-1
lines changed

3 files changed

+14
-1
lines changed

pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212

1313
<groupId>in.kuros</groupId>
1414
<artifactId>jFirebase</artifactId>
15-
<version>1.3.1</version>
15+
<version>1.3.2</version>
1616

1717

1818
<description>This project aims at building a wrapper over nosql technologies - Firebase</description>

src/main/java/in/kuros/jfirebase/PersistenceService.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,8 @@ public interface PersistenceService {
4545

4646
List<WriteResult> writeInBatch(Consumer<WriteBatch> batchConsumer);
4747

48+
<T> long count(Query<T> query);
49+
4850
static void init() {
4951
}
5052
}

src/main/java/in/kuros/jfirebase/provider/firebase/PersistenceServiceImpl.java

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -278,6 +278,17 @@ public List<WriteResult> writeInBatch(final Consumer<WriteBatch> batchConsumer)
278278
}
279279
}
280280

281+
@Override
282+
public <T> long count(Query<T> query) {
283+
try {
284+
AggregateQuery aggregateQuery = QueryAdapter.toFirebaseQuery(firestore, query).count();
285+
final ApiFuture<AggregateQuerySnapshot> querySnapshot = aggregateQuery.get();
286+
return querySnapshot.get().getCount();
287+
} catch (final Exception e) {
288+
throw new PersistenceException(e);
289+
}
290+
}
291+
281292
@SuppressWarnings("unchecked")
282293
private <T> Class<T> getClass(final T entity) {
283294
return (Class<T>) entity.getClass();

0 commit comments

Comments
 (0)