|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||
java.lang.Objectde.akquinet.jbosscc.needle.db.testdata.AbstractTestdataBuilder<T>
T - The type of the object to build.public abstract class AbstractTestdataBuilder<T>
An abstract implementation of TestdataBuilder.
Implementation example: public class PersonTestDataBuilder extends AbstractTestdataBuilder{ ... public PersonTestDataBuilder() { super(); } public PersonTestDataBuilder(EntityManager entityManager) { super(entityManager); } public PersonTestDataBuilder withName(String name){ this.withName = name; return this; } public PersonTestDataBuilder withAddress(Address address){ this.withName = name; return this; } public Person build() { Person person = new Person(); ... return person; } Usage example: Person transientPerson = new PersonTestDataBuilder(em).build(); Person persistedPerson = new PersonTestDataBuilder(em).buildAndSave(); new PersonTestDataBuilder(em).withAddress(address).buildAndSave();
| Constructor Summary | |
|---|---|
AbstractTestdataBuilder()
Creates a new TestdataBuilder without persistence. |
|
AbstractTestdataBuilder(javax.persistence.EntityManager entityManager)
Creates a new TestdataBuilder with persistence. |
|
| Method Summary | |
|---|---|
T |
buildAndSave()
Creates a new instance of type T and saves the instance. |
protected void |
ensureEntityManager()
Ensure the TestdataBuilder is constructed with an
EntityManager |
protected javax.persistence.EntityManager |
getEntityManager()
Returns the EntityManager or null. |
protected int |
getId()
Returns an integer value from a static counter. |
protected boolean |
hasEntityManager()
Returns whether the TestdataBuilder is constructed with an
EntityManager |
| Methods inherited from class java.lang.Object |
|---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
| Methods inherited from interface de.akquinet.jbosscc.needle.db.testdata.TestdataBuilder |
|---|
build |
| Constructor Detail |
|---|
public AbstractTestdataBuilder(javax.persistence.EntityManager entityManager)
TestdataBuilder with persistence.
entityManager - EntityManager to be used by this TestdataBuilderpublic AbstractTestdataBuilder()
TestdataBuilder without persistence.
| Method Detail |
|---|
protected final javax.persistence.EntityManager getEntityManager()
EntityManager or nullprotected final boolean hasEntityManager()
TestdataBuilder is constructed with an
EntityManager
EntityManager is available, else falseprotected final void ensureEntityManager()
TestdataBuilder is constructed with an
EntityManager
IllegalStateException - if the TestdataBuilder is constructed without an
EntityManagerpublic final T buildAndSave()
T and saves the instance. Executed within a new transaction.
buildAndSave in interface TestdataBuilder<T>T
IllegalStateException - if the TestdataBuilder is constructed without an
EntityManagerprotected final int getId()
|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||