|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||
java.lang.Objectorg.wamblee.support.persistence.JpaBuilder
public class JpaBuilder
Utility for building an appropriately configured EntityManagerFactory. The idea is that a persistence.xml is used unchanged from the production version. This utility will then add the additional properties required for execution in a standalone environment. The other purpose is to to shield dependencies of the test code on a particular JPA provider.
| Nested Class Summary | |
|---|---|
static interface |
JpaBuilder.JpaUnitOfWork<T>
Callback interface to execute some JPA code within a transaction with the entitymanager to use provided as input. |
| Constructor Summary | |
|---|---|
JpaBuilder(javax.sql.DataSource aDataSource,
PersistenceUnitDescription aPersistenceUnit)
Constructs the builder. |
|
| Method Summary | ||
|---|---|---|
javax.persistence.EntityManagerFactory |
createFactory()
Creates a new entity manager factory. |
|
|
execute(JpaBuilder.JpaUnitOfWork<T> aWork)
Executes a unit of work. |
|
void |
start()
Starts the builder, which in particular, mocks JNDI, binds the datasource the JNDI where the persistence unit expects it, creates the entity manager factory, and forces creation of the database schema. |
|
void |
stop()
Stops the entity manager factory and disables JNDI mocking. |
|
| Methods inherited from class java.lang.Object |
|---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
| Constructor Detail |
|---|
public JpaBuilder(javax.sql.DataSource aDataSource,
PersistenceUnitDescription aPersistenceUnit)
aDataSource - Datasource of database.aPersistenceUnit - Persistence unit.| Method Detail |
|---|
public void start()
throws java.lang.Exception
java.lang.Exceptionpublic void stop()
public javax.persistence.EntityManagerFactory createFactory()
public <T> T execute(JpaBuilder.JpaUnitOfWork<T> aWork)
throws java.lang.Exception
JpaBuilder.JpaUnitOfWork.execute(EntityManager) within a transaction,
passing it the entity manager. Use of this method saves a lot of typing
for applications.
aWork - Work to execute.
java.lang.Exception
|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||