You are viewing a plain text version of this content. The canonical link for it is here.
Posted to derby-commits@db.apache.org by ka...@apache.org on 2011/03/21 20:37:42 UTC

svn commit: r1083917 - in /db/derby/code/trunk/java: client/org/apache/derby/client/am/ client/org/apache/derby/client/net/ engine/org/apache/derby/impl/jdbc/ testing/org/apache/derbyTesting/functionTests/tests/jdbc4/

Author: kahatlen
Date: Mon Mar 21 19:37:41 2011
New Revision: 1083917

URL: http://svn.apache.org/viewvc?rev=1083917&view=rev
Log:
DERBY-5143: Remove unnecessary copying of the map in getTypeMap()

- made the JDBC 4.0 overrides of getTypeMap() just call
  super.getTypeMap(), and added SuppressWarnings annotation to silence
  the unchecked conversion warnings in the overridden methods

- made the client implementation return EMPTY_MAP (immutable) instead
  of an empty HashMap (mutable), to match the embedded implementation

- updated ConnectionTest to expect the returned map to be immutable

Modified:
    db/derby/code/trunk/java/client/org/apache/derby/client/am/Connection.java
    db/derby/code/trunk/java/client/org/apache/derby/client/net/NetConnection40.java
    db/derby/code/trunk/java/engine/org/apache/derby/impl/jdbc/EmbedConnection40.java
    db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/jdbc4/ConnectionTest.java

Modified: db/derby/code/trunk/java/client/org/apache/derby/client/am/Connection.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/client/org/apache/derby/client/am/Connection.java?rev=1083917&r1=1083916&r2=1083917&view=diff
==============================================================================
--- db/derby/code/trunk/java/client/org/apache/derby/client/am/Connection.java (original)
+++ db/derby/code/trunk/java/client/org/apache/derby/client/am/Connection.java Mon Mar 21 19:37:41 2011
@@ -26,6 +26,7 @@ import org.apache.derby.jdbc.ClientDataS
 import org.apache.derby.shared.common.reference.SQLState;
 
 import java.sql.SQLException;
+import java.util.Collections;
 import org.apache.derby.client.net.NetXAResource;
 import org.apache.derby.shared.common.sanity.SanityManager;
 
@@ -1407,7 +1408,7 @@ public abstract class Connection
                 agent_.logWriter_.traceEntry(this, "getTypeMap");
             }
             checkForClosedConnection();
-            java.util.Map map = new java.util.HashMap();
+            java.util.Map map = Collections.EMPTY_MAP;
             if (agent_.loggingEnabled()) {
                 agent_.logWriter_.traceExit(this, "getTypeMap", map);
             }

Modified: db/derby/code/trunk/java/client/org/apache/derby/client/net/NetConnection40.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/client/org/apache/derby/client/net/NetConnection40.java?rev=1083917&r1=1083916&r2=1083917&view=diff
==============================================================================
--- db/derby/code/trunk/java/client/org/apache/derby/client/net/NetConnection40.java (original)
+++ db/derby/code/trunk/java/client/org/apache/derby/client/net/NetConnection40.java Mon Mar 21 19:37:41 2011
@@ -24,9 +24,6 @@ package org.apache.derby.client.net;
 import java.sql.Array;
 import org.apache.derby.client.am.SQLExceptionFactory;
 import org.apache.derby.client.am.SqlException;
-import java.sql.Blob;
-import java.sql.Clob;
-import java.sql.Connection;
 import java.sql.NClob;
 import java.sql.PreparedStatement;
 import java.sql.ResultSet;
@@ -35,10 +32,8 @@ import java.sql.SQLException;
 import java.sql.SQLPermission;
 import java.sql.SQLXML;
 import java.sql.Struct;
-import java.util.HashMap;
 import java.util.Map;
 import java.util.Properties;
-import java.util.Enumeration;
 import java.util.concurrent.Executor;
 import org.apache.derby.client.ClientPooledConnection;
 import org.apache.derby.client.am.ClientMessageId;
@@ -338,19 +333,12 @@ public class  NetConnection40 extends or
      * @return type map for this connection
      * @exception SQLException if a database access error occurs
      */
+    @SuppressWarnings("unchecked")
     public final Map<String, Class<?>> getTypeMap() throws SQLException {
-        // This method is already implemented with a non-generic
-        // signature in am/Connection. We could just use that method
-        // directly, but then we get a compiler warning (unchecked
-        // cast/conversion). Copy the map to avoid the compiler
-        // warning.
-        Map typeMap = super.getTypeMap();
-        if (typeMap == null) return null;
-        Map<String, Class<?>> genericTypeMap = new HashMap<String, Class<?>>();
-        for (Object key : typeMap.keySet()) {
-            genericTypeMap.put((String) key, (Class) typeMap.get(key));
-        }
-        return genericTypeMap;
+        // Return the map from the super class. The method is overridden
+        // just to get the generic signature and prevent an unchecked warning
+        // at compile time.
+        return super.getTypeMap();
     }
 
     /**

Modified: db/derby/code/trunk/java/engine/org/apache/derby/impl/jdbc/EmbedConnection40.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/engine/org/apache/derby/impl/jdbc/EmbedConnection40.java?rev=1083917&r1=1083916&r2=1083917&view=diff
==============================================================================
--- db/derby/code/trunk/java/engine/org/apache/derby/impl/jdbc/EmbedConnection40.java (original)
+++ db/derby/code/trunk/java/engine/org/apache/derby/impl/jdbc/EmbedConnection40.java Mon Mar 21 19:37:41 2011
@@ -22,19 +22,14 @@
 package org.apache.derby.impl.jdbc;
 
 import java.sql.Array;
-import java.sql.Blob;
 import java.sql.SQLClientInfoException;
-import java.sql.Clob;
-import java.sql.Connection;
 import java.sql.NClob;
 import java.sql.SQLException;
 import java.sql.SQLPermission;
 import java.sql.SQLXML;
 import java.sql.Struct;
-import java.util.HashMap;
 import java.util.Map;
 import java.util.Properties;
-import java.util.Enumeration;
 import java.util.concurrent.Executor;
 import org.apache.derby.jdbc.InternalDriver;
 import org.apache.derby.iapi.reference.SQLState;
@@ -212,19 +207,12 @@ public class EmbedConnection40 extends E
      * @return type map for this connection
      * @exception SQLException if a database access error occurs
      */
+    @SuppressWarnings("unchecked")
     public final Map<String, Class<?>> getTypeMap() throws SQLException {
-        // This method is already implemented with a non-generic
-        // signature in EmbedConnection. We could just use that method
-        // directly, but then we get a compiler warning (unchecked
-        // cast/conversion). Copy the map to avoid the compiler
-        // warning.
-        Map typeMap = super.getTypeMap();
-        if (typeMap == null) return null;
-        Map<String, Class<?>> genericTypeMap = new HashMap<String, Class<?>>();
-        for (Object key : typeMap.keySet()) {
-            genericTypeMap.put((String) key, (Class) typeMap.get(key));
-        }
-        return genericTypeMap;
+        // Return the map from the super class. The method is overridden
+        // just to get the generic signature and prevent an unchecked warning
+        // at compile time.
+        return super.getTypeMap();
     }
     
     /**

Modified: db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/jdbc4/ConnectionTest.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/jdbc4/ConnectionTest.java?rev=1083917&r1=1083916&r2=1083917&view=diff
==============================================================================
--- db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/jdbc4/ConnectionTest.java (original)
+++ db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/jdbc4/ConnectionTest.java Mon Mar 21 19:37:41 2011
@@ -28,6 +28,7 @@ import org.apache.derbyTesting.junit.Tes
 
 import java.sql.*;
 import java.util.ArrayList;
+import java.util.HashMap;
 import java.util.List;
 import java.util.Map;
 import java.util.Properties;
@@ -213,6 +214,16 @@ public class ConnectionTest
         ps.execute();     
         
         Map<String, Class<?>> map = getConnection().getTypeMap();
+        try {
+            map.put("JAVA_UTIL_LIST", List.class);
+            fail("returned map should be immutable");
+        } catch (UnsupportedOperationException uoe) {
+            // Ignore expected exception
+        }
+
+        // Create a non-empty map to test setTypeMap(). setTypeMap() raises
+        // a feature not supported exception if the map isn't empty.
+        map = new HashMap<String, Class<?>>();
         map.put("JAVA_UTIL_LIST", List.class);
         
         try {