commons-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Rafael U. C. Afonso" <r.u.c.afo...@uol.com.br>
Subject [BeanUtils]SqlDateConverter: Better implmentation.
Date Fri, 06 Aug 2004 02:14:31 GMT
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


Mime
View raw message