KickJava   Java API By Example, From Geeks To Geeks.

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


1 //$Id: LongType.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>long</tt>: A type that maps an SQL BIGINT to a Java Long.
15  * @author Gavin King
16  */

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