|
||||||||||
| 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>
A 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 an new TestdataBuilder without persistence. |
|
AbstractTestdataBuilder(javax.persistence.EntityManager entityManager)
Creates an new TestdataBuilder with persistence. |
|
| Method Summary | |
|---|---|
T |
buildAndSave()
Creates a new instance of type T and save the instance. |
protected void |
ensureEntityManager()
Ensure the TestdataBuilder is constructed with a
EntityManager |
protected javax.persistence.EntityManager |
getEntityManager()
Returns the EntityManager or null. |
protected int |
getId()
Returns an integer value from an static counter. |
protected boolean |
hasEntityManager()
Returns whether the TestdataBuilder is constructed with a
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 - public AbstractTestdataBuilder()
TestdataBuilder without persistence.
| Method Detail |
|---|
protected final javax.persistence.EntityManager getEntityManager()
EntityManager or nullprotected final boolean hasEntityManager()
TestdataBuilder is constructed with a
EntityManager
EntityManager is available, else falseprotected final void ensureEntityManager()
TestdataBuilder is constructed with a
EntityManager
IllegalStateException - if the TestdataBuilder is constructed without a
EntityManagerpublic final T buildAndSave()
T and save the instance. Executed within a new transaction.
buildAndSave in interface TestdataBuilder<T>T
IllegalStateException - if the TestdataBuilder is constructed without a
EntityManagerprotected final int getId()
|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||