openjpa-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ppod...@apache.org
Subject svn commit: r892949 - /openjpa/trunk/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/kernel/exps/Count.java
Date Mon, 21 Dec 2009 19:57:12 GMT
Author: ppoddar
Date: Mon Dec 21 19:57:11 2009
New Revision: 892949

URL: http://svn.apache.org/viewvc?rev=892949&view=rev
Log:
OPENJPA-1440: Allow COUNT(*) syntax when DBDictionary.useWildCardForCount=true

Modified:
    openjpa/trunk/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/kernel/exps/Count.java

Modified: openjpa/trunk/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/kernel/exps/Count.java
URL: http://svn.apache.org/viewvc/openjpa/trunk/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/kernel/exps/Count.java?rev=892949&r1=892948&r2=892949&view=diff
==============================================================================
--- openjpa/trunk/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/kernel/exps/Count.java
(original)
+++ openjpa/trunk/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/kernel/exps/Count.java
Mon Dec 21 19:57:11 2009
@@ -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 @@
     public boolean isAggregate() {
         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, "*");
+            }
+        }
+    }
+
 }
 



Mime
View raw message