001/* 002 * Copyright 2002-2012 the original author or authors. 003 * 004 * Licensed under the Apache License, Version 2.0 (the "License"); 005 * you may not use this file except in compliance with the License. 006 * You may obtain a copy of the License at 007 * 008 * https://www.apache.org/licenses/LICENSE-2.0 009 * 010 * Unless required by applicable law or agreed to in writing, software 011 * distributed under the License is distributed on an "AS IS" BASIS, 012 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 013 * See the License for the specific language governing permissions and 014 * limitations under the License. 015 */ 016 017package org.springframework.orm.jpa.persistenceunit; 018 019import javax.persistence.spi.PersistenceUnitInfo; 020 021/** 022 * Interface that defines an abstraction for finding and managing 023 * JPA PersistenceUnitInfos. Used by 024 * {@link org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean} 025 * in order to obtain a {@link javax.persistence.spi.PersistenceUnitInfo} 026 * for building a concrete {@link javax.persistence.EntityManagerFactory}. 027 * 028 * <p>Obtaining a PersistenceUnitInfo instance is an exclusive process. 029 * A PersistenceUnitInfo instance is not available for further calls 030 * anymore once it has been obtained. 031 * 032 * @author Juergen Hoeller 033 * @since 2.0 034 * @see DefaultPersistenceUnitManager 035 * @see org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean#setPersistenceUnitManager 036 */ 037public interface PersistenceUnitManager { 038 039 /** 040 * Obtain the default PersistenceUnitInfo from this manager. 041 * @return the PersistenceUnitInfo (never {@code null}) 042 * @throws IllegalStateException if there is no default PersistenceUnitInfo defined 043 * or it has already been obtained 044 */ 045 PersistenceUnitInfo obtainDefaultPersistenceUnitInfo() throws IllegalStateException; 046 047 /** 048 * Obtain the specified PersistenceUnitInfo from this manager. 049 * @param persistenceUnitName the name of the desired persistence unit 050 * @return the PersistenceUnitInfo (never {@code null}) 051 * @throws IllegalArgumentException if no PersistenceUnitInfo with the given 052 * name is defined 053 * @throws IllegalStateException if the PersistenceUnitInfo with the given 054 * name has already been obtained 055 */ 056 PersistenceUnitInfo obtainPersistenceUnitInfo(String persistenceUnitName) 057 throws IllegalArgumentException, IllegalStateException; 058 059}