You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@cayenne.apache.org by aa...@apache.org on 2006/10/12 05:17:09 UTC

svn commit: r463122 - in /incubator/cayenne/main/trunk/integration-test/itest-common/src/main/java/org/apache/cayenne/itest: ItestDBUtils.java RowTemplate.java

Author: aadamchik
Date: Wed Oct 11 20:17:08 2006
New Revision: 463122

URL: http://svn.apache.org/viewvc?view=rev&rev=463122
Log:
added itest utility method to check table row count

Modified:
    incubator/cayenne/main/trunk/integration-test/itest-common/src/main/java/org/apache/cayenne/itest/ItestDBUtils.java
    incubator/cayenne/main/trunk/integration-test/itest-common/src/main/java/org/apache/cayenne/itest/RowTemplate.java

Modified: incubator/cayenne/main/trunk/integration-test/itest-common/src/main/java/org/apache/cayenne/itest/ItestDBUtils.java
URL: http://svn.apache.org/viewvc/incubator/cayenne/main/trunk/integration-test/itest-common/src/main/java/org/apache/cayenne/itest/ItestDBUtils.java?view=diff&rev=463122&r1=463121&r2=463122
==============================================================================
--- incubator/cayenne/main/trunk/integration-test/itest-common/src/main/java/org/apache/cayenne/itest/ItestDBUtils.java (original)
+++ incubator/cayenne/main/trunk/integration-test/itest-common/src/main/java/org/apache/cayenne/itest/ItestDBUtils.java Wed Oct 11 20:17:08 2006
@@ -110,6 +110,22 @@
         }
     }
 
+    public int getRowCount(String table) throws SQLException {
+        String sql = "select count(*) from " + table;
+        
+        final int[] result = new int[1];
+        RowTemplate template = new RowTemplate(this) {
+
+            @Override
+            void readRow(ResultSet rs, String sql) throws SQLException {
+                result[0] = rs.getInt(1);
+            }
+        };
+
+        template.execute(sql);
+        return result[0];
+    }
+
     public Object getObject(String table, String column) throws SQLException {
         final String sql = "select " + column + " from " + table;
 

Modified: incubator/cayenne/main/trunk/integration-test/itest-common/src/main/java/org/apache/cayenne/itest/RowTemplate.java
URL: http://svn.apache.org/viewvc/incubator/cayenne/main/trunk/integration-test/itest-common/src/main/java/org/apache/cayenne/itest/RowTemplate.java?view=diff&rev=463122&r1=463121&r2=463122
==============================================================================
--- incubator/cayenne/main/trunk/integration-test/itest-common/src/main/java/org/apache/cayenne/itest/RowTemplate.java (original)
+++ incubator/cayenne/main/trunk/integration-test/itest-common/src/main/java/org/apache/cayenne/itest/RowTemplate.java Wed Oct 11 20:17:08 2006
@@ -21,6 +21,11 @@
 import java.sql.ResultSet;
 import java.sql.SQLException;
 
+/**
+ * A JDBC template for reading a single row from the database.
+ * 
+ * @author Andrus Adamchik
+ */
 abstract class RowTemplate extends ResultSetTemplate {
 
     public RowTemplate(ItestDBUtils parent) {