You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@commons.apache.org by Pa...@xtl.com on 2008/09/10 21:35:38 UTC

[beanutils] RowSetDynaClass

I'm having a ConversionException issue when creating a RowSetDynaClass from a
ResultSet.  Apparently I'm not the only person's who's experienced this.  The
exception is saying "Cannot assign value of type 'java.lang.Integer' to property
'vsize' of type 'java.lang.Short'.  Does somebody have a solution to this
problem?  I'm using Beanutils 1.8.
(Embedded image moved to file: pic25667.jpg)

Re: [beanutils] RowSetDynaClass

Posted by Pa...@xtl.com.
When a RowSetDynaClass object is created from a ResultSet, how does it handle
deleted records in the ResultSet?  Does each object in the DynaBean representing
a deleted record just get a null value?  I looked at the source of
JDBCDynaClass, specifically the introspect method.  I don't see that it handles
deleted records.  In my class when I'm retrieving data from the DynaBean, should
I have a check to see if the value of an object is null to avoid a
NullPointerException?
(Embedded image moved to file: pic29599.jpg)

Re: [beanutils] RowSetDynaClass

Posted by Pa...@xtl.com.
I'm running into a new issue that seems to be intermittent.  The process I
created selects data from tables in one database and inserts it into another
database.  At the beginning of my process, I initialize an array of
HarvestRowSetDynaClass (this is my custom class that extends RowSetDynaClass)
with an initial array length equivalent to the number of tables I need to
harvest in my source database.  The source database is constantly being updated
over the web.  The query to the first table returns 20000 records (not sure why
it's such a round number), but that changes as the database gets updated from
the web.  I create a new HarvestRowSetDynaClass object in my array for each
ResultSet.  Later in my process, I iterate through my array, get the rows from
each HarvestRowSetDynaClass object, then I iterate over it's DynaBeans to get
the data and insert it into my target database.  Every once in a while though,
my process gets through the 20000 records from the first HarvestRowSetDynaClass
object, moves on to the next one in the array and throws a NullPointerException.
This behaviour seems intermittent because the process runs fine at other times.

Could this be due to the garbage collector clearing my HarvestRowSetDynaClass
array before I have the chance to read from it again?  Would I be better off
storing my HarvestRowSetDynaClass objects in a list rather than just a simple
array?

Thanks,
Patrick



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


Re: [beanutils] RowSetDynaClass

Posted by Pa...@xtl.com.
Thanks Niall,

I took your suggestion and just had to modify it a bit.  At first when I tried
your suggestion, my process crashed when it came across a java.sql.Timestamp
property.  What I did in the end was look at the source of JDBCDynaClass and I
copied some of the logic from it's getObject() method into my class that extends
RowSetDynaClass.  The code I copied basically handles Timestamp, Date and Time
properties just like JDBCDynaClass, except I'm handling them like "if else
if..." instead of just a normal if statement for each.  That allowed me to add
your suggested code as the last option in my if else if tree.

Thanks again.
Patrick



                                                                                
             "Niall Pemberton"                                                  
             <niall.pemberton@gm                                                
             ail.com>                                                        To 
                                         "Commons Users List"                   
             09/10/2008 05:29 PM         <us...@commons.apache.org>              
                                                                             cc 
                                                                                
              Please respond to                                         Subject 
               "Commons Users            Re: [beanutils] RowSetDynaClass        
                    List"                                                       
             <user@commons.apach                                                
                   e.org>                                                       
                                                                                
                                                                                
                                                                                




On Wed, Sep 10, 2008 at 8:35 PM,  <Pa...@xtl.com> wrote:
> I'm having a ConversionException issue when creating a RowSetDynaClass from a
> ResultSet.  Apparently I'm not the only person's who's experienced this.  The
> exception is saying "Cannot assign value of type 'java.lang.Integer' to
property
> 'vsize' of type 'java.lang.Short'.  Does somebody have a solution to this
> problem?  I'm using Beanutils 1.8.

You could override the getObject(ResultSet, String) method and use
ConvertUtils to convert the value, something like:

protected Object getObject(ResultSet resultSet, String name) throws
SQLException {
    Object value = super.getObject(resultSet, name);
    DynaProperty property = getDynaProperty(name);
    if (property != null) {
        value = ConvertUtils.convert(value, property.getType());
    }
    return value;
}

I did something like this for BEANUTILS-142[1] - but then backed it
out - because it didn't solve that particular issue - and used another
solution. But perhaps I should have left that in as well.

Niall


[1] http://issues.apache.org/jira/browse/BEANUTILS-142

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





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


Re: [beanutils] RowSetDynaClass

Posted by Niall Pemberton <ni...@gmail.com>.
On Wed, Sep 10, 2008 at 8:35 PM,  <Pa...@xtl.com> wrote:
> I'm having a ConversionException issue when creating a RowSetDynaClass from a
> ResultSet.  Apparently I'm not the only person's who's experienced this.  The
> exception is saying "Cannot assign value of type 'java.lang.Integer' to property
> 'vsize' of type 'java.lang.Short'.  Does somebody have a solution to this
> problem?  I'm using Beanutils 1.8.

You could override the getObject(ResultSet, String) method and use
ConvertUtils to convert the value, something like:

protected Object getObject(ResultSet resultSet, String name) throws
SQLException {
    Object value = super.getObject(resultSet, name);
    DynaProperty property = getDynaProperty(name);
    if (property != null) {
        value = ConvertUtils.convert(value, property.getType());
    }
    return value;
}

I did something like this for BEANUTILS-142[1] - but then backed it
out - because it didn't solve that particular issue - and used another
solution. But perhaps I should have left that in as well.

Niall


[1] http://issues.apache.org/jira/browse/BEANUTILS-142

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