01: /*
02: * Copyright 2004-2006 the original author or authors.
03: *
04: * Licensed under the Apache License, Version 2.0 (the "License");
05: * you may not use this file except in compliance with the License.
06: * You may obtain a copy of the License at
07: *
08: * http://www.apache.org/licenses/LICENSE-2.0
09: *
10: * Unless required by applicable law or agreed to in writing, software
11: * distributed under the License is distributed on an "AS IS" BASIS,
12: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13: * See the License for the specific language governing permissions and
14: * limitations under the License.
15: */
16:
17: package org.compass.core.converter.extended;
18:
19: import java.sql.Timestamp;
20: import java.util.Date;
21:
22: import org.compass.core.converter.ConversionException;
23: import org.compass.core.converter.basic.DateConverter;
24: import org.compass.core.mapping.ResourcePropertyMapping;
25: import org.compass.core.marshall.MarshallingContext;
26:
27: /**
28: * @author kimchy
29: */
30: public class SqlTimestampConverter extends DateConverter {
31:
32: /**
33: * Sql Timestamp has no default format, it uses the {@link java.sql.Time#toString()}.
34: */
35: protected String doGetDefaultFormat() {
36: return null;
37: }
38:
39: protected String doToString(Object o,
40: ResourcePropertyMapping resourcePropertyMapping,
41: MarshallingContext context) {
42: if (hasFormatter) {
43: return super
44: .doToString(o, resourcePropertyMapping, context);
45: }
46: return o.toString();
47: }
48:
49: protected Object doFromString(String str,
50: ResourcePropertyMapping resourcePropertyMapping,
51: MarshallingContext context) throws ConversionException {
52: if (hasFormatter) {
53: Date date = (Date) super .doFromString(str,
54: resourcePropertyMapping, context);
55: return new Timestamp(date.getTime());
56: }
57: return Timestamp.valueOf(str);
58: }
59: }
|