You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user-java@ibatis.apache.org by Michael Schall <mi...@gmail.com> on 2010/03/04 19:53:54 UTC

Should IntegerTypeHandler use Integer.valueOf instead of new Integer()

I have been doing some performance tuning and looking a heap dumps.
The number of Integer objects in memory is staggering. Looking at the
1.5 java docs, using Integer.valueOf should help.
http://java.sun.com/j2se/1.5.0/docs/api/java/lang/Integer.html#valueOf(int)

This could be extended to most of the number type TypeHandlers in the
2.3.4 code base as it requires Java 1.5.  How is this handled in 3.0?

IntegerTypeHandler (version 2.3.4 )
  public Object getResult(ResultSet rs, String columnName)
      throws SQLException {
    int i = rs.getInt(columnName);
    if (rs.wasNull()) {
      return null;
    } else {
      return new Integer(i);
    }
  }

Mike

---------------------------------------------------------------------
To unsubscribe, e-mail: user-java-unsubscribe@ibatis.apache.org
For additional commands, e-mail: user-java-help@ibatis.apache.org


Re: Should IntegerTypeHandler use Integer.valueOf instead of new Integer()

Posted by Clinton Begin <cl...@gmail.com>.
Yes, that's correct.

Cheers,
Clinton

On Fri, Mar 5, 2010 at 1:13 PM, Michael Schall <mi...@gmail.com> wrote:
> In looking at this further... Resultset.getInt returns an int...
> http://java.sun.com/j2se/1.5.0/docs/api/java/sql/ResultSet.html#getInt(int)
>
> However the autoboxing feature of Java 1.5 converts it to an Integer.
>
>        public void testAutoboxing() {
>                int i = 1;
>                Object o = i;
>                assertTrue(o.getClass().equals(Integer.class));
>        }
>
> So the 2.3.4 IntegerTypeHandler should be able to be...
>
>  public Object getResult(ResultSet rs, String columnName)
>      throws SQLException {
>    int i = rs.getInt(columnName);
>    if (rs.wasNull()) {
>      return null;
>    } else {
>      return i;
>    }
>  }
>
> Correct?
> Mike
>
>
> On Thu, Mar 4, 2010 at 3:39 PM, Nathan Maves <na...@gmail.com> wrote:
>> Here is how IB3 does it
>> BaseTypeHandler
>>   public Object getResult(ResultSet rs, String columnName)
>>       throws SQLException {
>>     Object result = getNullableResult(rs, columnName);
>>     if (rs.wasNull()) {
>>       return null;
>>     } else {
>>       return result;
>>     }
>>   }
>> IntegerTypeHandler
>>   public Object getNullableResult(ResultSet rs, String columnName)
>>       throws SQLException {
>>     return rs.getInt(columnName);
>>   }
>> So the actual Integer creation is done by the driver.
>> On Thu, Mar 4, 2010 at 11:53 AM, Michael Schall <mi...@gmail.com>
>> wrote:
>>>
>>> I have been doing some performance tuning and looking a heap dumps.
>>> The number of Integer objects in memory is staggering. Looking at the
>>> 1.5 java docs, using Integer.valueOf should help.
>>>
>>> http://java.sun.com/j2se/1.5.0/docs/api/java/lang/Integer.html#valueOf(int)
>>>
>>> This could be extended to most of the number type TypeHandlers in the
>>> 2.3.4 code base as it requires Java 1.5.  How is this handled in 3.0?
>>>
>>> IntegerTypeHandler (version 2.3.4 )
>>>  public Object getResult(ResultSet rs, String columnName)
>>>      throws SQLException {
>>>    int i = rs.getInt(columnName);
>>>    if (rs.wasNull()) {
>>>      return null;
>>>    } else {
>>>      return new Integer(i);
>>>    }
>>>  }
>>>
>>> Mike
>>>
>>> ---------------------------------------------------------------------
>>> To unsubscribe, e-mail: user-java-unsubscribe@ibatis.apache.org
>>> For additional commands, e-mail: user-java-help@ibatis.apache.org
>>>
>>
>>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: user-java-unsubscribe@ibatis.apache.org
> For additional commands, e-mail: user-java-help@ibatis.apache.org
>
>

---------------------------------------------------------------------
To unsubscribe, e-mail: user-java-unsubscribe@ibatis.apache.org
For additional commands, e-mail: user-java-help@ibatis.apache.org


Re: Should IntegerTypeHandler use Integer.valueOf instead of new Integer()

Posted by Michael Schall <mi...@gmail.com>.
In looking at this further... Resultset.getInt returns an int...
http://java.sun.com/j2se/1.5.0/docs/api/java/sql/ResultSet.html#getInt(int)

However the autoboxing feature of Java 1.5 converts it to an Integer.

	public void testAutoboxing() {
		int i = 1;
		Object o = i;
		assertTrue(o.getClass().equals(Integer.class));
	}

So the 2.3.4 IntegerTypeHandler should be able to be...

  public Object getResult(ResultSet rs, String columnName)
      throws SQLException {
    int i = rs.getInt(columnName);
    if (rs.wasNull()) {
      return null;
    } else {
      return i;
    }
  }

Correct?
Mike


On Thu, Mar 4, 2010 at 3:39 PM, Nathan Maves <na...@gmail.com> wrote:
> Here is how IB3 does it
> BaseTypeHandler
>   public Object getResult(ResultSet rs, String columnName)
>       throws SQLException {
>     Object result = getNullableResult(rs, columnName);
>     if (rs.wasNull()) {
>       return null;
>     } else {
>       return result;
>     }
>   }
> IntegerTypeHandler
>   public Object getNullableResult(ResultSet rs, String columnName)
>       throws SQLException {
>     return rs.getInt(columnName);
>   }
> So the actual Integer creation is done by the driver.
> On Thu, Mar 4, 2010 at 11:53 AM, Michael Schall <mi...@gmail.com>
> wrote:
>>
>> I have been doing some performance tuning and looking a heap dumps.
>> The number of Integer objects in memory is staggering. Looking at the
>> 1.5 java docs, using Integer.valueOf should help.
>>
>> http://java.sun.com/j2se/1.5.0/docs/api/java/lang/Integer.html#valueOf(int)
>>
>> This could be extended to most of the number type TypeHandlers in the
>> 2.3.4 code base as it requires Java 1.5.  How is this handled in 3.0?
>>
>> IntegerTypeHandler (version 2.3.4 )
>>  public Object getResult(ResultSet rs, String columnName)
>>      throws SQLException {
>>    int i = rs.getInt(columnName);
>>    if (rs.wasNull()) {
>>      return null;
>>    } else {
>>      return new Integer(i);
>>    }
>>  }
>>
>> Mike
>>
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: user-java-unsubscribe@ibatis.apache.org
>> For additional commands, e-mail: user-java-help@ibatis.apache.org
>>
>
>

---------------------------------------------------------------------
To unsubscribe, e-mail: user-java-unsubscribe@ibatis.apache.org
For additional commands, e-mail: user-java-help@ibatis.apache.org


Re: Should IntegerTypeHandler use Integer.valueOf instead of new Integer()

Posted by Nathan Maves <na...@gmail.com>.
Here is how IB3 does it

*BaseTypeHandler*
*
*
  public Object getResult(ResultSet rs, String columnName)
      throws SQLException {
    Object result = getNullableResult(rs, columnName);
    if (rs.wasNull()) {
      return null;
    } else {
      return result;
    }
  }

*IntegerTypeHandler*

  public Object getNullableResult(ResultSet rs, String columnName)
      throws SQLException {
    return rs.getInt(columnName);
  }

So the actual Integer creation is done by the driver.

On Thu, Mar 4, 2010 at 11:53 AM, Michael Schall <mi...@gmail.com>wrote:

> I have been doing some performance tuning and looking a heap dumps.
> The number of Integer objects in memory is staggering. Looking at the
> 1.5 java docs, using Integer.valueOf should help.
> http://java.sun.com/j2se/1.5.0/docs/api/java/lang/Integer.html#valueOf(int)
>
> This could be extended to most of the number type TypeHandlers in the
> 2.3.4 code base as it requires Java 1.5.  How is this handled in 3.0?
>
> IntegerTypeHandler (version 2.3.4 )
>  public Object getResult(ResultSet rs, String columnName)
>      throws SQLException {
>    int i = rs.getInt(columnName);
>    if (rs.wasNull()) {
>      return null;
>    } else {
>      return new Integer(i);
>    }
>  }
>
> Mike
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: user-java-unsubscribe@ibatis.apache.org
> For additional commands, e-mail: user-java-help@ibatis.apache.org
>
>