4444import java .util .TimeZone ;
4545import java .util .UUID ;
4646import java .util .concurrent .ConcurrentHashMap ;
47- import com . google . common . base . Strings ;
47+
4848import javax .naming .ConfigurationException ;
4949import javax .persistence .AttributeOverride ;
5050import javax .persistence .Column ;
5555import javax .persistence .Table ;
5656import javax .persistence .TableGenerator ;
5757
58- import net .sf .cglib .proxy .Callback ;
59- import net .sf .cglib .proxy .CallbackFilter ;
60- import net .sf .cglib .proxy .Enhancer ;
61- import net .sf .cglib .proxy .Factory ;
62- import net .sf .cglib .proxy .MethodInterceptor ;
63- import net .sf .cglib .proxy .NoOp ;
64- import net .sf .ehcache .Cache ;
65- import net .sf .ehcache .CacheManager ;
66- import net .sf .ehcache .Element ;
67-
6858import org .apache .log4j .Logger ;
6959
7060import com .cloud .utils .DateUtil ;
7969import com .cloud .utils .exception .CloudRuntimeException ;
8070import com .cloud .utils .net .Ip ;
8171import com .cloud .utils .net .NetUtils ;
72+ import com .google .common .base .Strings ;
73+
74+ import net .sf .cglib .proxy .Callback ;
75+ import net .sf .cglib .proxy .CallbackFilter ;
76+ import net .sf .cglib .proxy .Enhancer ;
77+ import net .sf .cglib .proxy .Factory ;
78+ import net .sf .cglib .proxy .MethodInterceptor ;
79+ import net .sf .cglib .proxy .NoOp ;
80+ import net .sf .ehcache .Cache ;
81+ import net .sf .ehcache .CacheManager ;
82+ import net .sf .ehcache .Element ;
8283
8384/**
8485 * GenericDaoBase is a simple way to implement DAOs. It DOES NOT
@@ -2014,8 +2015,6 @@ public Integer getCount(SearchCriteria<T> sc) {
20142015 }
20152016 }
20162017
2017- // we have to disable group by in getting count, since count for groupBy clause will be different.
2018- //List<Object> groupByValues = addGroupBy(str, sc);
20192018 final TransactionLegacy txn = TransactionLegacy .currentTxn ();
20202019 final String sql = str .toString ();
20212020
@@ -2033,14 +2032,6 @@ public Integer getCount(SearchCriteria<T> sc) {
20332032 i = addJoinAttributes (i , pstmt , joins );
20342033 }
20352034
2036- /*
2037- if (groupByValues != null) {
2038- for (Object value : groupByValues) {
2039- pstmt.setObject(i++, value);
2040- }
2041- }
2042- */
2043-
20442035 final ResultSet rs = pstmt .executeQuery ();
20452036 while (rs .next ()) {
20462037 return rs .getInt (1 );
@@ -2056,6 +2047,13 @@ public Integer getCount(SearchCriteria<T> sc) {
20562047 @ DB ()
20572048 protected StringBuilder createCountSelect (SearchCriteria <?> sc , final boolean whereClause ) {
20582049 StringBuilder sql = new StringBuilder (_count );
2050+ if (sc != null ) {
2051+ Pair <GroupBy <?, ?, ?>, List <Object >> groupBys = sc .getGroupBy ();
2052+ if (groupBys != null ) {
2053+ final SqlGenerator generator = new SqlGenerator (_entityBeanType );
2054+ sql = new StringBuilder (generator .buildCountSqlWithGroupBy (groupBys .first ()));
2055+ }
2056+ }
20592057
20602058 if (!whereClause ) {
20612059 sql .delete (sql .length () - (_discriminatorClause == null ? 6 : 4 ), sql .length ());
0 commit comments