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.dao.orm.jpa;
16  
17  import com.liferay.portal.kernel.dao.orm.Dialect;
18  import com.liferay.portal.kernel.dao.orm.ORMException;
19  import com.liferay.portal.kernel.dao.orm.Session;
20  import com.liferay.portal.kernel.dao.orm.SessionFactory;
21  
22  import java.sql.Connection;
23  
24  import javax.persistence.EntityManager;
25  import javax.persistence.EntityManagerFactory;
26  import javax.persistence.PersistenceUnit;
27  
28  /**
29   * <a href="SessionFactoryImpl.java.html"><b><i>View Source</i></b></a>
30   *
31   * @author Prashant Dighe
32   * @author Brian Wing Shun Chan
33   */
34  public class SessionFactoryImpl implements SessionFactory {
35  
36      public void closeSession(Session session) throws ORMException {
37          session.close();
38      }
39  
40      public Dialect getDialect() throws ORMException {
41          return new DialectImpl();
42      }
43  
44      public Session openNewSession(Connection connection) throws ORMException {
45          EntityManager entityManager =
46              _entityManagerFactory.createEntityManager();
47  
48          return new NewSessionImpl(entityManager);
49      }
50  
51      public Session openSession() throws ORMException {
52          return _session;
53      }
54  
55      @PersistenceUnit
56      public void setEntityManagerFactory(
57          EntityManagerFactory entityManagerFactory) {
58  
59          _entityManagerFactory = entityManagerFactory;
60      }
61  
62      public void setSession(Session session) {
63          _session = session;
64      }
65  
66      private EntityManagerFactory _entityManagerFactory;
67      private Session _session;
68  
69  }