KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > hibernate > type > ByteType


1 //$Id: ByteType.java,v 1.4 2004/09/11 11:29:23 oneovthafew Exp $
2
package org.hibernate.type;
3
4 import java.io.Serializable JavaDoc;
5 import java.sql.PreparedStatement JavaDoc;
6 import java.sql.ResultSet JavaDoc;
7 import java.sql.SQLException JavaDoc;
8 import java.sql.Types JavaDoc;
9 import java.util.Comparator JavaDoc;
10
11 import org.hibernate.util.ComparableComparator;
12
13 /**
14  * <tt>byte</tt>: A type that maps an SQL TINYINT to a Java Byte.
15  * @author Gavin King
16  */

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