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 import java.sql.Types ; 31 32 36 public class FloatDataType extends AbstractDataType 37 { 38 FloatDataType() 39 { 40 super("REAL", Types.REAL, Float .class, true); 41 } 42 43 46 public Object typeCast(Object value) throws TypeCastException 47 { 48 if (value == null || value == ITable.NO_VALUE) 49 { 50 return null; 51 } 52 53 if (value instanceof Number ) 54 { 55 return new Float (((Number )value).floatValue()); 56 } 57 58 try 59 { 60 return typeCast(new BigDecimal (value.toString())); 61 } 62 catch (java.lang.NumberFormatException e) 63 { 64 throw new TypeCastException(value, this, e); 65 } 66 } 67 68 public Object getSqlValue(int column, ResultSet resultSet) 69 throws SQLException , TypeCastException 70 { 71 float value = resultSet.getFloat(column); 72 if (resultSet.wasNull()) 73 { 74 return null; 75 } 76 return new Float (value); 77 } 78 79 public void setSqlValue(Object value, int column, PreparedStatement statement) 80 throws SQLException , TypeCastException 81 { 82 statement.setFloat(column, ((Number )typeCast(value)).floatValue()); 83 } 84 } 85 86 87 88 89 90 | Popular Tags |