1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package org.seasar.cubby.converter.impl;
17
18 import java.util.Date;
19
20 import org.seasar.cubby.converter.ConversionException;
21 import org.seasar.cubby.converter.ConversionHelper;
22
23
24
25
26
27
28
29
30
31 public class SqlTimestampConverter extends AbstractDateConverter {
32
33
34
35
36 public Class<?> getObjectType() {
37 return java.sql.Timestamp.class;
38 }
39
40
41
42
43 public Object convertToObject(final Object value,
44 final Class<?> objectType, final ConversionHelper helper)
45 throws ConversionException {
46 if (value == null) {
47 return null;
48 }
49 final String pattern = helper.getFormatPattern().getTimestampPattern();
50 final Date date = toDate(value.toString(), pattern);
51 return new java.sql.Timestamp(date.getTime());
52 }
53
54
55
56
57 public String convertToString(final Object value,
58 final ConversionHelper helper) {
59 if (value == null) {
60 return null;
61 }
62 final String pattern = helper.getFormatPattern().getTimestampPattern();
63 return toString((java.sql.Timestamp) value, pattern);
64 }
65
66 }