01: //$Id: ShortType.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>short</tt>: A type that maps an SQL SMALLINT to a Java Short.
17: * @author Gavin King
18: */
19: public class ShortType extends PrimitiveType implements
20: DiscriminatorType, VersionType {
21:
22: private static final Short ZERO = new Short((short) 0);
23:
24: public Serializable getDefaultValue() {
25: return ZERO;
26: }
27:
28: public Object get(ResultSet rs, String name) throws SQLException {
29: return new Short(rs.getShort(name));
30: }
31:
32: public Class getPrimitiveClass() {
33: return short.class;
34: }
35:
36: public Class getReturnedClass() {
37: return Short.class;
38: }
39:
40: public void set(PreparedStatement st, Object value, int index)
41: throws SQLException {
42: st.setShort(index, ((Short) value).shortValue());
43: }
44:
45: public int sqlType() {
46: return Types.SMALLINT;
47: }
48:
49: public String getName() {
50: return "short";
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 Short(xml);
60: }
61:
62: public Object next(Object current, SessionImplementor session) {
63: return new Short((short) (((Short) current).shortValue() + 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 Short(xml);
76: }
77:
78: }
|