| TransactionAwareConfiguration.java |
1 /**
2 * Copyright (c) 2000-2010 Liferay, Inc. All rights reserved.
3 *
4 * The contents of this file are subject to the terms of the Liferay Enterprise
5 * Subscription License ("License"). You may not use this file except in
6 * compliance with the License. You can obtain a copy of the License by
7 * contacting Liferay, Inc. See the License for the specific language governing
8 * permissions and limitations under the License, including but not limited to
9 * distribution rights of the Software.
10 *
11 *
12 *
13 */
14
15 package com.liferay.portal.spring.hibernate;
16
17 import java.lang.reflect.Proxy;
18
19 import org.hibernate.SessionFactory;
20 import org.hibernate.engine.SessionFactoryImplementor;
21
22 import org.springframework.orm.hibernate3.LocalSessionFactoryBean;
23
24 /**
25 * <a href="TransactionAwareConfiguration.java.html"><b><i>View Source</i></b>
26 * </a>
27 *
28 * @author Brian Wing Shun Chan
29 */
30 public class TransactionAwareConfiguration extends LocalSessionFactoryBean {
31
32 protected SessionFactory wrapSessionFactoryIfNecessary(
33 SessionFactory sessionFactory) {
34
35 // LEP-2996
36
37 Class<?> sessionFactoryInterface = SessionFactory.class;
38
39 if (sessionFactory instanceof SessionFactoryImplementor) {
40 sessionFactoryInterface = SessionFactoryImplementor.class;
41 }
42
43 return (SessionFactory)Proxy.newProxyInstance(
44 sessionFactoryInterface.getClassLoader(),
45 new Class[] {sessionFactoryInterface},
46 new SessionFactoryInvocationHandler(sessionFactory));
47 }
48
49 }