/******************************************************************************* * Copyright (c) 2008 - 2013 Oracle Corporation. All rights reserved. * * This program and the accompanying materials are made available under the * terms of the Eclipse Public License v1.0 and Eclipse Distribution License v. 1.0 * which accompanies this distribution. * The Eclipse Public License is available at http://www.eclipse.org/legal/epl-v10.html * and the Eclipse Distribution License is available at * http://www.eclipse.org/org/documents/edl-v10.php. * * Contributors: * Linda DeMichiel - Java Persistence 2.1 * Linda DeMichiel - Java Persistence 2.0 * ******************************************************************************/ package javax.persistence; import java.util.List; import java.util.Map; import java.util.Set; import java.util.HashSet; import javax.persistence.spi.PersistenceProvider; import javax.persistence.spi.PersistenceProviderResolver; import javax.persistence.spi.PersistenceProviderResolverHolder; import javax.persistence.spi.LoadState; /** * Bootstrap class that is used to obtain an {@link EntityManagerFactory} * in Java SE environments. It may also be used to cause schema * generation to occur. * *
The Persistence
class is available in a Java EE
* container environment as well; however, support for the Java SE
* bootstrapping APIs is not required in container environments.
*
*
The
* Called when schema generation is to occur as a separate phase
* from creation of the entity manager factory.
*
* @param persistenceUnitName the name of the persistence unit
* @param map properties for schema generation; these may
* also contain provider-specific properties. The
* value of these properties override any values that
* may have been configured elsewhere..
* @throws PersistenceException if insufficient or inconsistent
* configuration information is provided or if schema
* generation otherwise fails.
*
* @since Java Persistence 2.1
*/
public static void generateSchema(String persistenceUnitName, Map map) {
PersistenceProviderResolver resolver = PersistenceProviderResolverHolder.getPersistenceProviderResolver();
ListPersistence
class is used to obtain a {@link
* javax.persistence.PersistenceUtil PersistenceUtil} instance in both
* Java EE and Java SE environments.
*
* @since Java Persistence 1.0
*/
public class Persistence {
/**
* Create and return an EntityManagerFactory for the named
* persistence unit.
*
* @param persistenceUnitName
* the name of the persistence unit
* @return the factory that creates EntityManagers configured according to
* the specified persistence unit
*/
public static EntityManagerFactory createEntityManagerFactory(String persistenceUnitName) {
return createEntityManagerFactory(persistenceUnitName, null);
}
/**
* Create and return an EntityManagerFactory for the named persistence unit
* using the given properties.
*
* @param persistenceUnitName
* the name of the persistence unit
* @param properties
* Additional properties to use when creating the factory.
* These properties may include properties to control
* schema generation. The values of these properties override
* any values that may have been configured elsewhere.
* @return the factory that creates EntityManagers configured according to
* the specified persistence unit.
*/
public static EntityManagerFactory createEntityManagerFactory(String persistenceUnitName, Map properties) {
EntityManagerFactory emf = null;
PersistenceProviderResolver resolver = PersistenceProviderResolverHolder.getPersistenceProviderResolver();
List