@@ -189,7 +189,7 @@ defined by the `@Data.Query` annotation:
189189include::{sourcedir}/includes/data/PetRepository.java[tag=PetRepository_class, indent=0]
190190----
191191
192- ==== Method with query defined by method name
192+ ==== Method with Query Defined by Method Name
193193
194194This method type infers the query based on the method name and does not use a specific annotation.
195195The method name must follow the _query-by-method-name_ syntax:
@@ -230,7 +230,7 @@ The method name must follow the _query-by-method-name_ syntax:
230230 direction :: "Asc" | "Desc"
231231----
232232
233- ===== Method name prefix and return type
233+ ===== Method Name Prefix and Return Type
234234
235235A method can have a user-defined prefix. The prefix is a sequence of letters and digits that does not
236236match any `<action-u>` keyword. This prefix has no influence on the query and can be used to distinguish
@@ -280,7 +280,7 @@ The return type depends on the action keyword:
280280NOTE: Validation of the keyword–return type mapping is not fully enforced by the code generator,
281281though this may change in future releases.
282282
283- ===== Projection in method name
283+ ===== Projection in Method Name
284284
285285The projection part is optional and follows directly after the return-type keyword. It consists
286286of `expression` and `property` components:
@@ -323,7 +323,7 @@ translates to the JPQL query `SELECT p.keeper.name FROM Pet p`.
323323include::{sourcedir}/includes/data/SimpleSnippets.java[tag=simple_model, indent=0]
324324----
325325
326- ===== Criteria in method name
326+ ===== Criteria in Method Name
327327
328328The criteria part of the method name is optional and represents the `WHERE` clause of the query.
329329It is a logical expression composed of individual conditions joined by the `AND` and `OR` operators.
@@ -452,7 +452,7 @@ Logical operators:
452452NOTE: In JPQL, operator precedence places `AND` above `OR` as defined in Jakarta Persistence 3.1, section 4.6.6.
453453 The same rule applies to SQL.
454454
455- ===== Ordering in method name
455+ ===== Ordering in Method Name
456456
457457The ordering part of the method name is optional and represents the `ORDER BY` clause of the query.
458458It is a list of ordering rules. A single ordering rule is the `property` optionally followed by
@@ -481,7 +481,7 @@ An example repository method with ordering:
481481include::{sourcedir}/includes/data/PetRepositorySnippets.java[tag=qbmn_sort_method, indent=0]
482482----
483483
484- ==== Method with query defined by `@Data.Query` annotation
484+ ==== Method with Query Defined by `@Data.Query` Annotation
485485
486486This method type must be annotated with `@Data.Query`. The annotation takes a single `String` value containing
487487the database query. Currently, JPQL is supported. Method arguments must match the query parameters:
@@ -589,4 +589,161 @@ The session instance is available through the `Data.SessionRepository<S>` interf
589589NOTE: The session instance is valid only while `run` or `call` method is being executed. This instance must not
590590 be stored and used after this method has ended.
591591
592- // end::data_session_access_2[]
592+ // end::data_session_access_2[]
593+
594+ // tag::data_transaction[]
595+
596+ == Transactions
597+
598+ Transaction handling is available through Helidon Transaction API.
599+
600+ To enable Helidon Transaction API, add the following dependency to your project’s `pom.xml`:
601+
602+ [source,xml]
603+ ----
604+ <dependency>
605+ <groupId>jakarta.transaction</groupId>
606+ <artifactId>jakarta.transaction-api</artifactId>
607+ </dependency>
608+ ----
609+
610+ Helidon JTA Transaction support, such as Narayana, may be provided at runtime to enable `JTA` transaction type:
611+
612+ [source,xml]
613+ ----
614+ <dependency>
615+ <groupId>io.helidon.transaction</groupId>
616+ <artifactId>helidon-transaction-narayana</artifactId>
617+ <scope>runtime</scope>
618+ </dependency>
619+ ----
620+
621+ If JTA transaction support is not provided, Helidon Data runtime will use `RESOURCE_LOCAL` transaction type.
622+
623+ === Transaction Types
624+
625+ The `Tx` class defines several ways how transactional support can be applied to transactional method executions.
626+ Those ways are defined in `Tx.Type` enum.
627+
628+ ==== Transaction Type Enum
629+ The `Tx.Type` enum is used to describe the possible ways in which transactional support must be applied
630+ to transactional method executions.
631+
632+ ===== Enum Values and Their Meanings
633+
634+ The Type enum has six values, each representing a different transactional behavior:
635+
636+ [cols=2*]
637+ |===
638+ |Name |Description
639+
640+ |`MANDATORY`
641+ |A transaction must already be in effect when a method executes. If called outside a transaction
642+ context, a `TxException` is thrown. If called inside a transaction context, method execution continues
643+ under that context.
644+
645+ |`NEW`
646+ |A new transaction is started when a method executes. If called outside a transaction context, a new
647+ transaction is begun. If called inside a transaction context, the current transaction is suspended, a new
648+ transaction is begun, and the method execution continues inside this new transaction context.
649+
650+ |`NEVER`
651+ |No transaction must be in effect when a method executes. If called outside a transaction context, method
652+ execution continues outside a transaction context. If called inside a transaction context, a `TxException`
653+ is thrown.
654+
655+ |`REQUIRED`
656+ |A transaction will be in effect when a method executes. If called outside a transaction context,
657+ a new transaction is begun. If called inside a transaction context, method execution continues inside
658+ that transaction context.
659+
660+ |`SUPPORTED`
661+ |A transaction may optionally be in effect when a method executes. If called outside a transaction
662+ context, method execution continues outside a transaction context. If called inside a transaction context,
663+ method execution continues inside that transaction context.
664+
665+ |`UNSUPPORTED`
666+ |No transaction will be in effect when a method executes. If called outside a transaction context, method
667+ execution continues outside a transaction context. If called inside a transaction context, the current
668+ transaction is suspended, method execution continues outside a transaction context, and the previously
669+ suspended transaction is resumed after method execution completes.
670+ |===
671+
672+ === Transaction Annotations
673+
674+ The `Tx` class defines several annotations that can be used to mark methods for transactional execution:
675+
676+ [cols=2*]
677+ |===
678+ |Annotation |Description
679+
680+ |`@Mandatory`
681+ |Indicates that a method will be executed with a managed transaction of type MANDATORY.
682+
683+ |`@New`
684+ |Indicates that a method will be executed with a managed transaction of type NEW.
685+
686+ |`@Never`
687+ |Indicates that a method will be executed with a managed transaction of type NEVER.
688+
689+ |`@Required`
690+ |Indicates that a method will be executed with a managed transaction of type REQUIRED.
691+
692+ |`@Supported`
693+ |Indicates that a method will be executed with a managed transaction of type SUPPORTED.
694+
695+ |`@Unsupported`
696+ |Indicates that a method will be executed with a managed transaction of type UNSUPPORTED.
697+ |===
698+
699+ === Transaction Methods
700+
701+ The `Tx` class provides several methods for executing tasks within a transaction:
702+
703+ [cols=2*]
704+ |===
705+ |Annotation |Description
706+
707+ |`transaction(Callable<T> task)`
708+ |Executes a task with a managed transaction of type `REQUIRED`.
709+
710+ |`transaction(Type type, Callable<T> task)`
711+ |Executes a task with a managed transaction of the specified type.
712+
713+ |`transaction(CheckedRunnable<Exception> task)`
714+ |Executes a task with a managed transaction of type `REQUIRED` without returning a result.
715+
716+ |`transaction(Type type, CheckedRunnable<Exception> task)`
717+ |Executes a task with a managed transaction of the specified type without returning a result.
718+ |===
719+
720+ === Usage
721+
722+ The `Tx.Type` enum is used to control the transactional behavior of methods. By specifying the desired transactional
723+ behavior using one of the enum values, developers can ensure that their methods are executed with the correct transactional
724+ context.
725+ For example, using `REQUIRED` ensures that a method is always executed within a transaction, while using `NEVER` ensures
726+ that a method is never executed within a transaction.
727+
728+ In this example, the `doSomething()` method is annotated with `@Tx.Required`, ensuring that it is always executed within
729+ a transaction. The `doSomethingElse()` method is annotated with `@Tx.Never`, ensuring that it is never executed within
730+ a transaction:
731+
732+ [source,java]
733+ ----
734+ include::{sourcedir}/includes/data/SimpleSnippets.java[tag=data_transaction_annotations, indent=0]
735+ ----
736+
737+ `PetService` class instance is obtained from service registry.
738+
739+ In this example, lambda expression in the `doSomething()` method is executed using `Tx.transaction` method with
740+ `Tx.Type.REQUIRED` argument, ensuring that it is always executed within a transaction. Lambda expression
741+ in the `doSomethingElse()` method is executed using `Tx.transaction` method with `Tx.Type.NEVER` argument, ensuring
742+ that it is never executed within a transaction:
743+
744+ [source,java]
745+ ----
746+ include::{sourcedir}/includes/data/SimpleSnippets.java[tag=data_transaction_methods, indent=0]
747+ ----
748+
749+ // end::data_transaction[]
0 commit comments