1
22
23 package com.liferay.portal.spring.hibernate;
24
25 import com.liferay.portal.kernel.util.Validator;
26 import com.liferay.portal.util.PropsKeys;
27 import com.liferay.portal.util.PropsUtil;
28
29 import java.io.InputStream;
30
31 import org.apache.commons.logging.Log;
32 import org.apache.commons.logging.LogFactory;
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 ClassLoader getConfigurationClassLoader() {
48 return getClass().getClassLoader();
49 }
50
51 protected String[] getConfigurationResources() {
52 return PropsUtil.getArray(PropsKeys.HIBERNATE_CONFIGS);
53 }
54
55 protected Configuration newConfiguration() {
56 Configuration configuration = new Configuration();
57
58 try {
59 ClassLoader classLoader = getConfigurationClassLoader();
60
61 String[] resources = getConfigurationResources();
62
63 for (String resource : resources) {
64 try {
65 InputStream is = classLoader.getResourceAsStream(resource);
66
67 if (is != null) {
68 configuration = configuration.addInputStream(is);
69
70 is.close();
71 }
72 }
73 catch (Exception e1) {
74 if (_log.isWarnEnabled()) {
75 _log.warn(e1);
76 }
77 }
78 }
79
80 configuration.setProperties(PropsUtil.getProperties());
81 }
82 catch (Exception e2) {
83 _log.error(e2, e2);
84 }
85
86 return configuration;
87 }
88
89 protected void postProcessConfiguration(Configuration configuration) {
90
91
96 String connectionReleaseMode = PropsUtil.get(
97 Environment.RELEASE_CONNECTIONS);
98
99 if (Validator.isNotNull(connectionReleaseMode)) {
100 configuration.setProperty(
101 Environment.RELEASE_CONNECTIONS, connectionReleaseMode);
102 }
103 }
104
105 private static Log _log =
106 LogFactory.getLog(PortalHibernateConfiguration.class);
107
108 }