2 * Copyright (C) 2009 EDIT
3 * European Distributed Institute of Taxonomy
4 * http://www.e-taxonomy.eu
6 * The contents of this file are subject to the Mozilla Public License Version 1.1
7 * See LICENSE.TXT at the top of this package for the full license terms.
9 package eu
.etaxonomy
.cdm
.hibernate
;
11 import java
.io
.Serializable
;
12 import java
.sql
.PreparedStatement
;
13 import java
.sql
.ResultSet
;
14 import java
.sql
.SQLException
;
16 import org
.hibernate
.HibernateException
;
17 import org
.hibernate
.engine
.spi
.SessionImplementor
;
18 import org
.hibernate
.usertype
.UserType
;
20 import eu
.etaxonomy
.cdm
.model
.validation
.EntityConstraintViolation
;
21 import eu
.etaxonomy
.cdm
.model
.validation
.Severity
;
25 * A hibernate {@code UserType} for persisting {@link Severity} instances.
27 * @see EntityConstraintViolation
29 * @author ayco_holleman
32 public class SeverityUserType
implements UserType
{
35 public int[] sqlTypes(){
36 return new int[] { java
.sql
.Types
.VARCHAR
};
40 @SuppressWarnings("rawtypes")
42 public Class
returnedClass(){
43 return Severity
.class;
49 public boolean equals(Object x
, Object y
) throws HibernateException
{
59 return ((Severity
) x
).equals(y
);
64 public int hashCode(Object x
) throws HibernateException
{
65 return x
.getClass().hashCode();
70 public Object
nullSafeGet(ResultSet rs
, String
[] names
, SessionImplementor session
, Object owner
) throws HibernateException
, SQLException
{
71 String severity
= rs
.getString(names
[0]);
72 return rs
.wasNull() ?
null : Severity
.forName(severity
);
77 public void nullSafeSet(PreparedStatement st
, Object value
, int index
, SessionImplementor session
) throws HibernateException
, SQLException
{
78 st
.setString(index
, value
== null ?
null : value
.toString());
83 public Object
deepCopy(Object value
) throws HibernateException
{
89 public boolean isMutable(){
95 public Serializable
disassemble(Object value
) throws HibernateException
{
101 public Object
assemble(Serializable cached
, Object owner
) throws HibernateException
{
107 public Object
replace(Object original
, Object target
, Object owner
) throws HibernateException
{