You are viewing a plain text version of this content. The canonical link for it is here.
Posted to derby-dev@db.apache.org by "Knut Anders Hatlen (JIRA)" <ji...@apache.org> on 2011/03/21 01:35:06 UTC

[jira] [Created] (DERBY-5143) Remove unnecessary copying of the map in getTypeMap()

Remove unnecessary copying of the map in getTypeMap()
-----------------------------------------------------

                 Key: DERBY-5143
                 URL: https://issues.apache.org/jira/browse/DERBY-5143
             Project: Derby
          Issue Type: Improvement
          Components: JDBC
    Affects Versions: 10.8.0.0
            Reporter: Knut Anders Hatlen
            Assignee: Knut Anders Hatlen
            Priority: Minor


The JDBC 4.0 Connection classes implement getTypeMap() by calling super.getTypeMap() and copying the resulting map. This is done to prevent an unchecked compiler warning that we would see if we simply returned super.getTypeMap() in this method. It would be cheaper and simpler to return super.getTypeMap() and ignore the warning.

--
This message is automatically generated by JIRA.
For more information on JIRA, see: http://www.atlassian.com/software/jira

[jira] [Commented] (DERBY-5143) Remove unnecessary copying of the map in getTypeMap()

Posted by "Lily Wei (JIRA)" <ji...@apache.org>.
    [ https://issues.apache.org/jira/browse/DERBY-5143?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=13009286#comment-13009286 ] 

Lily Wei commented on DERBY-5143:
---------------------------------

Thank you so much, Knut. I run derby-5143-1a.diff patch for ConnectionTest test against JDBC 3.0 and JDBC 4.1. +1 for the patch.

> Remove unnecessary copying of the map in getTypeMap()
> -----------------------------------------------------
>
>                 Key: DERBY-5143
>                 URL: https://issues.apache.org/jira/browse/DERBY-5143
>             Project: Derby
>          Issue Type: Improvement
>          Components: JDBC
>    Affects Versions: 10.8.0.0
>            Reporter: Knut Anders Hatlen
>            Assignee: Knut Anders Hatlen
>            Priority: Minor
>         Attachments: derby-5143-1a.diff, getTypeMap-warning.diff
>
>
> The JDBC 4.0 Connection classes implement getTypeMap() by calling super.getTypeMap() and copying the resulting map. This is done to prevent an unchecked compiler warning that we would see if we simply returned super.getTypeMap() in this method. It would be cheaper and simpler to return super.getTypeMap() and ignore the warning.

--
This message is automatically generated by JIRA.
For more information on JIRA, see: http://www.atlassian.com/software/jira

[jira] [Commented] (DERBY-5143) Remove unnecessary copying of the map in getTypeMap()

Posted by "Dave Brosius (JIRA)" <ji...@apache.org>.
    [ https://issues.apache.org/jira/browse/DERBY-5143?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=13008998#comment-13008998 ] 

Dave Brosius commented on DERBY-5143:
-------------------------------------

It seems to me like the entire NetConnection40.getTypeMap method can be removed, as the parent class always just returns an empty Map. In fact, Connection.getTypeMap, could just return a static field Map defined as

static final Map typeMap = Collections.unmodfiableSet(new HashSet());

> Remove unnecessary copying of the map in getTypeMap()
> -----------------------------------------------------
>
>                 Key: DERBY-5143
>                 URL: https://issues.apache.org/jira/browse/DERBY-5143
>             Project: Derby
>          Issue Type: Improvement
>          Components: JDBC
>    Affects Versions: 10.8.0.0
>            Reporter: Knut Anders Hatlen
>            Assignee: Knut Anders Hatlen
>            Priority: Minor
>         Attachments: getTypeMap-warning.diff
>
>
> The JDBC 4.0 Connection classes implement getTypeMap() by calling super.getTypeMap() and copying the resulting map. This is done to prevent an unchecked compiler warning that we would see if we simply returned super.getTypeMap() in this method. It would be cheaper and simpler to return super.getTypeMap() and ignore the warning.

--
This message is automatically generated by JIRA.
For more information on JIRA, see: http://www.atlassian.com/software/jira

[jira] [Commented] (DERBY-5143) Remove unnecessary copying of the map in getTypeMap()

Posted by "Knut Anders Hatlen (JIRA)" <ji...@apache.org>.
    [ https://issues.apache.org/jira/browse/DERBY-5143?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=13009099#comment-13009099 ] 

Knut Anders Hatlen commented on DERBY-5143:
-------------------------------------------

I think the reason why we added the getTypeMap() method in the first place was that the compilation of NetConnection40 would generate the following warning:

Compiling 1 source file to /code/derby/trunk0/classes
/code/derby/trunk0/java/client/org/apache/derby/client/net/NetConnection40.java:48: warning: getTypeMap() in org.apache.derby.client.am.Connection implements getTypeMap() in java.sql.Connection; return type requires unchecked conversion
found   : java.util.Map
required: java.util.Map<java.lang.String,java.lang.Class<?>>
public class  NetConnection40 extends org.apache.derby.client.net.NetConnection {
1 warning

And suppressing unchecked warnings for the entire class wasn't considered a good alternative. There may be other ways to silence this specific warning only, but I'm not aware of any.

You're of course right that Connection.getTypeMap() should return Collections.EMPTY_MAP. I thought it already did, but that's only on the embedded driver. Will fix that too.

> Remove unnecessary copying of the map in getTypeMap()
> -----------------------------------------------------
>
>                 Key: DERBY-5143
>                 URL: https://issues.apache.org/jira/browse/DERBY-5143
>             Project: Derby
>          Issue Type: Improvement
>          Components: JDBC
>    Affects Versions: 10.8.0.0
>            Reporter: Knut Anders Hatlen
>            Assignee: Knut Anders Hatlen
>            Priority: Minor
>         Attachments: getTypeMap-warning.diff
>
>
> The JDBC 4.0 Connection classes implement getTypeMap() by calling super.getTypeMap() and copying the resulting map. This is done to prevent an unchecked compiler warning that we would see if we simply returned super.getTypeMap() in this method. It would be cheaper and simpler to return super.getTypeMap() and ignore the warning.

--
This message is automatically generated by JIRA.
For more information on JIRA, see: http://www.atlassian.com/software/jira

[jira] [Issue Comment Edited] (DERBY-5143) Remove unnecessary copying of the map in getTypeMap()

Posted by "Dave Brosius (JIRA)" <ji...@apache.org>.
    [ https://issues.apache.org/jira/browse/DERBY-5143?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=13008998#comment-13008998 ] 

Dave Brosius edited comment on DERBY-5143 at 3/21/11 1:05 AM:
--------------------------------------------------------------

It seems to me like the entire NetConnection40.getTypeMap method can be removed, as the parent class always just returns an empty Map. In fact, Connection.getTypeMap, could just return a static field Map defined as

static final Map typeMap = Collections.unmodfiableSet(new HashSet());

or perhaps even better, just return Collections.EMPTY_SET;

      was (Author: dbrosius@apache.org):
    It seems to me like the entire NetConnection40.getTypeMap method can be removed, as the parent class always just returns an empty Map. In fact, Connection.getTypeMap, could just return a static field Map defined as

static final Map typeMap = Collections.unmodfiableSet(new HashSet());
  
> Remove unnecessary copying of the map in getTypeMap()
> -----------------------------------------------------
>
>                 Key: DERBY-5143
>                 URL: https://issues.apache.org/jira/browse/DERBY-5143
>             Project: Derby
>          Issue Type: Improvement
>          Components: JDBC
>    Affects Versions: 10.8.0.0
>            Reporter: Knut Anders Hatlen
>            Assignee: Knut Anders Hatlen
>            Priority: Minor
>         Attachments: getTypeMap-warning.diff
>
>
> The JDBC 4.0 Connection classes implement getTypeMap() by calling super.getTypeMap() and copying the resulting map. This is done to prevent an unchecked compiler warning that we would see if we simply returned super.getTypeMap() in this method. It would be cheaper and simpler to return super.getTypeMap() and ignore the warning.

--
This message is automatically generated by JIRA.
For more information on JIRA, see: http://www.atlassian.com/software/jira

[jira] [Commented] (DERBY-5143) Remove unnecessary copying of the map in getTypeMap()

Posted by "Knut Anders Hatlen (JIRA)" <ji...@apache.org>.
    [ https://issues.apache.org/jira/browse/DERBY-5143?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=13008991#comment-13008991 ] 

Knut Anders Hatlen commented on DERBY-5143:
-------------------------------------------

One unintended side effect from the copying is that the returned map is mutable when using the JDBC 4.0 driver, whereas it's immutable with the JDBC 3.0 driver.

> Remove unnecessary copying of the map in getTypeMap()
> -----------------------------------------------------
>
>                 Key: DERBY-5143
>                 URL: https://issues.apache.org/jira/browse/DERBY-5143
>             Project: Derby
>          Issue Type: Improvement
>          Components: JDBC
>    Affects Versions: 10.8.0.0
>            Reporter: Knut Anders Hatlen
>            Assignee: Knut Anders Hatlen
>            Priority: Minor
>
> The JDBC 4.0 Connection classes implement getTypeMap() by calling super.getTypeMap() and copying the resulting map. This is done to prevent an unchecked compiler warning that we would see if we simply returned super.getTypeMap() in this method. It would be cheaper and simpler to return super.getTypeMap() and ignore the warning.

--
This message is automatically generated by JIRA.
For more information on JIRA, see: http://www.atlassian.com/software/jira

[jira] [Updated] (DERBY-5143) Remove unnecessary copying of the map in getTypeMap()

Posted by "Knut Anders Hatlen (JIRA)" <ji...@apache.org>.
     [ https://issues.apache.org/jira/browse/DERBY-5143?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]

Knut Anders Hatlen updated DERBY-5143:
--------------------------------------

    Attachment: derby-5143-1a.diff

Attaching a new patch (derby-5143-1a.diff) with the following changes from the initial patch:

- simplified the getTypeMap() overrides a little more

- 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

> Remove unnecessary copying of the map in getTypeMap()
> -----------------------------------------------------
>
>                 Key: DERBY-5143
>                 URL: https://issues.apache.org/jira/browse/DERBY-5143
>             Project: Derby
>          Issue Type: Improvement
>          Components: JDBC
>    Affects Versions: 10.8.0.0
>            Reporter: Knut Anders Hatlen
>            Assignee: Knut Anders Hatlen
>            Priority: Minor
>         Attachments: derby-5143-1a.diff, getTypeMap-warning.diff
>
>
> The JDBC 4.0 Connection classes implement getTypeMap() by calling super.getTypeMap() and copying the resulting map. This is done to prevent an unchecked compiler warning that we would see if we simply returned super.getTypeMap() in this method. It would be cheaper and simpler to return super.getTypeMap() and ignore the warning.

--
This message is automatically generated by JIRA.
For more information on JIRA, see: http://www.atlassian.com/software/jira

[jira] [Updated] (DERBY-5143) Remove unnecessary copying of the map in getTypeMap()

Posted by "Knut Anders Hatlen (JIRA)" <ji...@apache.org>.
     [ https://issues.apache.org/jira/browse/DERBY-5143?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]

Knut Anders Hatlen updated DERBY-5143:
--------------------------------------

    Attachment: getTypeMap-warning.diff

The attached patch shows how to silence the compiler warning without copying the map.

A side effect of this change is that the returned map in the JDBC 4.0 driver is exactly the same as the one that would have been returned by the JDBC 3.0 driver, and it is immutable. One of the JDBC 4.0 tests (ConnectionTest.testGetTypeMapReturnsAsExpected) calls put() on the returned map, and therefore starts failing with an UnsupportedOperationException now that the returned map isn't mutable. I think the test should be changed, and the map should stay immutable.

> Remove unnecessary copying of the map in getTypeMap()
> -----------------------------------------------------
>
>                 Key: DERBY-5143
>                 URL: https://issues.apache.org/jira/browse/DERBY-5143
>             Project: Derby
>          Issue Type: Improvement
>          Components: JDBC
>    Affects Versions: 10.8.0.0
>            Reporter: Knut Anders Hatlen
>            Assignee: Knut Anders Hatlen
>            Priority: Minor
>         Attachments: getTypeMap-warning.diff
>
>
> The JDBC 4.0 Connection classes implement getTypeMap() by calling super.getTypeMap() and copying the resulting map. This is done to prevent an unchecked compiler warning that we would see if we simply returned super.getTypeMap() in this method. It would be cheaper and simpler to return super.getTypeMap() and ignore the warning.

--
This message is automatically generated by JIRA.
For more information on JIRA, see: http://www.atlassian.com/software/jira

[jira] [Resolved] (DERBY-5143) Remove unnecessary copying of the map in getTypeMap()

Posted by "Knut Anders Hatlen (JIRA)" <ji...@apache.org>.
     [ https://issues.apache.org/jira/browse/DERBY-5143?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]

Knut Anders Hatlen resolved DERBY-5143.
---------------------------------------

       Resolution: Fixed
    Fix Version/s: 10.8.0.0

Thank you, Lily, for testing the patch. I also ran suites.All and derbyall with Java 6 without any failures.

Committed revision 1083917.

> Remove unnecessary copying of the map in getTypeMap()
> -----------------------------------------------------
>
>                 Key: DERBY-5143
>                 URL: https://issues.apache.org/jira/browse/DERBY-5143
>             Project: Derby
>          Issue Type: Improvement
>          Components: JDBC
>    Affects Versions: 10.8.0.0
>            Reporter: Knut Anders Hatlen
>            Assignee: Knut Anders Hatlen
>            Priority: Minor
>             Fix For: 10.8.0.0
>
>         Attachments: derby-5143-1a.diff, getTypeMap-warning.diff
>
>
> The JDBC 4.0 Connection classes implement getTypeMap() by calling super.getTypeMap() and copying the resulting map. This is done to prevent an unchecked compiler warning that we would see if we simply returned super.getTypeMap() in this method. It would be cheaper and simpler to return super.getTypeMap() and ignore the warning.

--
This message is automatically generated by JIRA.
For more information on JIRA, see: http://www.atlassian.com/software/jira