1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package org.jadira.usertype.spi.shared;
17
18 import java.io.Serializable;
19 import java.util.Properties;
20
21 import org.hibernate.usertype.EnhancedUserType;
22 import org.jadira.usertype.spi.utils.reflection.TypeHelper;
23
24 public abstract class AbstractKnownClassHeuristicUserType<T> extends AbstractHeuristicUserType implements EnhancedUserType, Serializable {
25
26 private static final long serialVersionUID = 2233911693851349367L;
27
28 private Class<T> mappedClass;
29
30 protected void setMappedClass(Class<T> mappedClass) {
31 this.mappedClass = mappedClass;
32 }
33
34 protected Class<T> getMappedClass() {
35 return mappedClass;
36 }
37
38 public void setParameterValues(Properties parameters) {
39
40 if (mappedClass == null) {
41
42 throw new IllegalStateException("No mapped class was defined for " + this.getClass().getName());
43 }
44
45 super.setParameterValues(parameters);
46 }
47
48 @SuppressWarnings("unchecked")
49 @Override
50 public Class<T> returnedClass() {
51 return (Class<T>) TypeHelper.getTypeArguments(AbstractKnownClassHeuristicUserType.class, getClass()).get(0);
52 }
53 }