1 16 package com.ibatis.sqlmap.engine.type; 17 18 import com.ibatis.sqlmap.client.SqlMapException; 19 20 import java.sql.CallableStatement ; 21 import java.sql.PreparedStatement ; 22 import java.sql.ResultSet ; 23 import java.sql.SQLException ; 24 import java.text.DateFormat ; 25 import java.text.ParseException ; 26 import java.text.SimpleDateFormat ; 27 import java.util.Date ; 28 29 32 public class TimeOnlyTypeHandler extends BaseTypeHandler implements TypeHandler { 33 34 private static final String DATE_FORMAT = "hh:mm:ss"; 35 private static final DateFormat format = new SimpleDateFormat (DATE_FORMAT); 36 37 public void setParameter(PreparedStatement ps, int i, Object parameter, String jdbcType) 38 throws SQLException { 39 ps.setTime(i, new java.sql.Time (((Date ) parameter).getTime())); 40 } 41 42 public Object getResult(ResultSet rs, String columnName) 43 throws SQLException { 44 java.sql.Time sqlTime = rs.getTime(columnName); 45 if (rs.wasNull()) { 46 return null; 47 } else { 48 return new java.util.Date (sqlTime.getTime()); 49 } 50 } 51 52 public Object getResult(ResultSet rs, int columnIndex) 53 throws SQLException { 54 java.sql.Time sqlTime = rs.getTime(columnIndex); 55 if (rs.wasNull()) { 56 return null; 57 } else { 58 return new java.util.Date (sqlTime.getTime()); 59 } 60 } 61 62 public Object getResult(CallableStatement cs, int columnIndex) 63 throws SQLException { 64 java.sql.Time sqlTime = cs.getTime(columnIndex); 65 if (cs.wasNull()) { 66 return null; 67 } else { 68 return new java.util.Date (sqlTime.getTime()); 69 } 70 } 71 72 public Object valueOf(String s) { 73 try { 74 return format.parse(s); 75 } catch (ParseException e) { 76 throw new SqlMapException("Error parsing default null value date. Format must be '" + DATE_FORMAT + "'. Cause: " + e); 77 } 78 } 79 80 } 81 | Popular Tags |