Skip to content

Instantly share code, notes, and snippets.

@scottmarlow
Created August 9, 2012 17:10
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save scottmarlow/3305977 to your computer and use it in GitHub Desktop.
Save scottmarlow/3305977 to your computer and use it in GitHub Desktop.
The idea of having a separate generateSchema() that might do the same work as would of been done in createContainerEntityManagerFactory() (if certain properties are specified), brings to mind some other recent discussions (one that I raised about deployment ordering concerns). Could we add other methods that provide a multi-step approach to creating the container manager entity manager factory?
The reason for turning createContainerEntityManagerFactory(), into multiple steps, is to allow the EE container to control when different JPA deployment operations can occur. More specifically, I would like to have control over when the persistence provider performs the following aspects of createContainerEntityManagerFactory():
- Scanning for annotations & adding class transformers (to ensure that this happens before other EE deployers load application classes).
- DataSource is used (this will help with use of @DataSourceDefinition which might not be initialized until after the other EE deployers have at least started scanning application classes for @DataSourceDefinition).
- Schema operations can be invoked (e.g. equivalent of generateSchema()).
We could have a factory builder (EntityManagerFactoryBuilder) object that is obtained from the persistence provider. The following is from an extension that we started to work on, to accomplish this.
public interface EntityManagerFactoryBuilder {
/**
* Scanning for annotations and registering class transformers
* can be performed.
*
*/
void manageClassLoader();
/**
* operations using DataSource can be performed
*
*/
void manageDataSource();
/**
* Schema operations can be performed
*
*/
void manageSchema();
/**
* Build {@link EntityManagerFactory} instance
*
*
* @return The built {@link EntityManagerFactory}
*/
EntityManagerFactory buildEntityManagerFactory();
/**
* Cancel the building processing. This is used to signal the builder
* to release any resources in the case of
* something having gone wrong during the bootstrap process
*/
void cancel();
}
PersistenceProvider will also have the factory builder method:
public interface PersistenceProvider {
...
getEntityManagerFactoryBuilder(PersistenceUnitInfo, Map);
...
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment