Project

General

Profile

Download (2.51 KB) Statistics
| Branch: | Tag: | Revision:
1
/**
2
* Copyright (C) 2009 EDIT
3
* European Distributed Institute of Taxonomy
4
* http://www.e-taxonomy.eu
5
*
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.
8
*/
9
package eu.etaxonomy.cdm.hibernate;
10

    
11
import java.io.Serializable;
12
import java.sql.PreparedStatement;
13
import java.sql.ResultSet;
14
import java.sql.SQLException;
15

    
16
import org.hibernate.HibernateException;
17
import org.hibernate.engine.spi.SharedSessionContractImplementor;
18
import org.hibernate.usertype.UserType;
19

    
20
import eu.etaxonomy.cdm.model.validation.EntityConstraintViolation;
21
import eu.etaxonomy.cdm.model.validation.Severity;
22

    
23

    
24
/**
25
 * A hibernate {@code UserType} for persisting {@link Severity} instances.
26
 *
27
 * @see EntityConstraintViolation
28
 *
29
 * @author ayco_holleman
30
 *
31
 */
32
public class SeverityUserType implements UserType {
33

    
34
	@Override
35
	public int[] sqlTypes(){
36
		return new int[] { java.sql.Types.VARCHAR };
37
	}
38

    
39

    
40
	@SuppressWarnings("rawtypes")
41
	@Override
42
	public Class returnedClass(){
43
		return Severity.class;
44

    
45
	}
46

    
47

    
48
	@Override
49
	public boolean equals(Object x, Object y) throws HibernateException{
50
		if (x == null) {
51
			if (y == null) {
52
				return true;
53
			}
54
			return false;
55
		}
56
		if (y == null) {
57
			return false;
58
		}
59
		return ((Severity) x).equals(y);
60
	}
61

    
62

    
63
	@Override
64
	public int hashCode(Object x) throws HibernateException{
65
		return x.getClass().hashCode();
66
	}
67

    
68

    
69
	@Override
70
	public Object nullSafeGet(ResultSet rs, String[] names, SharedSessionContractImplementor session, Object owner) throws HibernateException, SQLException{
71
		String severity = rs.getString(names[0]);
72
		return rs.wasNull() ? null : Severity.forName(severity);
73
	}
74

    
75

    
76
	@Override
77
	public void nullSafeSet(PreparedStatement st, Object value, int index, SharedSessionContractImplementor session) throws HibernateException, SQLException{
78
		st.setString(index, value == null ? null : value.toString());
79
	}
80

    
81

    
82
	@Override
83
	public Object deepCopy(Object value) throws HibernateException{
84
		return value;
85
	}
86

    
87

    
88
	@Override
89
	public boolean isMutable(){
90
		return false;
91
	}
92

    
93

    
94
	@Override
95
	public Serializable disassemble(Object value) throws HibernateException{
96
		return null;
97
	}
98

    
99

    
100
	@Override
101
	public Object assemble(Serializable cached, Object owner) throws HibernateException{
102
		return null;
103
	}
104

    
105

    
106
	@Override
107
	public Object replace(Object original, Object target, Object owner) throws HibernateException{
108
		return original;
109
	}
110

    
111
}
(7-7/11)