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 "Petr V." <gr...@yahoo.com> on 2009/01/15 21:13:09 UTC

Java.util.calendar to SQLType ??

Database schema has column of type Timestamp .

Java POJO has corresponding property defined as java.util.Calendar

Result Map is defined as

<resultMap class="Job" id="JobResult">
��� <result column="STIME" jdbcType="TIMESTAMP"� javaType="java.util.Calendar" property="sTime" />
</resultMap>

I understand, I would have to define typeHandler to convert jdbc type to java Calendar.

I am wondering what should I define jdbcType is my sql map, should it be TimeStamp or should it be of type date. What would be the better?

Thanks,

Petr


      

Re: Java.util.calendar to SQLType ??

Posted by "Petr V." <gr...@yahoo.com>.
I am using Calendar objects because I need to use different TimeZones.

I would be storing UTC in DB but before I show it to user, I would be converting into different TimeZones. TimeZones are only supported by Calendar in java. Date and Timestamp classes do not support time zones and locales.

Thanks,

Petr,

--- On Fri, 1/16/09, Vadim <de...@gmail.com> wrote:
From: Vadim <de...@gmail.com>
Subject: Re: Java.util.calendar to SQLType ??
To: user-java@ibatis.apache.org, greatman787@yahoo.com
Date: Friday, January 16, 2009, 5:44 PM

I wonder, what's the motivation behind making Calendar an object property? If you need some Calendar specific operations, create some accessor/mutator methods to hide the actual Calendar instance. This way you won't need explicit TypeHandlers and your implementation won't depend on the Calendar (which isn't the best piece of API for time manipulation).


On Thu, Jan 15, 2009 at 10:13 PM, Petr V. <gr...@yahoo.com> wrote:


Database schema has column of type Timestamp .

Java POJO has corresponding property defined as java.util.Calendar

Result Map is defined as

<resultMap class="Job" id="JobResult">

��� <result column="STIME" jdbcType="TIMESTAMP"� javaType="java.util.Calendar" property="sTime" />
</resultMap>

I understand, I would have to define typeHandler to convert jdbc type to java Calendar.


I am wondering what should I define jdbcType is my sql map, should it be TimeStamp or should it be of type date. What would be the better?

Thanks,

Petr


      




      

Re: Java.util.calendar to SQLType ??

Posted by Vadim <de...@gmail.com>.
I wonder, what's the motivation behind making Calendar an object property?
If you need some Calendar specific operations, create some accessor/mutator
methods to hide the actual Calendar instance. This way you won't need
explicit TypeHandlers and your implementation won't depend on the Calendar
(which isn't the best piece of API for time manipulation).

On Thu, Jan 15, 2009 at 10:13 PM, Petr V. <gr...@yahoo.com> wrote:

> Database schema has column of type Timestamp .
>
> Java POJO has corresponding property defined as java.util.Calendar
>
> Result Map is defined as
>
> <resultMap class="Job" id="JobResult">
>     <result column="STIME" jdbcType="TIMESTAMP"
> javaType="java.util.Calendar" property="sTime" />
> </resultMap>
>
> I understand, I would have to define typeHandler to convert jdbc type to
> java Calendar.
>
> I am wondering what should I define jdbcType is my sql map, should it be
> TimeStamp or should it be of type date. What would be the better?
>
> Thanks,
>
> Petr
>

Re: Java.util.calendar to SQLType ??

Posted by Ch...@sybase.com.
Type Handler:
        public Object getResult(ResultGetter getter) throws SQLException {
                if (getter.wasNull())
                        return null;

                java.util.Calendar cal = java.util.Calendar.getInstance();
                java.sql.Timestamp ts = getter.getTimestamp(cal);
 
                cal.setTime(ts);
 
                return cal;
        }

        public void setParameter(ParameterSetter setter, Object parameter)
                        throws SQLException {

                if(parameter == null) {
                        setter.setNull(java.sql.Types.DATE);
                }
                else {
                        java.util.Calendar cal = 
(java.util.Calendar)parameter;
                        setter.setTimestamp(new 
java.sql.Timestamp(cal.getTimeInMillis()), cal);
                }
        }

Result Map:
    <result column="mod_date" jdbcType="TIMESTAMP" property="modifiedDate" 
/>


Don't forget to register the type handler.

I Hope this helps.




"Petr V." <gr...@yahoo.com> 
01/15/2009 12:13 PM
Please respond to
user-java@ibatis.apache.org


To
user-java@ibatis.apache.org
cc

Subject
Java.util.calendar to SQLType ??







Database schema has column of type Timestamp .

Java POJO has corresponding property defined as java.util.Calendar

Result Map is defined as

<resultMap class="Job" id="JobResult">
    <result column="STIME" jdbcType="TIMESTAMP" 
javaType="java.util.Calendar" property="sTime" />
</resultMap>

I understand, I would have to define typeHandler to convert jdbc type to 
java Calendar.

I am wondering what should I define jdbcType is my sql map, should it be 
TimeStamp or should it be of type date. What would be the better?

Thanks,

Petr