You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@commons.apache.org by "Rafael U. C. Afonso" <r....@uol.com.br> on 2004/08/06 04:14:31 UTC

[BeanUtils]SqlDateConverter: Better implmentation.

Hello:

I read the code of SqlDateConverter.convert(). It is 
implmented in this form:

        if (value == null) {
            if (useDefault) {
                return (defaultValue);
            } else {
                throw new ConversionException("No value 
specified");
            }
        }

        if (value instanceof Date) { // java.sql.Date
            return (value);
        }

        try {
            return (Date.valueOf(value.toString()));
        } catch (Exception e) {
            if (useDefault) {
                return (defaultValue);
            } else {
                throw new ConversionException(e);
            }
        }

About null values, I understand. My question is about case if 
value is not a java.sql.Date. It could be a java.util.Date or 
a other subclass (not java.sql.Date). IMHO a more acurate 
algoritm could be this:

// same procedure if value is null

        if (value instanceof java.sql.Date) { // java.sql.Date
            return (value);
        }
        if (value instanceof java.utilDate) { // java.sql.Date
            return new java.sql.Date(((java.util.Date)
value).getTime());
        }
// same procedure if value is not a java.util.Date


Some thing similar could be done with SqlTimeConverter and 
SqlTimestampConverter.
If you do not agree this alternative I would like know the 
reason

Thanks,

Rafael Ubiratam Clemente Afonso
r.u.c.afonso@uol.com.br
---------------------------------
Where is Debug?
Debug is on the Table!
 
__________________________________________________________________________
Acabe com aquelas janelinhas que pulam na sua tela.
AntiPop-up UOL - É grátis!
http://antipopup.uol.com.br/



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


Re: [BeanUtils]SqlDateConverter: Better implmentation.

Posted by Craig McClanahan <cr...@gmail.com>.
This is an interesting idea.  The best way to make sure it doesn't get
lost in the email shuffle is to file an enhancement request in our
issue tracking system (http://issues.apache.org/bugzilla).  If you've
got a proposed patch, you can add it as an attachment after creating
the issue.

Craig

On Thu,  5 Aug 2004 23:14:31 -0300, Rafael U. C. Afonso
<r....@uol.com.br> wrote:
> Hello:
> 
> I read the code of SqlDateConverter.convert(). It is
> implmented in this form:
> 
>         if (value == null) {
>             if (useDefault) {
>                 return (defaultValue);
>             } else {
>                 throw new ConversionException("No value
> specified");
>             }
>         }
> 
>         if (value instanceof Date) { // java.sql.Date
>             return (value);
>         }
> 
>         try {
>             return (Date.valueOf(value.toString()));
>         } catch (Exception e) {
>             if (useDefault) {
>                 return (defaultValue);
>             } else {
>                 throw new ConversionException(e);
>             }
>         }
> 
> About null values, I understand. My question is about case if
> value is not a java.sql.Date. It could be a java.util.Date or
> a other subclass (not java.sql.Date). IMHO a more acurate
> algoritm could be this:
> 
> // same procedure if value is null
> 
>         if (value instanceof java.sql.Date) { // java.sql.Date
>             return (value);
>         }
>         if (value instanceof java.utilDate) { // java.sql.Date
>             return new java.sql.Date(((java.util.Date)
> value).getTime());
>         }
> // same procedure if value is not a java.util.Date
> 
> Some thing similar could be done with SqlTimeConverter and
> SqlTimestampConverter.
> If you do not agree this alternative I would like know the
> reason
> 
> Thanks,
> 
> Rafael Ubiratam Clemente Afonso
> r.u.c.afonso@uol.com.br
> ---------------------------------
> Where is Debug?
> Debug is on the Table!
> 
> __________________________________________________________________________
> Acabe com aquelas janelinhas que pulam na sua tela.
> AntiPop-up UOL - É grátis!
> http://antipopup.uol.com.br/
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: commons-user-unsubscribe@jakarta.apache.org
> For additional commands, e-mail: commons-user-help@jakarta.apache.org
> 
>

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