    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 java.util.Map;
    017
    018/**
    019 * Manages <code>EntityManager</code>s for the current thread.
    020 * An <code>EntityManager</code> is created as needed and closed at the end of each request.
    021 *
    022 *
    023 *
    024 * The implementation of this service is per-thread.
    025 *
    026 * @since 5.3
    027 */
    028public interface EntityManagerManager
    029{
    030    /**
    031     * Gets the active EntityManager for this request, creating it as necessary.
    032     *
    033     * @param persistenceUnitName the name of a persistence unit as defined in {@code persistence.xml}
    034     * @return EntityManager for the persistence unit,
    035     */
    036    EntityManager getEntityManager(String persistenceUnitName);
    037
    038    /**
    039     * Gets all active EntityManagers for this request, creating them as necessary.
    040     *
    041     * @return Map in which persistence unit names are associated with EntityManagers
    042     */
    043    Map<String, EntityManager> getEntityManagers();
    044}