1
//$Id: ShortType.java 7825 2005-08-10 20:23:55Z oneovthafew $
2
package org.hibernate.type;
4
import java.io.Serializable;
5
import java.sql.PreparedStatement;
6
import java.sql.ResultSet;
7
import java.sql.SQLException;
9
import java.util.Comparator;
11
import org.hibernate.util.ComparableComparator;
12
import org.hibernate.dialect.Dialect;
13
import org.hibernate.engine.SessionImplementor;
16
* <tt>short</tt>: A type that maps an SQL SMALLINT to a Java Short.
19
public class ShortType extends PrimitiveType implements DiscriminatorType, VersionType {
21
private static final Short ZERO = new Short( (short) 0 );
23
public Serializable getDefaultValue() {
27
public Object get(ResultSet rs, String name) throws SQLException {
28
return new Short( rs.getShort(name) );
31
public Class getPrimitiveClass() {
35
public Class getReturnedClass() {
39
public void set(PreparedStatement st, Object value, int index) throws SQLException {
40
st.setShort( index, ( (Short) value ).shortValue() );
43
public int sqlType() {
44
return Types.SMALLINT;
47
public String getName() { return "short"; }
49
public String objectToSQLString(Object value, Dialect dialect) throws Exception {
50
return value.toString();
53
public Object stringToObject(String xml) throws Exception {
54
return new Short(xml);
57
public Object next(Object current, SessionImplementor session) {
58
return new Short( (short) ( ( (Short) current ).shortValue() + 1 ) );
61
public Object seed(SessionImplementor session) {
65
public Comparator getComparator() {
66
return ComparableComparator.INSTANCE;
69
public Object fromStringValue(String xml) {
70
return new Short(xml);