001
014
015 package com.liferay.portal.dao.orm.hibernate;
016
017 import java.io.Serializable;
018
019 import java.sql.PreparedStatement;
020 import java.sql.ResultSet;
021 import java.sql.SQLException;
022 import java.sql.Types;
023
024 import org.hibernate.Hibernate;
025 import org.hibernate.HibernateException;
026 import org.hibernate.usertype.UserType;
027
028
031 public class ShortType implements Serializable, UserType {
032
033 public static final short DEFAULT_VALUE = 0;
034
035 public static final int[] SQL_TYPES = new int[] {Types.SMALLINT};
036
037 public Object assemble(Serializable cached, Object owner) {
038 return cached;
039 }
040
041 public Object deepCopy(Object obj) {
042 return obj;
043 }
044
045 public Serializable disassemble(Object value) {
046 return (Serializable)value;
047 }
048
049 public boolean equals(Object x, Object y) {
050 if (x == y) {
051 return true;
052 }
053 else if (x == null || y == null) {
054 return false;
055 }
056 else {
057 return x.equals(y);
058 }
059 }
060
061 public int hashCode(Object x) {
062 return x.hashCode();
063 }
064
065 public boolean isMutable() {
066 return false;
067 }
068
069 public Object nullSafeGet(ResultSet rs, String[] names, Object obj)
070 throws HibernateException, SQLException {
071
072 Short value = (Short)Hibernate.SHORT.nullSafeGet(rs, names[0]);
073
074 if (value == null) {
075 return new Short(DEFAULT_VALUE);
076 }
077 else {
078 return value;
079 }
080 }
081
082 public void nullSafeSet(PreparedStatement ps, Object obj, int index)
083 throws HibernateException, SQLException {
084
085 if (obj == null) {
086 obj = new Short(DEFAULT_VALUE);
087 }
088
089 Hibernate.SHORT.nullSafeSet(ps, obj, index);
090 }
091
092 public Object replace(Object original, Object target, Object owner) {
093 return original;
094 }
095
096 public Class<Short> returnedClass() {
097 return Short.class;
098 }
099
100 public int[] sqlTypes() {
101 return SQL_TYPES;
102 }
103
104 }