The @Endpoint
annotation contains the isTransactional
method that can identify endpoints that require a transaction. The framework supports the @preAction
and @postAction
annotations. A method that is annotated with the @preAction
annotation is invoked by the framework immediately prior to invoking the endpoint itself. A method that is annotated with the @postAction
annotation is invoked by the framework immediately after invoking the endpoint.
By default, the framework wraps any endpoint method invocation in its own transaction. Any preAction
or postAction
methods or validation also takes place inside this transaction. Automatic transactions can be disabled by setting the @Endpoint
annotation isTransactional
to false
.
Note: It is best to use global resource components, which are resolved upon server start up and reused rather than being resolved for every request. You can use request-scoped resource components, unless the resource is a parent resource that contains sub-resources.
You can also add transaction support and protection against concurrent updates for your endpoint resources by using the isTransactional
flag in the @Endpoint
annotation to create a new transaction for a resource. The flag is set to true
by default.
The invoke
method of the RestEndpointInvocationHandler
class checks for the value true
for this annotation on the target endpoint and, if found, wraps the endpoint invocation in a new transaction. For endpoints that are called asynchronously, use the JAXRSEndpointWorker
class, which configures the new thread. You can subclass the JAXRSEndpointWorker
class and implement your logic in the doAction
method. For information on this class, refer to the ATG Platform API Reference