1   /**
2    * Copyright (c) 2000-2010 Liferay, Inc. All rights reserved.
3    *
4    * This library is free software; you can redistribute it and/or modify it under
5    * the terms of the GNU Lesser General Public License as published by the Free
6    * Software Foundation; either version 2.1 of the License, or (at your option)
7    * any later version.
8    *
9    * This library is distributed in the hope that it will be useful, but WITHOUT
10   * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
11   * FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
12   * details.
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  }