package com.qianwen.smartman.common.typehandlers;
|
|
|
import java.sql.CallableStatement;
|
import java.sql.PreparedStatement;
|
import java.sql.ResultSet;
|
import java.sql.SQLException;
|
import java.sql.Timestamp;
|
|
import org.apache.ibatis.type.BaseTypeHandler;
|
import org.apache.ibatis.type.JdbcType;
|
import org.apache.ibatis.type.MappedJdbcTypes;
|
import org.apache.ibatis.type.MappedTypes;
|
|
@MappedTypes(value = Timestamp.class)
|
@MappedJdbcTypes(value = {JdbcType.BIGINT,JdbcType.INTEGER})
|
public class NullableSqlTimestampTypeHandler extends BaseTypeHandler<Timestamp>{
|
|
@Override
|
public void setNonNullParameter(PreparedStatement ps, int i, Timestamp parameter, JdbcType jdbcType)
|
throws SQLException {
|
ps.setTimestamp(i, parameter);
|
|
}
|
|
@Override
|
public Timestamp getNullableResult(ResultSet rs, String columnName) throws SQLException {
|
Timestamp val = rs.getTimestamp(columnName);
|
if(rs.wasNull()) {
|
return null;
|
}else {
|
return val;
|
}
|
//return rs.getTimestamp(columnName);
|
}
|
|
@Override
|
public Timestamp getNullableResult(ResultSet rs, int columnIndex) throws SQLException {
|
Timestamp val = rs.getTimestamp(columnIndex);
|
if(rs.wasNull()) {
|
return null;
|
}else {
|
return val;
|
}
|
//return rs.getTimestamp(columnIndex);
|
}
|
|
@Override
|
public Timestamp getNullableResult(CallableStatement cs, int columnIndex) throws SQLException {
|
Timestamp val = cs.getTimestamp(columnIndex);
|
if(cs.wasNull()) {
|
return null;
|
}else {
|
return val;
|
}
|
//return cs.getTimestamp(columnIndex);
|
}
|
|
}
|