Skip to content

Commit c1e562a

Browse files
behrwindbehrwind
authored andcommitted
updated documentation
1 parent 9ff2bb9 commit c1e562a

File tree

1 file changed

+23
-3
lines changed

1 file changed

+23
-3
lines changed

src/main/groovy/de/triology/blog/testdataloader/TestDataLoader.groovy

Lines changed: 23 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,9 @@ import javax.persistence.EntityManager
3434
*/
3535
class TestDataLoader {
3636

37+
/**
38+
* Defines the transaction type that the {@link EntityManager} passed to the {@code TestDataLoader} is configured with.
39+
*/
3740
public enum TransactionType {
3841
RESOURCE_LOCAL, JTA
3942
}
@@ -46,16 +49,33 @@ class TestDataLoader {
4649
private TransactionType transactionType;
4750

4851
/**
49-
* Create a new TestDataLoader that uses the specified JPA EntityManager to save and delete entities.
50-
* The EntityManager is expected to be fully initialized and ready to use.
52+
* Creates a new TestDataLoader that uses the specified JPA EntityManager to save and delete entities.
53+
* The EntityManager is expected to be fully initialized and ready to use.<br>
54+
* <br>
55+
* The {@code TestDataLoader} will assume a {@code TransactionType.RESOURCE_LOCAL} configuration when created with
56+
* this constructor and therefore try an manage transactions itself. If this is undesired, e. g. in a container
57+
* environment with managed persistence, use the {@code TestDataLoader(EntityManager, TransactionType)}
58+
* constructor with {@code TransactionType.JTA} .
5159
*
5260
* @param entityManager {@link EntityManager}
5361
*/
5462
TestDataLoader(EntityManager entityManager) {
5563
this(entityManager, TransactionType.RESOURCE_LOCAL)
5664
}
5765

58-
// TODO: javadoc -> hint that client needs to take care of transaction management when JTA is specified
66+
/**
67+
* Creates a new TestDataLoader that uses the specified JPA EntityManager to save and delete entities.
68+
* The EntityManager is expected to be configured with the specified transaction type and to be fully initialized
69+
* and ready to use.<br>
70+
* <br>
71+
* Note that when specifying {@code TransactionType.RESOURCE_LOCAL}, the {@code TestDataLoader} will try and manage
72+
* transactions itself. This might not be desired and even lead to runtime exceptions, e. g. in a container
73+
* environment with managed persistence. Specify {@code TransactionType.JTA} in this case, the {@code TestDataLoader}
74+
* will assume transactions to be managed by client code then.
75+
*
76+
* @param entityManager {@link EntityManager}
77+
* @param transactionType {@link TransactionType}
78+
*/
5979
TestDataLoader(EntityManager entityManager, TransactionType transactionType) {
6080
if (transactionType == null) throw new IllegalArgumentException("transactionType must not be null")
6181
checkTransactionType(entityManager, transactionType)

0 commit comments

Comments
 (0)