db-derby-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From kahat...@apache.org
Subject svn commit: r420436 - in /db/derby/code/trunk/java: build/org/apache/derbyBuild/ client/org/apache/derby/client/am/ engine/org/apache/derby/iapi/reference/ engine/org/apache/derby/iapi/types/ engine/org/apache/derby/impl/jdbc/ engine/org/apache/derby/l...
Date Mon, 10 Jul 2006 06:31:34 GMT
Author: kahatlen
Date: Sun Jul  9 23:31:33 2006
New Revision: 420436

URL: http://svn.apache.org/viewvc?rev=420436&view=rev
Log:
DERBY-1393: PreparedStatement.setObject(int,Object,int) should throw
SQLFeatureNotSupportedException for unsupported types

Description of the patch:

  The new setObject() methods call checkForSupportedDataType() to
  check whether targetSqlType is supported.

  Added a new error message "The data type ''{0}'' is not supported."
  with SQL state 0A000 (which ensures that the exception is converted
  to SQLFeatureNotSupportedException). This error message is used when
  targetSqlType is not supported.

  Added more JDBC 4.0 constants (from java.sql.Types) to
  JDBC40Translation and created a test JDBC40TranslationTest which
  tests that the constants are correct (the values of the constants
  are hard coded, so we don't get the compile-time check as with
  JDBC{2,3}0Translation).

  New test case SetObjectUnsupportedTest which is run as part of
  PreparedStatementTest and CallableStatementTest in the jdbc40 suite.

Added:
    db/derby/code/trunk/java/engine/org/apache/derby/iapi/reference/JDBC40Translation.java
  (with props)
    db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/jdbc4/JDBC40TranslationTest.java
  (with props)
    db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/jdbc4/SetObjectUnsupportedTest.java
  (with props)
Modified:
    db/derby/code/trunk/java/build/org/apache/derbyBuild/splitmessages.java
    db/derby/code/trunk/java/client/org/apache/derby/client/am/PreparedStatement.java
    db/derby/code/trunk/java/client/org/apache/derby/client/am/Types.java
    db/derby/code/trunk/java/engine/org/apache/derby/iapi/types/TypeId.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/Util.java
    db/derby/code/trunk/java/engine/org/apache/derby/loc/messages_en.properties
    db/derby/code/trunk/java/shared/org/apache/derby/shared/common/reference/JDBC40Translation.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/suites/jdbc40.runall
    db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/jdbc4/CallableStatementTest.java
    db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/jdbc4/PreparedStatementTest.java

Modified: db/derby/code/trunk/java/build/org/apache/derbyBuild/splitmessages.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/build/org/apache/derbyBuild/splitmessages.java?rev=420436&r1=420435&r2=420436&view=diff
==============================================================================
--- db/derby/code/trunk/java/build/org/apache/derbyBuild/splitmessages.java (original)
+++ db/derby/code/trunk/java/build/org/apache/derbyBuild/splitmessages.java Sun Jul  9 23:31:33
2006
@@ -105,6 +105,7 @@
         clientMessageIds.add(SQLState.CANT_CONVERT_UNICODE_TO_EBCDIC);
         clientMessageIds.add(SQLState.SECMECH_NOT_SUPPORTED);
         clientMessageIds.add(SQLState.DRDA_COMMAND_NOT_IMPLEMENTED);
+        clientMessageIds.add(SQLState.DATA_TYPE_NOT_SUPPORTED);
         clientMessageIds.add(SQLState.JDBC_DRIVER_REGISTER);
         clientMessageIds.add(SQLState.NO_CURRENT_ROW);
         clientMessageIds.add(SQLState.LANG_IDENTIFIER_TOO_LONG);

Modified: db/derby/code/trunk/java/client/org/apache/derby/client/am/PreparedStatement.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/client/org/apache/derby/client/am/PreparedStatement.java?rev=420436&r1=420435&r2=420436&view=diff
==============================================================================
--- db/derby/code/trunk/java/client/org/apache/derby/client/am/PreparedStatement.java (original)
+++ db/derby/code/trunk/java/client/org/apache/derby/client/am/PreparedStatement.java Sun
Jul  9 23:31:33 2006
@@ -20,6 +20,7 @@
 
 package org.apache.derby.client.am;
 
+import org.apache.derby.shared.common.reference.JDBC40Translation;
 import org.apache.derby.shared.common.reference.SQLState;
 
 import java.io.InputStream;
@@ -1214,6 +1215,7 @@
                             int targetJdbcType,
                             int scale) throws SqlException {
         parameterIndex = checkSetterPreconditions(parameterIndex);
+        checkForSupportedDataType(targetJdbcType);
         checkForValidScale(scale);
 
         if (x == null) {
@@ -2159,6 +2161,45 @@
             throw new SqlException(agent_.logWriter_, 
                 new ClientMessageId(SQLState.BAD_SCALE_VALUE),
                 new Integer(scale));
+        }
+    }
+
+    /**
+     * 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
+     */
+    private 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 java.sql.Types.ARRAY:
+        case java.sql.Types.DATALINK:
+        case JDBC40Translation.NCHAR:
+        case JDBC40Translation.NCLOB:
+        case JDBC40Translation.NVARCHAR:
+        case JDBC40Translation.LONGNVARCHAR:
+        case java.sql.Types.REF:
+        case JDBC40Translation.ROWID:
+        case JDBC40Translation.SQLXML:
+        case java.sql.Types.STRUCT:
+            throw new SqlException
+                (agent_.logWriter_,
+                 new ClientMessageId(SQLState.DATA_TYPE_NOT_SUPPORTED),
+                 Types.getTypeString(dataType));
         }
     }
 

Modified: db/derby/code/trunk/java/client/org/apache/derby/client/am/Types.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/client/org/apache/derby/client/am/Types.java?rev=420436&r1=420435&r2=420436&view=diff
==============================================================================
--- db/derby/code/trunk/java/client/org/apache/derby/client/am/Types.java (original)
+++ db/derby/code/trunk/java/client/org/apache/derby/client/am/Types.java Sun Jul  9 23:31:33
2006
@@ -21,6 +21,7 @@
 
 import org.apache.derby.iapi.reference.DRDAConstants;
 import org.apache.derby.iapi.reference.JDBC30Translation;
+import org.apache.derby.iapi.reference.JDBC40Translation;
 
 // This enumeration of types represents the typing scheme used by our jdbc driver.
 // Once this is finished, we need to review our switches to make sure they are exhaustive
@@ -102,6 +103,18 @@
             case TIMESTAMP:     return "TIMESTAMP";
             case VARBINARY:     return "VARBINARY";
             case VARCHAR:       return "VARCHAR";
+            // Types we don't support:
+            case java.sql.Types.ARRAY: return "ARRAY";
+            case java.sql.Types.DATALINK: return "DATALINK";
+            case JDBC40Translation.NCHAR: return "NATIONAL CHAR";
+            case JDBC40Translation.NCLOB: return "NCLOB";
+            case JDBC40Translation.NVARCHAR: return "NATIONAL CHAR VARYING";
+            case JDBC40Translation.LONGNVARCHAR: return "LONG NVARCHAR";
+            case java.sql.Types.REF: return "REF";
+            case JDBC40Translation.ROWID: return "ROWID";
+            case JDBC40Translation.SQLXML: return "SQLXML";
+            case java.sql.Types.STRUCT: return "STRUCT";
+            // Unknown type:
             default:            return "<UNKNOWN>";
         }
     }

Added: db/derby/code/trunk/java/engine/org/apache/derby/iapi/reference/JDBC40Translation.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/engine/org/apache/derby/iapi/reference/JDBC40Translation.java?rev=420436&view=auto
==============================================================================
--- db/derby/code/trunk/java/engine/org/apache/derby/iapi/reference/JDBC40Translation.java
(added)
+++ db/derby/code/trunk/java/engine/org/apache/derby/iapi/reference/JDBC40Translation.java
Sun Jul  9 23:31:33 2006
@@ -0,0 +1,28 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.derby.iapi.reference;
+
+/**
+ * This class is a refactoring wrapper around the shared
+ * JDBC40Translation class.
+ */
+public interface JDBC40Translation extends
+    org.apache.derby.shared.common.reference.JDBC40Translation {
+}

Propchange: db/derby/code/trunk/java/engine/org/apache/derby/iapi/reference/JDBC40Translation.java
------------------------------------------------------------------------------
    svn:eol-style = native

Modified: db/derby/code/trunk/java/engine/org/apache/derby/iapi/types/TypeId.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/engine/org/apache/derby/iapi/types/TypeId.java?rev=420436&r1=420435&r2=420436&view=diff
==============================================================================
--- db/derby/code/trunk/java/engine/org/apache/derby/iapi/types/TypeId.java (original)
+++ db/derby/code/trunk/java/engine/org/apache/derby/iapi/types/TypeId.java Sun Jul  9 23:31:33
2006
@@ -174,6 +174,19 @@
         // section "10.2 Type name determination".
         public static final String      XML_NAME = "XML";
         
+        // ARRAY and STRUCT are JDBC 2.0 data types that are not
+        // supported by Derby.
+        public static final String      ARRAY_NAME = "ARRAY";
+        public static final String      STRUCT_NAME = "STRUCT";
+
+        // DATALINK is a JDBC 3.0 data type. Not supported by Derby.
+        public static final String      DATALINK_NAME = "DATALINK";
+
+        // ROWID and SQLXML are new types in JDBC 4.0. Not supported
+        // by Derby.
+        public static final String      ROWID_NAME = "ROWID";
+        public static final String      SQLXML_NAME = "SQLXML";
+
         /**
          * The following constants define the type precedence hierarchy.
          */

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=420436&r1=420435&r2=420436&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
Sun Jul  9 23:31:33 2006
@@ -42,6 +42,7 @@
 import org.apache.derby.iapi.services.io.LimitReader;
 
 import org.apache.derby.iapi.reference.SQLState;
+import org.apache.derby.iapi.reference.JDBC40Translation;
 import org.apache.derby.iapi.reference.JDBC30Translation;
 import org.apache.derby.iapi.reference.JDBC20Translation;
 
@@ -1010,6 +1011,8 @@
     public final void setObject(int parameterIndex, Object x, int targetSqlType, int scale)
             throws SQLException {
 
+        checkForSupportedDataType(targetSqlType);
+
 		if (x == null) {
 			setNull(parameterIndex, targetSqlType);
 			return;
@@ -1562,8 +1565,44 @@
             }
             throw sqle;
         }
-        
-               
+
+    /**
+     * 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
+     */
+    private 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 JDBC30Translation.DATALINK:
+        case JDBC40Translation.NCHAR:
+        case JDBC40Translation.NCLOB:
+        case JDBC40Translation.NVARCHAR:
+        case JDBC40Translation.LONGNVARCHAR:
+        case Types.REF:
+        case JDBC40Translation.ROWID:
+        case JDBC40Translation.SQLXML:
+        case Types.STRUCT:
+            throw newSQLException(SQLState.DATA_TYPE_NOT_SUPPORTED,
+                                  Util.typeName(dataType));
+        }
+    }
+
    //jdbc 4.0 methods
 
    

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=420436&r1=420435&r2=420436&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 Sun Jul  9 23:31:33
2006
@@ -32,6 +32,7 @@
 import org.apache.derby.iapi.reference.SQLState;
 import org.apache.derby.iapi.reference.MessageId;
 import org.apache.derby.iapi.reference.JDBC30Translation;
+import org.apache.derby.iapi.reference.JDBC40Translation;
 
 import java.sql.SQLException;
 import java.sql.Types;
@@ -265,8 +266,10 @@
 
 	public static String typeName(int jdbcType) {
 		switch (jdbcType) {
+			case Types.ARRAY: return TypeId.ARRAY_NAME;
 			case Types.BIT 		:  return TypeId.BIT_NAME;
 			case JDBC30Translation.SQL_TYPES_BOOLEAN  : return TypeId.BOOLEAN_NAME;
+			case JDBC30Translation.DATALINK: return TypeId.DATALINK_NAME;
 			case Types.TINYINT 	:  return TypeId.TINYINT_NAME;
 			case Types.SMALLINT	:  return TypeId.SMALLINT_NAME;
 			case Types.INTEGER 	:  return TypeId.INTEGER_NAME;
@@ -280,9 +283,16 @@
 			case Types.DECIMAL	:  return TypeId.DECIMAL_NAME;
 
 			case Types.CHAR		:  return TypeId.CHAR_NAME;
+			case JDBC40Translation.NCHAR:
+				return TypeId.NATIONAL_CHAR_NAME;
 			case Types.VARCHAR 	:  return TypeId.VARCHAR_NAME;
+			case JDBC40Translation.NVARCHAR:
+				return TypeId.NATIONAL_VARCHAR_NAME;
 			case Types.LONGVARCHAR 	:  return "LONGVARCHAR";
+			case JDBC40Translation.LONGNVARCHAR:
+				return TypeId.NATIONAL_LONGVARCHAR_NAME;
             case Types.CLOB     :  return TypeId.CLOB_NAME;
+			case JDBC40Translation.NCLOB: return TypeId.NCLOB_NAME;
 
 			case Types.DATE 		:  return TypeId.DATE_NAME;
 			case Types.TIME 		:  return TypeId.TIME_NAME;
@@ -295,7 +305,11 @@
 
 			case Types.OTHER		:  return "OTHER";
 			case Types.JAVA_OBJECT	:  return "Types.JAVA_OBJECT";
+			case Types.REF : return TypeId.REF_NAME;
+			case JDBC40Translation.ROWID: return TypeId.ROWID_NAME;
+			case Types.STRUCT: return TypeId.STRUCT_NAME;
 			case StoredFormatIds.XML_TYPE_ID :  return TypeId.XML_NAME;
+			case JDBC40Translation.SQLXML: return TypeId.SQLXML_NAME;
 			default : return String.valueOf(jdbcType);
 		}
 	}

Modified: db/derby/code/trunk/java/engine/org/apache/derby/loc/messages_en.properties
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/engine/org/apache/derby/loc/messages_en.properties?rev=420436&r1=420435&r2=420436&view=diff
==============================================================================
--- db/derby/code/trunk/java/engine/org/apache/derby/loc/messages_en.properties (original)
+++ db/derby/code/trunk/java/engine/org/apache/derby/loc/messages_en.properties Sun Jul  9
23:31:33 2006
@@ -1272,7 +1272,7 @@
 0A000.S.4=cancel() not supported by the server.
 0A000.S.5=Security mechanism ''{0}'' is not supported.
 0A000.C.6=The DRDA command {0} is not currently implemented.  The connection has been terminated.
-
+0A000.S.7=The data type ''{0}'' is not supported.
 
 XJ004.C=Database ''{0}'' not found.
 A020=Invalid authentication.

Modified: db/derby/code/trunk/java/shared/org/apache/derby/shared/common/reference/JDBC40Translation.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/shared/org/apache/derby/shared/common/reference/JDBC40Translation.java?rev=420436&r1=420435&r2=420436&view=diff
==============================================================================
--- db/derby/code/trunk/java/shared/org/apache/derby/shared/common/reference/JDBC40Translation.java
(original)
+++ db/derby/code/trunk/java/shared/org/apache/derby/shared/common/reference/JDBC40Translation.java
Sun Jul  9 23:31:33 2006
@@ -25,10 +25,12 @@
         new public statics in the jdbc 4.0 interfaces.  By providing
         an intermediary class with hard-coded copies of constants that
         will be available in jdbc 4.0, it becomes possible to refer to
-        these constants when compiling against older jdk versions. The
-        jdbc40 test suite (compiled against jdk16) contains tests that
-        verifies that these hard coded constants are in fact equal to
-        those found in jdk16.
+        these constants when compiling against older jdk versions.
+
+        <P>The test <code>jdbc4/JDBC40TranslationTest.junit</code>,
+        which is compiled against jdk16, contains tests that verifies
+        that these hard coded constants are in fact equal to those
+        found in jdk16.
 
         <P>
         This class should not be shipped with the product.
@@ -51,4 +53,12 @@
     public static final int FUNCTION_NO_NULLS          = 0;
     public static final int FUNCTION_NULLABLE          = 1;
     public static final int FUNCTION_NULLABLE_UNKNOWN  = 2;
+
+    // constants from java.sql.Types
+    public static final int NCHAR = -8;
+    public static final int NVARCHAR = -9;
+    public static final int LONGNVARCHAR = -10;
+    public static final int NCLOB = 2007;
+    public static final int ROWID = 2008;
+    public static final int SQLXML = 2009;
 }

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=420436&r1=420435&r2=420436&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
Sun Jul  9 23:31:33 2006
@@ -1318,6 +1318,7 @@
     String CANCEL_NOT_SUPPORTED_BY_SERVER                           = "0A000.S.4";
     String SECMECH_NOT_SUPPORTED                                    = "0A000.S.5";
     String DRDA_COMMAND_NOT_IMPLEMENTED                             = "0A000.C.6";
+    String DATA_TYPE_NOT_SUPPORTED = "0A000.S.7";
 
 
 

Modified: db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/suites/jdbc40.runall
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/suites/jdbc40.runall?rev=420436&r1=420435&r2=420436&view=diff
==============================================================================
--- db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/suites/jdbc40.runall
(original)
+++ db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/suites/jdbc40.runall
Sun Jul  9 23:31:33 2006
@@ -14,6 +14,7 @@
 jdbc4/ClosedObjectTest.junit
 jdbc4/ConnectionTest.junit
 jdbc4/DataSourceTest.junit
+jdbc4/JDBC40TranslationTest.junit
 jdbc4/ParameterMetaDataWrapperTest.junit
 jdbc4/PreparedStatementTest.junit
 jdbc4/ResultSetMetaDataTest.junit

Modified: db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/jdbc4/CallableStatementTest.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/jdbc4/CallableStatementTest.java?rev=420436&r1=420435&r2=420436&view=diff
==============================================================================
--- db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/jdbc4/CallableStatementTest.java
(original)
+++ db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/jdbc4/CallableStatementTest.java
Sun Jul  9 23:31:33 2006
@@ -602,9 +602,12 @@
      * Return suite with all tests of the class.
      */
     public static Test suite() {
+        TestSuite mainSuite = new TestSuite();
         TestSuite suite = new TestSuite(CallableStatementTest.class,
                                         "CallableStatementTest suite");
-        return new CallableStatementTestSetup(suite);
+        mainSuite.addTest(new CallableStatementTestSetup(suite));
+        mainSuite.addTest(SetObjectUnsupportedTest.suite(true));
+        return mainSuite;
     }
     
 } // End class CallableStatementTest

Added: db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/jdbc4/JDBC40TranslationTest.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/jdbc4/JDBC40TranslationTest.java?rev=420436&view=auto
==============================================================================
--- db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/jdbc4/JDBC40TranslationTest.java
(added)
+++ db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/jdbc4/JDBC40TranslationTest.java
Sun Jul  9 23:31:33 2006
@@ -0,0 +1,96 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.derbyTesting.functionTests.tests.jdbc4;
+
+import java.sql.DatabaseMetaData;
+import java.sql.Types;
+import org.apache.derby.shared.common.reference.JDBC40Translation;
+import org.apache.derbyTesting.functionTests.util.BaseJDBCTestCase;
+
+/**
+ * JUnit test which checks that the constants in JDBC40Translation are
+ * correct. Each constant in JDBC40Translation should have a test
+ * method comparing it to the value in the java.sql interface.
+ */
+public class JDBC40TranslationTest extends BaseJDBCTestCase {
+
+    public JDBC40TranslationTest(String name) {
+        super(name);
+    }
+
+    public void testDatabaseMetaDataFUNCTION_PARAMETER_UNKNOWN() {
+        assertEquals(DatabaseMetaData.functionParameterUnknown,
+                     JDBC40Translation.FUNCTION_PARAMETER_UNKNOWN);
+    }
+
+    public void testDatabaseMetaDataFUNCTION_PARAMETER_IN() {
+        assertEquals(DatabaseMetaData.functionParameterIn,
+                     JDBC40Translation.FUNCTION_PARAMETER_IN);
+    }
+
+    public void testDatabaseMetaDataFUNCTION_PARAMETER_INOUT() {
+        assertEquals(DatabaseMetaData.functionParameterInOut,
+                     JDBC40Translation.FUNCTION_PARAMETER_INOUT);
+    }
+
+    public void testDatabaseMetaDataFUNCTION_RETURN() {
+        assertEquals(DatabaseMetaData.functionReturn,
+                     JDBC40Translation.FUNCTION_RETURN);
+    }
+
+    public void testDatabaseMetaDataFUNCTION_NO_NULLS() {
+        assertEquals(DatabaseMetaData.functionNoNulls,
+                     JDBC40Translation.FUNCTION_NO_NULLS);
+    }
+
+    public void testDatabaseMetaDataFUNCTION_NULLABLE() {
+        assertEquals(DatabaseMetaData.functionNullable,
+                     JDBC40Translation.FUNCTION_NULLABLE);
+    }
+
+    public void testDatabaseMetaDataFUNCTION_NULLABLE_UNKNOWN() {
+        assertEquals(DatabaseMetaData.functionNullableUnknown,
+                     JDBC40Translation.FUNCTION_NULLABLE_UNKNOWN);
+    }
+
+    public void testTypesNCHAR() {
+        assertEquals(Types.NCHAR, JDBC40Translation.NCHAR);
+    }
+
+    public void testTypesNVARCHAR() {
+        assertEquals(Types.NVARCHAR, JDBC40Translation.NVARCHAR);
+    }
+
+    public void testTypesLONGNVARCHAR() {
+        assertEquals(Types.LONGNVARCHAR, JDBC40Translation.LONGNVARCHAR);
+    }
+
+    public void testTypesNCLOB() {
+        assertEquals(Types.NCLOB, JDBC40Translation.NCLOB);
+    }
+
+    public void testTypesROWID() {
+        assertEquals(Types.ROWID, JDBC40Translation.ROWID);
+    }
+
+    public void testTypesSQLXML() {
+        assertEquals(Types.SQLXML, JDBC40Translation.SQLXML);
+    }
+}

Propchange: db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/jdbc4/JDBC40TranslationTest.java
------------------------------------------------------------------------------
    svn:eol-style = native

Modified: db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/jdbc4/PreparedStatementTest.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/jdbc4/PreparedStatementTest.java?rev=420436&r1=420435&r2=420436&view=diff
==============================================================================
--- db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/jdbc4/PreparedStatementTest.java
(original)
+++ db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/jdbc4/PreparedStatementTest.java
Sun Jul  9 23:31:33 2006
@@ -102,6 +102,13 @@
         }
         conn = null;
     }
+
+    public static Test suite() {
+        TestSuite suite = new TestSuite();
+        suite.addTestSuite(PreparedStatementTest.class);
+        suite.addTest(SetObjectUnsupportedTest.suite(false));
+        return suite;
+    }
     
     //--------------------------------------------------------------------------
     //BEGIN THE TEST OF THE METHODS THAT THROW AN UNIMPLEMENTED EXCEPTION IN

Added: db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/jdbc4/SetObjectUnsupportedTest.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/jdbc4/SetObjectUnsupportedTest.java?rev=420436&view=auto
==============================================================================
--- db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/jdbc4/SetObjectUnsupportedTest.java
(added)
+++ db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/jdbc4/SetObjectUnsupportedTest.java
Sun Jul  9 23:31:33 2006
@@ -0,0 +1,141 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.derbyTesting.functionTests.tests.jdbc4;
+
+import java.sql.Connection;
+import java.sql.PreparedStatement;
+import java.sql.SQLException;
+import java.sql.SQLFeatureNotSupportedException;
+import java.sql.Types;
+import junit.framework.Test;
+import junit.framework.TestSuite;
+import org.apache.derbyTesting.functionTests.util.BaseJDBCTestCase;
+
+/**
+ * Tests that calling <code>setObject()</code> with
+ * <code>sqlTargetType</code> set to an unsupported type fails with
+ * <code>SQLFeatureNotSupportedException</code>.
+ *
+ * <p> The test is run as part of <code>PreparedStatementTest</code>
+ * and <code>CallableStatementTest</code>.
+ */
+public class SetObjectUnsupportedTest extends BaseJDBCTestCase {
+    /** Name and id of the target type used in the test. */
+    private final TypeInfo typeInfo;
+    /** Flag indicating whether the test should use a
+     * CallableStatement instead of a PreparedStatement. */
+    private final boolean callable;
+
+    /**
+     * Creates a new <code>SetObjectUnsupportedTest</code> instance.
+     *
+     * @param name name of the test
+     * @param typeInfo description of the target type to use in the test
+     * @param callable if <code>true</code>, use a
+     * <code>CallableStatement</code> instead of a
+     * <code>PreparedStatement</code>.
+     */
+    private SetObjectUnsupportedTest(String name, TypeInfo typeInfo,
+                                     boolean callable) {
+        super(name);
+        this.typeInfo = typeInfo;
+        this.callable = callable;
+    }
+
+    /**
+     * Returns the name of the test.
+     */
+    public String getName() {
+        return super.getName() + "_" + typeInfo.name;
+    }
+
+    /**
+     * Prepares a <code>PreparedStatement</code> or a
+     * <code>CallableStatement</code> to use in the test.
+     *
+     * @return a statement (prepared or callable)
+     * @exception SQLException if a database error occurs
+     */
+    private PreparedStatement prepare() throws SQLException {
+        String sql = "values (CAST (? AS VARCHAR(128)))";
+        Connection c = getConnection();
+        return callable ? c.prepareCall(sql) : c.prepareStatement(sql);
+    }
+
+    /**
+     * Test that <code>setObject()</code> with the specified
+     * <code>sqlTargetType</code>.
+     *
+     * @exception SQLException if a database error occurs
+     */
+    public void testUnsupportedSetObject() throws SQLException {
+        PreparedStatement ps = prepare();
+        try {
+            ps.setObject(1, null, typeInfo.type);
+            fail("No exception thrown.");
+        } catch (SQLFeatureNotSupportedException e) {
+            // expected exception
+        }
+    }
+
+    /**
+     * The target types to test.
+     */
+    private static final TypeInfo[] TYPES = {
+        new TypeInfo("ARRAY", Types.ARRAY),
+        new TypeInfo("DATALINK", Types.DATALINK),
+        new TypeInfo("NCHAR", Types.NCHAR),
+        new TypeInfo("NCLOB", Types.NCLOB),
+        new TypeInfo("NVARCHAR", Types.NVARCHAR),
+        new TypeInfo("LONGNVARCHAR", Types.LONGNVARCHAR),
+        new TypeInfo("REF", Types.REF),
+        new TypeInfo("ROWID", Types.ROWID),
+        new TypeInfo("SQLXML", Types.SQLXML),
+        new TypeInfo("STRUCT", Types.STRUCT),
+    };
+
+    /**
+     * Build a test suite which tests <code>setObject()</code> with
+     * each of the types in <code>TYPES</code>.
+     *
+     * @param callable if <code>true</code>, test with a
+     * <code>CallableStatement</code>; otherwise, test with a
+     * <code>PreparedStatement</code>
+     * @return a test suite
+     */
+    static Test suite(boolean callable) {
+        TestSuite suite = new TestSuite();
+        for (TypeInfo typeInfo : TYPES) {
+            suite.addTest(new SetObjectUnsupportedTest
+                          ("testUnsupportedSetObject", typeInfo, callable));
+        }
+        return suite;
+    }
+
+    /** Class with name and id for the target type used in a test. */
+    private static class TypeInfo {
+        final String name;
+        final int type;
+        TypeInfo(String name, int type) {
+            this.name = name;
+            this.type = type;
+        }
+    }
+}

Propchange: db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/jdbc4/SetObjectUnsupportedTest.java
------------------------------------------------------------------------------
    svn:eol-style = native



Mime
View raw message