01: //$Id: IntegerType.java 7825 2005-08-10 20:23:55Z oneovthafew $
02: package org.hibernate.type;
03:
04: import java.io.Serializable;
05: import java.sql.PreparedStatement;
06: import java.sql.ResultSet;
07: import java.sql.SQLException;
08: import java.sql.Types;
09: import java.util.Comparator;
10:
11: import org.hibernate.util.ComparableComparator;
12: import org.hibernate.dialect.Dialect;
13: import org.hibernate.engine.SessionImplementor;
14:
15: /**
16: * <tt>integer</tt>: A type that maps an SQL INT to a Java Integer.
17: * @author Gavin King
18: */
19: public class IntegerType extends PrimitiveType implements
20: DiscriminatorType, VersionType {
21:
22: private static final Integer ZERO = new Integer(0);
23:
24: public Serializable getDefaultValue() {
25: return ZERO;
26: }
27:
28: public Object get(ResultSet rs, String name) throws SQLException {
29: return new Integer(rs.getInt(name));
30: }
31:
32: public Class getPrimitiveClass() {
33: return int.class;
34: }
35:
36: public Class getReturnedClass() {
37: return Integer.class;
38: }
39:
40: public void set(PreparedStatement st, Object value, int index)
41: throws SQLException {
42: st.setInt(index, ((Integer) value).intValue());
43: }
44:
45: public int sqlType() {
46: return Types.INTEGER;
47: }
48:
49: public String getName() {
50: return "integer";
51: }
52:
53: public String objectToSQLString(Object value, Dialect dialect)
54: throws Exception {
55: return value.toString();
56: }
57:
58: public Object stringToObject(String xml) throws Exception {
59: return new Integer(xml);
60: }
61:
62: public Object next(Object current, SessionImplementor session) {
63: return new Integer(((Integer) current).intValue() + 1);
64: }
65:
66: public Object seed(SessionImplementor session) {
67: return ZERO;
68: }
69:
70: public Comparator getComparator() {
71: return ComparableComparator.INSTANCE;
72: }
73:
74: public Object fromStringValue(String xml) {
75: return new Integer(xml);
76: }
77:
78: }
|