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 LongDataType extends AbstractDataType 37 { 38 LongDataType() 39 { 40 super("BIGINT", Types.BIGINT, Long .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 Long (((Number )value).longValue()); 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 long value = resultSet.getLong(column); 72 if (resultSet.wasNull()) 73 { 74 return null; 75 } 76 return new Long (value); 77 } 78 79 public void setSqlValue(Object value, int column, PreparedStatement statement) 80 throws SQLException , TypeCastException 81 { 82 statement.setLong(column, ((Number )typeCast(value)).longValue()); 83 } 84 } 85 86 87 88 89 90 | Popular Tags |