1 19 package org.apache.cayenne.access.types; 20 21 import java.math.BigInteger ; 22 import java.sql.CallableStatement ; 23 import java.sql.PreparedStatement ; 24 import java.sql.ResultSet ; 25 26 import org.apache.cayenne.dba.TypesMapping; 27 import org.apache.cayenne.map.DbAttribute; 28 import org.apache.cayenne.validation.ValidationResult; 29 30 34 public class BigIntegerType implements ExtendedType { 35 36 public String getClassName() { 37 return BigInteger .class.getName(); 38 } 39 40 public Object materializeObject(ResultSet rs, int index, int type) throws Exception { 41 Object object = rs.getObject(index); 42 if (rs.wasNull()) { 43 return null; 44 } 45 46 return new BigInteger (object.toString()); 47 } 48 49 public Object materializeObject(CallableStatement rs, int index, int type) 50 throws Exception { 51 Object object = rs.getObject(index); 52 if (rs.wasNull()) { 53 return null; 54 } 55 56 return new BigInteger (object.toString()); 57 } 58 59 public void setJdbcObject( 60 PreparedStatement statement, 61 Object value, 62 int pos, 63 int type, 64 int precision) throws Exception { 65 66 if (value == null) { 67 statement.setNull(pos, type); 68 } 69 else if (TypesMapping.isNumeric(type)) { 70 statement.setLong(pos, ((BigInteger ) value).longValue()); 71 } 72 else { 73 throw new IllegalArgumentException ( 74 "Can't map BigInteger to a non-numeric type: " 75 + TypesMapping.getSqlNameByType(type)); 76 } 77 } 78 79 82 public boolean validateProperty( 83 Object source, 84 String property, 85 Object value, 86 DbAttribute dbAttribute, 87 ValidationResult validationResult) { 88 return true; 89 } 90 } 91 | Popular Tags |