mirror of https://github.com/apache/openjpa.git
OPENJPA-1440: Allow COUNT(*) syntax when DBDictionary.useWildCardForCount=true
git-svn-id: https://svn.apache.org/repos/asf/openjpa/trunk@892949 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
14a0241792
commit
ac6dab1d07
|
@ -18,6 +18,7 @@
|
||||||
*/
|
*/
|
||||||
package org.apache.openjpa.jdbc.kernel.exps;
|
package org.apache.openjpa.jdbc.kernel.exps;
|
||||||
|
|
||||||
|
import org.apache.openjpa.jdbc.sql.SQLBuffer;
|
||||||
import org.apache.openjpa.jdbc.sql.Select;
|
import org.apache.openjpa.jdbc.sql.Select;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -51,5 +52,21 @@ class Count
|
||||||
public boolean isAggregate() {
|
public boolean isAggregate() {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Overrides SQL formation by replacing COUNT(column) by COUNT(*) when specific conditions are met and
|
||||||
|
* DBDictionary configuration <code>useWildCardForCount</code> 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, "*");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue