Skip to content

Commit fefb889

Browse files
authored
JTA/JPA CDI integrations
Addresses helidon-io#496. Signed-off-by: Laird Nelson <laird.nelson@oracle.com>
1 parent 0dbbf29 commit fefb889

67 files changed

Lines changed: 7680 additions & 16 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,3 +67,5 @@ node/
6767
# Other
6868
*~
6969
user.txt
70+
ObjectStore/
71+
PutObjectStoreDirHere/

bom/pom.xml

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -403,11 +403,36 @@
403403
<artifactId>helidon-integrations-cdi-datasource-hikaricp</artifactId>
404404
<version>${project.version}</version>
405405
</dependency>
406+
<dependency>
407+
<groupId>io.helidon.integrations.cdi</groupId>
408+
<artifactId>helidon-integrations-cdi-eclipselink</artifactId>
409+
<version>${project.version}</version>
410+
</dependency>
406411
<dependency>
407412
<groupId>io.helidon.integrations.cdi</groupId>
408413
<artifactId>helidon-integrations-cdi-jedis</artifactId>
409414
<version>${project.version}</version>
410415
</dependency>
416+
<dependency>
417+
<groupId>io.helidon.integrations.cdi</groupId>
418+
<artifactId>helidon-integrations-cdi-jpa</artifactId>
419+
<version>${project.version}</version>
420+
</dependency>
421+
<dependency>
422+
<groupId>io.helidon.integrations.cdi</groupId>
423+
<artifactId>helidon-integrations-cdi-jpa-weld</artifactId>
424+
<version>${project.version}</version>
425+
</dependency>
426+
<dependency>
427+
<groupId>io.helidon.integrations.cdi</groupId>
428+
<artifactId>helidon-integrations-cdi-jta</artifactId>
429+
<version>${project.version}</version>
430+
</dependency>
431+
<dependency>
432+
<groupId>io.helidon.integrations.cdi</groupId>
433+
<artifactId>helidon-integrations-cdi-jta-weld</artifactId>
434+
<version>${project.version}</version>
435+
</dependency>
411436
<dependency>
412437
<groupId>io.helidon.integrations.cdi</groupId>
413438
<artifactId>helidon-integrations-cdi-oci-objectstorage</artifactId>

docs/src/main/docs/extensions/01_overview.adoc

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,4 +51,11 @@ Create and inject a Jedis pool in your application code.
5151
Create and inject an Oracle Cloud Infrastructure Object Storage client in your
5252
application code.
5353
--
54+
55+
[CARD]
56+
.Java Transaction API objects
57+
[link=extensions/05_cdi_jta.adoc]
58+
--
59+
Use the Java Transaction API in your application code.
60+
--
5461
====
Lines changed: 84 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,84 @@
1+
///////////////////////////////////////////////////////////////////////////////
2+
3+
Copyright (c) 2019 Oracle and/or its affiliates. All rights reserved.
4+
5+
Licensed under the Apache License, Version 2.0 (the "License");
6+
you may not use this file except in compliance with the License.
7+
You may obtain a copy of the License at
8+
9+
http://www.apache.org/licenses/LICENSE-2.0
10+
11+
Unless required by applicable law or agreed to in writing, software
12+
distributed under the License is distributed on an "AS IS" BASIS,
13+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
See the License for the specific language governing permissions and
15+
limitations under the License.
16+
17+
///////////////////////////////////////////////////////////////////////////////
18+
19+
= CDI extension for JTA
20+
:description: Helidon CDI extension for JTA
21+
:keywords: helidon, java, microservices, microprofile, extensions, cdi, jta
22+
23+
This https://docs.jboss.org/cdi/spec/2.0/cdi-spec.html#spi[CDI
24+
portable extension] provides support for JTA (Java Transaction API)
25+
transactions in your Helidon MicroProfile applications.
26+
27+
== Prerequsites
28+
29+
Declare the following dependency fragment in your project's `pom.xml`:
30+
31+
[source,xml]
32+
----
33+
<dependency>
34+
<groupId>io.helidon.integrations.cdi</groupId>
35+
<artifactId>helidon-integrations-cdi-jta-weld</artifactId>
36+
<scope>runtime</scope>
37+
</dependency>
38+
39+
<dependency>
40+
<groupId>javax.transaction</groupId>
41+
<artifactId>javax.transaction-api</artifactId>
42+
<scope>provided</scope>
43+
</dependency>
44+
----
45+
46+
== Declaring a method to be transactional
47+
48+
The following example shows how to declare a transactional method.
49+
50+
[source,java]
51+
.Transactional method declaration
52+
----
53+
@Transactional(Transactional.TxType.REQUIRED)
54+
public void doSomethingTransactionally() {
55+
56+
}
57+
----
58+
59+
The extension ensures that a transaction is started before and
60+
committed after the method executes. If the method throws an
61+
exception, the transaction will be rolled back.
62+
63+
You can further specify the transactional behavior of the extension by
64+
using different instances of the `Transactional` annotation. For more
65+
information, see the
66+
https://static.javadoc.io/javax.transaction/javax.transaction-api/1.2/javax/transaction/Transactional.html[`Transactional`
67+
annotation documentation].
68+
69+
Transactional method support is implemented by CDI interception
70+
facilities. Among other things, this means that the method to which
71+
you apply the `Transactional` annotation must not be `private` and
72+
must in all other ways be a _business method_. See the
73+
https://jcp.org/aboutJava/communityprocess/mrel/jsr318/index3.html[Java
74+
Interceptors specification] for more details.
75+
76+
During a transactional method invocation, the extension makes the
77+
following objects available for injection via the `Inject` annotation:
78+
79+
* https://static.javadoc.io/javax.transaction/javax.transaction-api/1.2/javax/transaction/UserTransaction.html[`UserTransaction`]
80+
* https://static.javadoc.io/javax.transaction/javax.transaction-api/1.2/javax/transaction/Transaction.html[`Transaction`]
81+
* https://static.javadoc.io/javax.transaction/javax.transaction-api/1.2/javax/transaction/UserTransactionManager.html[`TransactionManager`]
82+
* https://static.javadoc.io/javax.transaction/javax.transaction-api/1.2/javax/transaction/UserTransactionSynchronizationRegistry.html[`TransactionSynchronizationRegistry`]
83+
84+
Lines changed: 245 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,245 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<!--
3+
4+
Copyright (c) 2019 Oracle and/or its affiliates. All rights reserved.
5+
6+
Licensed under the Apache License, Version 2.0 (the "License");
7+
you may not use this file except in compliance with the License.
8+
You may obtain a copy of the License at
9+
10+
http://www.apache.org/licenses/LICENSE-2.0
11+
12+
Unless required by applicable law or agreed to in writing, software
13+
distributed under the License is distributed on an "AS IS" BASIS,
14+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15+
See the License for the specific language governing permissions and
16+
limitations under the License.
17+
18+
-->
19+
<project xmlns="http://maven.apache.org/POM/4.0.0"
20+
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
21+
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0
22+
http://maven.apache.org/xsd/maven-4.0.0.xsd">
23+
<modelVersion>4.0.0</modelVersion>
24+
<parent>
25+
<groupId>io.helidon.examples.integrations.cdi</groupId>
26+
<artifactId>helidon-examples-integrations-cdi-project</artifactId>
27+
<version>1.0.4-SNAPSHOT</version>
28+
</parent>
29+
<artifactId>helidon-integrations-examples-jpa</artifactId>
30+
<name>Helidon CDI Extensions Examples JPA</name>
31+
32+
<properties>
33+
<dependenciesDirectory>libs</dependenciesDirectory>
34+
</properties>
35+
36+
<build>
37+
<resources>
38+
<resource>
39+
<directory>src/main/resources</directory>
40+
<filtering>true</filtering>
41+
</resource>
42+
</resources>
43+
<plugins>
44+
<plugin>
45+
<groupId>com.ethlo.persistence.tools</groupId>
46+
<artifactId>eclipselink-maven-plugin</artifactId>
47+
<version>2.7.1.1</version>
48+
<dependencies>
49+
<dependency>
50+
<groupId>javax.annotation</groupId>
51+
<artifactId>javax.annotation-api</artifactId>
52+
<version>${version.lib.annotation-api}</version>
53+
</dependency>
54+
<dependency>
55+
<groupId>javax.xml.bind</groupId>
56+
<artifactId>jaxb-api</artifactId>
57+
<version>${version.lib.jaxb-api}</version>
58+
</dependency>
59+
</dependencies>
60+
<executions>
61+
<execution>
62+
<id>weave</id>
63+
<phase>process-classes</phase>
64+
<goals>
65+
<goal>weave</goal>
66+
</goals>
67+
</execution>
68+
<execution>
69+
<id>modelgen</id>
70+
<phase>generate-sources</phase>
71+
<goals>
72+
<goal>modelgen</goal>
73+
</goals>
74+
</execution>
75+
</executions>
76+
</plugin>
77+
<plugin>
78+
<groupId>org.jboss.jandex</groupId>
79+
<artifactId>jandex-maven-plugin</artifactId>
80+
<executions>
81+
<execution>
82+
<id>make-index</id>
83+
<goals>
84+
<goal>jandex</goal>
85+
</goals>
86+
</execution>
87+
</executions>
88+
</plugin>
89+
<plugin>
90+
<artifactId>maven-dependency-plugin</artifactId>
91+
<executions>
92+
<execution>
93+
<id>copy-dependencies</id>
94+
<phase>prepare-package</phase>
95+
<goals>
96+
<goal>copy-dependencies</goal>
97+
</goals>
98+
<configuration>
99+
<outputDirectory>${project.build.directory}/${dependenciesDirectory}</outputDirectory>
100+
<overWriteReleases>false</overWriteReleases>
101+
<overWriteSnapshots>false</overWriteSnapshots>
102+
<overWriteIfNewer>true</overWriteIfNewer>
103+
<overWriteIfNewer>true</overWriteIfNewer>
104+
<includeScope>runtime</includeScope>
105+
<excludeScope>test</excludeScope>
106+
</configuration>
107+
</execution>
108+
</executions>
109+
</plugin>
110+
<plugin>
111+
<artifactId>maven-jar-plugin</artifactId>
112+
<configuration>
113+
<archive>
114+
<manifest>
115+
<addClasspath>true</addClasspath>
116+
<classpathPrefix>${dependenciesDirectory}</classpathPrefix>
117+
<mainClass>io.helidon.microprofile.server.Main</mainClass>
118+
</manifest>
119+
</archive>
120+
</configuration>
121+
</plugin>
122+
</plugins>
123+
</build>
124+
<dependencies>
125+
<!-- Test-scoped dependencies. -->
126+
<dependency>
127+
<groupId>org.junit.jupiter</groupId>
128+
<artifactId>junit-jupiter-api</artifactId>
129+
<scope>test</scope>
130+
</dependency>
131+
<dependency>
132+
<groupId>org.hamcrest</groupId>
133+
<artifactId>hamcrest-all</artifactId>
134+
<scope>test</scope>
135+
</dependency>
136+
137+
<!-- Runtime-scoped dependencies. -->
138+
<dependency>
139+
<groupId>com.h2database</groupId>
140+
<artifactId>h2</artifactId>
141+
<scope>runtime</scope>
142+
</dependency>
143+
<dependency>
144+
<groupId>org.jboss.weld.se</groupId>
145+
<artifactId>weld-se-core</artifactId>
146+
<scope>runtime</scope>
147+
<exclusions>
148+
<exclusion>
149+
<groupId>org.jboss.spec.javax.el</groupId>
150+
<artifactId>jboss-el-api_3.0_spec</artifactId>
151+
</exclusion>
152+
<exclusion>
153+
<groupId>org.jboss.spec.javax.interceptor</groupId>
154+
<artifactId>jboss-interceptors-api_1.2_spec</artifactId>
155+
</exclusion>
156+
</exclusions>
157+
</dependency>
158+
<dependency>
159+
<groupId>io.helidon.integrations.cdi</groupId>
160+
<artifactId>helidon-integrations-cdi-eclipselink</artifactId>
161+
<version>${project.version}</version>
162+
<scope>runtime</scope>
163+
</dependency>
164+
<dependency>
165+
<groupId>io.helidon.integrations.cdi</groupId>
166+
<artifactId>helidon-integrations-cdi-jta-weld</artifactId>
167+
<version>${project.version}</version>
168+
<scope>runtime</scope>
169+
</dependency>
170+
<dependency>
171+
<groupId>io.helidon.integrations.cdi</groupId>
172+
<artifactId>helidon-integrations-cdi-datasource-hikaricp</artifactId>
173+
<version>${project.version}</version>
174+
<scope>runtime</scope>
175+
</dependency>
176+
<dependency>
177+
<groupId>io.helidon.integrations.cdi</groupId>
178+
<artifactId>helidon-integrations-cdi-jpa-weld</artifactId>
179+
<version>${project.version}</version>
180+
<scope>runtime</scope>
181+
</dependency>
182+
<dependency>
183+
<groupId>org.jboss</groupId>
184+
<artifactId>jandex</artifactId>
185+
<scope>runtime</scope>
186+
</dependency>
187+
<dependency>
188+
<groupId>io.helidon.microprofile.server</groupId>
189+
<artifactId>helidon-microprofile-server</artifactId>
190+
<version>${project.version}</version>
191+
<scope>runtime</scope>
192+
<exclusions>
193+
<exclusion>
194+
<groupId>org.glassfish.hk2.external</groupId>
195+
<artifactId>javax.inject</artifactId>
196+
</exclusion>
197+
</exclusions>
198+
</dependency>
199+
<dependency>
200+
<groupId>io.helidon.microprofile.config</groupId>
201+
<artifactId>helidon-microprofile-config-cdi</artifactId>
202+
<version>${project.version}</version>
203+
<scope>runtime</scope>
204+
</dependency>
205+
<dependency>
206+
<groupId>org.eclipse.microprofile.config</groupId>
207+
<artifactId>microprofile-config-api</artifactId>
208+
<scope>runtime</scope>
209+
</dependency>
210+
211+
<!-- Provided-scoped dependencies. -->
212+
<dependency>
213+
<groupId>jakarta.persistence</groupId>
214+
<artifactId>jakarta.persistence-api</artifactId>
215+
<scope>provided</scope>
216+
</dependency>
217+
<dependency>
218+
<groupId>javax.transaction</groupId>
219+
<artifactId>javax.transaction-api</artifactId>
220+
<scope>provided</scope>
221+
</dependency>
222+
223+
<!-- Compile-scoped dependencies. -->
224+
<dependency>
225+
<groupId>javax.annotation</groupId>
226+
<artifactId>javax.annotation-api</artifactId>
227+
<scope>compile</scope>
228+
</dependency>
229+
<dependency>
230+
<groupId>javax.enterprise</groupId>
231+
<artifactId>cdi-api</artifactId>
232+
<scope>compile</scope>
233+
</dependency>
234+
<dependency>
235+
<groupId>javax.inject</groupId>
236+
<artifactId>javax.inject</artifactId>
237+
<scope>compile</scope>
238+
</dependency>
239+
<dependency>
240+
<groupId>javax.ws.rs</groupId>
241+
<artifactId>javax.ws.rs-api</artifactId>
242+
<scope>compile</scope>
243+
</dependency>
244+
</dependencies>
245+
</project>

0 commit comments

Comments
 (0)