1 package org.hibernate.type; 3 4 import java.math.BigDecimal ; 5 import java.math.BigInteger ; 6 import java.sql.PreparedStatement ; 7 import java.sql.ResultSet ; 8 import java.sql.SQLException ; 9 import java.sql.Types ; 10 11 import org.hibernate.EntityMode; 12 import org.hibernate.HibernateException; 13 14 20 public class BigIntegerType extends ImmutableType implements DiscriminatorType { 21 22 public String objectToSQLString(Object value) throws Exception { 23 return value.toString(); 24 } 25 26 public Object stringToObject(String xml) throws Exception { 27 return new BigInteger (xml); 28 } 29 30 public Object get(ResultSet rs, String name) 31 throws HibernateException, SQLException { 32 BigDecimal bigDecimal = rs.getBigDecimal(name); 34 return bigDecimal==null ? null : 35 bigDecimal.setScale(0, BigDecimal.ROUND_UNNECESSARY).unscaledValue(); 36 } 37 38 public void set(PreparedStatement st, Object value, int index) 39 throws HibernateException, SQLException { 40 st.setBigDecimal( index, new BigDecimal ( (BigInteger ) value ) ); 41 } 42 43 public int sqlType() { 44 return Types.NUMERIC; 45 } 46 47 public String toString(Object value) throws HibernateException { 48 return value.toString(); 49 } 50 51 public Class getReturnedClass() { 52 return BigInteger .class; 53 } 54 55 public boolean isEqual(Object x, Object y) { 56 return x==y || ( x!=null && y!=null && ( (BigInteger ) x ).compareTo( (BigInteger ) y )==0 ); 57 } 58 59 public int getHashCode(Object x, EntityMode entityMode) { 60 return ( (BigInteger ) x ).intValue(); 61 } 62 63 public String getName() { 64 return "big_integer"; 65 } 66 67 public Object fromStringValue(String xml) { 68 return new BigInteger (xml); 69 } 70 71 72 } 73 74 75 76 77 78 79 | Popular Tags |