1 21 22 package org.dbunit.dataset.datatype; 23 24 import org.dbunit.dataset.ITable; 25 26 import java.math.BigDecimal ; 27 import java.sql.PreparedStatement ; 28 import java.sql.ResultSet ; 29 import java.sql.SQLException ; 30 31 35 public class DoubleDataType extends AbstractDataType 36 { 37 DoubleDataType(String name, int sqlType) 38 { 39 super(name, sqlType, Double .class, true); 40 } 41 42 45 public Object typeCast(Object value) throws TypeCastException 46 { 47 if (value == null || value == ITable.NO_VALUE) 48 { 49 return null; 50 } 51 52 if (value instanceof Number ) 53 { 54 return new Double (((Number )value).doubleValue()); 55 } 56 57 try 58 { 59 return typeCast(new BigDecimal (value.toString())); 60 } 61 catch (java.lang.NumberFormatException e) 62 { 63 throw new TypeCastException(value, this, e); 64 } 65 } 66 67 public Object getSqlValue(int column, ResultSet resultSet) 68 throws SQLException , TypeCastException 69 { 70 double value = resultSet.getDouble(column); 71 if (resultSet.wasNull()) 72 { 73 return null; 74 } 75 return new Double (value); 76 } 77 78 public void setSqlValue(Object value, int column, PreparedStatement statement) 79 throws SQLException , TypeCastException 80 { 81 statement.setDouble(column, ((Number )typeCast(value)).doubleValue()); 82 } 83 84 } 85 86 87 88 89 90 | Popular Tags |