|
17 | 17 | package org.springframework.orm.hibernate5;
|
18 | 18 |
|
19 | 19 | import java.lang.reflect.Method;
|
| 20 | +import java.util.Map; |
20 | 21 | import javax.sql.DataSource;
|
21 | 22 |
|
22 | 23 | import org.apache.commons.logging.Log;
|
|
62 | 63 | import org.springframework.dao.PessimisticLockingFailureException;
|
63 | 64 | import org.springframework.jdbc.datasource.DataSourceUtils;
|
64 | 65 | import org.springframework.util.Assert;
|
| 66 | +import org.springframework.util.ClassUtils; |
65 | 67 | import org.springframework.util.ReflectionUtils;
|
66 | 68 |
|
67 | 69 | /**
|
@@ -148,12 +150,16 @@ public static void closeSession(Session session) {
|
148 | 150 | * @see ConnectionProvider
|
149 | 151 | */
|
150 | 152 | public static DataSource getDataSource(SessionFactory sessionFactory) {
|
151 |
| - if (sessionFactory instanceof SessionFactoryImplementor) { |
152 |
| - SessionFactoryImplementor sfi = (SessionFactoryImplementor) sessionFactory; |
153 |
| - Object dataSourceValue = sfi.getProperties().get(Environment.DATASOURCE); |
| 153 | + Method getProperties = ClassUtils.getMethodIfAvailable(sessionFactory.getClass(), "getProperties"); |
| 154 | + if (getProperties != null) { |
| 155 | + Map<?, ?> props = (Map<?, ?>) ReflectionUtils.invokeMethod(getProperties, sessionFactory); |
| 156 | + Object dataSourceValue = props.get(Environment.DATASOURCE); |
154 | 157 | if (dataSourceValue instanceof DataSource) {
|
155 | 158 | return (DataSource) dataSourceValue;
|
156 | 159 | }
|
| 160 | + } |
| 161 | + if (sessionFactory instanceof SessionFactoryImplementor) { |
| 162 | + SessionFactoryImplementor sfi = (SessionFactoryImplementor) sessionFactory; |
157 | 163 | try {
|
158 | 164 | ConnectionProvider cp = sfi.getServiceRegistry().getService(ConnectionProvider.class);
|
159 | 165 | if (cp != null) {
|
|
0 commit comments