db-derby-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From rhille...@apache.org
Subject svn commit: r1563135 - in /db/derby/code/trunk/java: engine/org/apache/derby/loc/ engine/org/apache/derby/vti/ shared/org/apache/derby/shared/common/reference/ testing/org/apache/derbyTesting/functionTests/tests/lang/
Date Fri, 31 Jan 2014 14:01:17 GMT
Author: rhillegas
Date: Fri Jan 31 14:01:17 2014
New Revision: 1563135

URL: http://svn.apache.org/r1563135
Log:
DERBY-6117: Allow StringColumnVTIs to change their column names (once) based on their runtime
environment; tests passed cleanly for me on derby-6117-02-aa-changeColumnNamesInStringColumnVTI.diff.

Modified:
    db/derby/code/trunk/java/engine/org/apache/derby/loc/messages.xml
    db/derby/code/trunk/java/engine/org/apache/derby/vti/StringColumnVTI.java
    db/derby/code/trunk/java/shared/org/apache/derby/shared/common/reference/SQLState.java
    db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/lang/AwareVTITest.java

Modified: db/derby/code/trunk/java/engine/org/apache/derby/loc/messages.xml
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/engine/org/apache/derby/loc/messages.xml?rev=1563135&r1=1563134&r2=1563135&view=diff
==============================================================================
--- db/derby/code/trunk/java/engine/org/apache/derby/loc/messages.xml (original)
+++ db/derby/code/trunk/java/engine/org/apache/derby/loc/messages.xml Fri Jan 31 14:01:17
2014
@@ -3707,7 +3707,12 @@ Guide.
                 <text>Cannot change constraint mode of {0}. It is not a deferrable
constraint.</text>
                 <arg>constraintName</arg>
             </msg>
-X0Y91
+
+            <msg>
+                <name>X0Y92.S</name>
+                <text>Cannot change the names of this table function's columns.</text>
+            </msg>
+
         </family>
 
 

Modified: db/derby/code/trunk/java/engine/org/apache/derby/vti/StringColumnVTI.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/engine/org/apache/derby/vti/StringColumnVTI.java?rev=1563135&r1=1563134&r2=1563135&view=diff
==============================================================================
--- db/derby/code/trunk/java/engine/org/apache/derby/vti/StringColumnVTI.java (original)
+++ db/derby/code/trunk/java/engine/org/apache/derby/vti/StringColumnVTI.java Fri Jan 31 14:01:17
2014
@@ -34,6 +34,8 @@ import java.sql.Timestamp;
 import java.text.DateFormat;
 import java.text.ParseException;
 
+import org.apache.derby.shared.common.reference.SQLState;
+import org.apache.derby.iapi.error.StandardException;
 import org.apache.derby.iapi.services.io.ArrayUtil;
 import org.apache.derby.iapi.types.HarmonySerialBlob;
 import org.apache.derby.iapi.types.HarmonySerialClob;
@@ -101,7 +103,10 @@ public  abstract    class   StringColumn
      */
     public  StringColumnVTI( String[] columnNames )
     {
-        _columnNames = ArrayUtil.copy( columnNames );
+        if ( columnNames != null )
+        {
+            _columnNames = ArrayUtil.copy( columnNames );
+        }
     }
     
     ///////////////////////////////////////////////////////////////////////////////////
@@ -112,6 +117,22 @@ public  abstract    class   StringColumn
 
     /**
      * <p>
+     * Set the column names for this table function. This is useful for AwareVTIs,
+     * which need to figure out their column names after analyzing their execution
+     * context. Throws an exception if the column names have already been set.
+     * </p>
+     */
+    public  void    setColumnNames( String[] columnNames )
+        throws SQLException
+    {
+        if ( _columnNames != null ) { throw makeSQLException( SQLState.LANG_CANNOT_CHANGE_COLUMN_NAMES
); }
+
+        _columnNames = ArrayUtil.copy( columnNames );
+    }
+
+    
+    /**
+     * <p>
      * Get the number of columns.
      * </p>
      */
@@ -392,4 +413,16 @@ public  abstract    class   StringColumn
         }
     }
 
+    /**
+     * <p>
+     * Construct a SQLException from a SQLState and args.
+     * </p>
+     */
+    private SQLException    makeSQLException( String sqlstate, Object... args )
+    {
+        StandardException   se = StandardException.newException( sqlstate, args );
+
+        return new SQLException( se.getMessage(), se.getSQLState() );
+    }
+
 }

Modified: db/derby/code/trunk/java/shared/org/apache/derby/shared/common/reference/SQLState.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/shared/org/apache/derby/shared/common/reference/SQLState.java?rev=1563135&r1=1563134&r2=1563135&view=diff
==============================================================================
--- db/derby/code/trunk/java/shared/org/apache/derby/shared/common/reference/SQLState.java
(original)
+++ db/derby/code/trunk/java/shared/org/apache/derby/shared/common/reference/SQLState.java
Fri Jan 31 14:01:17 2014
@@ -1404,6 +1404,7 @@ public interface SQLState {
 	String LANG_BAD_OPTIONAL_TOOL_ARGS                                = "X0Y89.S";
 	String LANG_CANT_INSTANTIATE_CLASS                                = "X0Y90.S";
     String LANG_SET_CONSTRAINT_NOT_DEFERRABLE                         = "X0Y91.S";
+    String LANG_CANNOT_CHANGE_COLUMN_NAMES                         = "X0Y92.S";
 
 	// TEMPORARY EXECUTION RESTRICTIONS
 

Modified: db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/lang/AwareVTITest.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/lang/AwareVTITest.java?rev=1563135&r1=1563134&r2=1563135&view=diff
==============================================================================
--- db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/lang/AwareVTITest.java
(original)
+++ db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/lang/AwareVTITest.java
Fri Jan 31 14:01:17 2014
@@ -25,6 +25,7 @@ import java.sql.Connection;
 import java.sql.PreparedStatement;
 import java.sql.ResultSet;
 import java.sql.Statement;
+import java.sql.SQLException;
 
 import junit.framework.Test;
 import junit.framework.TestSuite;
@@ -46,6 +47,8 @@ public class AwareVTITest  extends Gener
     //
     ///////////////////////////////////////////////////////////////////////////////////
 
+    private static  final   String  CANNOT_CHANGE_COLUMNS = "X0Y92";
+
     ///////////////////////////////////////////////////////////////////////////////////
     //
     // STATE
@@ -132,6 +135,39 @@ public class AwareVTITest  extends Gener
              );
     }
 
+    /**
+     * <p>
+     * Test that column names can be set in a StringColumnVTI, but only
+     * if they haven't already been set.
+     * </p>
+     */
+    public void test_02_StringColumnVTI() throws Exception
+    {
+        Connection conn = getConnection();
+
+        String[][]  rows = new String[][]
+            {
+                { "foo", "bar" },
+                { "wibble", "baz" }
+            };
+        UnnamedColumnsVTI   ucv = new UnnamedColumnsVTI( rows );
+
+        // you can set the column names once...
+        ucv.setColumnNames( new String [] { "A", "B" } );
+
+        // ...but only once
+        try {
+            ucv.setColumnNames( new String [] { "C", "D" } );
+            fail( "Attempt to reset column names should have failed." );
+        }
+        catch (SQLException se)
+        {
+            assertEquals( CANNOT_CHANGE_COLUMNS, se.getSQLState() );
+        }
+
+        assertResults( ucv, rows, false );
+    }
+    
     ///////////////////////////////////////////////////////////////////////////////////
     //
     // ROUTINES
@@ -143,5 +179,19 @@ public class AwareVTITest  extends Gener
         return new DummyAwareVTI();
     }
 
+    ///////////////////////////////////////////////////////////////////////////////////
+    //
+    // NESTED CLASSES
+    //
+    ///////////////////////////////////////////////////////////////////////////////////
+
+    public  static  class   UnnamedColumnsVTI    extends StringArrayVTI
+    {
+        public  UnnamedColumnsVTI( String[][] rows )
+        {
+            super( null, rows );
+        }
+    }
+
 }
 



Mime
View raw message