db-derby-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From rhille...@apache.org
Subject svn commit: r1431623 - /db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/lang/VarargsRoutines.java
Date Thu, 10 Jan 2013 20:41:24 GMT
Author: rhillegas
Date: Thu Jan 10 20:41:24 2013
New Revision: 1431623

URL: http://svn.apache.org/viewvc?rev=1431623&view=rev
Log:
DERBY-3069: Add stringArrayTable, a VTI useful for testing VTIs.

Modified:
    db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/lang/VarargsRoutines.java

Modified: db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/lang/VarargsRoutines.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/lang/VarargsRoutines.java?rev=1431623&r1=1431622&r2=1431623&view=diff
==============================================================================
--- db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/lang/VarargsRoutines.java
(original)
+++ db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/lang/VarargsRoutines.java
Thu Jan 10 20:41:24 2013
@@ -31,6 +31,8 @@ import java.sql.Timestamp;
 import java.sql.SQLException;
 
 import java.text.MessageFormat;
+import java.util.ArrayList;
+import java.util.StringTokenizer;
 
 import org.apache.derby.iapi.types.HarmonySerialBlob;
 import org.apache.derby.iapi.types.HarmonySerialClob;
@@ -450,4 +452,61 @@ public  class   VarargsRoutines
 
         return new StringArrayVTI( columnNames, rows );
     }
+
+    /**
+     * <p>
+     * This is a table function which creates a StringArrayVTI out of
+     * a space separated list of column names, and a varargs of rows.
+     * Each row is a space separated list of column values. Here is
+     * a sample usage:
+     * </p>
+     *
+     * <pre>
+     * connect 'jdbc:derby:memory:db;create=true';
+     * 
+     * create function leftTable
+     * (
+     *     columnNames varchar( 32672 ),
+     *     rowContents varchar( 32672 ) ...
+     * )
+     * returns table
+     * (
+     *     a   varchar( 5 ),
+     *     b   varchar( 5 )
+     * )
+     * language java parameter style derby_jdbc_result_set no sql
+     * external name 'org.apache.derbyTesting.functionTests.tests.lang.VarargsRoutines.stringArrayTable';
+     * 
+     * select * from table( leftTable( 'A B', 'APP T', 'APP S' ) ) l;
+     * </pre>
+     */
+    public  static  ResultSet   stringArrayTable
+        (
+         String columnNames,
+         String... rows
+         )
+    {
+        ArrayList<String>   columnList = new ArrayList<String>();
+        StringTokenizer colToks = new StringTokenizer( columnNames );
+        while( colToks.hasMoreTokens() ) { columnList.add( colToks.nextToken()  ); }
+        String[]    colNameArg = new String[ columnList.size() ];
+        columnList.toArray( colNameArg );
+
+        ArrayList<String[]> rowList = new ArrayList<String[]>();
+        for ( String row : rows )
+        {
+            ArrayList<String>   valueList = new ArrayList<String>();
+            StringTokenizer valueToks = new StringTokenizer( row );
+            while( valueToks.hasMoreTokens() ) { valueList.add( valueToks.nextToken() );
}
+            String[]    valueRow = new String[ valueList.size() ];
+            valueList.toArray( valueRow );
+            rowList.add( valueRow );
+        }
+
+        String[][]  rowsArg = new String[ rowList.size() ][];
+        rowList.toArray( rowsArg );
+
+        return new StringArrayVTI( colNameArg, rowsArg );
+    }
+    
 }



Mime
View raw message