cayenne-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From aadamc...@apache.org
Subject svn commit: r951629 - in /cayenne/main/trunk/build-tools/cayenne-test-utilities/src/main/java/org/apache/cayenne/test: DBHelper.java TableHelper.java
Date Sat, 05 Jun 2010 01:09:20 GMT
Author: aadamchik
Date: Sat Jun  5 01:09:19 2010
New Revision: 951629

URL: http://svn.apache.org/viewvc?rev=951629&view=rev
Log:
adding 'select' to the test utils

Modified:
    cayenne/main/trunk/build-tools/cayenne-test-utilities/src/main/java/org/apache/cayenne/test/DBHelper.java
    cayenne/main/trunk/build-tools/cayenne-test-utilities/src/main/java/org/apache/cayenne/test/TableHelper.java

Modified: cayenne/main/trunk/build-tools/cayenne-test-utilities/src/main/java/org/apache/cayenne/test/DBHelper.java
URL: http://svn.apache.org/viewvc/cayenne/main/trunk/build-tools/cayenne-test-utilities/src/main/java/org/apache/cayenne/test/DBHelper.java?rev=951629&r1=951628&r2=951629&view=diff
==============================================================================
--- cayenne/main/trunk/build-tools/cayenne-test-utilities/src/main/java/org/apache/cayenne/test/DBHelper.java
(original)
+++ cayenne/main/trunk/build-tools/cayenne-test-utilities/src/main/java/org/apache/cayenne/test/DBHelper.java
Sat Jun  5 01:09:19 2010
@@ -42,6 +42,37 @@ public class DBHelper {
     }
 
     /**
+     * Selects a single row.
+     */
+    public Object[] select(String table, final String[] columns) throws SQLException {
+
+        if (columns.length == 0) {
+            throw new IllegalArgumentException("No columns");
+        }
+
+        StringBuilder sql = new StringBuilder("select ");
+        sql.append(columns[0]);
+        for (int i = 1; i < columns.length; i++) {
+            sql.append(", ").append(columns[i]);
+        }
+        sql.append(" from ").append(table);
+
+        return new RowTemplate<Object[]>(this) {
+
+            @Override
+            Object[] readRow(ResultSet rs, String sql) throws SQLException {
+
+                Object[] result = new Object[columns.length];
+                for (int i = 1; i <= result.length; i++) {
+                    result[i - 1] = rs.getObject(i);
+                }
+
+                return result;
+            }
+        }.execute(sql.toString());
+    }
+
+    /**
      * Inserts a single row.
      */
     public void insert(String table, String[] columns, Object[] values)

Modified: cayenne/main/trunk/build-tools/cayenne-test-utilities/src/main/java/org/apache/cayenne/test/TableHelper.java
URL: http://svn.apache.org/viewvc/cayenne/main/trunk/build-tools/cayenne-test-utilities/src/main/java/org/apache/cayenne/test/TableHelper.java?rev=951629&r1=951628&r2=951629&view=diff
==============================================================================
--- cayenne/main/trunk/build-tools/cayenne-test-utilities/src/main/java/org/apache/cayenne/test/TableHelper.java
(original)
+++ cayenne/main/trunk/build-tools/cayenne-test-utilities/src/main/java/org/apache/cayenne/test/TableHelper.java
Sat Jun  5 01:09:19 2010
@@ -47,6 +47,9 @@ public class TableHelper {
         return this;
     }
 
+    /**
+     * Sets columns that will be implicitly used in subsequent inserts and selects.
+     */
     public TableHelper setColumns(String... columns) {
         this.columns = columns;
         return this;
@@ -66,6 +69,13 @@ public class TableHelper {
         return this;
     }
 
+    /**
+     * Selects a single row from the mapped table.
+     */
+    public Object[] select() throws SQLException {
+        return dbHelper.select(tableName, columns);
+    }
+
     public int getRowCount() throws SQLException {
         return dbHelper.getRowCount(tableName);
     }



Mime
View raw message