~ubuntu-branches/ubuntu/wily/libhibernate3-java/wily-proposed

« back to all changes in this revision

Viewing changes to src/org/hibernate/type/ShortType.java

  • Committer: Bazaar Package Importer
  • Author(s): Torsten Werner
  • Date: 2007-10-14 14:43:34 UTC
  • Revision ID: james.westby@ubuntu.com-20071014144334-eamc8i0q10gs1aro
Tags: upstream-3.2.5
ImportĀ upstreamĀ versionĀ 3.2.5

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
//$Id: ShortType.java 7825 2005-08-10 20:23:55Z oneovthafew $
 
2
package org.hibernate.type;
 
3
 
 
4
import java.io.Serializable;
 
5
import java.sql.PreparedStatement;
 
6
import java.sql.ResultSet;
 
7
import java.sql.SQLException;
 
8
import java.sql.Types;
 
9
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 DiscriminatorType, VersionType {
 
20
 
 
21
        private static final Short ZERO = new Short( (short) 0 );
 
22
 
 
23
        public Serializable getDefaultValue() {
 
24
                return ZERO;
 
25
        }
 
26
        
 
27
        public Object get(ResultSet rs, String name) throws SQLException {
 
28
                return new Short( rs.getShort(name) );
 
29
        }
 
30
 
 
31
        public Class getPrimitiveClass() {
 
32
                return short.class;
 
33
        }
 
34
 
 
35
        public Class getReturnedClass() {
 
36
                return Short.class;
 
37
        }
 
38
 
 
39
        public void set(PreparedStatement st, Object value, int index) throws SQLException {
 
40
                st.setShort( index, ( (Short) value ).shortValue() );
 
41
        }
 
42
 
 
43
        public int sqlType() {
 
44
                return Types.SMALLINT;
 
45
        }
 
46
 
 
47
        public String getName() { return "short"; }
 
48
 
 
49
        public String objectToSQLString(Object value, Dialect dialect) throws Exception {
 
50
                return value.toString();
 
51
        }
 
52
 
 
53
        public Object stringToObject(String xml) throws Exception {
 
54
                return new Short(xml);
 
55
        }
 
56
 
 
57
        public Object next(Object current, SessionImplementor session) {
 
58
                return new Short( (short) ( ( (Short) current ).shortValue() + 1 ) );
 
59
        }
 
60
 
 
61
        public Object seed(SessionImplementor session) {
 
62
                return ZERO;
 
63
        }
 
64
 
 
65
        public Comparator getComparator() {
 
66
                return ComparableComparator.INSTANCE;
 
67
        }
 
68
        
 
69
        public Object fromStringValue(String xml) {
 
70
                return new Short(xml);
 
71
        }
 
72
 
 
73
}
 
74
 
 
75
 
 
76
 
 
77
 
 
78