1 package org.jadira.usertype.spi.shared;
2
3 import java.util.Properties;
4
5 import org.hibernate.SessionFactory;
6 import org.hibernate.engine.spi.SharedSessionContractImplementor;
7 import org.hibernate.usertype.ParameterizedType;
8 import org.jadira.usertype.spi.timezone.proxy.WrapsSession;
9 import org.jadira.usertype.spi.utils.lang.ConcurrentHashMapBackedProperties;
10 import org.jadira.usertype.spi.utils.runtime.JavaVersion;
11
12 public abstract class AbstractParameterizedMultiColumnUserType<T> extends AbstractMultiColumnUserType<T> implements ParameterizedType, IntegratorConfiguredType {
13
14 private static final long serialVersionUID = -5378286101759906332L;
15
16 private Properties parameterValues;
17
18 @Override
19 public void setParameterValues(Properties parameters) {
20 this.parameterValues = new ConcurrentHashMapBackedProperties(parameters);
21 }
22
23 protected Properties getParameterValues() {
24 return parameterValues;
25 }
26
27 @Override
28 public void applyConfiguration(SessionFactory sessionFactory) {
29 doApplyConfiguration();
30 }
31
32 private <Z> void doApplyConfiguration() {
33
34 if (JavaVersion.isJava8OrLater() &&
35 Jdbc42Configured.class.isAssignableFrom(this.getClass())) {
36 Jdbc42Configured next = (Jdbc42Configured)this;
37 performJdbc42Configuration(next);
38 }
39
40 for (int i = 0; i < getColumnMappers().length; i++) {
41
42 if (JavaVersion.isJava8OrLater() &&
43 Jdbc42Configured.class.isAssignableFrom(getColumnMappers()[i].getClass())) {
44 Jdbc42Configured next = (Jdbc42Configured)this;
45 performJdbc42Configuration(next);
46 }
47 }
48 }
49
50 @SuppressWarnings("unused")
51 private void performJdbc42Configuration(Jdbc42Configured next) {
52
53 Boolean jdbc42Apis = null;
54 if (getParameterValues() != null) {
55 String apisString = getParameterValues().getProperty("jdbc42Apis");
56 if (apisString != null) {
57 jdbc42Apis = Boolean.parseBoolean(apisString);
58 }
59 }
60 if (jdbc42Apis == null) {
61 jdbc42Apis = ConfigurationHelper.getUse42Api();
62 }
63 if (jdbc42Apis == null) {
64 jdbc42Apis = Boolean.FALSE;
65 }
66
67 next.setUseJdbc42Apis(jdbc42Apis);
68 }
69
70 @Override
71 protected SharedSessionContractImplementor doWrapSession(SharedSessionContractImplementor session) {
72 SharedSessionContractImplementor mySession = session;
73 for (ColumnMapper<?, ?> next : getColumnMappers()) {
74 if (WrapsSession.class.isAssignableFrom(next.getClass())) {
75 mySession = ((WrapsSession)next).wrapSession(mySession);
76 }
77 }
78 if (WrapsSession.class.isAssignableFrom(this.getClass())) {
79 mySession = ((WrapsSession)this).wrapSession(mySession);
80 }
81 return mySession;
82 }
83 }