This is an automated email from the ASF dual-hosted git repository. ntimofeev pushed a commit to branch master in repository https://gitbox.apache.org/repos/asf/cayenne.git
The following commit(s) were added to refs/heads/master by this push: new 53cdf6e CAY-2689 ServerRuntime API: missing some variants of the performInTransaction() method 53cdf6e is described below commit 53cdf6e1164228adc7dc67c35de614d4ba32b9ed Author: Nikita Timofeev <stari...@gmail.com> AuthorDate: Mon Nov 9 17:56:52 2020 +0300 CAY-2689 ServerRuntime API: missing some variants of the performInTransaction() method --- RELEASE-NOTES.txt | 2 + .../configuration/server/ServerRuntime.java | 46 ++++++++++++++++++++-- 2 files changed, 44 insertions(+), 4 deletions(-) diff --git a/RELEASE-NOTES.txt b/RELEASE-NOTES.txt index 083c19c..efbbd65 100644 --- a/RELEASE-NOTES.txt +++ b/RELEASE-NOTES.txt @@ -13,6 +13,8 @@ Date: ---------------------------------- Changes/New Features: +CAY-2689 ServerRuntime API: missing some variants of the performInTransaction() method + Bug Fixes: CAY-2683 Don't use DISTINCT for joins on to-one related tables diff --git a/cayenne-server/src/main/java/org/apache/cayenne/configuration/server/ServerRuntime.java b/cayenne-server/src/main/java/org/apache/cayenne/configuration/server/ServerRuntime.java index 9a264fa..9cc96d5 100644 --- a/cayenne-server/src/main/java/org/apache/cayenne/configuration/server/ServerRuntime.java +++ b/cayenne-server/src/main/java/org/apache/cayenne/configuration/server/ServerRuntime.java @@ -21,18 +21,15 @@ package org.apache.cayenne.configuration.server; import org.apache.cayenne.access.DataDomain; import org.apache.cayenne.access.DataNode; import org.apache.cayenne.configuration.CayenneRuntime; -import org.apache.cayenne.di.ListBuilder; import org.apache.cayenne.di.Module; +import org.apache.cayenne.tx.TransactionDescriptor; import org.apache.cayenne.tx.TransactionListener; import org.apache.cayenne.tx.TransactionManager; import org.apache.cayenne.tx.TransactionalOperation; import javax.sql.DataSource; -import java.util.ArrayList; import java.util.Collection; -import static java.util.Arrays.asList; - /** * Object representing Cayenne stack. Serves as an entry point to Cayenne for user applications and a factory of ObjectContexts. * Implementation is a thin wrapper of the dependency injection container. @@ -106,6 +103,47 @@ public class ServerRuntime extends CayenneRuntime { } /** + * Runs provided operation wrapped in a single transaction. Transaction + * handling delegated to the internal {@link TransactionManager}. Nested + * calls to 'performInTransaction' are safe and attached to the same + * in-progress transaction. TransactionalOperation can be some arbitrary + * user code, which most often than not will consist of multiple Cayenne + * operations. + * + * @param op an operation to perform within the transaction. + * @param descriptor describes additional transaction parameters + * @param <T> result type + * @return a value returned by the "op" operation. + * + * @since 4.2 + */ + public <T> T performInTransaction(TransactionalOperation<T> op, TransactionDescriptor descriptor) { + TransactionManager tm = injector.getInstance(TransactionManager.class); + return tm.performInTransaction(op, descriptor); + } + + /** + * Runs provided operation wrapped in a single transaction. Transaction + * handling delegated to the internal {@link TransactionManager}. Nested + * calls to 'performInTransaction' are safe and attached to the same + * in-progress transaction. TransactionalOperation can be some arbitrary + * user code, which most often than not will consist of multiple Cayenne + * operations. + * + * @param op an operation to perform within the transaction. + * @param callback a callback to notify as transaction progresses through stages. + * @param descriptor describes additional transaction parameters + * @param <T> returned value type + * @return a value returned by the "op" operation. + * + * @since 4.2 + */ + public <T> T performInTransaction(TransactionalOperation<T> op, TransactionListener callback, TransactionDescriptor descriptor) { + TransactionManager tm = injector.getInstance(TransactionManager.class); + return tm.performInTransaction(op, callback, descriptor); + } + + /** * Returns the main runtime DataDomain. Note that by default the returned * DataDomain is the same as the main DataChannel returned by * {@link #getChannel()}. Although users may redefine DataChannel provider