01: /*
02: * Copyright 2004 Clinton Begin
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: package com.ibatis.sqlmap.engine.type;
17:
18: import java.sql.CallableStatement;
19: import java.sql.PreparedStatement;
20: import java.sql.ResultSet;
21: import java.sql.SQLException;
22: import java.util.Date;
23:
24: /**
25: * Time (only) implementation of TypeHandler
26: */
27: public class TimeOnlyTypeHandler extends BaseTypeHandler implements
28: TypeHandler {
29:
30: private static final String DATE_FORMAT = "hh:mm:ss";
31:
32: public void setParameter(PreparedStatement ps, int i,
33: Object parameter, String jdbcType) throws SQLException {
34: ps.setTime(i, new java.sql.Time(((Date) parameter).getTime()));
35: }
36:
37: public Object getResult(ResultSet rs, String columnName)
38: throws SQLException {
39: java.sql.Time sqlTime = rs.getTime(columnName);
40: if (rs.wasNull()) {
41: return null;
42: } else {
43: return new java.util.Date(sqlTime.getTime());
44: }
45: }
46:
47: public Object getResult(ResultSet rs, int columnIndex)
48: throws SQLException {
49: java.sql.Time sqlTime = rs.getTime(columnIndex);
50: if (rs.wasNull()) {
51: return null;
52: } else {
53: return new java.util.Date(sqlTime.getTime());
54: }
55: }
56:
57: public Object getResult(CallableStatement cs, int columnIndex)
58: throws SQLException {
59: java.sql.Time sqlTime = cs.getTime(columnIndex);
60: if (cs.wasNull()) {
61: return null;
62: } else {
63: return new java.util.Date(sqlTime.getTime());
64: }
65: }
66:
67: public Object valueOf(String s) {
68: return SimpleDateFormatter.format(DATE_FORMAT, s);
69: }
70:
71: }
|