|
21 | 21 | import org.apache.cayenne.access.DataDomain; |
22 | 22 | import org.apache.cayenne.access.DataNode; |
23 | 23 | import org.apache.cayenne.configuration.CayenneRuntime; |
24 | | -import org.apache.cayenne.di.ListBuilder; |
25 | 24 | import org.apache.cayenne.di.Module; |
| 25 | +import org.apache.cayenne.tx.TransactionDescriptor; |
26 | 26 | import org.apache.cayenne.tx.TransactionListener; |
27 | 27 | import org.apache.cayenne.tx.TransactionManager; |
28 | 28 | import org.apache.cayenne.tx.TransactionalOperation; |
29 | 29 |
|
30 | 30 | import javax.sql.DataSource; |
31 | | -import java.util.ArrayList; |
32 | 31 | import java.util.Collection; |
33 | 32 |
|
34 | | -import static java.util.Arrays.asList; |
35 | | - |
36 | 33 | /** |
37 | 34 | * Object representing Cayenne stack. Serves as an entry point to Cayenne for user applications and a factory of ObjectContexts. |
38 | 35 | * Implementation is a thin wrapper of the dependency injection container. |
@@ -105,6 +102,47 @@ public <T> T performInTransaction(TransactionalOperation<T> op, TransactionListe |
105 | 102 | return tm.performInTransaction(op, callback); |
106 | 103 | } |
107 | 104 |
|
| 105 | + /** |
| 106 | + * Runs provided operation wrapped in a single transaction. Transaction |
| 107 | + * handling delegated to the internal {@link TransactionManager}. Nested |
| 108 | + * calls to 'performInTransaction' are safe and attached to the same |
| 109 | + * in-progress transaction. TransactionalOperation can be some arbitrary |
| 110 | + * user code, which most often than not will consist of multiple Cayenne |
| 111 | + * operations. |
| 112 | + * |
| 113 | + * @param op an operation to perform within the transaction. |
| 114 | + * @param descriptor describes additional transaction parameters |
| 115 | + * @param <T> result type |
| 116 | + * @return a value returned by the "op" operation. |
| 117 | + * |
| 118 | + * @since 4.2 |
| 119 | + */ |
| 120 | + public <T> T performInTransaction(TransactionalOperation<T> op, TransactionDescriptor descriptor) { |
| 121 | + TransactionManager tm = injector.getInstance(TransactionManager.class); |
| 122 | + return tm.performInTransaction(op, descriptor); |
| 123 | + } |
| 124 | + |
| 125 | + /** |
| 126 | + * Runs provided operation wrapped in a single transaction. Transaction |
| 127 | + * handling delegated to the internal {@link TransactionManager}. Nested |
| 128 | + * calls to 'performInTransaction' are safe and attached to the same |
| 129 | + * in-progress transaction. TransactionalOperation can be some arbitrary |
| 130 | + * user code, which most often than not will consist of multiple Cayenne |
| 131 | + * operations. |
| 132 | + * |
| 133 | + * @param op an operation to perform within the transaction. |
| 134 | + * @param callback a callback to notify as transaction progresses through stages. |
| 135 | + * @param descriptor describes additional transaction parameters |
| 136 | + * @param <T> returned value type |
| 137 | + * @return a value returned by the "op" operation. |
| 138 | + * |
| 139 | + * @since 4.2 |
| 140 | + */ |
| 141 | + public <T> T performInTransaction(TransactionalOperation<T> op, TransactionListener callback, TransactionDescriptor descriptor) { |
| 142 | + TransactionManager tm = injector.getInstance(TransactionManager.class); |
| 143 | + return tm.performInTransaction(op, callback, descriptor); |
| 144 | + } |
| 145 | + |
108 | 146 | /** |
109 | 147 | * Returns the main runtime DataDomain. Note that by default the returned |
110 | 148 | * DataDomain is the same as the main DataChannel returned by |
|
0 commit comments