001    /**
002     * Copyright (c) 2000-2010 Liferay, Inc. All rights reserved.
003     *
004     * The contents of this file are subject to the terms of the Liferay Enterprise
005     * Subscription License ("License"). You may not use this file except in
006     * compliance with the License. You can obtain a copy of the License by
007     * contacting Liferay, Inc. See the License for the specific language governing
008     * permissions and limitations under the License, including but not limited to
009     * distribution rights of the Software.
010     *
011     *
012     *
013     */
014    
015    package com.liferay.portal.dao.orm.jpa;
016    
017    import com.liferay.portal.kernel.dao.orm.Dialect;
018    import com.liferay.portal.kernel.dao.orm.ORMException;
019    import com.liferay.portal.kernel.dao.orm.Session;
020    import com.liferay.portal.kernel.dao.orm.SessionFactory;
021    
022    import java.sql.Connection;
023    
024    import javax.persistence.EntityManager;
025    import javax.persistence.EntityManagerFactory;
026    import javax.persistence.PersistenceUnit;
027    
028    /**
029     * @author Prashant Dighe
030     * @author Brian Wing Shun Chan
031     */
032    public class SessionFactoryImpl implements SessionFactory {
033    
034            public void closeSession(Session session) throws ORMException {
035                    session.close();
036            }
037    
038            public Dialect getDialect() throws ORMException {
039                    return new DialectImpl();
040            }
041    
042            public Session openNewSession(Connection connection) throws ORMException {
043                    EntityManager entityManager =
044                            _entityManagerFactory.createEntityManager();
045    
046                    return new NewSessionImpl(entityManager);
047            }
048    
049            public Session openSession() throws ORMException {
050                    return _session;
051            }
052    
053            @PersistenceUnit
054            public void setEntityManagerFactory(
055                    EntityManagerFactory entityManagerFactory) {
056    
057                    _entityManagerFactory = entityManagerFactory;
058            }
059    
060            public void setSession(Session session) {
061                    _session = session;
062            }
063    
064            private EntityManagerFactory _entityManagerFactory;
065            private Session _session;
066    
067    }