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