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
43 public class PortalHibernateConfiguration
44 extends TransactionAwareConfiguration {
45
46 protected String determineDialect() {
47 return DialectDetector.determineDialect(getDataSource());
48 }
49
50 protected ClassLoader getConfigurationClassLoader() {
51 return getClass().getClassLoader();
52 }
53
54 protected String[] getConfigurationResources() {
55 return PropsUtil.getArray(PropsKeys.HIBERNATE_CONFIGS);
56 }
57
58 protected Configuration newConfiguration() {
59 Configuration configuration = new Configuration();
60
61 try {
62 ClassLoader classLoader = getConfigurationClassLoader();
63
64 String[] resources = getConfigurationResources();
65
66 for (String resource : resources) {
67 try {
68 InputStream is = classLoader.getResourceAsStream(resource);
69
70 if (is != null) {
71 configuration = configuration.addInputStream(is);
72
73 is.close();
74 }
75 }
76 catch (Exception e1) {
77 if (_log.isWarnEnabled()) {
78 _log.warn(e1);
79 }
80 }
81 }
82
83 if (Validator.isNull(PropsValues.HIBERNATE_DIALECT)) {
84 String dialect = determineDialect();
85
86 configuration.setProperty("hibernate.dialect", dialect);
87 }
88
89 configuration.setProperties(PropsUtil.getProperties());
90 }
91 catch (Exception e2) {
92 _log.error(e2, e2);
93 }
94
95 return configuration;
96 }
97
98 protected void postProcessConfiguration(Configuration configuration) {
99
100
105 String connectionReleaseMode = PropsUtil.get(
106 Environment.RELEASE_CONNECTIONS);
107
108 if (Validator.isNotNull(connectionReleaseMode)) {
109 configuration.setProperty(
110 Environment.RELEASE_CONNECTIONS, connectionReleaseMode);
111 }
112 }
113
114 private static Log _log =
115 LogFactoryUtil.getLog(PortalHibernateConfiguration.class);
116
117 }