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