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 ShortType extends PrimitiveType implements DiscriminatorType, VersionType { 18 19 private static final Short ZERO = new Short ( (short) 0 ); 20 21 public Serializable getDefaultValue() { 22 return ZERO; 23 } 24 25 public Object get(ResultSet rs, String name) throws SQLException { 26 return new Short ( rs.getShort(name) ); 27 } 28 29 public Class getPrimitiveClass() { 30 return short.class; 31 } 32 33 public Class getReturnedClass() { 34 return Short .class; 35 } 36 37 public void set(PreparedStatement st, Object value, int index) throws SQLException { 38 st.setShort( index, ( (Short ) value ).shortValue() ); 39 } 40 41 public int sqlType() { 42 return Types.SMALLINT; 43 } 44 45 public String getName() { return "short"; } 46 47 public String objectToSQLString(Object value) throws Exception { 48 return value.toString(); 49 } 50 51 public Object stringToObject(String xml) throws Exception { 52 return new Short (xml); 53 } 54 55 public Object next(Object current) { 56 return new Short ( (short) ( ( (Short ) current ).shortValue() + 1 ) ); 57 } 58 59 public Object seed() { 60 return ZERO; 61 } 62 63 public Comparator getComparator() { 64 return ComparableComparator.INSTANCE; 65 } 66 67 public Object fromStringValue(String xml) { 68 return new Short (xml); 69 } 70 71 } 72 73 74 75 76 77 | Popular Tags |