From 1b21df99941c3ffb8d52c74b8ebdc02ea5124535 Mon Sep 17 00:00:00 2001 From: Michael Bayne Date: Sat, 18 Dec 2010 18:01:57 +0000 Subject: [PATCH] Added Funcs.countStar() because it's such a common SQL operation. --- src/main/java/com/samskivert/depot/Funcs.java | 9 +++++++++ src/main/java/com/samskivert/depot/Query.java | 2 +- 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/src/main/java/com/samskivert/depot/Funcs.java b/src/main/java/com/samskivert/depot/Funcs.java index e40076a..9cb415f 100644 --- a/src/main/java/com/samskivert/depot/Funcs.java +++ b/src/main/java/com/samskivert/depot/Funcs.java @@ -53,6 +53,15 @@ public class Funcs return new Average(expr, true); } + /** + * Creates an aggregate expression that counts the number of rows that match the other clauses + * in this query. + */ + public static FluentExp countStar () + { + return new Count(Exps.literal("*")); + } + /** * Creates an aggregate expression that counts the number of rows from the supplied * expression. This would usually be used in a FieldOverride and supplied with a ColumnExp. diff --git a/src/main/java/com/samskivert/depot/Query.java b/src/main/java/com/samskivert/depot/Query.java index 0e39019..725f2b2 100644 --- a/src/main/java/com/samskivert/depot/Query.java +++ b/src/main/java/com/samskivert/depot/Query.java @@ -373,7 +373,7 @@ public class Query */ public int selectCount () { - checkState(_groupBy == null, "Do you mean to select(Funcs.count(Exps.literal(\"*\")))?"); + checkState(_groupBy == null, "Do you mean to select(Funcs.countStar())?"); _fromOverride = new FromOverride(_pclass); return _repo.load(CountRecord.class, _cache, getClauseArray()).count; }