db-derby-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From rhille...@apache.org
Subject svn commit: r1455602 [1/2] - in /db/derby/code/trunk/java: client/org/apache/derby/client/am/ engine/org/apache/derby/impl/jdbc/ engine/org/apache/derby/impl/sql/ testing/org/apache/derbyTesting/functionTests/master/ testing/org/apache/derbyTesting/fun...
Date Tue, 12 Mar 2013 16:21:36 GMT
Author: rhillegas
Date: Tue Mar 12 16:21:35 2013
New Revision: 1455602

URL: http://svn.apache.org/r1455602
Log:
DERBY-6089: Make old overloads of CallableStatement.registerOutParameter raise a SQLFeatureNotSupportedException
when illegal types are used.

Modified:
    db/derby/code/trunk/java/client/org/apache/derby/client/am/CallableStatement.java
    db/derby/code/trunk/java/engine/org/apache/derby/impl/jdbc/ConnectionChild.java
    db/derby/code/trunk/java/engine/org/apache/derby/impl/jdbc/EmbedCallableStatement42.java
    db/derby/code/trunk/java/engine/org/apache/derby/impl/jdbc/EmbedPreparedStatement.java
    db/derby/code/trunk/java/engine/org/apache/derby/impl/jdbc/EmbedPreparedStatement42.java
    db/derby/code/trunk/java/engine/org/apache/derby/impl/jdbc/EmbedResultSet42.java
    db/derby/code/trunk/java/engine/org/apache/derby/impl/jdbc/Util.java
    db/derby/code/trunk/java/engine/org/apache/derby/impl/jdbc/Util42.java
    db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/GenericParameterValueSet.java
    db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/master/outparams.out
    db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/jdbc4/PreparedStatementTest42.java

Modified: db/derby/code/trunk/java/client/org/apache/derby/client/am/CallableStatement.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/client/org/apache/derby/client/am/CallableStatement.java?rev=1455602&r1=1455601&r2=1455602&view=diff
==============================================================================
--- db/derby/code/trunk/java/client/org/apache/derby/client/am/CallableStatement.java (original)
+++ db/derby/code/trunk/java/client/org/apache/derby/client/am/CallableStatement.java Tue
Mar 12 16:21:35 2013
@@ -186,6 +186,7 @@ public class CallableStatement extends P
 
     private void registerOutParameterX(int parameterIndex, int jdbcType, int scale) throws
SqlException {
         super.checkForValidParameterIndex(parameterIndex);
+        agent_.checkForSupportedDataType( jdbcType );
         checkForValidScale(scale);
         outputRegistered_ = true; // this variable is only used by Batch
         //parameterSetOrRegistered_[parameterIndex - 1] = true;

Modified: db/derby/code/trunk/java/engine/org/apache/derby/impl/jdbc/ConnectionChild.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/engine/org/apache/derby/impl/jdbc/ConnectionChild.java?rev=1455602&r1=1455601&r2=1455602&view=diff
==============================================================================
--- db/derby/code/trunk/java/engine/org/apache/derby/impl/jdbc/ConnectionChild.java (original)
+++ db/derby/code/trunk/java/engine/org/apache/derby/impl/jdbc/ConnectionChild.java Tue Mar
12 16:21:35 2013
@@ -148,47 +148,6 @@ abstract class ConnectionChild {
 		return cal;
 	}
 
-    /**
-     * Checks whether a data type is supported for
-     * <code>setObject(int, Object, int)</code> and
-     * <code>setObject(int, Object, int, int)</code>.
-     *
-     * @param dataType the data type to check
-     * @exception SQLException if the type is not supported
-     */
-    public void checkForSupportedDataType(int dataType) throws SQLException {
-
-        // JDBC 4.0 javadoc for setObject() says:
-        //
-        // Throws: (...) SQLFeatureNotSupportedException - if
-        // targetSqlType is a ARRAY, BLOB, CLOB, DATALINK,
-        // JAVA_OBJECT, NCHAR, NCLOB, NVARCHAR, LONGNVARCHAR, REF,
-        // ROWID, SQLXML or STRUCT data type and the JDBC driver does
-        // not support this data type
-        //
-        // Of these types, we only support BLOB, CLOB and
-        // (sort of) JAVA_OBJECT.
-
-        switch (dataType) {
-        case Types.ARRAY:
-        case Types.DATALINK:
-        case Types.DISTINCT:
-        case JDBC40Translation.NCHAR:
-        case JDBC40Translation.NCLOB:
-        case JDBC40Translation.NVARCHAR:
-        case JDBC40Translation.LONGNVARCHAR:
-        case Types.NULL:
-        case Types.OTHER:
-        case Types.REF:
-        case JDBC40Translation.REF_CURSOR:
-        case JDBC40Translation.ROWID:
-        case JDBC40Translation.SQLXML:
-        case Types.STRUCT:
-            throw newSQLException(SQLState.DATA_TYPE_NOT_SUPPORTED,
-                                  Util.typeName(dataType));
-        }
-    }
-
 	SQLException newSQLException(String messageId) {
 		return localConn.newSQLException(messageId);
 	}

Modified: db/derby/code/trunk/java/engine/org/apache/derby/impl/jdbc/EmbedCallableStatement42.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/engine/org/apache/derby/impl/jdbc/EmbedCallableStatement42.java?rev=1455602&r1=1455601&r2=1455602&view=diff
==============================================================================
--- db/derby/code/trunk/java/engine/org/apache/derby/impl/jdbc/EmbedCallableStatement42.java
(original)
+++ db/derby/code/trunk/java/engine/org/apache/derby/impl/jdbc/EmbedCallableStatement42.java
Tue Mar 12 16:21:35 2013
@@ -40,42 +40,42 @@ public class EmbedCallableStatement42 ex
         throws SQLException
     {
         checkStatus();
-        registerOutParameter( parameterIndex, Util42.getTypeAsInt( this, sqlType ) );
+        registerOutParameter( parameterIndex, Util42.getTypeAsInt( sqlType ) );
     }
     
     public  void registerOutParameter( int parameterIndex, SQLType sqlType, int scale )
         throws SQLException
     {
         checkStatus();
-        registerOutParameter( parameterIndex, Util42.getTypeAsInt( this, sqlType ), scale
);
+        registerOutParameter( parameterIndex, Util42.getTypeAsInt( sqlType ), scale );
     }
     
     public  void registerOutParameter( int parameterIndex, SQLType sqlType, String typeName
)
         throws SQLException
     {
         checkStatus();
-        registerOutParameter( parameterIndex, Util42.getTypeAsInt( this, sqlType ), typeName
);
+        registerOutParameter( parameterIndex, Util42.getTypeAsInt( sqlType ), typeName );
     }
     
     public  void registerOutParameter( String parameterName, SQLType sqlType )
         throws SQLException
     {
         checkStatus();
-        registerOutParameter( parameterName, Util42.getTypeAsInt( this, sqlType ) );
+        registerOutParameter( parameterName, Util42.getTypeAsInt( sqlType ) );
     }
     
     public  void registerOutParameter( String parameterName, SQLType sqlType, int scale )
         throws SQLException
     {
         checkStatus();
-        registerOutParameter( parameterName, Util42.getTypeAsInt( this, sqlType ), scale
);
+        registerOutParameter( parameterName, Util42.getTypeAsInt( sqlType ), scale );
     }
     
     public  void registerOutParameter( String parameterName,  SQLType sqlType, String typeName
)
         throws SQLException
     {
         checkStatus();
-        registerOutParameter( parameterName, Util42.getTypeAsInt( this, sqlType ), typeName
);
+        registerOutParameter( parameterName, Util42.getTypeAsInt( sqlType ), typeName );
     }
 
     public  void setObject
@@ -83,7 +83,7 @@ public class EmbedCallableStatement42 ex
         throws SQLException
     {
         checkStatus();
-        setObject( parameterIndex, x, Util42.getTypeAsInt( this, targetSqlType ) );
+        setObject( parameterIndex, x, Util42.getTypeAsInt( targetSqlType ) );
     }
     
     public void setObject
@@ -93,21 +93,21 @@ public class EmbedCallableStatement42 ex
          )  throws SQLException
     {
         checkStatus();
-        setObject( parameterIndex, x, Util42.getTypeAsInt( this, targetSqlType ), scaleOrLength
);
+        setObject( parameterIndex, x, Util42.getTypeAsInt( targetSqlType ), scaleOrLength
);
     }
 
     public  void setObject( String parameterName, Object x, SQLType sqlType )
         throws SQLException
     {
         checkStatus();
-        setObject( parameterName, x, Util42.getTypeAsInt( this, sqlType ) );
+        setObject( parameterName, x, Util42.getTypeAsInt( sqlType ) );
     }
     
     public  void setObject( String parameterName, Object x, SQLType sqlType, int scaleOrLength
)
         throws SQLException
     {
         checkStatus();
-        setObject( parameterName, x, Util42.getTypeAsInt( this, sqlType ), scaleOrLength
);
+        setObject( parameterName, x, Util42.getTypeAsInt( sqlType ), scaleOrLength );
     }
     
 }

Modified: db/derby/code/trunk/java/engine/org/apache/derby/impl/jdbc/EmbedPreparedStatement.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/engine/org/apache/derby/impl/jdbc/EmbedPreparedStatement.java?rev=1455602&r1=1455601&r2=1455602&view=diff
==============================================================================
--- db/derby/code/trunk/java/engine/org/apache/derby/impl/jdbc/EmbedPreparedStatement.java
(original)
+++ db/derby/code/trunk/java/engine/org/apache/derby/impl/jdbc/EmbedPreparedStatement.java
Tue Mar 12 16:21:35 2013
@@ -335,7 +335,7 @@ public class EmbedPreparedStatement
      */
     public void setNull(int parameterIndex, int sqlType) throws SQLException {
 
-		checkForSupportedDataType(sqlType);
+		Util.checkForSupportedDataType(sqlType);
 		checkStatus();
 
 		int jdbcTypeId = getParameterJDBCType(parameterIndex);
@@ -1196,7 +1196,7 @@ public class EmbedPreparedStatement
 			return;
 		}
 
-		checkForSupportedDataType(targetSqlType);
+		Util.checkForSupportedDataType(targetSqlType);
 
 		int paramJDBCType = getParameterJDBCType(parameterIndex);
 

Modified: db/derby/code/trunk/java/engine/org/apache/derby/impl/jdbc/EmbedPreparedStatement42.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/engine/org/apache/derby/impl/jdbc/EmbedPreparedStatement42.java?rev=1455602&r1=1455601&r2=1455602&view=diff
==============================================================================
--- db/derby/code/trunk/java/engine/org/apache/derby/impl/jdbc/EmbedPreparedStatement42.java
(original)
+++ db/derby/code/trunk/java/engine/org/apache/derby/impl/jdbc/EmbedPreparedStatement42.java
Tue Mar 12 16:21:35 2013
@@ -54,7 +54,7 @@ public class EmbedPreparedStatement42 ex
         setObject
             (
              parameterIndex, x,
-             Util42.getTypeAsInt( this, targetSqlType )
+             Util42.getTypeAsInt( targetSqlType )
              );
     }
     
@@ -68,7 +68,7 @@ public class EmbedPreparedStatement42 ex
         setObject
             (
              parameterIndex, x,
-             Util42.getTypeAsInt( this, targetSqlType ),
+             Util42.getTypeAsInt( targetSqlType ),
              scaleOrLength
              );
     }

Modified: db/derby/code/trunk/java/engine/org/apache/derby/impl/jdbc/EmbedResultSet42.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/engine/org/apache/derby/impl/jdbc/EmbedResultSet42.java?rev=1455602&r1=1455601&r2=1455602&view=diff
==============================================================================
--- db/derby/code/trunk/java/engine/org/apache/derby/impl/jdbc/EmbedResultSet42.java (original)
+++ db/derby/code/trunk/java/engine/org/apache/derby/impl/jdbc/EmbedResultSet42.java Tue Mar
12 16:21:35 2013
@@ -51,7 +51,7 @@ public class EmbedResultSet42 extends or
         throws SQLException
     {
         checkIfClosed("updateObject");
-        updateObject( columnIndex, x, Util42.getTypeAsInt( this, targetSqlType ) );
+        updateObject( columnIndex, x, Util42.getTypeAsInt( targetSqlType ) );
     }
 
     public void updateObject
@@ -59,7 +59,7 @@ public class EmbedResultSet42 extends or
         throws SQLException
     {
         checkIfClosed("updateObject");
-        updateObject( columnIndex, x, Util42.getTypeAsInt( this, targetSqlType ) );
+        updateObject( columnIndex, x, Util42.getTypeAsInt( targetSqlType ) );
         adjustScale( columnIndex, scaleOrLength );
     }
 
@@ -68,7 +68,7 @@ public class EmbedResultSet42 extends or
         throws SQLException
     {
         checkIfClosed("updateObject");
-        updateObject( columnName, x, Util42.getTypeAsInt( this, targetSqlType ) );
+        updateObject( columnName, x, Util42.getTypeAsInt( targetSqlType ) );
     }
 
     public void updateObject

Modified: db/derby/code/trunk/java/engine/org/apache/derby/impl/jdbc/Util.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/engine/org/apache/derby/impl/jdbc/Util.java?rev=1455602&r1=1455601&r2=1455602&view=diff
==============================================================================
--- db/derby/code/trunk/java/engine/org/apache/derby/impl/jdbc/Util.java (original)
+++ db/derby/code/trunk/java/engine/org/apache/derby/impl/jdbc/Util.java Tue Mar 12 16:21:35
2013
@@ -207,6 +207,71 @@ public abstract class Util  {
 		}
 	}
 
+    /**
+     * Checks whether a data type is supported and raises a SQLException
+     * if it isn't.
+     */
+    public static   void checkForSupportedDataType(int dataType) throws SQLException
+    {
+        if ( !isSupportedType( dataType ) )
+        {
+            throw generateCsSQLException( SQLState.DATA_TYPE_NOT_SUPPORTED, typeName( dataType
) );
+        }
+    }
+
+    /**
+     * Checks whether a data type is supported and raises a StandardException
+     * if it isn't.
+     */
+    public static   void checkSupportedRaiseStandard(int dataType) throws StandardException
+    {
+        if ( !isSupportedType( dataType ) )
+        {
+            throw StandardException.newException( SQLState.DATA_TYPE_NOT_SUPPORTED, typeName(
dataType ) );
+        }
+    }
+
+    /**
+     * Returns false if a data type is not supported for:
+     * <code>setObject(int, Object, int)</code> and
+     * <code>setObject(int, Object, int, int)</code>.
+     *
+     * @param dataType the data type to check
+     */
+    private static   boolean isSupportedType(int dataType)
+    {
+        // JDBC 4.0 javadoc for setObject() says:
+        //
+        // Throws: (...) SQLFeatureNotSupportedException - if
+        // targetSqlType is a ARRAY, BLOB, CLOB, DATALINK,
+        // JAVA_OBJECT, NCHAR, NCLOB, NVARCHAR, LONGNVARCHAR, REF,
+        // ROWID, SQLXML or STRUCT data type and the JDBC driver does
+        // not support this data type
+        //
+        // Of these types, we only support BLOB, CLOB and
+        // (sort of) JAVA_OBJECT.
+
+        switch (dataType) {
+        case Types.ARRAY:
+        case Types.DATALINK:
+        case Types.DISTINCT:
+        case JDBC40Translation.NCHAR:
+        case JDBC40Translation.NCLOB:
+        case JDBC40Translation.NVARCHAR:
+        case JDBC40Translation.LONGNVARCHAR:
+        case Types.NULL:
+        case Types.OTHER:
+        case Types.REF:
+        case JDBC40Translation.REF_CURSOR:
+        case JDBC40Translation.ROWID:
+        case JDBC40Translation.SQLXML:
+        case Types.STRUCT:
+            return false;
+        }
+
+        return true;
+    }
+
 	/*
 	** There is at least one static method for each message id.
 	** Its parameters are specific to its message.

Modified: db/derby/code/trunk/java/engine/org/apache/derby/impl/jdbc/Util42.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/engine/org/apache/derby/impl/jdbc/Util42.java?rev=1455602&r1=1455601&r2=1455602&view=diff
==============================================================================
--- db/derby/code/trunk/java/engine/org/apache/derby/impl/jdbc/Util42.java (original)
+++ db/derby/code/trunk/java/engine/org/apache/derby/impl/jdbc/Util42.java Tue Mar 12 16:21:35
2013
@@ -40,7 +40,7 @@ public class Util42
      * Get the int type id from java.sql.Types which corresponds to the SQLType.
      * </p>
      */
-    public  static  int getTypeAsInt( ConnectionChild connChild, SQLType sqlType )
+    public  static  int getTypeAsInt( SQLType sqlType )
         throws SQLException
     {
         // must correspond to something in java.sql.Types
@@ -48,13 +48,12 @@ public class Util42
         {
             int     jdbcType = ((JDBCType) sqlType).getVendorTypeNumber();
             
-            connChild.checkForSupportedDataType( jdbcType );
+            Util.checkForSupportedDataType( jdbcType );
         
             return jdbcType;
         }
 
-        throw connChild.newSQLException
-            ( SQLState.DATA_TYPE_NOT_SUPPORTED, sqlType );
+        throw Util.generateCsSQLException( SQLState.DATA_TYPE_NOT_SUPPORTED, sqlType );
     }
     
 }    

Modified: db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/GenericParameterValueSet.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/GenericParameterValueSet.java?rev=1455602&r1=1455601&r2=1455602&view=diff
==============================================================================
--- db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/GenericParameterValueSet.java
(original)
+++ db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/GenericParameterValueSet.java
Tue Mar 12 16:21:35 2013
@@ -33,6 +33,7 @@ import org.apache.derby.iapi.types.UserD
 import org.apache.derby.iapi.types.SQLBit;
 import org.apache.derby.iapi.types.SQLBlob;
 import org.apache.derby.iapi.types.SQLChar;
+import org.apache.derby.impl.jdbc.Util;
 
 import java.io.InputStream;
 import java.sql.Types;
@@ -341,16 +342,17 @@ final class GenericParameterValueSet imp
 	 *
 	 * @param parameterIndex	The ordinal parameterIndex of a parameter to set
 	 *			to the given value.
-	 * @param sqlType	A type from java.sql.Types
+	 * @param jdbcType	A type from java.sql.Types
 	 * @param scale		the scale to use.  -1 means ignore scale
 	 *
 	 * @exception StandardException on error
 	 */
-	public void registerOutParameter(int parameterIndex, int sqlType, int scale)
+	public void registerOutParameter(int parameterIndex, int jdbcType, int scale)
 		throws StandardException
 	{
-		checkPosition(parameterIndex);
-		parms[parameterIndex].setOutParameter(sqlType, scale);
+		checkPosition( parameterIndex );
+        Util.checkSupportedRaiseStandard( jdbcType );
+		parms[ parameterIndex ].setOutParameter( jdbcType, scale );
 	}
 
 	/**



Mime
View raw message