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:
23: /**
24: * SQL timestamp implementation of TypeHandler
25: */
26: public class SqlTimestampTypeHandler extends BaseTypeHandler implements
27: TypeHandler {
28:
29: private static final String DATE_FORMAT = "yyyy/MM/dd hh:mm:ss";
30:
31: public void setParameter(PreparedStatement ps, int i,
32: Object parameter, String jdbcType) throws SQLException {
33: ps.setTimestamp(i, (java.sql.Timestamp) parameter);
34: }
35:
36: public Object getResult(ResultSet rs, String columnName)
37: throws SQLException {
38: Object sqlTimestamp = rs.getTimestamp(columnName);
39: if (rs.wasNull()) {
40: return null;
41: } else {
42: return sqlTimestamp;
43: }
44: }
45:
46: public Object getResult(ResultSet rs, int columnIndex)
47: throws SQLException {
48: Object sqlTimestamp = rs.getTimestamp(columnIndex);
49: if (rs.wasNull()) {
50: return null;
51: } else {
52: return sqlTimestamp;
53: }
54: }
55:
56: public Object getResult(CallableStatement cs, int columnIndex)
57: throws SQLException {
58: Object sqlTimestamp = cs.getTimestamp(columnIndex);
59: if (cs.wasNull()) {
60: return null;
61: } else {
62: return sqlTimestamp;
63: }
64: }
65:
66: public Object valueOf(String s) {
67: return SimpleDateFormatter.format(DATE_FORMAT, s);
68: }
69:
70: }
|