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