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