ParmConverters for Enumeration#Value and org.joda.time.LocalDateTime

12 views
Skip to first unread message

Eduardo M. Cavalcanti

unread,
Jun 1, 2011, 4:40:02 PM6/1/11
to orbroker
Hi,
I have coded these two converters, maybe they are useful to someone in
need.
In the case of the LocalDateTime converter the getLocalMillis method
is protected, so I have used a somewhat ugly path, but correct, I
think, to make the conversion.
The EnumerationValueConv converts to String the Values of any Scala
Enumeration.
Regards.

object JodaLocalDateTimeConv extends ParmConverter {
type T = org.joda.time.LocalDateTime
val fromType = classOf[T]
def toJdbcType(ts: T) = {
val jdkDate = ts.toLocalDate.toDateTimeAtStartOfDay.toDate
jdkDate.setHours(ts.getHourOfDay)
jdkDate.setMinutes(ts.getMinuteOfHour)
jdkDate.setSeconds(ts.getSecondOfMinute)
val jsts = new java.sql.Timestamp(jdkDate.getTime)
jsts.setNanos(ts.getMillisOfSecond * 1000000)
jsts
}
}

object EnumerationValueConv extends ParmConverter {
type T = Enumeration#Value
val fromType = classOf[T]
def toJdbcType(ts: T) = {
ts.toString
}
}

Nils Kilden-Pedersen

unread,
Jun 7, 2011, 7:26:06 AM6/7/11
to orbr...@googlegroups.com
Just back from vacation. Will take a look. Thanks.

Eduardo M. Cavalcanti

unread,
Jun 7, 2011, 11:00:25 AM6/7/11
to orbr...@googlegroups.com
Hi,
Thanks for reply.

In the case of the Enumeration Value converter, maybe this is even better:

object EnumValueToStringConv extends ParmConverter {

 type T = Enumeration#Value
 val fromType = classOf[T]
 def toJdbcType(ts: T) = {
       ts.toString
 }
}

object EnumValueToIntConv extends ParmConverter {

 type T = Enumeration#Value
 val fromType = classOf[T]
 def toJdbcType(ts: T) = {
       ts.id
Reply all
Reply to author
Forward
0 new messages