OK this is the patch. :=) Could it look like this?

NOTE: second method was created in hurry - it will not manage
            SQL with GROUP BY clause for example (is it possible with 
Criteria object? - I don't remember)
            perhaps in next version I can build SQL WHERE clause from 
Criteria as it is
            done in createQueryString ...

                                        Regards
                                                Oskar


Index: BasePeer.java
===================================================================
RCS file: 
/products/cvs/turbine/turbine/src/java/org/apache/turbine/om/peer/BasePeer.java,v
retrieving revision 1.27
diff -u -r1.27 BasePeer.java
--- BasePeer.java       2001/02/06 21:30:37     1.27
+++ BasePeer.java       2001/02/08 14:35:47
@@ -1767,4 +1767,62 @@
          }
          return null;
      }
+
+
+    /**
+     * Get number of all records in a table
+     *
+     * @param tablename - the name of a table
+    */
+
+    public static int getCountAll(String tablename) throws Exception {
+
+        Vector result =  executeQuery("select count(*) from "+tablename,
+                         getMapBuilder().getDatabaseMap().getName(),
+                         true);
+
+        return 
((com.workingdogs.village.Record)result.firstElement()).getValue(1).asInt();
+    }
+
+
+
+    /**
+     * Get number of records from a table according to given condition
+     *
+     * @param criteria - Criteria object used to specify select condition
+    */
+
+    public static int getCount(Criteria criteria) throws Exception
+    {
+        String table = null;
+        Enumeration keys = criteria.keys();
+        if ( keys.hasMoreElements() )
+        {
+            table  = criteria.getTableName((String)keys.nextElement());
+        }
+        else
+        {
+            throw new Exception("Cannot determine table name!");
+        }
+
+        String basequery = createQueryString(criteria);
+
+        int i = basequery.indexOf("WHERE");
+
+        if ( i==-1 )
+        {
+             throw new Exception("No where clause?");
+        }
+
+        String query = "select count(*) from "+table+" 
"+basequery.substring(i);
+
+
+        Vector result =  executeQuery(query,
+                         getMapBuilder().getDatabaseMap().getName(),
+                         true);
+
+        return 
((com.workingdogs.village.Record)result.firstElement()).getValue(1).asInt();
+
+    }
+
  }



------------------------------------------------------------
To subscribe:        [EMAIL PROTECTED]
To unsubscribe:      [EMAIL PROTECTED]
Search: <http://www.mail-archive.com/turbine%40list.working-dogs.com/>
Problems?:           [EMAIL PROTECTED]

Reply via email to