KickJava   Java API By Example, From Geeks To Geeks.

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


1 //$Id: IntegerType.java,v 1.3 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>integer</tt>: A type that maps an SQL INT to a Java Integer.
15  * @author Gavin King
16  */

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