1 package org.hibernate.type; 3 4 import java.io.Serializable ; 5 import java.sql.PreparedStatement ; 6 import java.sql.ResultSet ; 7 import java.sql.SQLException ; 8 import java.sql.Types ; 9 import java.util.Comparator ; 10 11 import org.hibernate.util.ComparableComparator; 12 13 17 public class IntegerType extends PrimitiveType implements DiscriminatorType, VersionType { 18 19 private static final Integer ZERO = new Integer (0); 20 21 public Serializable getDefaultValue() { 22 return ZERO; 23 } 24 25 public Object get(ResultSet rs, String name) throws SQLException { 26 return new Integer ( rs.getInt(name) ); 27 } 28 29 public Class getPrimitiveClass() { 30 return int.class; 31 } 32 33 public Class getReturnedClass() { 34 return Integer .class; 35 } 36 37 public void set(PreparedStatement st, Object value, int index) 38 throws SQLException { 39 st.setInt( index, ( (Integer ) value ).intValue() ); 40 } 41 42 public int sqlType() { 43 return Types.INTEGER; 44 } 45 46 public String getName() { return "integer"; } 47 48 public String objectToSQLString(Object value) throws Exception { 49 return value.toString(); 50 } 51 52 public Object stringToObject(String xml) throws Exception { 53 return new Integer (xml); 54 } 55 56 public Object next(Object current) { 57 return new Integer ( ( (Integer ) current ).intValue() + 1 ); 58 } 59 60 public Object seed() { 61 return ZERO; 62 } 63 64 public Comparator getComparator() { 65 return ComparableComparator.INSTANCE; 66 } 67 68 public Object fromStringValue(String xml) { 69 return new Integer (xml); 70 } 71 72 } 73 74 75 76 77 78 | Popular Tags |