diff --git a/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/kernel/exps/Count.java b/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/kernel/exps/Count.java index 0286bc37d..e58ffbbf0 100644 --- a/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/kernel/exps/Count.java +++ b/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/kernel/exps/Count.java @@ -18,6 +18,7 @@ */ package org.apache.openjpa.jdbc.kernel.exps; +import org.apache.openjpa.jdbc.sql.SQLBuffer; import org.apache.openjpa.jdbc.sql.Select; /** @@ -51,5 +52,21 @@ class Count public boolean isAggregate() { return true; } + + /** + * Overrides SQL formation by replacing COUNT(column) by COUNT(*) when specific conditions are met and + * DBDictionary configuration useWildCardForCount is set. + */ + @Override + public void appendTo(Select sel, ExpContext ctx, ExpState state, SQLBuffer sql, int index) { + super.appendTo(sel, ctx, state, sql, index); + if (ctx.store.getDBDictionary().useWildCardForCount && state.joins.isEmpty()) { + String s = sql.getSQL(); + if (s.startsWith("COUNT(") && s.endsWith(")")) { + sql.replaceSqlString("COUNT(".length(), s.length()-1, "*"); + } + } + } + }