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.util.Properties;
19
20 import org.hibernate.SessionFactory;
21 import org.hibernate.engine.spi.SharedSessionContractImplementor;
22 import org.hibernate.usertype.ParameterizedType;
23 import org.jadira.usertype.spi.timezone.proxy.WrapsSession;
24 import org.jadira.usertype.spi.utils.lang.ConcurrentHashMapBackedProperties;
25 import org.jadira.usertype.spi.utils.runtime.JavaVersion;
26
27 public abstract class AbstractParameterizedUserType<T, J, C extends ColumnMapper<T, J>> extends AbstractSingleColumnUserType<T, J, C> implements ParameterizedType, IntegratorConfiguredType {
28
29 private static final long serialVersionUID = -8038898451426631564L;
30
31 private Properties parameterValues;
32
33 @Override
34 public void setParameterValues(Properties parameters) {
35 this.parameterValues = new ConcurrentHashMapBackedProperties(parameters);
36 }
37
38 protected Properties getParameterValues() {
39 return parameterValues;
40 }
41
42
43 @Override
44 public void applyConfiguration(SessionFactory sessionFactory) {
45 doApplyConfiguration();
46 }
47
48 private <Z> void doApplyConfiguration() {
49
50 if (JavaVersion.isJava8OrLater() &&
51 Jdbc42Configured.class.isAssignableFrom(this.getClass())) {
52 Jdbc42Configured next = (Jdbc42Configured)this;
53 performJdbc42Configuration(next);
54 }
55
56 if (JavaVersion.isJava8OrLater() &&
57 Jdbc42Configured.class.isAssignableFrom(getColumnMapper().getClass())) {
58 Jdbc42Configured next = (Jdbc42Configured)this;
59 performJdbc42Configuration(next);
60 }
61 }
62
63 @SuppressWarnings("unused")
64 private void performJdbc42Configuration(Jdbc42Configured next) {
65
66 Boolean jdbc42Apis = null;
67 if (getParameterValues() != null) {
68 String apisString = getParameterValues().getProperty("jdbc42Apis");
69 if (apisString != null) {
70 jdbc42Apis = Boolean.parseBoolean(apisString);
71 }
72 }
73 if (jdbc42Apis == null) {
74 jdbc42Apis = ConfigurationHelper.getUse42Api();
75 }
76 if (jdbc42Apis == null) {
77 jdbc42Apis = Boolean.FALSE;
78 }
79
80 next.setUseJdbc42Apis(jdbc42Apis);
81 }
82
83 @Override
84 protected SharedSessionContractImplementor doWrapSession(SharedSessionContractImplementor session) {
85 SharedSessionContractImplementor mySession = session;
86 if (WrapsSession.class.isAssignableFrom(getColumnMapper().getClass())) {
87 mySession = ((WrapsSession)getColumnMapper()).wrapSession(mySession);
88 }
89 if (WrapsSession.class.isAssignableFrom(this.getClass())) {
90 mySession = ((WrapsSession)this).wrapSession(mySession);
91 }
92 return mySession;
93 }
94 }