|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||
java.lang.Objectorg.wamblee.test.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(java.lang.String aUrl,
java.lang.String aUser,
java.lang.String aPassword,
PersistenceUnitDescription aPersistenceUnit)
Constructs the builder. |
|
| Method Summary | ||
|---|---|---|
javax.persistence.EntityManager |
begin()
Begins a transaction. |
|
void |
commit(javax.persistence.EntityManager aEntityManager)
Commits the transaction. |
|
javax.persistence.EntityManagerFactory |
createFactory()
Creates a new entity manager factory. |
|
|
execute(JpaBuilder.JpaUnitOfWork<T> aWork)
Executes a unit of work. |
|
javax.persistence.EntityManager |
getContextualEntityManager()
Gets a contextual reference to an entity manager that delegates to the appropriate (current) one which is active for the current transaction. |
|
void |
rollback(javax.persistence.EntityManager aEntityManager)
Rolls back a transaction. |
|
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(java.lang.String aUrl,
java.lang.String aUser,
java.lang.String aPassword,
PersistenceUnitDescription aPersistenceUnit)
aUrl - JDBC URLaUser - User nameaPassword - Password.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.Exceptionpublic javax.persistence.EntityManager begin()
TransactionResource
begin in interface TransactionResource<javax.persistence.EntityManager>public void commit(javax.persistence.EntityManager aEntityManager)
TransactionResource
commit in interface TransactionResource<javax.persistence.EntityManager>aEntityManager - Object that manages the transaction for the resource.public void rollback(javax.persistence.EntityManager aEntityManager)
TransactionResource
rollback in interface TransactionResource<javax.persistence.EntityManager>aEntityManager - Object that manages the transaction for the resource.public javax.persistence.EntityManager getContextualEntityManager()
|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||