Skip to content
This repository has been archived by the owner on Oct 26, 2022. It is now read-only.

Commit

Permalink
JPA-38 - Schema generation requirements
Browse files Browse the repository at this point in the history
  • Loading branch information
sebersole committed Jan 29, 2013
1 parent 43e1817 commit ebf7774
Show file tree
Hide file tree
Showing 2 changed files with 60 additions and 0 deletions.
26 changes: 26 additions & 0 deletions src/main/java/javax/persistence/Persistence.java
Expand Up @@ -69,6 +69,32 @@ private static List<PersistenceProvider> getProviders() {
.getPersistenceProviders();
}

/**
* Create database schemas and/or tables and/or create DDL scripts as determined by the supplied properties
*
* 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 properties properties for schema generation; these may also contain provider-specific properties. The
* values 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.
*/
public static void generateSchema(String persistenceUnitName, Map properties) {
List<PersistenceProvider> providers = getProviders();
for ( PersistenceProvider provider : providers ) {
final boolean generated = provider.generateSchema( persistenceUnitName, properties );
if ( generated ) {
return;
}
}

throw new PersistenceException(
"No persistence provider found for schema generation for persistence-unit named " + persistenceUnitName
);
}

/**
* @return Returns a <code>PersistenceUtil</code> instance.
*/
Expand Down
34 changes: 34 additions & 0 deletions src/main/java/javax/persistence/spi/PersistenceProvider.java
Expand Up @@ -56,6 +56,40 @@ public interface PersistenceProvider {
*/
public EntityManagerFactory createContainerEntityManagerFactory(PersistenceUnitInfo info, Map map);

/**
* Create database schemas and/or tables and/or create DDL
* scripts as determined by the supplied properties.
*
* Called by the container when schema generation is to
* occur as a separate phase from creation of the entity
* manager factory.
*
* @param info metadata for use by the persistence provider
* @param map properties for schema generation; these may also include provider-specific properties
*
* @throws javax.persistence.PersistenceException if insufficient or inconsistent configuration information is
* provided or if schema generation otherwise fails.
*/
public void generateSchema(PersistenceUnitInfo info, Map map);

/**
* Create database schemas and/or tables and/or create DDL
* scripts as determined by the supplied properties.
* Called by the Persistence class 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.
*
* @return true if schema was generated, otherwise false
*
* @throws javax.persistence.PersistenceException if insufficient or inconsistent configuration information is
* provided or if schema generation otherwise fails.
*/
public boolean generateSchema(String persistenceUnitName, Map map);

/**
* Return the utility interface implemented by the persistence
* provider.
Expand Down

0 comments on commit ebf7774

Please sign in to comment.