1
22
23 package com.liferay.portal.spring.hibernate;
24
25 import com.liferay.portal.kernel.log.Log;
26 import com.liferay.portal.kernel.log.LogFactoryUtil;
27 import com.liferay.portal.kernel.util.Validator;
28 import com.liferay.portal.util.PropsKeys;
29 import com.liferay.portal.util.PropsUtil;
30 import com.liferay.portal.util.PropsValues;
31
32 import java.io.InputStream;
33
34 import org.hibernate.cfg.Configuration;
35 import org.hibernate.cfg.Environment;
36
37
44 public class PortalHibernateConfiguration
45 extends TransactionAwareConfiguration {
46
47 protected String determineDialect() {
48 return DialectDetector.determineDialect(getDataSource());
49 }
50
51 protected ClassLoader getConfigurationClassLoader() {
52 return getClass().getClassLoader();
53 }
54
55 protected String[] getConfigurationResources() {
56 return PropsUtil.getArray(PropsKeys.HIBERNATE_CONFIGS);
57 }
58
59 protected Configuration newConfiguration() {
60 Configuration configuration = new Configuration();
61
62 try {
63 ClassLoader classLoader = getConfigurationClassLoader();
64
65 String[] resources = getConfigurationResources();
66
67 for (String resource : resources) {
68 try {
69 InputStream is = classLoader.getResourceAsStream(resource);
70
71 if (is != null) {
72 configuration = configuration.addInputStream(is);
73
74 is.close();
75 }
76 }
77 catch (Exception e2) {
78 if (_log.isWarnEnabled()) {
79 _log.warn(e2, e2);
80 }
81 }
82 }
83
84 if (Validator.isNull(PropsValues.HIBERNATE_DIALECT)) {
85 String dialect = determineDialect();
86
87 configuration.setProperty("hibernate.dialect", dialect);
88 }
89
90 configuration.setProperties(PropsUtil.getProperties());
91 }
92 catch (Exception e1) {
93 _log.error(e1, e1);
94 }
95
96 return configuration;
97 }
98
99 protected void postProcessConfiguration(Configuration configuration) {
100
101
106 String connectionReleaseMode = PropsUtil.get(
107 Environment.RELEASE_CONNECTIONS);
108
109 if (Validator.isNotNull(connectionReleaseMode)) {
110 configuration.setProperty(
111 Environment.RELEASE_CONNECTIONS, connectionReleaseMode);
112 }
113 }
114
115 private static Log _log =
116 LogFactoryUtil.getLog(PortalHibernateConfiguration.class);
117
118 }