Skip to content

Commit 53cdf6e

Browse files
committed
CAY-2689 ServerRuntime API: missing some variants of the performInTransaction() method
1 parent 516b32b commit 53cdf6e

2 files changed

Lines changed: 44 additions & 4 deletions

File tree

RELEASE-NOTES.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,8 @@ Date:
1313
----------------------------------
1414
Changes/New Features:
1515

16+
CAY-2689 ServerRuntime API: missing some variants of the performInTransaction() method
17+
1618
Bug Fixes:
1719

1820
CAY-2683 Don't use DISTINCT for joins on to-one related tables

cayenne-server/src/main/java/org/apache/cayenne/configuration/server/ServerRuntime.java

Lines changed: 42 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -21,18 +21,15 @@
2121
import org.apache.cayenne.access.DataDomain;
2222
import org.apache.cayenne.access.DataNode;
2323
import org.apache.cayenne.configuration.CayenneRuntime;
24-
import org.apache.cayenne.di.ListBuilder;
2524
import org.apache.cayenne.di.Module;
25+
import org.apache.cayenne.tx.TransactionDescriptor;
2626
import org.apache.cayenne.tx.TransactionListener;
2727
import org.apache.cayenne.tx.TransactionManager;
2828
import org.apache.cayenne.tx.TransactionalOperation;
2929

3030
import javax.sql.DataSource;
31-
import java.util.ArrayList;
3231
import java.util.Collection;
3332

34-
import static java.util.Arrays.asList;
35-
3633
/**
3734
* Object representing Cayenne stack. Serves as an entry point to Cayenne for user applications and a factory of ObjectContexts.
3835
* Implementation is a thin wrapper of the dependency injection container.
@@ -105,6 +102,47 @@ public <T> T performInTransaction(TransactionalOperation<T> op, TransactionListe
105102
return tm.performInTransaction(op, callback);
106103
}
107104

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+
108146
/**
109147
* Returns the main runtime DataDomain. Note that by default the returned
110148
* DataDomain is the same as the main DataChannel returned by

0 commit comments

Comments
 (0)