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