001    // Copyright 2011 The Apache Software Foundation
002    //
003    // Licensed under the Apache License, Version 2.0 (the "License");
004    // you may not use this file except in compliance with the License.
005    // You may obtain a copy of the License at
006    //
007    // http://www.apache.org/licenses/LICENSE-2.0
008    //
009    // Unless required by applicable law or agreed to in writing, software
010    // distributed under the License is distributed on an "AS IS" BASIS,
011    // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
012    // See the License for the specific language governing permissions and
013    // limitations under the License.
014    
015    package org.apache.tapestry5.jpa;
016    
017    import java.util.List;
018    
019    import javax.persistence.EntityManager;
020    import javax.persistence.EntityManagerFactory;
021    import javax.persistence.spi.PersistenceUnitInfo;
022    
023    /**
024     * Responsible for creating an EntityManager as needed.
025     *
026     * @since 5.3
027     */
028    public interface EntityManagerSource
029    {
030        /**
031         * Creates an <code>EntityManager</code> for the given persistence unit name.
032         *
033         * @param persistenceUnitName the name of a persistence unit as defined in <code>persistence.xml<code>
034         * @return  EntityManager for the given persistence unit name
035         */
036        EntityManager create(String persistenceUnitName);
037    
038        /**
039         * Gets the <code>EntityManagerFactory</code> for the given persistence unit name, creating it as necessary.
040         *
041         * @param persistenceUnitName the name of a persistence unit as defined in <code>persistence.xml<code>
042         *
043         * @return EntityManagerFactory for the given persistence unit name
044         */
045        EntityManagerFactory getEntityManagerFactory(String persistenceUnitName);
046    
047        /**
048         * Get the list of {@linkplain PersistenceUnitInfo} parsed from <code>persistence.xml<code>.
049         *
050         * @return list of PersistenceUnitInfos
051         */
052        List<PersistenceUnitInfo> getPersistenceUnitInfos();
053    }